File indexing completed on 2024-05-12 16:39:41

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004-2013 Jarosław Staniek <staniek@kde.org>
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; either
0007    version 2 of the License, or (at your option) any later version.
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 
0020 #include "kexitextmsghandler.h"
0021 #include "kexi.h"
0022 #include <kexiutils/utils.h>
0023 
0024 #include <KDbUtils>
0025 
0026 #include <KLocalizedString>
0027 
0028 class Q_DECL_HIDDEN KexiTextMessageHandler::Private
0029 {
0030 public:
0031     Private(QString* msgTarget, QString* dTarget);
0032     ~Private();
0033 
0034     QString *messageTarget, *detailsTarget;
0035 };
0036 
0037 KexiTextMessageHandler::Private::Private(QString* msgTarget, QString* dTarget)
0038     :messageTarget(msgTarget), detailsTarget(dTarget)
0039 {
0040     messageTarget->clear();
0041     detailsTarget->clear();
0042 }
0043 
0044 KexiTextMessageHandler::Private::~Private()
0045 {
0046 
0047 }
0048 
0049 KexiTextMessageHandler::KexiTextMessageHandler(QString *messageTarget, QString *detailsTarget)
0050         : KexiGUIMessageHandler(0)
0051         ,d(new Private(messageTarget, detailsTarget))
0052 {
0053     Q_ASSERT(messageTarget);
0054     Q_ASSERT(detailsTarget);
0055 }
0056 
0057 KexiTextMessageHandler::~KexiTextMessageHandler()
0058 {
0059     delete d;
0060 }
0061 
0062 void KexiTextMessageHandler::showErrorMessage(const QString &title, const QString &details)
0063 {
0064     if (!messagesEnabled()) {
0065         return;
0066     }
0067     if (guiRedirection()) {
0068         guiRedirection()->showErrorMessage(title, details);
0069         return;
0070     }
0071     showMessage(KDbMessageHandler::Error, title, details);
0072 }
0073 
0074 void KexiTextMessageHandler::showMessage(MessageType type,
0075                                          const QString &title, const QString &details,
0076                                          const QString& dontShowAgainName)
0077 {
0078     Q_UNUSED(type);
0079     Q_UNUSED(dontShowAgainName);
0080     if (!messagesEnabled()) {
0081         return;
0082     }
0083     if (guiRedirection()) {
0084         guiRedirection()->showMessage(type, title, details, dontShowAgainName);
0085         return;
0086     }
0087     //'wait' cursor is a nonsense now
0088     KexiUtils::removeWaitCursor();
0089 
0090     QString msg(title);
0091     if (title.isEmpty())
0092         msg = xi18n("Unknown error");
0093     msg = "<qt><p>" + msg + "</p>";
0094     *d->messageTarget = msg;
0095     *d->detailsTarget = details;
0096 }
0097