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

KDECore

  • KAuth
  • ActionReply
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
KAuth::ActionReply Class Reference

#include <kauthactionreply.h>

Public Types

enum  Error {
  NoError = 0, NoResponder, NoSuchAction, InvalidAction,
  AuthorizationDenied, UserCancelled, HelperBusy, DBusError
}
 
enum  Type { KAuthError, HelperError, Success }
 

Public Member Functions

 ActionReply ()
 
 ActionReply (Type type)
 
 ActionReply (int errorCode)
 
 ActionReply (const ActionReply &reply)
 
virtual ~ActionReply ()
 
void addData (const QString &key, const QVariant &value)
 
QVariantMap data () const
 
int errorCode () const
 
QString errorDescription () const
 
bool failed () const
 
bool operator!= (const ActionReply &reply) const
 
ActionReply & operator= (const ActionReply &reply)
 
bool operator== (const ActionReply &reply) const
 
QByteArray serialized () const
 
void setData (const QVariantMap &data)
 
void setErrorCode (int errorCode)
 
void setErrorDescription (const QString &error)
 
void setType (Type type)
 
bool succeeded () const
 
Type type () const
 

Static Public Member Functions

static ActionReply deserialize (const QByteArray &data)
 

Static Public Attributes

static const ActionReply AuthorizationDeniedReply = ActionReply(ActionReply::AuthorizationDenied)
 
static const ActionReply DBusErrorReply = ActionReply(ActionReply::DBusError)
 
static const ActionReply HelperBusyReply = ActionReply(ActionReply::HelperBusy)
 
static const ActionReply HelperErrorReply = ActionReply(ActionReply::HelperError)
 
static const ActionReply InvalidActionReply = ActionReply(ActionReply::InvalidAction)
 
static const ActionReply NoResponderReply = ActionReply(ActionReply::NoResponder)
 
static const ActionReply NoSuchActionReply = ActionReply(ActionReply::NoSuchAction)
 
static const ActionReply SuccessReply = ActionReply()
 
static const ActionReply UserCancelledReply = ActionReply(ActionReply::UserCancelled)
 

Friends

QDataStream & operator<< (QDataStream &, const ActionReply &)
 
QDataStream & operator>> (QDataStream &, ActionReply &)
 

Detailed Description

Class that encapsulates a reply coming from the helper after executing an action.

An instance of ActionReply is returned every time you execute an action with the Action class. You get the reply directly from the Action::execute() method or indirectly as a parameter of the ActionWatcher::actionPerformed() signal.

ActionReply objects can contain both data from a successful action or an error indicator. In case of success, the errorCode() is ActionReply::NoError (zero) and the type() is ActionReply::Success. The data() method returns a QVariantMap object that may contain custom data sent back by the helper.

In case of errors coming from the library, the type() is ActionReply::KAuthError. In this case, errorCode() will always be one of the predefined errors from the ActionReply::Error enum. An error reply of KAuthError type always contains an empty data() object. For some kind of errors you could get a human-readable description with errorDescription().

If, instead, the helper itself has to report some errors occurred during the action execution, the type() will be (and has to be) ActionReply::HelperError. In this case the data() object can contain custom data from the helper, and the errorCode() and errorDescription() values are application-dependent.

In the helper, to create an action reply object you have two choices: using the constructor, or the predefined replies. For example, to create a successful reply you can use the default constructor but to create a helper error reply, instead of writing ActionReply(ActionReply::HelperError) you could use the more convenient ActionReply::HelperErrorReply constant.

You should not use the predefined error replies to create and return new errors. Replies with the KAuthError type are intended to be returned by the library only. However, you can use them for comparisons.

To quickly check for success or failure of an action, you can use succeeded() or failed().

Since
4.4

Definition at line 370 of file kauthactionreply.h.

Member Enumeration Documentation

enum KAuth::ActionReply::Error

The enumeration of the possible values of errorCode() when type() is ActionReply::KAuthError.

Enumerator
NoError 

No error.

NoResponder 

The helper responder object hasn't been set. This shouldn't happen if you use the KDE4_AUTH_HELPER macro in the helper source.

NoSuchAction 

The action you tried to execute doesn't exist.

InvalidAction 

You tried to execute an invalid action object.

AuthorizationDenied 

You don't have the authorization to execute the action.

