File indexing completed on 2024-03-24 15:27:44

0001 /*  This file is part of the KDE libraries
0002     Copyright (C) 2006 Michaƫl Larouche <michael.larouche@kdemail.net>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; version 2
0007     of the License.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 #include "kpassivepopupmessagehandler.h"
0020 
0021 #include <QLatin1String>
0022 #include <QPixmap>
0023 #include <QIcon>
0024 
0025 #include <kpassivepopup.h>
0026 
0027 KPassivePopupMessageHandler::KPassivePopupMessageHandler(QWidget *parent)
0028     : QObject(parent), KMessageHandler()
0029 {}
0030 
0031 void KPassivePopupMessageHandler::message(KMessage::MessageType messageType, const QString &text, const QString &caption)
0032 {
0033     showPassivePopup(messageType, text, caption);
0034 }
0035 
0036 void KPassivePopupMessageHandler::showPassivePopup(KMessage::MessageType messageType, const QString &text, const QString &caption)
0037 {
0038     QPixmap resultIcon;
0039     QString iconName;
0040 
0041     switch (messageType) {
0042     case KMessage::Information:
0043     default:
0044         iconName = QLatin1String("dialog-information");
0045         break;
0046     case KMessage::Sorry:
0047     case KMessage::Warning:
0048         iconName = QLatin1String("dialog-warning");
0049         break;
0050     case KMessage::Error:
0051     case KMessage::Fatal:
0052         iconName = QLatin1String("dialog-error");
0053         break;
0054     }
0055 
0056     resultIcon = QIcon::fromTheme(iconName).pixmap(32);
0057 
0058     KPassivePopup::message(caption, text, resultIcon, parentWidget());
0059 }
0060 
0061 QWidget *KPassivePopupMessageHandler::parentWidget()
0062 {
0063     return qobject_cast<QWidget *>(parent());
0064 }
0065 
0066 #include "moc_kpassivepopupmessagehandler.cpp"