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
51Action::Action()
52 : d(new ActionData())
53{
54}
55
56Action::Action(const Action &action)
57 : d(action.d)
58{
59}
60
61Action::Action(const QString &name)
62 : d(new ActionData())
63{
64 setName(name);
65 BackendsManager::authBackend()->setupAction(d->name);
66}
67
68Action::Action(const QString &name, const DetailsMap &details)
69 : d(new ActionData())
70{
71 setName(name);
72 setDetailsV2(details);
73 BackendsManager::authBackend()->setupAction(d->name);
74}
75
76Action::~Action()
77{
78}
79
80// Operators
81Action &Action::operator=(const Action &action)
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
103QString Action::name() const
104{
105 return d->name;
106}
107
108void Action::setName(const QString &name)
109{
110 d->name = name;
111}
112
113// Accessors
114int Action::timeout() const
115{
116 return d->timeout;
117}
118
119void Action::setTimeout(int timeout)
120{
121 d->timeout = timeout;
122}
123
124Action::DetailsMap Action::detailsV2() const
125{
126 return d->details;
127}
128
129void Action::setDetailsV2(const DetailsMap &details)
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
154QString Action::helperId() const
155{
156 return d->helperId;
157}
158
159// TODO: Check for helper id's syntax
160void Action::setHelperId(const QString &id)
161{
162 d->helperId = id;
163}
164
165void Action::setParentWindow(QWindow *parent)
166{
167 d->parent = parent;
168}
169
170QWindow *Action::parentWindow() const
171{
172 return d->parent.data();
173}
174
175Action::AuthStatus Action::status() const
176{
177 if (!isValid()) {
178 return Action::InvalidStatus;
179 }
180
181 return BackendsManager::authBackend()->actionStatus(action: d->name);
182}
183
184ExecuteJob *Action::execute(ExecutionMode mode)
185{
186 return new ExecuteJob(*this, mode, nullptr);
187}
188
189bool Action::hasHelper() const
190{
191 return !d->helperId.isEmpty();
192}
193
194} // namespace Auth
195
196#include "moc_action.cpp"
197

source code of kauth/src/action.cpp