/
ssud.cpp
201 lines (154 loc) · 3.94 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
19
20
21
22
23
24
25
26
27
28
#include <QDBusConnection>
const char *Ssud::SERVICE_NAME = "org.nemo.ssu";
const char *Ssud::OBJECT_PATH = "/org/nemo/ssu";
Ssud::Ssud(QObject *parent): QObject(parent){
QDBusConnection connection = QDBusConnection::systemBus();
if (!connection.registerService(SERVICE_NAME)) {
qFatal("Cannot register D-Bus service at %s", SERVICE_NAME);
}
if (!connection.registerObject(OBJECT_PATH, this)) {
qFatal("Cannot register object at %s", OBJECT_PATH);
}
29
30
31
32
33
34
35
36
37
// prepare for controlled suicide on boredom
const int AUTOCLOSE_TIMEOUT_MS = 180 * 1000;
autoclose.setSingleShot(true);
autoclose.setInterval(AUTOCLOSE_TIMEOUT_MS);
connect(&autoclose, SIGNAL(timeout()),
this, SLOT(quit()));
38
39
40
41
42
43
44
45
new SsuAdaptor(this);
connect(&ssu, SIGNAL(done()),
this, SIGNAL(done()));
connect(&ssu, SIGNAL(credentialsChanged()),
this, SIGNAL(credentialsChanged()));
connect(&ssu, SIGNAL(registrationStatusChanged()),
this, SIGNAL(registrationStatusChanged()));
46
47
48
// a cry for help everytime we do something to prevent suicide
autoclose.start();
49
50
51
52
53
54
55
56
}
Ssud::~Ssud(){
}
QString Ssud::deviceModel(){
SsuDeviceInfo deviceInfo;
57
autoclose.start();
58
return deviceInfo.deviceModel();
59
60
61
62
63
}
QString Ssud::deviceFamily(){
SsuDeviceInfo deviceInfo;
64
autoclose.start();
65
66
return deviceInfo.deviceFamily();
}
67
68
69
70
QString Ssud::deviceUid(){
SsuDeviceInfo deviceInfo;
71
autoclose.start();
72
return deviceInfo.deviceUid();
73
74
75
76
77
}
QString Ssud::deviceVariant(){
SsuDeviceInfo deviceInfo;
78
autoclose.start();
79
80
return deviceInfo.deviceVariant();
}
81
82
83
84
85
86
87
88
QString Ssud::displayName(int type){
SsuDeviceInfo deviceInfo;
autoclose.start();
return deviceInfo.displayName(type);
}
89
bool Ssud::error(){
90
autoclose.start();
91
92
93
94
return ssu.error();
}
QString Ssud::lastError(){
95
autoclose.start();
96
97
98
99
100
101
102
return ssu.lastError();
}
void Ssud::quit(){
QCoreApplication::quit();
}
103
bool Ssud::isRegistered(){
104
autoclose.start();
105
106
107
return ssu.isRegistered();
}
108
void Ssud::registerDevice(const QString &username, const QString &password){
109
autoclose.stop();
110
ssu.sendRegistration(username, password);
111
autoclose.start();
112
113
114
}
void Ssud::unregisterDevice(){
115
autoclose.start();
116
117
ssu.unregister();
};
118
119
120
int Ssud::deviceMode(){
121
autoclose.start();
122
123
124
125
126
127
128
129
return ssu.deviceMode();
}
void Ssud::setDeviceMode(int mode){
ssu.setDeviceMode(mode);
SsuRepoManager repoManager;
repoManager.update();
130
autoclose.start();
131
132
133
}
QString Ssud::flavour(){
134
autoclose.start();
135
136
137
138
139
140
141
142
return ssu.flavour();
}
void Ssud::setFlavour(const QString &flavour){
ssu.setFlavour(flavour);
SsuRepoManager repoManager;
repoManager.update();
143
autoclose.start();
144
145
146
147
}
QString Ssud::release(bool rnd){
148
autoclose.start();
149
150
151
152
153
154
155
156
return ssu.release(rnd);
}
void Ssud::setRelease(const QString &release, bool rnd){
ssu.setRelease(release, rnd);
SsuRepoManager repoManager;
repoManager.update();
157
autoclose.start();
158
159
160
161
162
}
void Ssud::modifyRepo(int action, const QString &repo){
SsuRepoManager repoManager;
163
164
autoclose.stop();
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
switch(action){
case Add:
repoManager.add(repo);
break;
case Remove:
repoManager.remove(repo);
break;
case Disable:
repoManager.disable(repo);
break;
case Enable:
repoManager.enable(repo);
break;
}
repoManager.update();
181
autoclose.start();
182
183
184
185
186
187
}
void Ssud::addRepo(const QString &repo, const QString &url){
SsuRepoManager repoManager;
repoManager.add(repo, url);
repoManager.update();
188
autoclose.start();
189
190
191
192
}
void Ssud::updateRepos(){
SsuRepoManager repoManager;
193
autoclose.stop();
194
repoManager.update();
195
autoclose.start();
196
}
197
198
199
200
201
void Ssud::updateStoreCredentials(const QString &userName, const QString &accessToken){
ssu.updateStoreCredentials(userName, accessToken);
autoclose.start();
}