Debian Codegraph @

tests/online-accounts-service/tst_ui_proxy/request-mock.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <[email protected]>
5 *
6 * This file is part of lomiri-online-accounts-service
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <online-accounts-common/globals.h>
22 #include "request-mock.h"
23
24 #include <QDebug>
25
26 using namespace OnlineAccountsUi;
27
28 RequestPrivate::RequestPrivate(const QDBusConnection &connection,
29 const QDBusMessage &message,
30 const QVariantMap &parameters,
31 Request *request):
32 QObject(request),
33 m_connection(connection),
34 m_message(message),
35 m_parameters(parameters),
36 m_inProgress(false),
37 m_delay(0),
38 q_ptr(request)
39 {
40 }
41
42 RequestPrivate::~RequestPrivate()
43 {
44 }
45
46 void RequestPrivate::setClientApparmorProfile(const QString &profile)
47 {
48 m_clientApparmorProfile = profile;
49 }
50
51 void RequestPrivate::setProviderId(const QString &provider)
52 {
53 m_providerId = provider;
54 }
55
56 Request::Request(const QDBusConnection &connection,
57 const QDBusMessage &message,
58 const QVariantMap &parameters,
59 QObject *parent):
60 QObject(parent),
61 d_ptr(new RequestPrivate(connection, message, parameters, this))
62 {
63 }
64
65 Request::~Request()
66 {
67 }
68
69 quint64 Request::windowId() const
70 {
71 Q_D(const Request);
72 return d->m_parameters[OAU_KEY_WINDOW_ID].toUInt();
73 }
74
75 void Request::setInProgress(bool inProgress)
76 {
77 Q_D(Request);
78 d->m_inProgress = inProgress;
79 }
80
81 bool Request::isInProgress() const
82 {
83 Q_D(const Request);
84 return d->m_inProgress;
85 }
86
87 const QVariantMap &Request::parameters() const
88 {
89 Q_D(const Request);
90 return d->m_parameters;
91 }
92
93 QString Request::clientApparmorProfile() const
94 {
95 Q_D(const Request);
96 return d->m_clientApparmorProfile;
97 }
98
99 QString Request::interface() const {
100 Q_D(const Request);
101 return d->m_message.interface();
102 }
103
104 QString Request::providerId() const {
105 Q_D(const Request);
106 return d->m_providerId;
107 }
108
109 void Request::setDelay(int delay)
110 {
111 Q_D(Request);
112 d->m_delay = delay;
113 }
114
115 int Request::delay() const
116 {
117 Q_D(const Request);
118 return d->m_delay;
119 }
120
121 void Request::cancel()
122 {
123 setCanceled();
124 }
125
126 void Request::fail(const QString &name, const QString &message)
127 {
128 Q_D(Request);
129 Q_EMIT d->failCalled(name, message);
130
131 Q_EMIT completed();
132 }
133
134 void Request::setCanceled()
135 {
136 Q_D(Request);
137 if (d->m_inProgress) {
138 fail(OAU_ERROR_USER_CANCELED, QStringLiteral("Cancelled"));
139 d->m_inProgress = false;
140 }
141 }
142
143 void Request::setResult(const QVariantMap &result)
144 {
145 Q_D(Request);
146 if (d->m_inProgress) {
147 Q_EMIT d->setResultCalled(result);
148
149 Q_EMIT completed();
150 d->m_inProgress = false;
151 }
152 }