kexi

kexiguimsghandler.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexiguimsghandler.h"
00021 
00022 #include "kexi.h"
00023 #include <kexidb/utils.h>
00024 #include <kexiutils/utils.h>
00025 
00026 #include <kmessagebox.h>
00027 
00028 KexiGUIMessageHandler::KexiGUIMessageHandler(QWidget *parent)
00029 : KexiDB::MessageHandler(parent)
00030 {
00031 }
00032 
00033 KexiGUIMessageHandler::~KexiGUIMessageHandler()
00034 {
00035 }
00036 
00037 /*virtual*/
00038 void
00039 KexiGUIMessageHandler::showErrorMessage(KexiDB::Object *obj, 
00040     const QString& msg)
00041 {
00042     QString _msg(msg);
00043     if (!obj) {
00044         showErrorMessage(_msg);
00045         return;
00046     }
00047     QString details;
00048     KexiDB::getHTMLErrorMesage(obj, _msg, details);
00049     showErrorMessage(_msg, details);
00050 }
00051 
00052 /*virtual*/
00053 void
00054 KexiGUIMessageHandler::showErrorMessage(const QString &title, const QString &details)
00055 {
00056     showMessage(Error, title, details);
00057 }
00058 
00059 void
00060 KexiGUIMessageHandler::showSorryMessage(const QString &title, const QString &details)
00061 {
00062     showMessage(Sorry, title, details);
00063 }
00064 
00065 void KexiGUIMessageHandler::showErrorMessage(const QString &msg, const QString &details, 
00066     KexiDB::Object *obj)
00067 {
00068     QString _msg(msg);
00069     if (!obj) {
00070         showErrorMessage(_msg, details);
00071         return;
00072     }
00073     QString _details(details);
00074     KexiDB::getHTMLErrorMesage(obj, _msg, _details);
00075     showErrorMessage(_msg, _details);
00076 }
00077 
00078 void
00079 KexiGUIMessageHandler::showErrorMessage(Kexi::ObjectStatus *status)
00080 {
00081     showErrorMessage("", status);
00082 }
00083 
00084 void
00085 KexiGUIMessageHandler::showErrorMessage(const QString &message, Kexi::ObjectStatus *status)
00086 {
00087     if (status && status->error()) {
00088         QString msg(message);
00089         if (msg.isEmpty()) {
00090             msg = status->message;
00091             status->message = status->description;
00092             status->description = "";
00093         }
00094         QString desc;
00095         if (!status->message.isEmpty()) {
00096             if (status->description.isEmpty()) {
00097                 desc = status->message;
00098             } else {
00099                 msg += (QString("<br><br>") + status->message);
00100                 desc = status->description;
00101             }
00102         }
00103         showErrorMessage(msg, desc, status->dbObject());
00104     }
00105     else {
00106         showErrorMessage(message);
00107     }
00108     status->clearStatus();
00109 }
00110 
00111 void
00112 KexiGUIMessageHandler::showMessage(MessageType type,
00113     const QString &title, const QString &details)
00114 {
00115     if (!m_enableMessages)
00116         return;
00117 
00118     //'wait' cursor is a nonsense now
00119     KexiUtils::removeWaitCursor();
00120 
00121     QString msg(title);
00122     if (title.isEmpty())
00123         msg = i18n("Unknown error");
00124     msg = "<qt><p>"+msg+"</p>";
00125     if (!details.isEmpty()) {
00126         switch (type) {
00127         case Error:
00128             KMessageBox::detailedError(m_messageHandlerParentWidget, msg, details);
00129             break;
00130         default: //Sorry
00131             KMessageBox::detailedSorry(m_messageHandlerParentWidget, msg, details);
00132         }
00133     }
00134     else {
00135         KMessageBox::messageBox(m_messageHandlerParentWidget, 
00136             type==Error ? KMessageBox::Error : KMessageBox::Sorry, msg);
00137     }
00138 }
00139 
00140 int KexiGUIMessageHandler::askQuestion( const QString& message, 
00141     KMessageBox::DialogType dlgType, KMessageBox::ButtonCode defaultResult,
00142     const KGuiItem &buttonYes, 
00143     const KGuiItem &buttonNo,
00144     const QString &dontShowAskAgainName,
00145     int options )
00146 {
00147     Q_UNUSED(defaultResult);
00148     if (KMessageBox::WarningContinueCancel == dlgType)
00149         return KMessageBox::warningContinueCancel(m_messageHandlerParentWidget,
00150             message, QString::null, buttonYes, dontShowAskAgainName, options);
00151     else
00152         return KMessageBox::messageBox(m_messageHandlerParentWidget,
00153             dlgType, message, QString::null, buttonYes, buttonNo, dontShowAskAgainName, options);
00154 }
00155 
KDE Home | KDE Accessibility Home | Description of Access Keys