KAuth 5.109.0
actionreply.h
1/*
2 SPDX-FileCopyrightText: 2008 Nicola Gigante <nicola.gigante@gmail.com>
3 SPDX-FileCopyrightText: 2009-2012 Dario Freddi <drf@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#ifndef KAUTH_ACTION_REPLY_H
9#define KAUTH_ACTION_REPLY_H
10
11#include "kauthcore_export.h"
12
13#include <QDataStream>
14#include <QMap>
15#include <QSharedDataPointer>
16#include <QString>
17#include <QVariant>
18
318namespace KAuth
319{
320class ActionReplyData;
321
334class KAUTHCORE_EXPORT ActionReply
335{
336public:
340 enum Type {
344 };
345
346 static const ActionReply SuccessReply();
348 static const ActionReply HelperErrorReply(int error);
349
358
362 enum Error {
363 NoError = 0,
373 };
374
377
390
400 ActionReply(int errorCode);
401
404
406 virtual ~ActionReply();
407
416 void setData(const QVariantMap &data);
417
427 QVariantMap data() const;
428
441 void addData(const QString &key, const QVariant &value);
442
444 Type type() const;
445
461 void setType(Type type);
462
464 bool succeeded() const;
465
467 bool failed() const;
468
478 int error() const;
479
490
503 void setError(int error);
504
515 void setErrorCode(Error errorCode);
516
527 QString errorDescription() const;
528
537 void setErrorDescription(const QString &error);
538
547 QByteArray serialized() const;
548
557 static ActionReply deserialize(const QByteArray &data);
558
561
577 bool operator==(const ActionReply &reply) const;
578
584 bool operator!=(const ActionReply &reply) const;
585
586private:
587 QSharedDataPointer<ActionReplyData> d;
588};
589
590} // namespace Auth
591
592Q_DECLARE_METATYPE(KAuth::ActionReply)
593
594#endif
Class that encapsulates a reply coming from the helper after executing an action.
Definition actionreply.h:335
static const ActionReply HelperBusyReply()
errorCode() == HelperBusy
ActionReply(int errorCode)
Constructor that creates a KAuthError reply with a specified error code.
bool operator!=(const ActionReply &reply) const
Negated comparison operator.
ActionReply & operator=(const ActionReply &reply)
Assignment operator.
void addData(const QString &key, const QVariant &value)
Convenience method to add some data to the reply.
bool operator==(const ActionReply &reply) const
Comparison operator.
void setType(Type type)
Sets the reply type.
static const ActionReply SuccessReply()
An empty successful reply. Same as using the default constructor.
void setErrorDescription(const QString &error)
Sets a human-readble description of the error.
static const ActionReply InvalidActionReply()
errorCode() == InvalidAction
static ActionReply deserialize(const QByteArray &data)
Deserialize a reply from a QByteArray.
Type type() const
Returns the reply's type.
QString errorDescription() const
Gets a human-readble description of the error, if available.
static const ActionReply UserCancelledReply()
errorCode() == UserCancelled
ActionReply(Type type)
Constructor to directly set the type.
Error
The enumeration of the possible values of errorCode() when type() is ActionReply::KAuthError.
Definition actionreply.h:362
@ DBusError
An error from D-Bus occurred.
Definition actionreply.h:371
@ AuthorizationDeniedError
You don't have the authorization to execute the action.
Definition actionreply.h:367
@ InvalidActionError
You tried to execute an invalid action object.
Definition actionreply.h:366
@ NoResponderError
The helper responder object hasn't been set. This shouldn't happen if you use the KAUTH_HELPER macro ...
Definition actionreply.h:364
@ BackendError
The underlying backend reported an error.
Definition actionreply.h:372
@ HelperBusyError
The helper is busy executing another action (or group of actions). Try later.
Definition actionreply.h:369
@ NoSuchActionError
The action you tried to execute doesn't exist.
Definition actionreply.h:365
@ UserCancelledError
Action execution has been cancelled by the user.
Definition actionreply.h:368
@ AlreadyStartedError
The action was already started and is currently running.
Definition actionreply.h:370
void setErrorCode(Error errorCode)
Sets the error code of an error reply.
Error errorCode() const
Returns the error code of an error reply.
ActionReply()
Default constructor. Sets type() to Success and errorCode() to zero.
static const ActionReply HelperErrorReply()
An empty reply with type() == HelperError and errorCode() == -1.
static const ActionReply HelperErrorReply(int error)
An empty reply with type() == HelperError and error is set to the passed value.
bool succeeded() const
Returns true if type() == Success.
static const ActionReply NoSuchActionReply()
errorCode() == NoSuchAction
static const ActionReply NoResponderReply()
errorCode() == NoResponder
Type
Enumeration of the different kinds of replies.
Definition actionreply.h:340
@ KAuthErrorType
An error reply generated by the library itself.
Definition actionreply.h:341
@ HelperErrorType
An error reply generated by the helper.
Definition actionreply.h:342
@ SuccessType
The action has been completed successfully.
Definition actionreply.h:343
void setError(int error)
Sets the error code of an error reply.
int error() const
Returns the error code of an error reply.
void setData(const QVariantMap &data)
Sets the custom data to send back to the application.
static const ActionReply DBusErrorReply()
errorCode() == DBusError
QByteArray serialized() const
Serialize the reply into a QByteArray.
static const ActionReply AlreadyStartedReply()
errorCode() == AlreadyStartedError
virtual ~ActionReply()
Virtual destructor.
ActionReply(const ActionReply &reply)
Copy constructor.
static const ActionReply AuthorizationDeniedReply()
errorCode() == AuthorizationDenied
QVariantMap data() const
Returns the custom data coming from the helper.
bool failed() const
Returns true if type() != Success.
Definition action.h:24