KAuth

action.cpp
1/*
2 SPDX-FileCopyrightText: 2009-2012 Dario Freddi <drf@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "action.h"
8
9#include <QPointer>
10#include <QRegularExpression>
11#include <QWindow>
12#include <QtGlobal>
13
14#include "executejob.h"
15
16#include "BackendsManager.h"
17
18namespace KAuth
19{
20class ActionData : public QSharedData
21{
22public:
23 ActionData()
24 : parent(nullptr)
25 , timeout(-1)
26 {
27 }
28 ActionData(const ActionData &other)
29 : QSharedData(other)
30 , name(other.name)
31 , helperId(other.helperId)
32 , details(other.details)
33 , args(other.args)
34 , parent(other.parent)
35 , timeout(other.timeout)
36 {
37 }
38 ~ActionData()
39 {
40 }
41
42 QString name;
43 QString helperId;
44 Action::DetailsMap details;
45 QVariantMap args;
46 QPointer<QWindow> parent;
47 int timeout;
48};
49
50// Constructors
52 : d(new ActionData())
53{
54}
55
56Action::Action(const Action &action)
57 : d(action.d)
58{
59}
60
62 : d(new ActionData())
63{
65 BackendsManager::authBackend()->setupAction(d->name);
66}
67
68Action::Action(const QString &name, const DetailsMap &details)
69 : d(new ActionData())
70{
72 setDetailsV2(details);
73 BackendsManager::authBackend()->setupAction(d->name);
74}
75
79
80// Operators
82{
83 if (this == &action) {
84 // Protect against self-assignment
85 return *this;
86 }
87
88 d = action.d;
89 return *this;
90}
91
92bool Action::operator==(const Action &action) const
93{
94 return d->name == action.d->name;
95}
96
97bool Action::operator!=(const Action &action) const
98{
99 return d->name != action.d->name;
100}
101
102// Accessors
104{
105 return d->name;
106}
107
108void Action::setName(const QString &name)
109{
110 d->name = name;
111}
112
113// Accessors
115{
116 return d->timeout;
117}
118
119void Action::setTimeout(int timeout)
120{
121 d->timeout = timeout;
122}
123
125{
126 return d->details;
127}
128
130{
131 d->details = details;
132}
133
134bool Action::isValid() const
135{
136 return !d->name.isEmpty();
137}
138
139void Action::setArguments(const QVariantMap &arguments)
140{
141 d->args = arguments;
142}
143
144void Action::addArgument(const QString &key, const QVariant &value)
145{
146 d->args.insert(key, value);
147}
148
149QVariantMap Action::arguments() const
150{
151 return d->args;
152}
153
155{
156 return d->helperId;
157}
158
159// TODO: Check for helper id's syntax
161{
162 d->helperId = id;
163}
164
166{
167 d->parent = parent;
168}
169
171{
172 return d->parent.data();
173}
174
176{
177 if (!isValid()) {
179 }
180
181 return BackendsManager::authBackend()->actionStatus(d->name);
182}
183
184ExecuteJob *Action::execute(ExecutionMode mode)
185{
186 return new ExecuteJob(*this, mode, nullptr);
187}
188
190{
191 return !d->helperId.isEmpty();
192}
193
194} // namespace Auth
195
196#include "moc_action.cpp"
Class to access, authorize and execute actions.
Definition action.h:78
void addArgument(const QString &key, const QVariant &value)
Convenience method to add an argument.
Definition action.cpp:144
AuthStatus status() const
Gets information about the authorization status of an action.
Definition action.cpp:175
QWindow * parentWindow() const
Returns the parent widget for the authentication dialog for this action.
Definition action.cpp:170
bool isValid() const
Returns if the object represents a valid action.
Definition action.cpp:134
void setTimeout(int timeout)
Sets the action's timeout.
Definition action.cpp:119
QVariantMap arguments() const
Returns map object used to pass arguments to the helper.
Definition action.cpp:149
Action()
Default constructor.
Definition action.cpp:51
void setDetailsV2(const DetailsMap &details)
Sets the action's details.
Definition action.cpp:129
void setName(const QString &name)
Sets the action's name.
Definition action.cpp:108
bool operator==(const Action &action) const
Comparison operator.
Definition action.cpp:92
void setHelperId(const QString &id)
Sets the default helper ID used for actions execution.
Definition action.cpp:160
Action & operator=(const Action &action)
Assignment operator.
Definition action.cpp:81
DetailsMap detailsV2() const
Gets the action's details.
Definition action.cpp:124
QString name() const
Gets the action's name.
Definition action.cpp:103
void setArguments(const QVariantMap &arguments)
Sets the map object used to pass arguments to the helper.
Definition action.cpp:139
bool operator!=(const Action &action) const
Negated comparison operator.
Definition action.cpp:97
ExecuteJob * execute(ExecutionMode mode=ExecuteMode)
Get the job object used to execute the action.
Definition action.cpp:184
~Action()
Virtual destructor.
Definition action.cpp:76
int timeout() const
Gets the action's timeout.
Definition action.cpp:114
void setParentWindow(QWindow *parent)
Sets a parent window for the authentication dialog.
Definition action.cpp:165
QString helperId() const
Gets the default helper ID used for actions execution.
Definition action.cpp:154
AuthStatus
The three values set by authorization methods.
Definition action.h:84
@ InvalidStatus
An invalid action cannot be authorized.
Definition action.h:87
bool hasHelper() const
Checks if the action has an helper.
Definition action.cpp:189
Job for executing an Action.
Definition executejob.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.