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