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 #include <kdialogbase.h>
00028 
00029 KexiGUIMessageHandler::KexiGUIMessageHandler(QWidget *parent)
00030 : KexiDB::MessageHandler(parent)
00031 {
00032 }
00033 
00034 KexiGUIMessageHandler::~KexiGUIMessageHandler()
00035 {
00036 }
00037 
00038 /*virtual*/
00039 void
00040 KexiGUIMessageHandler::showErrorMessage(KexiDB::Object *obj, 
00041     const QString& msg)
00042 {
00043     QString _msg(msg);
00044     if (!obj) {
00045         showErrorMessage(_msg);
00046         return;
00047     }
00048     QString details;
00049     KexiDB::getHTMLErrorMesage(obj, _msg, details);
00050     showErrorMessage(_msg, details);
00051 }
00052 
00053 /*virtual*/
00054 void
00055 KexiGUIMessageHandler::showErrorMessage(const QString &title, const QString &details)
00056 {
00057     showMessage(Error, title, details);
00058 }
00059 
00060 void
00061 KexiGUIMessageHandler::showSorryMessage(const QString &title, const QString &details)
00062 {
00063     showMessage(Sorry, title, details);
00064 }
00065 
00066 void KexiGUIMessageHandler::showErrorMessage(const QString &msg, const QString &details, 
00067     KexiDB::Object *obj)
00068 {
00069     QString _msg(msg);
00070     if (!obj) {
00071         showErrorMessage(_msg, details);
00072         return;
00073     }
00074     QString _details(details);
00075     KexiDB::getHTMLErrorMesage(obj, _msg, _details);
00076     showErrorMessage(_msg, _details);
00077 }
00078 
00079 void
00080 KexiGUIMessageHandler::showErrorMessage(Kexi::ObjectStatus *status)
00081 {
00082     showErrorMessage("", status);
00083 }
00084 
00085 void
00086 KexiGUIMessageHandler::showErrorMessage(const QString &message, Kexi::ObjectStatus *status)
00087 {
00088     if (status && status->error()) {
00089         QString msg(message);
00090         if (msg.isEmpty() || msg==status->message) {
00091             msg = status->message;
00092             status->message = status->description;
00093             status->description = "";
00094         }
00095         QString desc;
00096         if (!status->message.isEmpty()) {
00097             if (status->description.isEmpty()) {
00098                 desc = status->message;
00099             } else {
00100                 msg += (QString("<br><br>") + status->message);
00101                 desc = status->description;
00102             }
00103         }
00104         showErrorMessage(msg, desc, status->dbObject());
00105     }
00106     else {
00107         showErrorMessage(message);
00108     }
00109     status->clearStatus();
00110 }
00111 
00112 void
00113 KexiGUIMessageHandler::showMessage(MessageType type,
00114     const QString &title, const QString &details, const QString& dontShowAgainName)
00115 {
00116     if (!m_enableMessages)
00117         return;
00118 
00119     //'wait' cursor is a nonsense now
00120     KexiUtils::removeWaitCursor();
00121 
00122     QString msg(title);
00123     if (title.isEmpty())
00124         msg = i18n("Unknown error");
00125     msg = "<qt><p>"+msg+"</p>";
00126     if (!details.isEmpty()) {
00127         switch (type) {
00128         case Error:
00129             KMessageBox::detailedError(m_messageHandlerParentWidget, msg, details);
00130             break;
00131         case Warning:
00132             showWarningContinueMessage(title, details, dontShowAgainName);
00133             break;
00134         default: //Sorry
00135             KMessageBox::detailedSorry(m_messageHandlerParentWidget, msg, details);
00136         }
00137     }
00138     else {
00139         KMessageBox::messageBox(m_messageHandlerParentWidget, 
00140             type==Error ? KMessageBox::Error : KMessageBox::Sorry, msg);
00141     }
00142 }
00143 
00144 void KexiGUIMessageHandler::showWarningContinueMessage(const QString &title, const QString &details,
00145     const QString& dontShowAgainName)
00146 {
00147     if (!KMessageBox::shouldBeShownContinue(dontShowAgainName))
00148         return;
00149     KDialogBase *dialog = new KDialogBase(
00150         futureI18n("Warning"), KDialogBase::Yes, KDialogBase::Yes, KDialogBase::No,
00151         m_messageHandlerParentWidget, "warningContinue", true, true, KStdGuiItem::cont() );
00152     bool checkboxResult = false;
00153     KMessageBox::createKMessageBox(dialog, QMessageBox::Warning, 
00154         title + (details.isEmpty() ? QString::null : (QString("\n")+details)), QStringList(),
00155         dontShowAgainName.isEmpty() ? QString::null : futureI18n("Do not show this message again"),
00156         &checkboxResult, 0);
00157     if (checkboxResult)
00158         KMessageBox::saveDontShowAgainContinue(dontShowAgainName);
00159 }
00160 
00161 int KexiGUIMessageHandler::askQuestion( const QString& message, 
00162     KMessageBox::DialogType dlgType, KMessageBox::ButtonCode defaultResult,
00163     const KGuiItem &buttonYes, 
00164     const KGuiItem &buttonNo,
00165     const QString &dontShowAskAgainName,
00166     int options )
00167 {
00168     Q_UNUSED(defaultResult);
00169     if (KMessageBox::WarningContinueCancel == dlgType)
00170         return KMessageBox::warningContinueCancel(m_messageHandlerParentWidget,
00171             message, QString::null, buttonYes, dontShowAskAgainName, options);
00172     else
00173         return KMessageBox::messageBox(m_messageHandlerParentWidget,
00174             dlgType, message, QString::null, buttonYes, buttonNo, dontShowAskAgainName, options);
00175 }
00176 
KDE Home | KDE Accessibility Home | Description of Access Keys