• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • kdecore
  • auth
kauthactionreply.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
3 * Copyright (C) 2009 Dario Freddi <drf@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
19 */
20 
21 #include "kauthactionreply.h"
22 
23 #include <QDebug>
24 
25 namespace KAuth
26 {
27 
28 class ActionReply::Private
29 {
30 public:
31  QVariantMap data; // User-defined data for success and helper error replies, empty for kauth errors
32  int errorCode;
33  QString errorDescription;
34  ActionReply::Type type;
35 };
36 
37 // Predefined replies
38 const ActionReply ActionReply::SuccessReply = ActionReply();
39 const ActionReply ActionReply::HelperErrorReply = ActionReply(ActionReply::HelperError);
40 const ActionReply ActionReply::NoResponderReply = ActionReply(ActionReply::NoResponder);
41 const ActionReply ActionReply::NoSuchActionReply = ActionReply(ActionReply::NoSuchAction);
42 const ActionReply ActionReply::InvalidActionReply = ActionReply(ActionReply::InvalidAction);
43 const ActionReply ActionReply::AuthorizationDeniedReply = ActionReply(ActionReply::AuthorizationDenied);
44 const ActionReply ActionReply::UserCancelledReply = ActionReply(ActionReply::UserCancelled);
45 const ActionReply ActionReply::HelperBusyReply = ActionReply(ActionReply::HelperBusy);
46 const ActionReply ActionReply::DBusErrorReply = ActionReply(ActionReply::DBusError);
47 
48 // Constructors
49 ActionReply::ActionReply(const ActionReply &reply)
50  : d(new Private())
51 {
52  *this = reply;
53 }
54 
55 ActionReply::ActionReply()
56  : d(new Private())
57 {
58  d->errorCode = 0;
59  d->type = Success;
60 }
61 
62 ActionReply::ActionReply(ActionReply::Type type)
63  : d(new Private())
64 {
65  d->errorCode = 0;
66  d->type = type;
67 }
68 
69 ActionReply::ActionReply(int error)
70  : d(new Private())
71 {
72  d->errorCode = error;
73  d->type = KAuthError;
74 }
75 
76 ActionReply::~ActionReply()
77 {
78  delete d;
79 }
80 
81 void ActionReply::setData(const QVariantMap &data)
82 {
83  d->data = data;
84 }
85 
86 void ActionReply::addData(const QString &key, const QVariant &value)
87 {
88  d->data.insert(key, value);
89 }
90 
91 QVariantMap ActionReply::data() const
92 {
93  return d->data;
94 }
95 
96 ActionReply::Type ActionReply::type() const
97 {
98  return d->type;
99 }
100 
101 void ActionReply::setType(ActionReply::Type type)
102 {
103  d->type = type;
104 }
105 
106 bool ActionReply::succeeded() const
107 {
108  return d->type == Success;
109 }
110 
111 bool ActionReply::failed() const
112 {
113  return d->type != Success;
114 }
115 
116 int ActionReply::errorCode() const
117 {
118  return d->errorCode;
119 }
120 
121 void ActionReply::setErrorCode(int errorCode)
122 {
123  d->errorCode = errorCode;
124  if (d->type != HelperError) {
125  d->type = KAuthError;
126  }
127 }
128 
129 QString ActionReply::errorDescription() const
130 {
131  return d->errorDescription;
132 }
133 
134 void ActionReply::setErrorDescription(const QString &error)
135 {
136  d->errorDescription = error;
137 }
138 
139 QByteArray ActionReply::serialized() const
140 {
141  QByteArray data;
142  QDataStream s(&data, QIODevice::WriteOnly);
143 
144  s << *this;
145 
146  return data;
147 }
148 
149 ActionReply ActionReply::deserialize(const QByteArray &data)
150 {
151  ActionReply reply;
152  QByteArray a(data);
153  QDataStream s(&a, QIODevice::ReadOnly);
154 
155  s >> reply;
156 
157  return reply;
158 }
159 
160 // Operators
161 ActionReply &ActionReply::operator=(const ActionReply & reply)
162 {
163  d->data = reply.d->data;
164  d->errorCode = reply.d->errorCode;
165  d->errorDescription = reply.d->errorDescription;
166  d->type = reply.d->type;
167 
168  return *this;
169 }
170 
171 bool ActionReply::operator==(const ActionReply &reply) const
172 {
173  return (d->type == reply.d->type && d->errorCode == reply.d->errorCode);
174 }
175 
176 bool ActionReply::operator!=(const ActionReply &reply) const
177 {
178  return (d->type != reply.d->type || d->errorCode != reply.d->errorCode);
179 }
180 
181 QDataStream &operator<<(QDataStream &d, const ActionReply &reply)
182 {
183  return d << reply.d->data << reply.d->errorCode << (quint32)reply.d->type << reply.d->errorDescription;
184 }
185 
186 QDataStream &operator>>(QDataStream &stream, ActionReply &reply)
187 {
188  quint32 i;
189  stream >> reply.d->data >> reply.d->errorCode >> i >> reply.d->errorDescription;
190  reply.d->type = (ActionReply::Type) i;
191 
192  return stream;
193 }
194 
195 } // namespace Auth
QVariant
KAuth::ActionReply::InvalidActionReply
static const ActionReply InvalidActionReply
errorCode() == InvalidAction
Definition: kauthactionreply.h:390
KAuth::ActionReply::errorCode
int errorCode() const
Returns the error code of an error reply.
Definition: kauthactionreply.cpp:116
KAuth::ActionReply::InvalidAction
You tried to execute an invalid action object.
Definition: kauthactionreply.h:403
KAuth::ActionReply::succeeded
bool succeeded() const
Returns true if type() == Success.
Definition: kauthactionreply.cpp:106
KAuth::ActionReply::KAuthError
An error reply generated by the library itself.
Definition: kauthactionreply.h:380
KAuth::ActionReply::~ActionReply
virtual ~ActionReply()
Virtual destructor.
Definition: kauthactionreply.cpp:76
KAuth::ActionReply::HelperBusyReply
static const ActionReply HelperBusyReply
errorCode() == HelperBusy
Definition: kauthactionreply.h:393
KAuth::ActionReply::SuccessReply
static const ActionReply SuccessReply
An empty successful reply. Same as using the default constructor.
Definition: kauthactionreply.h:385
KAuth::ActionReply::setType
void setType(Type type)
Sets the reply type.
Definition: kauthactionreply.cpp:101
quint32
KAuth::ActionReply::operator==
bool operator==(const ActionReply &reply) const
Comparison operator.
Definition: kauthactionreply.cpp:171
QString
KAuth::ActionReply::addData
void addData(const QString &key, const QVariant &value)
Convenience method to add some data to the reply.
Definition: kauthactionreply.cpp:86
KAuth::ActionReply::HelperErrorReply
static const ActionReply HelperErrorReply
An empty reply with type() == HelperError.
Definition: kauthactionreply.h:386
KAuth::ActionReply::NoResponderReply
static const ActionReply NoResponderReply
errorCode() == NoResponder
Definition: kauthactionreply.h:388
KAuth::ActionReply::AuthorizationDenied
You don't have the authorization to execute the action.
Definition: kauthactionreply.h:404
KAuth::ActionReply::AuthorizationDeniedReply
static const ActionReply AuthorizationDeniedReply
errorCode() == AuthorizationDenied
Definition: kauthactionreply.h:391
KAuth::ActionReply::UserCancelled
Action execution has been cancelled by the user.
Definition: kauthactionreply.h:405
KAuth::ActionReply::data
QVariantMap data() const
Returns the custom data coming from the helper.
Definition: kauthactionreply.cpp:91
KAuth::ActionReply::HelperError
An error reply generated by the helper.
Definition: kauthactionreply.h:381
KAuth::ActionReply::setErrorDescription
void setErrorDescription(const QString &error)
Sets a human-readble description of the error.
Definition: kauthactionreply.cpp:134
KAuth::ActionReply::deserialize
static ActionReply deserialize(const QByteArray &data)
Deserialize a reply from a QByteArray.
Definition: kauthactionreply.cpp:149
KAuth::ActionReply::setErrorCode
void setErrorCode(int errorCode)
Sets the error code of an error reply.
Definition: kauthactionreply.cpp:121
KAuth::ActionReply::Type
Type
Enumeration of the different kinds of replies.
Definition: kauthactionreply.h:379
KAuth::ActionReply::UserCancelledReply
static const ActionReply UserCancelledReply
errorCode() == UserCancelled
Definition: kauthactionreply.h:392
KAuth::ActionReply::operator!=
bool operator!=(const ActionReply &reply) const
Negated comparison operator.
Definition: kauthactionreply.cpp:176
KAuth::ActionReply::DBusErrorReply
static const ActionReply DBusErrorReply
errorCode() == DBusError
Definition: kauthactionreply.h:394
KAuth::ActionReply::NoSuchActionReply
static const ActionReply NoSuchActionReply
errorCode() == NoSuchAction
Definition: kauthactionreply.h:389
KAuth::ActionReply::operator=
ActionReply & operator=(const ActionReply &reply)
Assignment operator.
Definition: kauthactionreply.cpp:161
KAuth::ActionReply::type
Type type() const
Returns the reply's type.
Definition: kauthactionreply.cpp:96
KAuth::ActionReply::failed
bool failed() const
Returns true if type() != Success.
Definition: kauthactionreply.cpp:111
KAuth::ActionReply::ActionReply
ActionReply()
Default constructor. Sets type() to Success and errorCode() to zero.
Definition: kauthactionreply.cpp:55
KAuth::ActionReply::serialized
QByteArray serialized() const
Serialize the reply into a QByteArray.
Definition: kauthactionreply.cpp:139
KAuth::ActionReply::NoResponder
The helper responder object hasn't been set. This shouldn't happen if you use the KDE4_AUTH_HELPER ma...
Definition: kauthactionreply.h:401
KAuth::ActionReply::Success
The action has been completed successfully.
Definition: kauthactionreply.h:382
KAuth::ActionReply::DBusError
An error from D-Bus occurred.
Definition: kauthactionreply.h:407
KAuth::ActionReply::setData
void setData(const QVariantMap &data)
Sets the custom data to send back to the application.
Definition: kauthactionreply.cpp:81
KAuth::ActionReply::HelperBusy
The helper is busy executing another action (or group of actions). Try later.
Definition: kauthactionreply.h:406
kauthactionreply.h
KAuth::operator>>
QDataStream & operator>>(QDataStream &stream, ActionReply &reply)
Definition: kauthactionreply.cpp:186
KAuth::ActionReply
Class that encapsulates a reply coming from the helper after executing an action. ...
Definition: kauthactionreply.h:370
KAuth::ActionReply::errorDescription
QString errorDescription() const
Gets a human-readble description of the error, if available.
Definition: kauthactionreply.cpp:129
KAuth::ActionReply::NoSuchAction
The action you tried to execute doesn't exist.
Definition: kauthactionreply.h:402
KAuth::operator<<
QDataStream & operator<<(QDataStream &d, const ActionReply &reply)
Definition: kauthactionreply.cpp:181
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal