KAuth

kauthactionreply.cpp
1 /*
2  SPDX-FileCopyrightText: 2009-2012 Dario Freddi <[email protected]>
3  SPDX-FileCopyrightText: 2008 Nicola Gigante <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #include "kauthactionreply.h"
9 
10 #include <QDebug>
11 
12 namespace KAuth
13 {
14 class ActionReplyData : public QSharedData
15 {
16 public:
17  ActionReplyData()
18  {
19  }
20  ActionReplyData(const ActionReplyData &other)
21  : QSharedData(other)
22  , data(other.data)
23  , errorCode(other.errorCode)
24  , errorDescription(other.errorDescription)
25  , type(other.type)
26  {
27  }
28  ~ActionReplyData()
29  {
30  }
31 
32  QVariantMap data; // User-defined data for success and helper error replies, empty for kauth errors
33  uint errorCode;
34  QString errorDescription;
36 };
37 
38 // Predefined replies
40 {
41  return ActionReply();
42 }
44 {
46  reply.setError(-1);
47  return reply;
48 }
50 {
52  reply.setError(error);
53  return reply;
54 }
56 {
58 }
60 {
62 }
64 {
66 }
68 {
70 }
72 {
74 }
76 {
78 }
80 {
82 }
84 {
86 }
87 
88 // Constructors
90  : d(reply.d)
91 {
92 }
93 
95  : d(new ActionReplyData())
96 {
97  d->errorCode = 0;
98  d->type = SuccessType;
99 }
100 
102  : d(new ActionReplyData())
103 {
104  d->errorCode = 0;
105  d->type = type;
106 }
107 
109  : d(new ActionReplyData())
110 {
111  d->errorCode = error;
112  d->type = KAuthErrorType;
113 }
114 
116 {
117 }
118 
119 void ActionReply::setData(const QVariantMap &data)
120 {
121  d->data = data;
122 }
123 
124 void ActionReply::addData(const QString &key, const QVariant &value)
125 {
126  d->data.insert(key, value);
127 }
128 
129 QVariantMap ActionReply::data() const
130 {
131  return d->data;
132 }
133 
135 {
136  return d->type;
137 }
138 
140 {
141  d->type = type;
142 }
143 
145 {
146  return d->type == SuccessType;
147 }
148 
150 {
151  return !succeeded();
152 }
153 
155 {
156  return (ActionReply::Error)d->errorCode;
157 }
158 
160 {
161  d->errorCode = errorCode;
162  if (d->type != HelperErrorType) {
163  d->type = KAuthErrorType;
164  }
165 }
166 
168 {
169  return d->errorCode;
170 }
171 
173 {
174  d->errorCode = error;
175 }
176 
178 {
179  return d->errorDescription;
180 }
181 
183 {
184  d->errorDescription = error;
185 }
186 
188 {
191 
192  s << *this;
193 
194  return data;
195 }
196 
198 {
199  ActionReply reply;
200  QByteArray a(data);
202 
203  s >> reply;
204 
205  return reply;
206 }
207 
208 // Operators
210 {
211  if (this == &reply) {
212  // Protect against self-assignment
213  return *this;
214  }
215 
216  d = reply.d;
217  return *this;
218 }
219 
220 bool ActionReply::operator==(const ActionReply &reply) const
221 {
222  return (d->type == reply.d->type && d->errorCode == reply.d->errorCode);
223 }
224 
225 bool ActionReply::operator!=(const ActionReply &reply) const
226 {
227  return (d->type != reply.d->type || d->errorCode != reply.d->errorCode);
228 }
229 
231 {
232  return d << reply.d->data << reply.d->errorCode << static_cast<quint32>(reply.d->type) << reply.d->errorDescription;
233 }
234 
236 {
237  quint32 i;
238  stream >> reply.d->data >> reply.d->errorCode >> i >> reply.d->errorDescription;
239  reply.d->type = static_cast<ActionReply::Type>(i);
240 
241  return stream;
242 }
243 
244 } // namespace Auth
The helper is busy executing another action (or group of actions). Try later.
friend QDataStream & operator<<(QDataStream &, const ActionReply &)
Output streaming operator for QDataStream.
The action was already started and is currently running.
void setError(int error)
Sets the error code of an error reply.
bool succeeded() const
Returns true if type() == Success.
The helper responder object hasn&#39;t been set. This shouldn&#39;t happen if you use the KAUTH_HELPER macro ...
You don&#39;t have the authorization to execute the action.
static const ActionReply HelperBusyReply()
errorCode() == HelperBusy
virtual ~ActionReply()
Virtual destructor.
void setType(Type type)
Sets the reply type.
static const ActionReply InvalidActionReply()
errorCode() == InvalidAction
static const ActionReply HelperErrorReply()
An empty reply with type() == HelperError and errorCode() == -1.
static const ActionReply DBusErrorReply()
errorCode() == DBusError
bool operator==(const ActionReply &reply) const
Comparison operator.
void addData(const QString &key, const QVariant &value)
Convenience method to add some data to the reply.
Error
The enumeration of the possible values of errorCode() when type() is ActionReply::KAuthError.
PartitionTable::TableType type
QVariantMap data() const
Returns the custom data coming from the helper.
void setErrorDescription(const QString &error)
Sets a human-readble description of the error.
static ActionReply deserialize(const QByteArray &data)
Deserialize a reply from a QByteArray.
static const ActionReply NoSuchActionReply()
errorCode() == NoSuchAction
static const ActionReply SuccessReply()
An empty successful reply. Same as using the default constructor.
Type
Enumeration of the different kinds of replies.
static const ActionReply NoResponderReply()
errorCode() == NoResponder
bool operator!=(const ActionReply &reply) const
Negated comparison operator.
Action execution has been cancelled by the user.
The action you tried to execute doesn&#39;t exist.
ActionReply & operator=(const ActionReply &reply)
Assignment operator.
void setErrorCode(Error errorCode)
Sets the error code of an error reply.
friend QDataStream & operator>>(QDataStream &, ActionReply &)
Input streaming operator for QDataStream.
Type type() const
Returns the reply&#39;s type.
static const ActionReply AlreadyStartedReply()
errorCode() == AlreadyStartedError
bool failed() const
Returns true if type() != Success.
static const ActionReply AuthorizationDeniedReply()
errorCode() == AuthorizationDenied
ActionReply()
Default constructor. Sets type() to Success and errorCode() to zero.
QByteArray serialized() const
Serialize the reply into a QByteArray.
static const ActionReply UserCancelledReply()
errorCode() == UserCancelled
An error from D-Bus occurred.
The action has been completed successfully.
void setData(const QVariantMap &data)
Sets the custom data to send back to the application.
Class that encapsulates a reply coming from the helper after executing an action. ...
Error errorCode() const
Returns the error code of an error reply.
QString errorDescription() const
Gets a human-readble description of the error, if available.
An error reply generated by the helper.
You tried to execute an invalid action object.
An error reply generated by the library itself.
int error() const
Returns the error code of an error reply.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:47:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.