• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 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 
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 16 2013 17:47:32 by doxygen 1.8.1.1 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.10.5 API Reference

Skip menu "kdelibs-4.10.5 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