KAuth::ActionReply

#include <KAuthActionReply>

Public Types

enum  Error {
  NoError = 0, NoResponderError, NoSuchActionError, InvalidActionError,
  AuthorizationDeniedError, UserCancelledError, HelperBusyError, AlreadyStartedError,
  DBusError, BackendError
}
 
enum  Type { KAuthErrorType, HelperErrorType, SuccessType }
 

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 error () const
 
Error errorCode () const
 
QString errorDescription () const
 
bool failed () const
 
bool operator!= (const ActionReply &reply) const
 
ActionReplyoperator= (const ActionReply &reply)
 
bool operator== (const ActionReply &reply) const
 
QByteArray serialized () const
 
void setData (const QVariantMap &data)
 
void setError (int error)
 
void setErrorCode (Error errorCode)
 
void setErrorDescription (const QString &error)
 
void setType (Type type)
 
bool succeeded () const
 
Type type () const
 

Static Public Member Functions

static const ActionReply AlreadyStartedReply ()
 
static const ActionReply AuthorizationDeniedReply ()
 
static const ActionReply DBusErrorReply ()
 
static ActionReply deserialize (const QByteArray &data)
 
static const ActionReply HelperBusyReply ()
 
static const ActionReply HelperErrorReply ()
 
static const ActionReply HelperErrorReply (int error)
 
static const ActionReply InvalidActionReply ()
 
static const ActionReply NoResponderReply ()
 
static const ActionReply NoSuchActionReply ()
 
static const ActionReply SuccessReply ()
 
static const ActionReply UserCancelledReply ()
 

Friends

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

Detailed Description

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

Helper applications will return this to describe the result of the action.

Callers should access the reply though the KAuth::ExecuteJob job.

Since
4.4

Definition at line 331 of file kauthactionreply.h.

Member Enumeration Documentation

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

Enumerator
NoError 

No error.

NoResponderError 

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

NoSuchActionError 

The action you tried to execute doesn't exist.

InvalidActionError 

You tried to execute an invalid action object.

AuthorizationDeniedError 

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

UserCancelledError 

Action execution has been cancelled by the user.

HelperBusyError 

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

AlreadyStartedError 

The action was already started and is currently running.

DBusError 

An error from D-Bus occurred.

BackendError 

The underlying backend reported an error.

Definition at line 359 of file kauthactionreply.h.

Enumeration of the different kinds of replies.

Enumerator
KAuthErrorType 

An error reply generated by the library itself.

HelperErrorType 

An error reply generated by the helper.

SuccessType 

The action has been completed successfully.

Definition at line 337 of file kauthactionreply.h.

Constructor & Destructor Documentation

KAuth::ActionReply::ActionReply ( )

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

Definition at line 89 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 96 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 103 of file kauthactionreply.cpp.

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

Copy constructor.

Definition at line 84 of file kauthactionreply.cpp.

KAuth::ActionReply::~ActionReply ( )
virtual

Virtual destructor.

Definition at line 110 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 119 of file kauthactionreply.cpp.

const ActionReply KAuth::ActionReply::AlreadyStartedReply ( )
static

errorCode() == AlreadyStartedError

Definition at line 74 of file kauthactionreply.cpp.

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

errorCode() == AuthorizationDenied

Definition at line 62 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 124 of file kauthactionreply.cpp.

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

errorCode() == DBusError

Definition at line 78 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 192 of file kauthactionreply.cpp.

int KAuth::ActionReply::error ( ) 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 162 of file kauthactionreply.cpp.

ActionReply::Error 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. Result is only valid if the type() == HelperError

Returns
The reply error code

Definition at line 149 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 172 of file kauthactionreply.cpp.

bool KAuth::ActionReply::failed ( ) const

Returns true if type() != Success.

Definition at line 144 of file kauthactionreply.cpp.

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

errorCode() == HelperBusy

Definition at line 70 of file kauthactionreply.cpp.

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

An empty reply with type() == HelperError and errorCode() == -1.

Definition at line 38 of file kauthactionreply.cpp.

const ActionReply KAuth::ActionReply::HelperErrorReply ( int  error)
static

An empty reply with type() == HelperError and error is set to the passed value.

Definition at line 44 of file kauthactionreply.cpp.

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

errorCode() == InvalidAction

Definition at line 58 of file kauthactionreply.cpp.

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

errorCode() == NoResponder

Definition at line 50 of file kauthactionreply.cpp.

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

errorCode() == NoSuchAction

Definition at line 54 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 220 of file kauthactionreply.cpp.

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

Assignment operator.

Definition at line 204 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:

// Do something...
}

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

Definition at line 215 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 182 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 114 of file kauthactionreply.cpp.

void KAuth::ActionReply::setError ( int  error)

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
errorThe new reply error code

Definition at line 167 of file kauthactionreply.cpp.

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

Sets the error code of an error reply.

See also
If you're setting the error code in the helper, use setError(int)

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

Parameters
errorCodeThe new reply error code

Definition at line 154 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 177 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 134 of file kauthactionreply.cpp.

bool KAuth::ActionReply::succeeded ( ) const

Returns true if type() == Success.

Definition at line 139 of file kauthactionreply.cpp.

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

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

Definition at line 34 of file kauthactionreply.cpp.

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

Returns the reply's type.

Definition at line 129 of file kauthactionreply.cpp.

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

errorCode() == UserCancelled

Definition at line 66 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 225 of file kauthactionreply.cpp.

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

Input streaming operator for QDataStream.

Definition at line 230 of file kauthactionreply.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:50:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.