File indexing completed on 2024-04-21 14:55:56
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 "kmessageboxmessagehandler.h" 0020 0021 #include <kmessagebox.h> 0022 0023 #include "kmessagebox_queued.h" 0024 0025 class KMessageBoxMessageHandlerPrivate 0026 { 0027 public: 0028 KMessageBoxMessageHandlerPrivate(KMessageBoxMessageHandler *q) 0029 : q(q) 0030 { 0031 } 0032 0033 void showMessageBox(KMessage::MessageType messageType, const QString &text, const QString &caption); 0034 QWidget *parentWidget(); 0035 0036 KMessageBoxMessageHandler *q; 0037 }; 0038 0039 KMessageBoxMessageHandler::KMessageBoxMessageHandler(QWidget *parent) 0040 : QObject(parent), d(new KMessageBoxMessageHandlerPrivate(this)) 0041 { 0042 } 0043 0044 KMessageBoxMessageHandler::~KMessageBoxMessageHandler() 0045 { 0046 delete d; 0047 } 0048 0049 void KMessageBoxMessageHandler::message(KMessage::MessageType messageType, const QString &text, const QString &caption) 0050 { 0051 d->showMessageBox(messageType, text, caption); 0052 } 0053 0054 void KMessageBoxMessageHandlerPrivate::showMessageBox(KMessage::MessageType messageType, 0055 const QString &text, const QString &caption) 0056 { 0057 KMessageBox::DialogType dlgType; 0058 0059 switch (messageType) { 0060 case KMessage::Information: 0061 default: 0062 dlgType = KMessageBox::Information; 0063 break; 0064 case KMessage::Error: 0065 case KMessage::Fatal: 0066 dlgType = KMessageBox::Error; 0067 break; 0068 case KMessage::Warning: 0069 case KMessage::Sorry: 0070 dlgType = KMessageBox::Sorry; 0071 break; 0072 } 0073 0074 KMessageBox::queuedMessageBox(parentWidget(), dlgType, text, caption); 0075 } 0076 0077 QWidget *KMessageBoxMessageHandlerPrivate::parentWidget() 0078 { 0079 return qobject_cast<QWidget *>(q->parent()); 0080 } 0081 0082 #include "moc_kmessageboxmessagehandler.cpp"