KAuth 5.109.0
action.h
1/*
2 SPDX-FileCopyrightText: 2009-2012 Dario Freddi <drf@kde.org>
3 SPDX-FileCopyrightText: 2008 Nicola Gigante <nicola.gigante@gmail.com>
4 SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7*/
8
9#ifndef KAUTH_ACTION_H
10#define KAUTH_ACTION_H
11
12#include "kauthcore_export.h"
13
14#include <QHash>
15#include <QSharedDataPointer>
16#include <QString>
17#include <QVariant>
18
19#if __has_include(<chrono>)
20#include <chrono>
21#endif
22
23namespace KAuth
24{
25class ExecuteJob;
26
27class ActionData;
75class KAUTHCORE_EXPORT Action
76{
77 Q_GADGET
78public:
89 };
90 Q_ENUM(AuthStatus)
91
92 enum ExecutionMode {
93 ExecuteMode,
94 AuthorizeOnlyMode,
95 };
96 Q_ENUM(ExecutionMode)
97
98
101 enum class AuthDetail {
102 DetailOther = 0,
103 DetailMessage,
104 };
105 Q_ENUM(AuthDetail)
106
107
110 typedef QMap<AuthDetail, QVariant> DetailsMap;
111
120
122 Action(const Action &action);
123
128 Action(const QString &name);
129
130#if KAUTHCORE_ENABLE_DEPRECATED_SINCE(5, 71)
139 KAUTHCORE_DEPRECATED_VERSION_BELATED(5, 71, 5, 68, "Use constructor with DetailsMap")
140 Action(const QString &name, const QString &details);
141#endif
142
151 Action(const QString &name, const DetailsMap &details);
152
155
157 Action &operator=(const Action &action);
158
170 bool operator==(const Action &action) const;
171
179 bool operator!=(const Action &action) const;
180
190 QString name() const;
191
200 void setName(const QString &name);
201
212 int timeout() const;
213
223 void setTimeout(int timeout);
224
225#if __has_include(<chrono>)
230 void setTimeout(std::chrono::milliseconds msec)
231 {
232 setTimeout(int(msec.count()));
233 }
234#endif
235
236#if KAUTHCORE_ENABLE_DEPRECATED_SINCE(5, 71)
246 KAUTHCORE_DEPRECATED_VERSION_BELATED(5, 71, 5, 68, "Use setDetailsV2() with DetailsMap")
247 void setDetails(const QString &details);
248#endif
249
262 void setDetailsV2(const DetailsMap &details);
263
264#if KAUTHCORE_ENABLE_DEPRECATED_SINCE(5, 71)
274 KAUTHCORE_DEPRECATED_VERSION_BELATED(5, 71, 5, 68, "Use detailsV2() with DetailsMap")
275 QString details() const;
276#endif
277
288
314 bool isValid() const;
315
328 QString helperId() const;
329
345 void setHelperId(const QString &id);
346
360 bool hasHelper() const;
361
372 void setArguments(const QVariantMap &arguments);
373
382 QVariantMap arguments() const;
383
396 void addArgument(const QString &key, const QVariant &value);
397
414
420 ExecuteJob *execute(ExecutionMode mode = ExecuteMode);
421
436 void setParentWidget(QWidget *parent);
437
445 QWidget *parentWidget() const;
446
447private:
448 QSharedDataPointer<ActionData> d;
449};
450
451} // namespace Auth
452
453#endif
Class to access, authorize and execute actions.
Definition action.h:76
QString helperId() const
Gets the default helper ID used for actions execution.
void setTimeout(int timeout)
Sets the action's timeout.
int timeout() const
Gets the action's timeout.
void setArguments(const QVariantMap &arguments)
Sets the map object used to pass arguments to the helper.
Action(const QString &name, const DetailsMap &details)
This creates a new action object with this name and details.
void addArgument(const QString &key, const QVariant &value)
Convenience method to add an argument.
QMap< AuthDetail, QVariant > DetailsMap
Map of details.
Definition action.h:110
void setName(const QString &name)
Sets the action's name.
AuthStatus status() const
Gets information about the authorization status of an action.
QString name() const
Gets the action's name.
bool hasHelper() const
Checks if the action has an helper.
bool operator!=(const Action &action) const
Negated comparison operator.
bool isValid() const
Returns if the object represents a valid action.
DetailsMap detailsV2() const
Gets the action's details.
~Action()
Virtual destructor.
void setHelperId(const QString &id)
Sets the default helper ID used for actions execution.
void setParentWidget(QWidget *parent)
Sets a parent widget for the authentication dialog.
QVariantMap arguments() const
Returns map object used to pass arguments to the helper.
Action & operator=(const Action &action)
Assignment operator.
ExecuteJob * execute(ExecutionMode mode=ExecuteMode)
Get the job object used to execute the action.
QWidget * parentWidget() const
Returns the parent widget for the authentication dialog for this action.
AuthStatus
The three values set by authorization methods.
Definition action.h:82
@ DeniedStatus
The authorization has been denied by the authorization backend.
Definition action.h:83
@ AuthRequiredStatus
The user could obtain the authorization after authentication.
Definition action.h:87
@ InvalidStatus
An invalid action cannot be authorized.
Definition action.h:85
@ UserCancelledStatus
The user pressed Cancel the authentication dialog. Currently used only on the mac.
Definition action.h:88
@ ErrorStatus
An error occurred.
Definition action.h:84
@ AuthorizedStatus
The authorization has been granted by the authorization backend.
Definition action.h:86
void setDetailsV2(const DetailsMap &details)
Sets the action's details.
bool operator==(const Action &action) const
Comparison operator.
AuthDetail
The backend specific details.
Definition action.h:101
Job for executing an Action.
Definition executejob.h:40
Definition action.h:24