KDb

KDbMessageHandler.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2004-2015 JarosÅ‚aw Staniek <[email protected]>
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 
24 class Q_DECL_HIDDEN KDbMessageGuard::Private
25 {
26 public:
27  Private() {}
28  const KDbResult *result;
29  KDbResultable *resultable;
30  KDbMessageHandler *handler;
31 private:
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 
51 KDbMessageGuard::~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 
64 KDbMessageTitleSetter::KDbMessageTitleSetter(KDbResult* result, const QString& message)
65  : m_result(result)
66  , m_prevMsgTitle(result->messageTitle())
67 {
68  m_result->setMessageTitle(message);
69 }
70 
71 KDbMessageTitleSetter::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 
78 KDbMessageTitleSetter::~KDbMessageTitleSetter()
79 {
80  m_result->setMessageTitle(m_prevMsgTitle);
81 }
82 
83 //------------------------------------------------
84 
85 class Q_DECL_HIDDEN KDbGuiItem::Private
86 {
87 public:
88  Private() {}
89  bool dummy;
90 };
91 
92 KDbGuiItem::KDbGuiItem()
93  : d(new Private)
94 {
95 }
96 
97 KDbGuiItem::~KDbGuiItem()
98 {
99  delete d;
100 }
101 
102 //------------------------------------------------
103 
104 class Q_DECL_HIDDEN KDbMessageHandler::Private
105 {
106 public:
107  Private()
108  : messageRedirection(nullptr)
109  , enableMessages(true)
110  {
111  }
112 
113  QPointer<QWidget> messageHandlerParentWidget;
114  KDbMessageHandler *messageRedirection;
115  bool enableMessages;
116 private:
117  Q_DISABLE_COPY(Private)
118 };
119 
120 //------------------------------------------------
121 
123  : d(new Private)
124 {
125  d->messageHandlerParentWidget = parent;
126 }
127 
128 KDbMessageHandler::~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 }
QuestionType
Question types.
An abstract class used to specify GUI information such as button texts tooltips and icons.
ButtonCode
Button codes.
void setMessagesEnabled(bool enable)
bool messagesEnabled() const
KDbMessageHandler * redirection()
Interface for classes providing a result.
void setRedirection(KDbMessageHandler *otherHandler)
KDbMessageHandler(QWidget *parent=nullptr)
KDbMessageGuard(KDbResultable *resultable)
Builds a guard in the current code block using resultable Infromation from resultable will be used in...
A guard class for transmitting messages based on KDbResult.
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=nullptr, KDbMessageHandler *msgHandler=nullptr)
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Sep 26 2022 04:04:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.