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

KDECore

kauthactionreply.cpp

Go to the documentation of this file.
00001 /*
00002 *   Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
00003 *   Copyright (C) 2009 Dario Freddi <drf@kde.org>
00004 *
00005 *   This program is free software; you can redistribute it and/or modify
00006 *   it under the terms of the GNU Lesser General Public License as published by
00007 *   the Free Software Foundation; either version 2.1 of the License, or
00008 *   (at your option) any later version.
00009 *
00010 *   This program is distributed in the hope that it will be useful,
00011 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 *   GNU General Public License for more details.
00014 *
00015 *   You should have received a copy of the GNU Lesser General Public License
00016 *   along with this program; if not, write to the
00017 *   Free Software Foundation, Inc.,
00018 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .
00019 */
00020 
00021 #include "kauthactionreply.h"
00022 
00023 #include <QDebug>
00024 
00025 namespace KAuth
00026 {
00027 
00028 class ActionReply::Private
00029 {
00030 public:
00031     QVariantMap data; // User-defined data for success and helper error replies, empty for kauth errors
00032     int errorCode;
00033     QString errorDescription;
00034     ActionReply::Type type;
00035 };
00036 
00037 // Predefined replies
00038 const ActionReply ActionReply::SuccessReply = ActionReply();
00039 const ActionReply ActionReply::HelperErrorReply = ActionReply(ActionReply::HelperError);
00040 const ActionReply ActionReply::NoResponderReply = ActionReply(ActionReply::NoResponder);
00041 const ActionReply ActionReply::NoSuchActionReply = ActionReply(ActionReply::NoSuchAction);
00042 const ActionReply ActionReply::InvalidActionReply = ActionReply(ActionReply::InvalidAction);
00043 const ActionReply ActionReply::AuthorizationDeniedReply = ActionReply(ActionReply::AuthorizationDenied);
00044 const ActionReply ActionReply::UserCancelledReply = ActionReply(ActionReply::UserCancelled);
00045 const ActionReply ActionReply::HelperBusyReply = ActionReply(ActionReply::HelperBusy);
00046 const ActionReply ActionReply::DBusErrorReply = ActionReply(ActionReply::DBusError);
00047 
00048 // Constructors
00049 ActionReply::ActionReply(const ActionReply &reply)
00050         : d(new Private())
00051 {
00052     *this = reply;
00053 }
00054 
00055 ActionReply::ActionReply()
00056         : d(new Private())
00057 {
00058     d->errorCode = 0;
00059     d->type = Success;
00060 }
00061 
00062 ActionReply::ActionReply(ActionReply::Type type)
00063         : d(new Private())
00064 {
00065     d->errorCode = 0;
00066     d->type = type;
00067 }
00068 
00069 ActionReply::ActionReply(int error)
00070         : d(new Private())
00071 {
00072     d->errorCode = error;
00073     d->type = KAuthError;
00074 }
00075 
00076 ActionReply::~ActionReply()
00077 {
00078     delete d;
00079 }
00080 
00081 void ActionReply::setData(const QVariantMap &data)
00082 {
00083     d->data = data;
00084 }
00085 
00086 void ActionReply::addData(const QString &key, const QVariant &value)
00087 {
00088     d->data.insert(key, value);
00089 }
00090 
00091 QVariantMap ActionReply::data() const
00092 {
00093     return d->data;
00094 }
00095 
00096 ActionReply::Type ActionReply::type() const
00097 {
00098     return d->type;
00099 }
00100 
00101 bool ActionReply::succeeded() const
00102 {
00103     return d->type == Success;
00104 }
00105 
00106 bool ActionReply::failed() const
00107 {
00108     return d->type != Success;
00109 }
00110 
00111 int ActionReply::errorCode() const
00112 {
00113     return d->errorCode;
00114 }
00115 
00116 void ActionReply::setErrorCode(int errorCode)
00117 {
00118     d->errorCode = errorCode;
00119     if (d->type != HelperError) {
00120         d->type = KAuthError;
00121     }
00122 }
00123 
00124 QString ActionReply::errorDescription() const
00125 {
00126     return d->errorDescription;
00127 }
00128 
00129 void ActionReply::setErrorDescription(const QString &error)
00130 {
00131     d->errorDescription = error;
00132 }
00133 
00134 QByteArray ActionReply::serialized() const
00135 {
00136     QByteArray data;
00137     QDataStream s(&data, QIODevice::WriteOnly);
00138 
00139     s << *this;
00140 
00141     return data;
00142 }
00143 
00144 ActionReply ActionReply::deserialize(const QByteArray &data)
00145 {
00146     ActionReply reply;
00147     QByteArray a(data);
00148     QDataStream s(&a, QIODevice::ReadOnly);
00149 
00150     s >> reply;
00151 
00152     return reply;
00153 }
00154 
00155 // Operators
00156 ActionReply &ActionReply::operator=(const ActionReply & reply)
00157 {
00158     d->data = reply.d->data;
00159     d->errorCode = reply.d->errorCode;
00160     d->errorDescription = reply.d->errorDescription;
00161     d->type = reply.d->type;
00162 
00163     return *this;
00164 }
00165 
00166 bool ActionReply::operator==(const ActionReply &reply) const
00167 {
00168     return (d->type == reply.d->type && d->errorCode == reply.d->errorCode);
00169 }
00170 
00171 bool ActionReply::operator!=(const ActionReply &reply) const
00172 {
00173     return (d->type != reply.d->type || d->errorCode != reply.d->errorCode);
00174 }
00175 
00176 QDataStream &operator<<(QDataStream &d, const ActionReply &reply)
00177 {
00178     return d << reply.d->data << reply.d->errorCode << (quint32)reply.d->type;
00179 }
00180 
00181 QDataStream &operator>>(QDataStream &stream, ActionReply &reply)
00182 {
00183     quint32 i;
00184     stream >> reply.d->data >> reply.d->errorCode >> i;
00185     reply.d->type = (ActionReply::Type) i;
00186 
00187     return stream;
00188 }
00189 
00190 } // namespace Auth

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal