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

KDECore

  • 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
25namespace KAuth
26{
27
28class ActionReply::Private
29{
30public:
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
38const ActionReply ActionReply::SuccessReply = ActionReply();
39const ActionReply ActionReply::HelperErrorReply = ActionReply(ActionReply::HelperError);
40const ActionReply ActionReply::NoResponderReply = ActionReply(ActionReply::NoResponder);
41const ActionReply ActionReply::NoSuchActionReply = ActionReply(ActionReply::NoSuchAction);
42const ActionReply ActionReply::InvalidActionReply = ActionReply(ActionReply::InvalidAction);
43const ActionReply ActionReply::AuthorizationDeniedReply = ActionReply(ActionReply::AuthorizationDenied);
44const ActionReply ActionReply::UserCancelledReply = ActionReply(ActionReply::UserCancelled);
45const ActionReply ActionReply::HelperBusyReply = ActionReply(ActionReply::HelperBusy);
46const ActionReply ActionReply::DBusErrorReply = ActionReply(ActionReply::DBusError);
47
48// Constructors
49ActionReply::ActionReply(const ActionReply &reply)
50 : d(new Private())
51{
52 *this = reply;
53}
54
55ActionReply::ActionReply()
56 : d(new Private())
57{
58 d->errorCode = 0;
59 d->type = Success;
60}
61
62ActionReply::ActionReply(ActionReply::Type type)
63 : d(new Private())
64{
65 d->errorCode = 0;
66 d->type = type;
67}
68
69ActionReply::ActionReply(int error)
70 : d(new Private())
71{
72 d->errorCode = error;
73 d->type = KAuthError;
74}
75
76ActionReply::~ActionReply()
77{
78 delete d;
79}
80
81void ActionReply::setData(const QVariantMap &data)
82{
83 d->data = data;
84}
85
86void ActionReply::addData(const QString &key, const QVariant &value)
87{
88 d->data.insert(key, value);
89}
90
91QVariantMap ActionReply::data() const
92{
93 return d->data;
94}
95
96ActionReply::Type ActionReply::type() const
97{
98 return d->type;
99}
100
101void ActionReply::setType(ActionReply::Type type)
102{
103 d->type = type;
104}
105
106bool ActionReply::succeeded() const
107{
108 return d->type == Success;
109}
110
111bool ActionReply::failed() const
112{
113 return d->type != Success;
114}
115
116int ActionReply::errorCode() const
117{
118 return d->errorCode;
119}
120
121void ActionReply::setErrorCode(int errorCode)
122{
123 d->errorCode = errorCode;
124 if (d->type != HelperError) {
125 d->type = KAuthError;
126 }
127}
128
129QString ActionReply::errorDescription() const
130{
131 return d->errorDescription;
132}
133
134void ActionReply::setErrorDescription(const QString &error)
135{
136 d->errorDescription = error;
137}
138
139QByteArray ActionReply::serialized() const
140{
141 QByteArray data;
142 QDataStream s(&data, QIODevice::WriteOnly);
143
144 s << *this;
145
146 return data;
147}
148
149ActionReply 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
161ActionReply &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
171bool ActionReply::operator==(const ActionReply &reply) const
172{
173 return (d->type == reply.d->type && d->errorCode == reply.d->errorCode);
174}
175
176bool ActionReply::operator!=(const ActionReply &reply) const
177{
178 return (d->type != reply.d->type || d->errorCode != reply.d->errorCode);
179}
180
181QDataStream &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
186QDataStream &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
KAuth::ActionReply
Class that encapsulates a reply coming from the helper after executing an action.
Definition: kauthactionreply.h:371
KAuth::ActionReply::HelperErrorReply
static const ActionReply HelperErrorReply
An empty reply with type() == HelperError.
Definition: kauthactionreply.h:386
KAuth::ActionReply::DBusErrorReply
static const ActionReply DBusErrorReply
errorCode() == DBusError
Definition: kauthactionreply.h:394
KAuth::ActionReply::operator!=
bool operator!=(const ActionReply &reply) const
Negated comparison operator.
Definition: kauthactionreply.cpp:176
KAuth::ActionReply::~ActionReply
virtual ~ActionReply()
Virtual destructor.
Definition: kauthactionreply.cpp:76
KAuth::ActionReply::errorCode
int errorCode() const
Returns the error code of an error reply.
Definition: kauthactionreply.cpp:116
KAuth::ActionReply::operator=
ActionReply & operator=(const ActionReply &reply)
Assignment operator.
Definition: kauthactionreply.cpp:161
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::SuccessReply
static const ActionReply SuccessReply
An empty successful reply. Same as using the default constructor.
Definition: kauthactionreply.h:385
KAuth::ActionReply::operator==
bool operator==(const ActionReply &reply) const
Comparison operator.
Definition: kauthactionreply.cpp:171
KAuth::ActionReply::InvalidActionReply
static const ActionReply InvalidActionReply
errorCode() == InvalidAction
Definition: kauthactionreply.h:390
KAuth::ActionReply::setType
void setType(Type type)
Sets the reply type.
Definition: kauthactionreply.cpp:101
KAuth::ActionReply::AuthorizationDeniedReply
static const ActionReply AuthorizationDeniedReply
errorCode() == AuthorizationDenied
Definition: kauthactionreply.h:391
KAuth::ActionReply::UserCancelledReply
static const ActionReply UserCancelledReply
errorCode() == UserCancelled
Definition: kauthactionreply.h:392
KAuth::ActionReply::setErrorDescription
void setErrorDescription(const QString &error)
Sets a human-readble description of the error.
Definition: kauthactionreply.cpp:134
KAuth::ActionReply::errorDescription
QString errorDescription() const
Gets a human-readble description of the error, if available.
Definition: kauthactionreply.cpp:129
KAuth::ActionReply::DBusError
@ DBusError
An error from D-Bus occurred.
Definition: kauthactionreply.h:407
KAuth::ActionReply::HelperBusy
@ HelperBusy
The helper is busy executing another action (or group of actions). Try later.
Definition: kauthactionreply.h:406
KAuth::ActionReply::UserCancelled
@ UserCancelled
Action execution has been cancelled by the user.
Definition: kauthactionreply.h:405
KAuth::ActionReply::NoResponder
@ 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::AuthorizationDenied
@ AuthorizationDenied
You don't have the authorization to execute the action.
Definition: kauthactionreply.h:404
KAuth::ActionReply::InvalidAction
@ InvalidAction
You tried to execute an invalid action object.
Definition: kauthactionreply.h:403
KAuth::ActionReply::NoSuchAction
@ NoSuchAction
The action you tried to execute doesn't exist.
Definition: kauthactionreply.h:402
KAuth::ActionReply::type
Type type() const
Returns the reply's type.
Definition: kauthactionreply.cpp:96
KAuth::ActionReply::ActionReply
ActionReply()
Default constructor. Sets type() to Success and errorCode() to zero.
Definition: kauthactionreply.cpp:55
KAuth::ActionReply::succeeded
bool succeeded() const
Returns true if type() == Success.
Definition: kauthactionreply.cpp:106
KAuth::ActionReply::deserialize
static ActionReply deserialize(const QByteArray &data)
Deserialize a reply from a QByteArray.
Definition: kauthactionreply.cpp:149
KAuth::ActionReply::Type
Type
Enumeration of the different kinds of replies.
Definition: kauthactionreply.h:379
KAuth::ActionReply::Success
@ Success
The action has been completed successfully.
Definition: kauthactionreply.h:382
KAuth::ActionReply::KAuthError
@ KAuthError
An error reply generated by the library itself.
Definition: kauthactionreply.h:380
KAuth::ActionReply::HelperError
@ HelperError
An error reply generated by the helper.
Definition: kauthactionreply.h:381
KAuth::ActionReply::setErrorCode
void setErrorCode(int errorCode)
Sets the error code of an error reply.
Definition: kauthactionreply.cpp:121
KAuth::ActionReply::HelperBusyReply
static const ActionReply HelperBusyReply
errorCode() == HelperBusy
Definition: kauthactionreply.h:393
KAuth::ActionReply::setData
void setData(const QVariantMap &data)
Sets the custom data to send back to the application.
Definition: kauthactionreply.cpp:81
KAuth::ActionReply::serialized
QByteArray serialized() const
Serialize the reply into a QByteArray.
Definition: kauthactionreply.cpp:139
KAuth::ActionReply::NoResponderReply
static const ActionReply NoResponderReply
errorCode() == NoResponder
Definition: kauthactionreply.h:388
KAuth::ActionReply::data
QVariantMap data() const
Returns the custom data coming from the helper.
Definition: kauthactionreply.cpp:91
KAuth::ActionReply::failed
bool failed() const
Returns true if type() != Success.
Definition: kauthactionreply.cpp:111
KAuth::ActionReply::NoSuchActionReply
static const ActionReply NoSuchActionReply
errorCode() == NoSuchAction
Definition: kauthactionreply.h:389
QString
QVariant
quint32
kauthactionreply.h
KAuth
Definition: AuthBackend.cpp:24
KAuth::operator<<
QDataStream & operator<<(QDataStream &d, const ActionReply &reply)
Definition: kauthactionreply.cpp:181
KAuth::operator>>
QDataStream & operator>>(QDataStream &stream, ActionReply &reply)
Definition: kauthactionreply.cpp:186
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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