KAuth::ActionReply Class
class KAuth::ActionReplyClass that encapsulates a reply coming from the helper after executing an action. More...
Header: | #include <KAuth/ActionReply> |
CMake: | find_package(KF6 REQUIRED COMPONENTS Auth) target_link_libraries(mytarget PRIVATE KF6::AuthCore) |
Since: | 4.4 |
Public Types
enum | Error { NoError, NoResponderError, NoSuchActionError, InvalidActionError, AuthorizationDeniedError, …, BackendError } |
enum | Type { KAuthErrorType, HelperErrorType, SuccessType } |
Public Functions
ActionReply() | |
ActionReply(KAuth::ActionReply::Type type) | |
ActionReply(int errorCode) | |
void | addData(const QString &key, const QVariant &value) |
QVariantMap | data() const |
int | error() const |
KAuth::ActionReply::Error | errorCode() const |
QString | errorDescription() const |
bool | failed() const |
QByteArray | serialized() const |
void | setData(const QVariantMap &data) |
void | setError(int error) |
void | setErrorCode(KAuth::ActionReply::Error errorCode) |
void | setErrorDescription(const QString &error) |
void | setType(KAuth::ActionReply::Type type) |
bool | succeeded() const |
KAuth::ActionReply::Type | type() const |
bool | operator!=(const KAuth::ActionReply &reply) const |
bool | operator==(const KAuth::ActionReply &reply) const |
Static Public Members
const KAuth::ActionReply | AlreadyStartedReply() |
const KAuth::ActionReply | AuthorizationDeniedReply() |
const KAuth::ActionReply | DBusErrorReply() |
const KAuth::ActionReply | HelperBusyReply() |
const KAuth::ActionReply | HelperErrorReply() |
const KAuth::ActionReply | HelperErrorReply(int error) |
const KAuth::ActionReply | InvalidActionReply() |
const KAuth::ActionReply | NoResponderReply() |
const KAuth::ActionReply | NoSuchActionReply() |
const KAuth::ActionReply | SuccessReply() |
const KAuth::ActionReply | UserCancelledReply() |
KAuth::ActionReply | deserialize(const QByteArray &data) |
Detailed Description
Helper applications will return this to describe the result of the action.
Callers should access the reply though the KAuth::ExecuteJob job.
Member Type Documentation
enum ActionReply::Error
The enumeration of the possible values of errorCode() when type() is ActionReply::KAuthError
Constant | Value | Description |
---|---|---|
KAuth::ActionReply::NoError | 0 | No error |
KAuth::ActionReply::NoResponderError | 1 | The helper responder object hasn't been set. This shouldn't happen if you use the KAUTH_HELPER macro in the helper source |
KAuth::ActionReply::NoSuchActionError | 2 | The action you tried to execute doesn't exist |
KAuth::ActionReply::InvalidActionError | 3 | You tried to execute an invalid action object |
KAuth::ActionReply::AuthorizationDeniedError | 4 | You don't have the authorization to execute the action |
KAuth::ActionReply::UserCancelledError | 5 | Action execution has been cancelled by the user |
KAuth::ActionReply::HelperBusyError | 6 | The helper is busy executing another action (or group of actions). Try later |
KAuth::ActionReply::AlreadyStartedError | 7 | The action was already started and is currently running |
KAuth::ActionReply::DBusError | 8 | An error from D-Bus occurred |
KAuth::ActionReply::BackendError | 9 | The underlying backend reported an error |
enum ActionReply::Type
Enumeration of the different kinds of replies.
Constant | Value | Description |
---|---|---|
KAuth::ActionReply::KAuthErrorType | 0 | An error reply generated by the library itself |
KAuth::ActionReply::HelperErrorType | 1 | An error reply generated by the helper |
KAuth::ActionReply::SuccessType | 2 | The action has been completed successfully |
Member Function Documentation
ActionReply::ActionReply()
Default constructor. Sets type() to Success and errorCode() to zero.
ActionReply::ActionReply(KAuth::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.
type The type of the new reply
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.
errorCode The error code of the new reply
[static]
const KAuth::ActionReply ActionReply::AlreadyStartedReply()
errorCode() == AlreadyStartedError
[static]
const KAuth::ActionReply ActionReply::AuthorizationDeniedReply()
errorCode() == AuthorizationDenied
[static]
const KAuth::ActionReply ActionReply::DBusErrorReply()
[static]
const KAuth::ActionReply ActionReply::HelperBusyReply()
errorCode() == HelperBusy
[static]
const KAuth::ActionReply ActionReply::HelperErrorReply()
An empty reply with type() == HelperError and errorCode() == -1
[static]
const KAuth::ActionReply ActionReply::HelperErrorReply(int error)
An empty reply with type() == HelperError and error is set to the passed value
[static]
const KAuth::ActionReply ActionReply::InvalidActionReply()
errorCode() == InvalidAction
[static]
const KAuth::ActionReply ActionReply::NoResponderReply()
errorCode() == NoResponder
[static]
const KAuth::ActionReply ActionReply::NoSuchActionReply()
errorCode() == NoSuchAction
[static]
const KAuth::ActionReply ActionReply::SuccessReply()
An empty successful reply. Same as using the default constructor
[static]
const KAuth::ActionReply ActionReply::UserCancelledReply()
errorCode() == UserCancelled
void 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.
key The new entry's key value The value of the new entry
QVariantMap 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
See also setData().
[static]
KAuth::ActionReply ActionReply::deserialize(const QByteArray &data)
Deserialize a reply from a QByteArray
This method returns a reply from a QByteArray obtained from the serialized() method.
data A QByteArray obtained with serialized()
int 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
See also setError().
KAuth::ActionReply::Error 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
See also setErrorCode().
QString 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
See also setErrorDescription().
bool ActionReply::failed() const
Returns true if type() != Success
QByteArray 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
void 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.
data The new QVariantMap object.
See also data().
void 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
error The new reply error code
See also error().
void ActionReply::setErrorCode(KAuth::ActionReply::Error errorCode)
Sets the error code of an error reply
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
errorCode The new reply error code
See also errorCode().
void 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
error The new error description
See also errorDescription().
void ActionReply::setType(KAuth::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.
type The new reply type
See also type().
bool ActionReply::succeeded() const
Returns true if type() == Success
KAuth::ActionReply::Type ActionReply::type() const
Returns the reply's type
See also setType().
bool ActionReply::operator!=(const KAuth::ActionReply &reply) const
Negated comparison operator
See the operator==() for an important notice.
bool ActionReply::operator==(const KAuth::ActionReply &reply) const
Comparison operator
Returns true if the type and the error code of this and reply 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:
if(reply == ActionReply::HelperBusyReply) { // Do something... }
Note that you can do it also by compare errorCode() with the relative enumeration value.