UserCancelled 

Action execution has been cancelled by the user.

HelperBusy 

The helper is busy executing another action (or group of actions). Try later.

DBusError 

An error from D-Bus occurred.

Definition at line 399 of file kauthactionreply.h.

enum KAuth::ActionReply::Type

Enumeration of the different kinds of replies.

Enumerator
KAuthError 

An error reply generated by the library itself.

HelperError 

An error reply generated by the helper.

Success 

The action has been completed successfully.

Definition at line 379 of file kauthactionreply.h.

Constructor & Destructor Documentation

KAuth::ActionReply::ActionReply ( )

Default constructor. Sets type() to Success and errorCode() to zero.

Definition at line 55 of file kauthactionreply.cpp.

KAuth::ActionReply::ActionReply ( ActionReply::Type  type)

Constructor to directly set the type.

This constructor directly sets the reply type. You shouldn't need to directly call this constructor, because you can use the more convenient predefined replies constants. You also shouldn't create a reply with the KAuthError type because it's reserved for errors coming from the library.

Parameters
typeThe type of the new reply

Definition at line 62 of file kauthactionreply.cpp.

KAuth::ActionReply::ActionReply ( int  errorCode)

Constructor that creates a KAuthError reply with a specified error code.

Do not use outside the library.

This constructor is for internal use only, since it creates a reply with KAuthError type, which is reserved for errors coming from the library.

Parameters
errorCodeThe error code of the new reply

Definition at line 69 of file kauthactionreply.cpp.

KAuth::ActionReply::ActionReply ( const ActionReply &  reply)

Copy constructor.

Definition at line 49 of file kauthactionreply.cpp.

KAuth::ActionReply::~ActionReply ( )
virtual

Virtual destructor.

Definition at line 76 of file kauthactionreply.cpp.

Member Function Documentation

void KAuth::ActionReply::addData ( const QString &  key,
const QVariant &  value 
)

Convenience method to add some data to the reply.

This method adds the pair key/value to the QVariantMap used to report back custom data to the application.

Use this method if you don't want to create a new QVariantMap only to add a new entry.

Parameters
keyThe new entry's key
valueThe value of the new entry

Definition at line 86 of file kauthactionreply.cpp.

QVariantMap KAuth::ActionReply::data ( ) const

Returns the custom data coming from the helper.

This method is used to get the object that contains the custom data coming from the helper. In the helper's code, you can set it using setData() or the convenience method addData().

Returns
The data coming from (or that will be sent by) the helper

Definition at line 91 of file kauthactionreply.cpp.

ActionReply KAuth::ActionReply::deserialize ( const QByteArray &  data)
static

Deserialize a reply from a QByteArray.

This method returns a reply from a QByteArray obtained from the serialized() method.

Parameters
dataA QByteArray obtained with serialized()

Definition at line 149 of file kauthactionreply.cpp.

int KAuth::ActionReply::errorCode ( ) const

Returns the error code of an error reply.

The error code returned is one of the values in the ActionReply::Error enumeration if type() == KAuthError, or is totally application-dependent if type() == HelperError. It also should be zero for successful replies.

Returns
The reply error code

Definition at line 116 of file kauthactionreply.cpp.

QString KAuth::ActionReply::errorDescription ( ) const

Gets a human-readble description of the error, if available.

Currently, replies of type KAuthError rarely report an error description. This situation could change in the future.

By now, you can use this method for custom errors of type HelperError.

Returns
The error human-readable description

Definition at line 129 of file kauthactionreply.cpp.

bool KAuth::ActionReply::failed ( ) const

Returns true if type() != Success.

Definition at line 111 of file kauthactionreply.cpp.

bool KAuth::ActionReply::operator!= ( const ActionReply &  reply) const

Negated comparison operator.

See the operator==() for an important notice.

Definition at line 176 of file kauthactionreply.cpp.

ActionReply & KAuth::ActionReply::operator= ( const ActionReply &  reply)

Assignment operator.

Definition at line 161 of file kauthactionreply.cpp.

bool KAuth::ActionReply::operator== ( const ActionReply &  reply) const

Comparison operator.

This operator checks if the type and the error code of two replies are the same. It doesn't compare the data or the error descriptions, so be careful.

The suggested use it to compare a reply agains one of the predefined error replies:

