/
ssud.cpp
233 lines (186 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
/**
* @file ssud.cpp
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/
#include "ssud.h"
#include "ssuadaptor.h"
#include "libssu/ssudeviceinfo.h"
12
#include "libssu/ssurepomanager.h"
13
14
15
16
17
18
#include <QDBusConnection>
const char *Ssud::SERVICE_NAME = "org.nemo.ssu";
const char *Ssud::OBJECT_PATH = "/org/nemo/ssu";
19
20
Ssud::Ssud(QObject *parent)
: QObject(parent)
21
22
23
24
25
{
QDBusConnection connection = QDBusConnection::systemBus();
if (!connection.registerObject(OBJECT_PATH, this)) {
qFatal("Cannot register object at %s", OBJECT_PATH);
}
26
27
28
29
if (!connection.registerService(SERVICE_NAME)) {
qFatal("Cannot register D-Bus service at %s", SERVICE_NAME);
}
30
31
32
// prepare for controlled suicide on boredom
const int AUTOCLOSE_TIMEOUT_MS = 180 * 1000;
33
34
35
autoclose.setSingleShot(true);
autoclose.setInterval(AUTOCLOSE_TIMEOUT_MS);
36
37
38
connect(&autoclose, SIGNAL(timeout()),
this, SLOT(quit()));
39
40
new SsuAdaptor(this);
41
42
43
44
45
46
47
connect(&ssu, SIGNAL(done()),
this, SIGNAL(done()));
connect(&ssu, SIGNAL(credentialsChanged()),
this, SIGNAL(credentialsChanged()));
connect(&ssu, SIGNAL(registrationStatusChanged()),
this, SIGNAL(registrationStatusChanged()));
48
49
50
// a cry for help everytime we do something to prevent suicide
autoclose.start();
51
52
}
53
54
Ssud::~Ssud()
{
55
56
}
57
58
59
QString Ssud::deviceModel()
{
SsuDeviceInfo deviceInfo;
60
61
62
autoclose.start();
return deviceInfo.deviceModel();
63
64
}
65
66
67
QString Ssud::deviceFamily()
{
SsuDeviceInfo deviceInfo;
68
69
70
autoclose.start();
return deviceInfo.deviceFamily();
71
}
72
73
74
75
QString Ssud::deviceUid()
{
SsuDeviceInfo deviceInfo;
76
77
78
autoclose.start();
return deviceInfo.deviceUid();
79
80
}
81
82
83
QString Ssud::deviceVariant()
{
SsuDeviceInfo deviceInfo;
84
85
86
autoclose.start();
return deviceInfo.deviceVariant();
87
}
88
89
90
91
QString Ssud::displayName(int type)
{
SsuDeviceInfo deviceInfo;
92
93
94
autoclose.start();
return deviceInfo.displayName(type);
95
96
}
97
98
99
100
bool Ssud::error()
{
autoclose.start();
return ssu.error();
101
102
}
103
104
105
106
QString Ssud::lastError()
{
autoclose.start();
return ssu.lastError();
107
108
}
109
110
111
void Ssud::quit()
{
QCoreApplication::quit();
112
113
}
114
115
116
117
bool Ssud::isRegistered()
{
autoclose.start();
return ssu.isRegistered();
118
119
}
120
121
122
123
124
void Ssud::registerDevice(const QString &username, const QString &password)
{
autoclose.stop();
ssu.sendRegistration(username, password);
autoclose.start();
125
126
}
127
128
129
130
void Ssud::unregisterDevice()
{
autoclose.start();
ssu.unregister();
131
};
132
133
134
QString Ssud::domain()
{
135
136
137
autoclose.start();
return ssu.domain();
}
138
139
140
// called by DBus Adaptor, return integer instead of enum Ssu::DeviceModeFlags
int Ssud::deviceMode()
141
142
143
{
autoclose.start();
return ssu.deviceMode();
144
145
}
146
147
148
void Ssud::setDeviceMode(int mode)
{
setDeviceMode(mode, Ssu::Replace);
149
150
}
151
152
153
154
155
void Ssud::setDeviceMode(int mode, int editMode)
{
ssu.setDeviceMode(
Ssu::DeviceModeFlags(mode),
Ssu::EditMode(editMode)
156
);
157
158
159
160
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
161
162
}
163
164
165
166
QString Ssud::flavour()
{
autoclose.start();
return ssu.flavour();
167
168
}
169
170
171
void Ssud::setFlavour(const QString &flavour)
{
ssu.setFlavour(flavour);
172
173
174
175
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
176
177
178
}
179
180
181
182
QString Ssud::release(bool rnd)
{
autoclose.start();
return ssu.release(rnd);
183
184
}
185
186
187
void Ssud::setRelease(const QString &release, bool rnd)
{
ssu.setRelease(release, rnd);
188
189
190
191
SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
192
193
}
194
195
196
void Ssud::modifyRepo(int action, const QString &repo)
{
SsuRepoManager repoManager;
197
198
autoclose.stop();
199
200
switch (action) {
201
case Add:
202
203
repoManager.add(repo);
break;
204
case Remove:
205
206
repoManager.remove(repo);
break;
207
case Disable:
208
209
repoManager.disable(repo);
break;
210
case Enable:
211
212
213
repoManager.enable(repo);
break;
}
214
215
216
repoManager.update();
autoclose.start();
217
218
}
219
220
221
222
223
224
void Ssud::addRepo(const QString &repo, const QString &url)
{
SsuRepoManager repoManager;
repoManager.add(repo, url);
repoManager.update();
autoclose.start();
225
226
}
227
228
229
230
231
232
void Ssud::updateRepos()
{
SsuRepoManager repoManager;
autoclose.stop();
repoManager.update();
autoclose.start();
233
}