1 /* This file is part of the KDE libraries
2 Copyright (C) 2006 Michaël Larouche <michael.larouche@kdemail.net>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; version 2
7 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19 #include "kmessageboxmessagehandler.h"
20
21 #include <kmessagebox.h>
22
23 #include "kmessagebox_queued.h"
24
25 class KMessageBoxMessageHandlerPrivate
26 {
27 public:
KMessageBoxMessageHandlerPrivate(KMessageBoxMessageHandler * q)28 KMessageBoxMessageHandlerPrivate(KMessageBoxMessageHandler *q)
29 : q(q)
30 {
31 }
32
33 void showMessageBox(KMessage::MessageType messageType, const QString &text, const QString &caption);
34 QWidget *parentWidget();
35
36 KMessageBoxMessageHandler *q;
37 };
38
KMessageBoxMessageHandler(QWidget * parent)39 KMessageBoxMessageHandler::KMessageBoxMessageHandler(QWidget *parent)
40 : QObject(parent), d(new KMessageBoxMessageHandlerPrivate(this))
41 {
42 }
43
~KMessageBoxMessageHandler()44 KMessageBoxMessageHandler::~KMessageBoxMessageHandler()
45 {
46 delete d;
47 }
48
message(KMessage::MessageType messageType,const QString & text,const QString & caption)49 void KMessageBoxMessageHandler::message(KMessage::MessageType messageType, const QString &text, const QString &caption)
50 {
51 d->showMessageBox(messageType, text, caption);
52 }
53
showMessageBox(KMessage::MessageType messageType,const QString & text,const QString & caption)54 void KMessageBoxMessageHandlerPrivate::showMessageBox(KMessage::MessageType messageType,
55 const QString &text, const QString &caption)
56 {
57 KMessageBox::DialogType dlgType;
58
59 switch (messageType) {
60 case KMessage::Information:
61 default:
62 dlgType = KMessageBox::Information;
63 break;
64 case KMessage::Error:
65 case KMessage::Fatal:
66 dlgType = KMessageBox::Error;
67 break;
68 case KMessage::Warning:
69 case KMessage::Sorry:
70 dlgType = KMessageBox::Sorry;
71 break;
72 }
73
74 KMessageBox::queuedMessageBox(parentWidget(), dlgType, text, caption);
75 }
76
parentWidget()77 QWidget *KMessageBoxMessageHandlerPrivate::parentWidget()
78 {
79 return qobject_cast<QWidget *>(q->parent());
80 }
81
82