KDb

KDbMessageHandler.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004-2015 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 "KDbMessageHandler.h"
21
22#include "KDbResult.h"
23
24class Q_DECL_HIDDEN KDbMessageGuard::Private
25{
26public:
27 Private() {}
28 const KDbResult *result;
29 KDbResultable *resultable;
30 KDbMessageHandler *handler;
31private:
32 Q_DISABLE_COPY(Private)
33};
34
36 : d(new Private)
37{
38 d->result = nullptr;
39 d->resultable = resultable;
40 d->handler = nullptr;
41}
42
44 : d(new Private)
45{
46 d->result = &result;
47 d->resultable = nullptr;
48 d->handler = handler;
49}
50
51KDbMessageGuard::~KDbMessageGuard()
52{
53 if (d->handler && d->result && d->result->isError()) { // variant 1
54 d->handler->showErrorMessage(*d->result);
55 }
56 else if (d->resultable && d->resultable->messageHandler() && d->resultable->result().isError()){ // variant 2
57 d->resultable->messageHandler()->showErrorMessage(d->resultable->result());
58 }
59 delete d;
60}
61
62//------------------------------------------------
63
64KDbMessageTitleSetter::KDbMessageTitleSetter(KDbResult* result, const QString& message)
65 : m_result(result)
66 , m_prevMsgTitle(result->messageTitle())
67{
68 m_result->setMessageTitle(message);
69}
70
71KDbMessageTitleSetter::KDbMessageTitleSetter(KDbResultable* resultable, const QString& message)
72 : m_result(&resultable->m_result)
73 , m_prevMsgTitle(resultable->result().messageTitle())
74{
75 m_result->setMessageTitle(message);
76}
77
78KDbMessageTitleSetter::~KDbMessageTitleSetter()
79{
80 m_result->setMessageTitle(m_prevMsgTitle);
81}
82
83//------------------------------------------------
84
85class Q_DECL_HIDDEN KDbGuiItem::Private
86{
87public:
88 Private() {}
89 bool dummy;
90};
91
92KDbGuiItem::KDbGuiItem()
93 : d(new Private)
94{
95}
96
97KDbGuiItem::~KDbGuiItem()
98{
99 delete d;
100}
101
102//------------------------------------------------
103
104class Q_DECL_HIDDEN KDbMessageHandler::Private
105{
106public:
107 Private()
108 : messageRedirection(nullptr)
109 , enableMessages(true)
110 {
111 }
112
113 QPointer<QWidget> messageHandlerParentWidget;
114 KDbMessageHandler *messageRedirection;
115 bool enableMessages;
116private:
117 Q_DISABLE_COPY(Private)
118};
119
120//------------------------------------------------
121
123 : d(new Private)
124{
125 d->messageHandlerParentWidget = parent;
126}
127
128KDbMessageHandler::~KDbMessageHandler()
129{
130 delete d;
131}
132
134{
135 return d->enableMessages;
136}
137
139{
140 d->enableMessages = enable;
141}
142
145 const QString& message,
146 const QString &caption,
147 KDbMessageHandler::ButtonCode defaultResult,
148 const KDbGuiItem &buttonYes,
149 const KDbGuiItem &buttonNo,
150 const QString &dontShowAskAgainName,
152 KDbMessageHandler* msgHandler)
153{
154 if (d->enableMessages && d->messageRedirection) {
155 return d->messageRedirection->askQuestion(messageType, message, caption, defaultResult,
156 buttonYes, buttonNo, dontShowAskAgainName,
157 options, msgHandler);
158 }
159 return defaultResult;
160}
161
163{
164 return d->messageRedirection;
165}
166
168{
169 return d->messageRedirection;
170}
171
173{
174 d->messageRedirection = otherHandler;
175}
176
178{
179 return d->messageHandlerParentWidget;
180}
An abstract class used to specify GUI information such as button texts tooltips and icons.
A guard class for transmitting messages based on KDbResult.
KDbMessageGuard(KDbResultable *resultable)
Builds a guard in the current code block using resultable Infromation from resultable will be used in...
void setRedirection(KDbMessageHandler *otherHandler)
virtual void showErrorMessage(KDbMessageHandler::MessageType messageType, const QString &message, const QString &details=QString(), const QString &caption=QString())=0
KDbMessageHandler * redirection()
virtual KDbMessageHandler::ButtonCode askQuestion(KDbMessageHandler::QuestionType messageType, const QString &message, const QString &caption=QString(), KDbMessageHandler::ButtonCode defaultResult=KDbMessageHandler::Yes, const KDbGuiItem &buttonYes=KDbGuiItem(), const KDbGuiItem &buttonNo=KDbGuiItem(), const QString &dontShowAskAgainName=QString(), KDbMessageHandler::Options options={}, KDbMessageHandler *msgHandler=nullptr)
QuestionType
Question types.
KDbMessageHandler(QWidget *parent=nullptr)
void setMessagesEnabled(bool enable)
bool isError() const
Definition KDbResult.cpp:64
Interface for classes providing a result.
KDbMessageHandler * messageHandler() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.