if(reply == ActionReply::HelperBusyReply) {
// Do something...
}

Note that you can do it also by compare errorCode() with the relative enumeration value.

Definition at line 171 of file kauthactionreply.cpp.

QByteArray KAuth::ActionReply::serialized ( ) const

Serialize the reply into a QByteArray.

This is a convenience method used internally to sent the reply to a remote peer. To recreate the reply, use deserialize()

Returns
A QByteArray representation of this reply

Definition at line 139 of file kauthactionreply.cpp.

void KAuth::ActionReply::setData ( const QVariantMap &  data)

Sets the custom data to send back to the application.

In the helper's code you can use this function to set an QVariantMap with custom data that will be sent back to the application.

Parameters
dataThe new QVariantMap object.

Definition at line 81 of file kauthactionreply.cpp.

void KAuth::ActionReply::setErrorCode ( int  errorCode)

Sets the error code of an error reply.

If you're setting the error code in the helper because you need to return an error to the application, please make sure you already have set the type to HelperError, either by calling setType() or by creating the reply in the right way.

If the type is Success when you call this method, it will become KAuthError

Parameters
errorCodeThe new reply error code

Definition at line 121 of file kauthactionreply.cpp.

void KAuth::ActionReply::setErrorDescription ( const QString &  error)

Sets a human-readble description of the error.

Call this method from the helper if you want to send back a description for a custom error. Note that this method doesn't affect the errorCode in any way

Parameters
errorThe new error description

Definition at line 134 of file kauthactionreply.cpp.

void KAuth::ActionReply::setType ( ActionReply::Type  type)

Sets the reply type.

Every time you create an action reply, you implicitly set a type. Default constructed replies or ActionReply::SuccessReply have type() == Success. ActionReply::HelperErrorReply has type() == HelperError. Predefined error replies have type() == KAuthError.

This means you rarely need to change the type after the creation, but if you need to, don't set it to KAuthError, because it's reserved for errors coming from the library.

Parameters
typeThe new reply type

Definition at line 101 of file kauthactionreply.cpp.

bool KAuth::ActionReply::succeeded ( ) const

Returns true if type() == Success.

Definition at line 106 of file kauthactionreply.cpp.

ActionReply::Type KAuth::ActionReply::type ( ) const

Returns the reply's type.

Definition at line 96 of file kauthactionreply.cpp.

Friends And Related Function Documentation

QDataStream& operator<< ( QDataStream &  d,
const ActionReply &  reply 
)
friend

Output streaming operator for QDataStream.

Definition at line 181 of file kauthactionreply.cpp.

QDataStream& operator>> ( QDataStream &  stream,
ActionReply &  reply 
)
friend

Input streaming operator for QDataStream.

Definition at line 186 of file kauthactionreply.cpp.

Member Data Documentation

const ActionReply KAuth::ActionReply::AuthorizationDeniedReply = ActionReply(ActionReply::AuthorizationDenied)
static

errorCode() == AuthorizationDenied

Definition at line 391 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::DBusErrorReply = ActionReply(ActionReply::DBusError)
static

errorCode() == DBusError

Definition at line 394 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::HelperBusyReply = ActionReply(ActionReply::HelperBusy)
static

errorCode() == HelperBusy

Definition at line 393 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::HelperErrorReply = ActionReply(ActionReply::HelperError)
static

An empty reply with type() == HelperError.

Definition at line 386 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::InvalidActionReply = ActionReply(ActionReply::InvalidAction)
static

errorCode() == InvalidAction

Definition at line 390 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::NoResponderReply = ActionReply(ActionReply::NoResponder)
static

errorCode() == NoResponder

Definition at line 388 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::NoSuchActionReply = ActionReply(ActionReply::NoSuchAction)
static

errorCode() == NoSuchAction

Definition at line 389 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::SuccessReply = ActionReply()
static

An empty successful reply. Same as using the default constructor.

Definition at line 385 of file kauthactionreply.h.

const ActionReply KAuth::ActionReply::UserCancelledReply = ActionReply(ActionReply::UserCancelled)
static

errorCode() == UserCancelled

Definition at line 392 of file kauthactionreply.h.


The documentation for this class was generated from the following files:
  • kauthactionreply.h
  • kauthactionreply.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:13 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • 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