KDE 4.9 PyKDE API Reference

- KDE's Python API

# ActionReply Class Reference

`from PyKDE4.kdecore import *`

Namespace: KAuth

## 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 <i>ActionReply(ActionReply.HelperError)</i> you could use the more convenient <i>ActionReply.HelperErrorReply</i> 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

## Enumerations
Error | { NoError, NoResponder, NoSuchAction, InvalidAction, AuthorizationDenied, UserCancelled, HelperBusy, DBusError }
Type | { KAuthError, HelperError, Success }
## Attributes
KAuth.ActionReply | AuthorizationDeniedReply
KAuth.ActionReply | DBusErrorReply
KAuth.ActionReply | HelperBusyReply
KAuth.ActionReply | HelperErrorReply
KAuth.ActionReply | InvalidActionReply
KAuth.ActionReply | NoResponderReply
KAuth.ActionReply | NoSuchActionReply
KAuth.ActionReply | SuccessReply
KAuth.ActionReply | UserCancelledReply
## Methods
| __init__ (self)
| __init__ (self, KAuth.ActionReply.Type type)
| __init__ (self, KAuth.ActionReply reply)
| addData (self, QString key, QVariant value)
{QString:QVariant} | data (self)
int | errorCode (self)
QString | errorDescription (self)
bool | failed (self)
bool | operator != (self, KAuth.ActionReply reply)
bool | operator == (self, KAuth.ActionReply reply)
QByteArray | serialized (self)
| setData (self, {QString:QVariant} data)
| setErrorCode (self, int errorCode)
| setErrorDescription (self, QString error)
bool | succeeded (self)
KAuth.ActionReply.Type | type (self)
## Static Methods
KAuth.ActionReply | deserialize (QByteArray data)

## Method Documentation

__init__ | ( |  | self ) |

__init__ | ( | self, |
|  | 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.

Parameters:

  | type | The type of the new reply

__init__ | ( | self, |
|  | KAuth.ActionReply | reply
| ) |  |  |

addData | ( | self, |
|  | QString | key,
|  | 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:

  | key | The new entry's key
  | value | The value of the new entry

{QString:QVariant} data | ( |  | self ) |

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

int errorCode | ( |  | self ) |

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

QString errorDescription | ( |  | self ) |

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

bool failed | ( |  | self ) |

bool operator != | ( | self, |
|  | KAuth.ActionReply | reply
| ) |  |  |

Negated comparison operator

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

bool operator == | ( | self, |
|  | KAuth.ActionReply | reply
| ) |  |  |

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.

QByteArray serialized | ( |  | self ) |

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

setData | ( | self, |
|  | {QString:QVariant} | 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.

setErrorCode | ( | self, |
|  | 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

setErrorDescription | ( | self, |
|  | 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

bool succeeded | ( |  | self ) |

KAuth.ActionReply.Type type | ( |  | self ) |

## Static Method Documentation

KAuth.ActionReply deserialize | ( | QByteArray | data
| ) |  |  |

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()

## Attribute Documentation

KAuth.ActionReply AuthorizationDeniedReply

KAuth.ActionReply DBusErrorReply

KAuth.ActionReply HelperBusyReply

KAuth.ActionReply HelperErrorReply

KAuth.ActionReply InvalidActionReply

KAuth.ActionReply NoResponderReply

KAuth.ActionReply NoSuchActionReply

KAuth.ActionReply SuccessReply

KAuth.ActionReply UserCancelledReply

## Enumeration Documentation

Error

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

Enumerator:

  UnknownError = 0 |
  ConnectionRefusedError |
  RemoteHostClosedError |
  HostNotFoundError |
  SocketAccessError |
  SocketResourceError |
  SocketTimeoutError |
  NetworkError |
  UnsupportedSocketOperationError |

Type

Enumeration of the different kinds of replies.

Enumerator:

  String = QVariant::String |
  DateTime = QVariant::DateTime |
  Invalid = QVariant::Invalid |