1 /* This file is part of the KDE project
2    Copyright (C) 2004-2013 Jarosław Staniek <staniek@kde.org>
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; either
7    version 2 of the License, or (at your option) any later version.
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 
20 #include "kexitextmsghandler.h"
21 #include "kexi.h"
22 #include <kexiutils/utils.h>
23 
24 #include <KDbUtils>
25 
26 #include <KLocalizedString>
27 
28 class Q_DECL_HIDDEN KexiTextMessageHandler::Private
29 {
30 public:
31     Private(QString* msgTarget, QString* dTarget);
32     ~Private();
33 
34     QString *messageTarget, *detailsTarget;
35 };
36 
Private(QString * msgTarget,QString * dTarget)37 KexiTextMessageHandler::Private::Private(QString* msgTarget, QString* dTarget)
38     :messageTarget(msgTarget), detailsTarget(dTarget)
39 {
40     messageTarget->clear();
41     detailsTarget->clear();
42 }
43 
~Private()44 KexiTextMessageHandler::Private::~Private()
45 {
46 
47 }
48 
KexiTextMessageHandler(QString * messageTarget,QString * detailsTarget)49 KexiTextMessageHandler::KexiTextMessageHandler(QString *messageTarget, QString *detailsTarget)
50         : KexiGUIMessageHandler(0)
51         ,d(new Private(messageTarget, detailsTarget))
52 {
53     Q_ASSERT(messageTarget);
54     Q_ASSERT(detailsTarget);
55 }
56 
~KexiTextMessageHandler()57 KexiTextMessageHandler::~KexiTextMessageHandler()
58 {
59     delete d;
60 }
61 
showErrorMessage(const QString & title,const QString & details)62 void KexiTextMessageHandler::showErrorMessage(const QString &title, const QString &details)
63 {
64     if (!messagesEnabled()) {
65         return;
66     }
67     if (guiRedirection()) {
68         guiRedirection()->showErrorMessage(title, details);
69         return;
70     }
71     showMessage(KDbMessageHandler::Error, title, details);
72 }
73 
showMessage(MessageType type,const QString & title,const QString & details,const QString & dontShowAgainName)74 void KexiTextMessageHandler::showMessage(MessageType type,
75                                          const QString &title, const QString &details,
76                                          const QString& dontShowAgainName)
77 {
78     Q_UNUSED(type);
79     Q_UNUSED(dontShowAgainName);
80     if (!messagesEnabled()) {
81         return;
82     }
83     if (guiRedirection()) {
84         guiRedirection()->showMessage(type, title, details, dontShowAgainName);
85         return;
86     }
87     //'wait' cursor is a nonsense now
88     KexiUtils::removeWaitCursor();
89 
90     QString msg(title);
91     if (title.isEmpty())
92         msg = xi18n("Unknown error");
93     msg = "<qt><p>" + msg + "</p>";
94     *d->messageTarget = msg;
95     *d->detailsTarget = details;
96 }
97 
98