Skip to content

Latest commit

 

History

History
293 lines (237 loc) · 5.88 KB

ssud.cpp

File metadata and controls

293 lines (237 loc) · 5.88 KB
 
1
2
/**
* @file ssud.cpp
Nov 5, 2019
Nov 5, 2019
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
* @copyright 2013 - 2019 Jolla Ltd.
* @copyright 2019 Open Mobile Platform LLC.
* @copyright LGPLv2+
* @date 2013 - 2019
*/
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
23
24
25
*/
#include "ssud.h"
Jul 11, 2018
Jul 11, 2018
26
#include "ssu_adaptor.h"
27
28
#include "libssu/ssudeviceinfo.h"
Sep 4, 2013
Sep 4, 2013
29
#include "libssu/ssurepomanager.h"
30
31
32
33
34
35
#include <QDBusConnection>
const char *Ssud::SERVICE_NAME = "org.nemo.ssu";
const char *Ssud::OBJECT_PATH = "/org/nemo/ssu";
May 24, 2017
May 24, 2017
36
37
Ssud::Ssud(QObject *parent)
: QObject(parent)
Oct 10, 2016
Oct 10, 2016
38
{
Jul 11, 2018
Jul 11, 2018
39
40
qDBusRegisterMetaType<SsuRepo>();
qDBusRegisterMetaType<QList<SsuRepo>>();
Oct 10, 2016
Oct 10, 2016
41
42
43
44
QDBusConnection connection = QDBusConnection::systemBus();
if (!connection.registerObject(OBJECT_PATH, this)) {
qFatal("Cannot register object at %s", OBJECT_PATH);
}
Oct 10, 2016
Oct 10, 2016
46
47
48
if (!connection.registerService(SERVICE_NAME)) {
qFatal("Cannot register D-Bus service at %s", SERVICE_NAME);
}
Sep 23, 2016
Sep 23, 2016
49
Oct 10, 2016
Oct 10, 2016
50
51
// prepare for controlled suicide on boredom
const int AUTOCLOSE_TIMEOUT_MS = 180 * 1000;
Oct 24, 2013
Oct 24, 2013
52
Oct 10, 2016
Oct 10, 2016
53
54
autoclose.setSingleShot(true);
autoclose.setInterval(AUTOCLOSE_TIMEOUT_MS);
Oct 24, 2013
Oct 24, 2013
55
Oct 10, 2016
Oct 10, 2016
56
57
connect(&autoclose, SIGNAL(timeout()),
this, SLOT(quit()));
Oct 24, 2013
Oct 24, 2013
58
Oct 10, 2016
Oct 10, 2016
59
new SsuAdaptor(this);
Oct 10, 2016
Oct 10, 2016
61
62
63
64
65
66
connect(&ssu, SIGNAL(done()),
this, SIGNAL(done()));
connect(&ssu, SIGNAL(credentialsChanged()),
this, SIGNAL(credentialsChanged()));
connect(&ssu, SIGNAL(registrationStatusChanged()),
this, SIGNAL(registrationStatusChanged()));
Oct 24, 2013
Oct 24, 2013
67
Oct 10, 2016
Oct 10, 2016
68
69
// a cry for help everytime we do something to prevent suicide
autoclose.start();
70
71
}
Oct 10, 2016
Oct 10, 2016
72
73
Ssud::~Ssud()
{
74
75
}
Apr 18, 2019
Apr 18, 2019
76
77
78
79
80
QString Ssud::brand() {
autoclose.start();
return ssu.brand();
}
Oct 10, 2016
Oct 10, 2016
81
82
83
QString Ssud::deviceModel()
{
SsuDeviceInfo deviceInfo;
Oct 10, 2016
Oct 10, 2016
85
86
autoclose.start();
return deviceInfo.deviceModel();
Sep 4, 2013
Sep 4, 2013
87
88
}
Oct 10, 2016
Oct 10, 2016
89
90
91
QString Ssud::deviceFamily()
{
SsuDeviceInfo deviceInfo;
Sep 4, 2013
Sep 4, 2013
92
Oct 10, 2016
Oct 10, 2016
93
94
autoclose.start();
return deviceInfo.deviceFamily();
Sep 4, 2013
Sep 4, 2013
95
}
Oct 10, 2016
Oct 10, 2016
97
98
99
QString Ssud::deviceUid()
{
SsuDeviceInfo deviceInfo;
Oct 10, 2016
Oct 10, 2016
101
102
autoclose.start();
return deviceInfo.deviceUid();
Sep 4, 2013
Sep 4, 2013
103
104
}
Oct 10, 2016
Oct 10, 2016
105
106
107
QString Ssud::deviceVariant()
{
SsuDeviceInfo deviceInfo;
Sep 4, 2013
Sep 4, 2013
108
Oct 10, 2016
Oct 10, 2016
109
110
autoclose.start();
return deviceInfo.deviceVariant();
Sep 4, 2013
Sep 4, 2013
111
}
Oct 10, 2016
Oct 10, 2016
113
114
115
QString Ssud::displayName(int type)
{
SsuDeviceInfo deviceInfo;
Oct 24, 2013
Oct 24, 2013
116
Oct 10, 2016
Oct 10, 2016
117
118
autoclose.start();
return deviceInfo.displayName(type);
Oct 24, 2013
Oct 24, 2013
119
120
}
Oct 10, 2016
Oct 10, 2016
121
122
123
124
bool Ssud::error()
{
autoclose.start();
return ssu.error();
125
126
}
Oct 10, 2016
Oct 10, 2016
127
128
129
130
QString Ssud::lastError()
{
autoclose.start();
return ssu.lastError();
131
132
}
Oct 10, 2016
Oct 10, 2016
133
134
135
void Ssud::quit()
{
QCoreApplication::quit();
136
137
}
Oct 10, 2016
Oct 10, 2016
138
139
140
141
bool Ssud::isRegistered()
{
autoclose.start();
return ssu.isRegistered();
Sep 4, 2013
Sep 4, 2013
142
143
}
Oct 10, 2016
Oct 10, 2016
144
145
146
147
148
void Ssud::registerDevice(const QString &username, const QString &password)
{
autoclose.stop();
ssu.sendRegistration(username, password);
autoclose.start();
149
150
}
Oct 10, 2016
Oct 10, 2016
151
152
153
154
void Ssud::unregisterDevice()
{
autoclose.start();
ssu.unregister();
Sep 4, 2013
Sep 4, 2013
156
Oct 10, 2016
Oct 10, 2016
157
158
QString Ssud::domain()
{
Oct 30, 2015
Oct 30, 2015
159
160
161
autoclose.start();
return ssu.domain();
}
Sep 4, 2013
Sep 4, 2013
162
Jan 10, 2018
Jan 10, 2018
163
164
// called by DBus Adaptor, return integer instead of enum Ssu::DeviceModeFlags
int Ssud::deviceMode()
Oct 10, 2016
Oct 10, 2016
165
166
167
{
autoclose.start();
return ssu.deviceMode();
Sep 4, 2013
Sep 4, 2013
168
169
}
Oct 10, 2016
Oct 10, 2016
170
171
172
void Ssud::setDeviceMode(int mode)
{
setDeviceMode(mode, Ssu::Replace);
Aug 24, 2015
Aug 24, 2015
173
174
}
Oct 10, 2016
Oct 10, 2016
175
176
177
178
179
void Ssud::setDeviceMode(int mode, int editMode)
{
ssu.setDeviceMode(
Ssu::DeviceModeFlags(mode),
Ssu::EditMode(editMode)
Aug 24, 2015
Aug 24, 2015
180
);
Sep 4, 2013
Sep 4, 2013
181
Oct 10, 2016
Oct 10, 2016
182
183
184
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
Sep 4, 2013
Sep 4, 2013
185
186
}
Oct 10, 2016
Oct 10, 2016
187
188
189
190
QString Ssud::flavour()
{
autoclose.start();
return ssu.flavour();
Sep 4, 2013
Sep 4, 2013
191
192
}
Oct 10, 2016
Oct 10, 2016
193
194
195
void Ssud::setFlavour(const QString &flavour)
{
ssu.setFlavour(flavour);
Sep 4, 2013
Sep 4, 2013
196
Oct 10, 2016
Oct 10, 2016
197
198
199
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
Sep 4, 2013
Sep 4, 2013
200
201
202
}
Oct 10, 2016
Oct 10, 2016
203
204
205
206
QString Ssud::release(bool rnd)
{
autoclose.start();
return ssu.release(rnd);
Sep 4, 2013
Sep 4, 2013
207
208
}
Oct 10, 2016
Oct 10, 2016
209
210
211
void Ssud::setRelease(const QString &release, bool rnd)
{
ssu.setRelease(release, rnd);
Sep 4, 2013
Sep 4, 2013
212
Oct 10, 2016
Oct 10, 2016
213
214
215
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
Sep 4, 2013
Sep 4, 2013
216
217
}
Oct 10, 2016
Oct 10, 2016
218
219
220
void Ssud::modifyRepo(int action, const QString &repo)
{
SsuRepoManager repoManager;
Sep 4, 2013
Sep 4, 2013
221
Oct 10, 2016
Oct 10, 2016
222
autoclose.stop();
Oct 24, 2013
Oct 24, 2013
223
Oct 10, 2016
Oct 10, 2016
224
switch (action) {
Sep 4, 2013
Sep 4, 2013
225
case Add:
Oct 10, 2016
Oct 10, 2016
226
227
repoManager.add(repo);
break;
Sep 4, 2013
Sep 4, 2013
228
case Remove:
Oct 10, 2016
Oct 10, 2016
229
230
repoManager.remove(repo);
break;
Sep 4, 2013
Sep 4, 2013
231
case Disable:
Oct 10, 2016
Oct 10, 2016
232
233
repoManager.disable(repo);
break;
Sep 4, 2013
Sep 4, 2013
234
case Enable:
Oct 10, 2016
Oct 10, 2016
235
236
237
repoManager.enable(repo);
break;
}
Sep 4, 2013
Sep 4, 2013
238
Oct 10, 2016
Oct 10, 2016
239
240
repoManager.update();
autoclose.start();
Sep 4, 2013
Sep 4, 2013
241
242
}
Oct 10, 2016
Oct 10, 2016
243
244
245
246
247
248
void Ssud::addRepo(const QString &repo, const QString &url)
{
SsuRepoManager repoManager;
repoManager.add(repo, url);
repoManager.update();
autoclose.start();
Sep 4, 2013
Sep 4, 2013
249
250
}
Oct 10, 2016
Oct 10, 2016
251
252
253
254
255
256
void Ssud::updateRepos()
{
SsuRepoManager repoManager;
autoclose.stop();
repoManager.update();
autoclose.start();
Sep 4, 2013
Sep 4, 2013
257
}
Jul 11, 2018
Jul 11, 2018
258
Jul 11, 2018
Jul 11, 2018
259
QList<SsuRepo> Ssud::listRepos(bool rnd)
Jul 11, 2018
Jul 11, 2018
260
{
Jul 11, 2018
Jul 11, 2018
261
QList<SsuRepo> reposList;
Jul 11, 2018
Jul 11, 2018
262
263
264
265
SsuRepoManager repoManager;
for (const QString &repo : repoManager.repos(rnd)) {
const QString repoUrl = ssu.repoUrl(repo, rnd);
Jul 11, 2018
Jul 11, 2018
266
267
268
269
270
271
SsuRepo ssuRepo;
ssuRepo.name = repo;
ssuRepo.url = repoUrl;
reposList.append(ssuRepo);
Jul 11, 2018
Jul 11, 2018
272
273
274
275
}
autoclose.start();
return reposList;
}
Nov 1, 2019
Nov 1, 2019
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
QStringList Ssud::listDomains()
{
autoclose.start();
return ssu.listDomains();
}
void Ssud::setDomainConfig(const QString &domain, QVariantMap config)
{
ssu.setDomainConfig(domain, config);
autoclose.start();
}
QVariantMap Ssud::getDomainConfig(const QString &domain)
{
autoclose.start();
return ssu.getDomainConfig(domain);
}