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 | class KMessageBoxMessageHandlerPrivate |
24 | { |
25 | public: |
26 | KMessageBoxMessageHandlerPrivate(KMessageBoxMessageHandler *q) |
27 | : q(q) |
28 | { |
29 | } |
30 | |
31 | void showMessageBox(KMessage::MessageType messageType, const QString &text, const QString &caption); |
32 | QWidget *parentWidget(); |
33 | |
34 | KMessageBoxMessageHandler *q; |
35 | }; |
36 | |
37 | |
38 | KMessageBoxMessageHandler::KMessageBoxMessageHandler(QWidget *parent) |
39 | : QObject(parent), d(new KMessageBoxMessageHandlerPrivate(this)) |
40 | { |
41 | } |
42 | |
43 | KMessageBoxMessageHandler::~KMessageBoxMessageHandler() |
44 | { |
45 | delete d; |
46 | } |
47 | |
48 | void KMessageBoxMessageHandler::message(KMessage::MessageType messageType, const QString &text, const QString &caption) |
49 | { |
50 | d->showMessageBox(messageType, text, caption); |
51 | } |
52 | |
53 | void KMessageBoxMessageHandlerPrivate::showMessageBox(KMessage::MessageType messageType, |
54 | const QString &text, const QString &caption) |
55 | { |
56 | KMessageBox::DialogType dlgType; |
57 | |
58 | switch (messageType) |
59 | { |
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 | |
77 | QWidget *KMessageBoxMessageHandlerPrivate::parentWidget() |
78 | { |
79 | return qobject_cast<QWidget*>(q->parent()); |
80 | } |
81 | |
82 | #include "kmessageboxmessagehandler.moc" |
83 | // kate: space-indent on; indent-width 4; encoding utf-8; replace-tabs on; |
84 | |