KAuth::ActionReply
#include <KAuth/ActionReply>
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 (const ActionReply &reply) | |
ActionReply (int errorCode) | |
ActionReply (Type type) | |
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 |
ActionReply & | operator= (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 () |
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 334 of file actionreply.h.
Member Enumeration Documentation
◆ Error
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 362 of file actionreply.h.
◆ Type
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 340 of file actionreply.h.
Constructor & Destructor Documentation
◆ ActionReply() [1/4]
KAuth::ActionReply::ActionReply | ( | ) |
Default constructor. Sets type() to Success and errorCode() to zero.
Definition at line 95 of file actionreply.cpp.
◆ ActionReply() [2/4]
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 102 of file actionreply.cpp.
◆ ActionReply() [3/4]
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 109 of file actionreply.cpp.
◆ ActionReply() [4/4]
KAuth::ActionReply::ActionReply | ( | const ActionReply & | reply | ) |
Copy constructor.
Definition at line 90 of file actionreply.cpp.
◆ ~ActionReply()
|
virtual |
Virtual destructor.
Definition at line 116 of file actionreply.cpp.
Member Function Documentation
◆ addData()
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 125 of file actionreply.cpp.
◆ AlreadyStartedReply()
|
static |
errorCode() == AlreadyStartedError
Definition at line 80 of file actionreply.cpp.
◆ AuthorizationDeniedReply()
|
static |
errorCode() == AuthorizationDenied
Definition at line 68 of file actionreply.cpp.
◆ data()
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 130 of file actionreply.cpp.
◆ DBusErrorReply()
|
static |
errorCode() == DBusError
Definition at line 84 of file actionreply.cpp.
◆ deserialize()
|
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 198 of file actionreply.cpp.
◆ error()
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 168 of file actionreply.cpp.
◆ errorCode()
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 155 of file actionreply.cpp.
◆ errorDescription()
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 178 of file actionreply.cpp.
◆ failed()
bool KAuth::ActionReply::failed | ( | ) | const |
Returns true if type() != Success.
Definition at line 150 of file actionreply.cpp.
◆ HelperBusyReply()
|
static |
errorCode() == HelperBusy
Definition at line 76 of file actionreply.cpp.
◆ HelperErrorReply() [1/2]
|
static |
An empty reply with type() == HelperError and errorCode() == -1.
Definition at line 44 of file actionreply.cpp.
◆ HelperErrorReply() [2/2]
|
static |
An empty reply with type() == HelperError and error is set to the passed value.
Definition at line 50 of file actionreply.cpp.
◆ InvalidActionReply()
|
static |
errorCode() == InvalidAction
Definition at line 64 of file actionreply.cpp.
◆ NoResponderReply()
|
static |
errorCode() == NoResponder
Definition at line 56 of file actionreply.cpp.
◆ NoSuchActionReply()
|
static |
errorCode() == NoSuchAction
Definition at line 60 of file actionreply.cpp.
◆ operator!=()
bool KAuth::ActionReply::operator!= | ( | const ActionReply & | reply | ) | const |
Negated comparison operator.
See the operator==() for an important notice.
Definition at line 228 of file actionreply.cpp.
◆ operator=()
ActionReply & KAuth::ActionReply::operator= | ( | const ActionReply & | reply | ) |
Assignment operator.
Definition at line 212 of file actionreply.cpp.
◆ operator==()
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 is to compare a reply against one of the predefined error replies:
Note that you can do it also by compare errorCode() with the relative enumeration value.
Definition at line 223 of file actionreply.cpp.
◆ serialized()
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 188 of file actionreply.cpp.
◆ setData()
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 120 of file actionreply.cpp.
◆ setError()
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
-
error The new reply error code
Definition at line 173 of file actionreply.cpp.
◆ setErrorCode()
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
-
errorCode The new reply error code
Definition at line 160 of file actionreply.cpp.
◆ setErrorDescription()
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 183 of file actionreply.cpp.
◆ setType()
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 140 of file actionreply.cpp.
◆ succeeded()
bool KAuth::ActionReply::succeeded | ( | ) | const |
Returns true if type() == Success.
Definition at line 145 of file actionreply.cpp.
◆ SuccessReply()
|
static |
An empty successful reply. Same as using the default constructor.
Definition at line 40 of file actionreply.cpp.
◆ type()
ActionReply::Type KAuth::ActionReply::type | ( | ) | const |
Returns the reply's type.
Definition at line 135 of file actionreply.cpp.
◆ UserCancelledReply()
|
static |
errorCode() == UserCancelled
Definition at line 72 of file actionreply.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:52:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.