/
ssud.cpp
293 lines (237 loc) · 5.88 KB
1
2
/**
* @file ssud.cpp
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"
26
#include "ssu_adaptor.h"
27
28
#include "libssu/ssudeviceinfo.h"
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";
36
37
Ssud::Ssud(QObject *parent)
: QObject(parent)
38
{
39
40
qDBusRegisterMetaType<SsuRepo>();
qDBusRegisterMetaType<QList<SsuRepo>>();
41
42
43
44
QDBusConnection connection = QDBusConnection::systemBus();
if (!connection.registerObject(OBJECT_PATH, this)) {
qFatal("Cannot register object at %s", OBJECT_PATH);
}
45
46
47
48
if (!connection.registerService(SERVICE_NAME)) {
qFatal("Cannot register D-Bus service at %s", SERVICE_NAME);
}
49
50
51
// prepare for controlled suicide on boredom
const int AUTOCLOSE_TIMEOUT_MS = 180 * 1000;
52
53
54
autoclose.setSingleShot(true);
autoclose.setInterval(AUTOCLOSE_TIMEOUT_MS);
55
56
57
connect(&autoclose, SIGNAL(timeout()),
this, SLOT(quit()));
58
59
new SsuAdaptor(this);
60
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()));
67
68
69
// a cry for help everytime we do something to prevent suicide
autoclose.start();
70
71
}
72
73
Ssud::~Ssud()
{
74
75
}
76
77
78
79
80
QString Ssud::brand() {
autoclose.start();
return ssu.brand();
}
81
82
83
QString Ssud::deviceModel()
{
SsuDeviceInfo deviceInfo;
84
85
86
autoclose.start();
return deviceInfo.deviceModel();
87
88
}
89
90
91
QString Ssud::deviceFamily()
{
SsuDeviceInfo deviceInfo;
92
93
94
autoclose.start();
return deviceInfo.deviceFamily();
95
}
96
97
98
99
QString Ssud::deviceUid()
{
SsuDeviceInfo deviceInfo;
100
101
102
autoclose.start();
return deviceInfo.deviceUid();
103
104
}
105
106
107
QString Ssud::deviceVariant()
{
SsuDeviceInfo deviceInfo;
108
109
110
autoclose.start();
return deviceInfo.deviceVariant();
111
}
112
113
114
115
QString Ssud::displayName(int type)
{
SsuDeviceInfo deviceInfo;
116
117
118
autoclose.start();
return deviceInfo.displayName(type);
119
120
}
121
122
123
124
bool Ssud::error()
{
autoclose.start();
return ssu.error();
125
126
}
127
128
129
130
QString Ssud::lastError()
{
autoclose.start();
return ssu.lastError();
131
132
}
133
134
135
void Ssud::quit()
{
QCoreApplication::quit();
136
137
}
138
139
140
141
bool Ssud::isRegistered()
{
autoclose.start();
return ssu.isRegistered();
142
143
}
144
145
146
147
148
void Ssud::registerDevice(const QString &username, const QString &password)
{
autoclose.stop();
ssu.sendRegistration(username, password);
autoclose.start();
149
150
}
151
152
153
154
void Ssud::unregisterDevice()
{
autoclose.start();
ssu.unregister();
155
};
156
157
158
QString Ssud::domain()
{
159
160
161
autoclose.start();
return ssu.domain();
}
162
163
164
// called by DBus Adaptor, return integer instead of enum Ssu::DeviceModeFlags
int Ssud::deviceMode()
165
166
167
{
autoclose.start();
return ssu.deviceMode();
168
169
}
170
171
172
void Ssud::setDeviceMode(int mode)
{
setDeviceMode(mode, Ssu::Replace);
173
174
}
175
176
177
178
179
void Ssud::setDeviceMode(int mode, int editMode)
{
ssu.setDeviceMode(
Ssu::DeviceModeFlags(mode),
Ssu::EditMode(editMode)
180
);
181
182
183
184
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
185
186
}
187
188
189
190
QString Ssud::flavour()
{
autoclose.start();
return ssu.flavour();
191
192
}
193
194
195
void Ssud::setFlavour(const QString &flavour)
{
ssu.setFlavour(flavour);
196
197
198
199
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
200
201
202
}
203
204
205
206
QString Ssud::release(bool rnd)
{
autoclose.start();
return ssu.release(rnd);
207
208
}
209
210
211
void Ssud::setRelease(const QString &release, bool rnd)
{
ssu.setRelease(release, rnd);
212
213
214
215
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
216
217
}
218
219
220
void Ssud::modifyRepo(int action, const QString &repo)
{
SsuRepoManager repoManager;
221
222
autoclose.stop();
223
224
switch (action) {
225
case Add:
226
227
repoManager.add(repo);
break;
228
case Remove:
229
230
repoManager.remove(repo);
break;
231
case Disable:
232
233
repoManager.disable(repo);
break;
234
case Enable:
235
236
237
repoManager.enable(repo);
break;
}
238
239
240
repoManager.update();
autoclose.start();
241
242
}
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();
249
250
}
251
252
253
254
255
256
void Ssud::updateRepos()
{
SsuRepoManager repoManager;
autoclose.stop();
repoManager.update();
autoclose.start();
257
}
258
259
QList<SsuRepo> Ssud::listRepos(bool rnd)
260
{
261
QList<SsuRepo> reposList;
262
263
264
265
SsuRepoManager repoManager;
for (const QString &repo : repoManager.repos(rnd)) {
const QString repoUrl = ssu.repoUrl(repo, rnd);
266
267
268
269
270
271
SsuRepo ssuRepo;
ssuRepo.name = repo;
ssuRepo.url = repoUrl;
reposList.append(ssuRepo);
272
273
274
275
}
autoclose.start();
return reposList;
}
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);
}