KDECore
#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
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.
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
-
type The 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
-
errorCode The 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.
|
virtual |
Virtual destructor.
Definition at line 76 of file kauthactionreply.cpp.
Member Function Documentation
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
-
key The new entry's key value The 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.
|
static |
Deserialize a reply from a QByteArray.
This method returns a reply from a QByteArray obtained from the serialized() method.
- Parameters
-
data A 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:
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
-
data The 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
-
errorCode The 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
-
error The 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
-
type The 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
|
friend |
Output streaming operator for QDataStream.
Definition at line 181 of file kauthactionreply.cpp.
|
friend |
Input streaming operator for QDataStream.
Definition at line 186 of file kauthactionreply.cpp.
Member Data Documentation
|
static |
errorCode() == AuthorizationDenied
Definition at line 391 of file kauthactionreply.h.
|
static |
errorCode() == DBusError
Definition at line 394 of file kauthactionreply.h.
|
static |
errorCode() == HelperBusy
Definition at line 393 of file kauthactionreply.h.
|
static |
An empty reply with type() == HelperError.
Definition at line 386 of file kauthactionreply.h.
|
static |
errorCode() == InvalidAction
Definition at line 390 of file kauthactionreply.h.
|
static |
errorCode() == NoResponder
Definition at line 388 of file kauthactionreply.h.
|
static |
errorCode() == NoSuchAction
Definition at line 389 of file kauthactionreply.h.
|
static |
An empty successful reply. Same as using the default constructor.
Definition at line 385 of file kauthactionreply.h.
|
static |
errorCode() == UserCancelled
Definition at line 392 of file kauthactionreply.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.