on xenial help sign in
switch to async DBUS calls
f5365ccLukáš Tinkl
plugins/AccountsService/AccountsService.cpp+31−42
@@ -23,10 +23,9 @@
23#include <QStringList>
23#include <QStringList>
24#include <QDebug>
24#include <QDebug>
25
25
26−AccountsService::AccountsService(QObject* parent)
26+AccountsService::AccountsService(QObject* parent, const QString &user)
27− : QObject(parent),
27+ : QObject(parent),
28 m_service(new AccountsServiceDBusAdaptor(this)),
28 m_service(new AccountsServiceDBusAdaptor(this)),
29− m_user(""),
30 m_demoEdges(false),
29 m_demoEdges(false),
31 m_enableLauncherWhileLocked(false),
30 m_enableLauncherWhileLocked(false),
32 m_enableIndicatorsWhileLocked(false),
31 m_enableIndicatorsWhileLocked(false),
@@ -36,12 +35,10 @@ AccountsService::AccountsService(QObject* parent)
36 m_hereEnabled(false),
35 m_hereEnabled(false),
37 m_hereLicensePath() // null means not set yet
36 m_hereLicensePath() // null means not set yet
38{
37{
39− connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
38+ connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
40− this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
41− connect(m_service, SIGNAL(maybeChanged(const QString &)),
39+ connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
42− this, SLOT(maybeChanged(const QString &)));
43
40
44− setUser(qgetenv("USER"));
41+ setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
45}
42}
46
43
47QString AccountsService::user() const
44QString AccountsService::user() const
@@ -173,19 +170,18 @@ void AccountsService::updateEnableLauncherWhileLocked(bool async)
173 connect(watcher, &QDBusPendingCallWatcher::finished,
170 connect(watcher, &QDBusPendingCallWatcher::finished,
174 this, [this](QDBusPendingCallWatcher* watcher) {
171 this, [this](QDBusPendingCallWatcher* watcher) {
175
172
176− QDBusPendingReply<QDBusVariant> reply = *watcher;
173+ QDBusPendingReply<QVariant> reply = *watcher;
174+ watcher->deleteLater();
177 if (reply.isError()) {
175 if (reply.isError()) {
178 qWarning() << "Failed to get 'EnableLauncherWhileLocked' property - " << reply.error().message();
176 qWarning() << "Failed to get 'EnableLauncherWhileLocked' property - " << reply.error().message();
179− watcher->deleteLater();
180 return;
177 return;
181 }
178 }
182
179
183− auto enableLauncherWhileLocked = reply.value().variant().toBool();
180+ const bool enableLauncherWhileLocked = reply.value().toBool();
184 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
181 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
185 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
182 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
186 Q_EMIT enableLauncherWhileLockedChanged();
183 Q_EMIT enableLauncherWhileLockedChanged();
187 }
184 }
188− watcher->deleteLater();
189 });
185 });
190 if (!async) {
186 if (!async) {
191 watcher->waitForFinished();
187 watcher->waitForFinished();
@@ -203,19 +199,18 @@ void AccountsService::updateEnableIndicatorsWhileLocked(bool async)
203 connect(watcher, &QDBusPendingCallWatcher::finished,
199 connect(watcher, &QDBusPendingCallWatcher::finished,
204 this, [this](QDBusPendingCallWatcher* watcher) {
200 this, [this](QDBusPendingCallWatcher* watcher) {
205
201
206− QDBusPendingReply<QDBusVariant> reply = *watcher;
202+ QDBusPendingReply<QVariant> reply = *watcher;
203+ watcher->deleteLater();
207 if (reply.isError()) {
204 if (reply.isError()) {
208 qWarning() << "Failed to get 'EnableIndicatorsWhileLocked' property - " << reply.error().message();
205 qWarning() << "Failed to get 'EnableIndicatorsWhileLocked' property - " << reply.error().message();
209− watcher->deleteLater();
210 return;
206 return;
211 }
207 }
212
208
213− auto enableIndicatorsWhileLocked = reply.value().variant().toBool();
209+ const bool enableIndicatorsWhileLocked = reply.value().toBool();
214 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
210 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
215 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
211 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
216 Q_EMIT enableIndicatorsWhileLockedChanged();
212 Q_EMIT enableIndicatorsWhileLockedChanged();
217 }
213 }
218− watcher->deleteLater();
219 });
214 });
220 if (!async) {
215 if (!async) {
221 watcher->waitForFinished();
216 watcher->waitForFinished();
@@ -233,19 +228,18 @@ void AccountsService::updateBackgroundFile(bool async)
233 connect(watcher, &QDBusPendingCallWatcher::finished,
228 connect(watcher, &QDBusPendingCallWatcher::finished,
234 this, [this](QDBusPendingCallWatcher* watcher) {
229 this, [this](QDBusPendingCallWatcher* watcher) {
235
230
236− QDBusPendingReply<QDBusVariant> reply = *watcher;
231+ QDBusPendingReply<QVariant> reply = *watcher;
232+ watcher->deleteLater();
237 if (reply.isError()) {
233 if (reply.isError()) {
238 qWarning() << "Failed to get 'BackgroundFile' property - " << reply.error().message();
234 qWarning() << "Failed to get 'BackgroundFile' property - " << reply.error().message();
239− watcher->deleteLater();
240 return;
235 return;
241 }
236 }
242
237
243− auto backgroundFile = reply.value().variant().toString();
238+ const QString backgroundFile = reply.value().toString();
244 if (m_backgroundFile != backgroundFile) {
239 if (m_backgroundFile != backgroundFile) {
245 m_backgroundFile = backgroundFile;
240 m_backgroundFile = backgroundFile;
246 Q_EMIT backgroundFileChanged();
241 Q_EMIT backgroundFileChanged();
247 }
242 }
248− watcher->deleteLater();
249 });
243 });
250 if (!async) {
244 if (!async) {
251 watcher->waitForFinished();
245 watcher->waitForFinished();
@@ -263,19 +257,18 @@ void AccountsService::updateStatsWelcomeScreen(bool async)
263 connect(watcher, &QDBusPendingCallWatcher::finished,
257 connect(watcher, &QDBusPendingCallWatcher::finished,
264 this, [this](QDBusPendingCallWatcher* watcher) {
258 this, [this](QDBusPendingCallWatcher* watcher) {
265
259
266− QDBusPendingReply<QDBusVariant> reply = *watcher;
260+ QDBusPendingReply<QVariant> reply = *watcher;
261+ watcher->deleteLater();
267 if (reply.isError()) {
262 if (reply.isError()) {
268 qWarning() << "Failed to get 'StatsWelcomeScreen' property - " << reply.error().message();
263 qWarning() << "Failed to get 'StatsWelcomeScreen' property - " << reply.error().message();
269− watcher->deleteLater();
270 return;
264 return;
271 }
265 }
272
266
273− auto statsWelcomeScreen = reply.value().variant().toBool();
267+ const bool statsWelcomeScreen = reply.value().toBool();
274 if (m_statsWelcomeScreen != statsWelcomeScreen) {
268 if (m_statsWelcomeScreen != statsWelcomeScreen) {
275 m_statsWelcomeScreen = statsWelcomeScreen;
269 m_statsWelcomeScreen = statsWelcomeScreen;
276 Q_EMIT statsWelcomeScreenChanged();
270 Q_EMIT statsWelcomeScreenChanged();
277 }
271 }
278− watcher->deleteLater();
279 });
272 });
280 if (!async) {
273 if (!async) {
281 watcher->waitForFinished();
274 watcher->waitForFinished();
@@ -293,19 +286,18 @@ void AccountsService::updatePasswordDisplayHint(bool async)
293 connect(watcher, &QDBusPendingCallWatcher::finished,
286 connect(watcher, &QDBusPendingCallWatcher::finished,
294 this, [this](QDBusPendingCallWatcher* watcher) {
287 this, [this](QDBusPendingCallWatcher* watcher) {
295
288
296− QDBusPendingReply<QDBusVariant> reply = *watcher;
289+ QDBusPendingReply<QVariant> reply = *watcher;
290+ watcher->deleteLater();
297 if (reply.isError()) {
291 if (reply.isError()) {
298 qWarning() << "Failed to get 'PasswordDisplayHint' property - " << reply.error().message();
292 qWarning() << "Failed to get 'PasswordDisplayHint' property - " << reply.error().message();
299− watcher->deleteLater();
300 return;
293 return;
301 }
294 }
302
295
303− PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().variant().toInt();
296+ const PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().toInt();
304 if (m_passwordDisplayHint != passwordDisplayHint) {
297 if (m_passwordDisplayHint != passwordDisplayHint) {
305 m_passwordDisplayHint = passwordDisplayHint;
298 m_passwordDisplayHint = passwordDisplayHint;
306 Q_EMIT passwordDisplayHintChanged();
299 Q_EMIT passwordDisplayHintChanged();
307 }
300 }
308− watcher->deleteLater();
309 });
301 });
310 if (!async) {
302 if (!async) {
311 watcher->waitForFinished();
303 watcher->waitForFinished();
@@ -323,19 +315,18 @@ void AccountsService::updateFailedLogins(bool async)
323 connect(watcher, &QDBusPendingCallWatcher::finished,
315 connect(watcher, &QDBusPendingCallWatcher::finished,
324 this, [this](QDBusPendingCallWatcher* watcher) {
316 this, [this](QDBusPendingCallWatcher* watcher) {
325
317
326− QDBusPendingReply<QDBusVariant> reply = *watcher;
318+ QDBusPendingReply<QVariant> reply = *watcher;
319+ watcher->deleteLater();
327 if (reply.isError()) {
320 if (reply.isError()) {
328 qWarning() << "Failed to get 'FailedLogins' property - " << reply.error().message();
321 qWarning() << "Failed to get 'FailedLogins' property - " << reply.error().message();
329− watcher->deleteLater();
330 return;
322 return;
331 }
323 }
332
324
333− uint failedLogins = reply.value().variant().toUInt();
325+ const uint failedLogins = reply.value().toUInt();
334 if (m_failedLogins != failedLogins) {
326 if (m_failedLogins != failedLogins) {
335 m_failedLogins = failedLogins;
327 m_failedLogins = failedLogins;
336 Q_EMIT failedLoginsChanged();
328 Q_EMIT failedLoginsChanged();
337 }
329 }
338− watcher->deleteLater();
339 });
330 });
340 if (!async) {
331 if (!async) {
341 watcher->waitForFinished();
332 watcher->waitForFinished();
@@ -353,19 +344,18 @@ void AccountsService::updateHereEnabled(bool async)
353 connect(watcher, &QDBusPendingCallWatcher::finished,
344 connect(watcher, &QDBusPendingCallWatcher::finished,
354 this, [this](QDBusPendingCallWatcher* watcher) {
345 this, [this](QDBusPendingCallWatcher* watcher) {
355
346
356− QDBusPendingReply<QDBusVariant> reply = *watcher;
347+ QDBusPendingReply<QVariant> reply = *watcher;
348+ watcher->deleteLater();
357 if (reply.isError()) {
349 if (reply.isError()) {
358 qWarning() << "Failed to get 'LicenseAccepted' property - " << reply.error().message();
350 qWarning() << "Failed to get 'LicenseAccepted' property - " << reply.error().message();
359− watcher->deleteLater();
360 return;
351 return;
361 }
352 }
362
353
363− auto hereEnabled = reply.value().variant().toBool();
354+ const bool hereEnabled = reply.value().toBool();
364 if (m_hereEnabled != hereEnabled) {
355 if (m_hereEnabled != hereEnabled) {
365 m_hereEnabled = hereEnabled;
356 m_hereEnabled = hereEnabled;
366 Q_EMIT hereEnabledChanged();
357 Q_EMIT hereEnabledChanged();
367 }
358 }
368− watcher->deleteLater();
369 });
359 });
370 if (!async) {
360 if (!async) {
371 watcher->waitForFinished();
361 watcher->waitForFinished();
@@ -383,14 +373,14 @@ void AccountsService::updateHereLicensePath(bool async)
383 connect(watcher, &QDBusPendingCallWatcher::finished,
373 connect(watcher, &QDBusPendingCallWatcher::finished,
384 this, [this](QDBusPendingCallWatcher* watcher) {
374 this, [this](QDBusPendingCallWatcher* watcher) {
385
375
386− QDBusPendingReply<QDBusVariant> reply = *watcher;
376+ QDBusPendingReply<QVariant> reply = *watcher;
377+ watcher->deleteLater();
387 if (reply.isError()) {
378 if (reply.isError()) {
388 qWarning() << "Failed to get 'LicenseBasePath' property - " << reply.error().message();
379 qWarning() << "Failed to get 'LicenseBasePath' property - " << reply.error().message();
389− watcher->deleteLater();
390 return;
380 return;
391 }
381 }
392
382
393− auto hereLicensePath = reply.value().variant().toString();
383+ QString hereLicensePath = reply.value().toString();
394 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
384 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
395 hereLicensePath = "";
385 hereLicensePath = "";
396
386
@@ -398,7 +388,6 @@ void AccountsService::updateHereLicensePath(bool async)
398 m_hereLicensePath = hereLicensePath;
388 m_hereLicensePath = hereLicensePath;
399 Q_EMIT hereLicensePathChanged();
389 Q_EMIT hereLicensePathChanged();
400 }
390 }
401− watcher->deleteLater();
402 });
391 });
403 if (!async) {
392 if (!async) {
404 watcher->waitForFinished();
393 watcher->waitForFinished();
@@ -421,7 +410,7 @@ void AccountsService::setFailedLogins(uint failedLogins)
421 }
410 }
422}
411}
423
412
424−void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
413+void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
425{
414{
426 if (m_user != user) {
415 if (m_user != user) {
427 return;
416 return;
@@ -459,7 +448,7 @@ void AccountsService::propertiesChanged(const QString &user, const QString &inte
459 }
448 }
460}
449}
461
450
462−void AccountsService::maybeChanged(const QString &user)
451+void AccountsService::onMaybeChanged(const QString &user)
463{
452{
464 if (m_user != user) {
453 if (m_user != user) {
465 return;
454 return;
plugins/AccountsService/AccountsService.h+4−3
@@ -72,7 +72,8 @@ public:
72 Numeric,
72 Numeric,
73 };
73 };
74
74
75− explicit AccountsService(QObject *parent = 0);
75+ explicit AccountsService(QObject *parent = 0, const QString & user = QString());
76+ ~AccountsService() = default;
76
77
77 QString user() const;
78 QString user() const;
78 void setUser(const QString &user);
79 void setUser(const QString &user);
@@ -103,8 +104,8 @@ Q_SIGNALS:
103 void hereLicensePathChanged();
104 void hereLicensePathChanged();
104
105
105private Q_SLOTS:
106private Q_SLOTS:
106− void propertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
107+ void onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
107− void maybeChanged(const QString &user);
108+ void onMaybeChanged(const QString &user);
108
109
109private:
110private:
110 void updateDemoEdges(bool async = true);
111 void updateDemoEdges(bool async = true);
plugins/AccountsService/AccountsServiceDBusAdaptor.cpp+13−11
@@ -21,35 +21,35 @@
21#include <QDBusConnectionInterface>
21#include <QDBusConnectionInterface>
22#include <QDBusMessage>
22#include <QDBusMessage>
23#include <QDBusVariant>
23#include <QDBusVariant>
24+#include <QDebug>
24
25
25AccountsServiceDBusAdaptor::AccountsServiceDBusAdaptor(QObject* parent)
26AccountsServiceDBusAdaptor::AccountsServiceDBusAdaptor(QObject* parent)
26 : QObject(parent),
27 : QObject(parent),
27 m_accountsManager(nullptr),
28 m_accountsManager(nullptr),
28− m_users(),
29 m_ignoreNextChanged(false)
29 m_ignoreNextChanged(false)
30{
30{
31 QDBusConnection connection = QDBusConnection::SM_BUSNAME();
31 QDBusConnection connection = QDBusConnection::SM_BUSNAME();
32 QDBusConnectionInterface *interface = connection.interface();
32 QDBusConnectionInterface *interface = connection.interface();
33 interface->startService("org.freedesktop.Accounts");
33 interface->startService("org.freedesktop.Accounts");
34 m_accountsManager = new QDBusInterface("org.freedesktop.Accounts",
34 m_accountsManager = new QDBusInterface("org.freedesktop.Accounts",
35− "/org/freedesktop/Accounts",
35+ "/org/freedesktop/Accounts",
36− "org.freedesktop.Accounts",
36+ "org.freedesktop.Accounts",
37− connection, this);
37+ connection, this);
38}
38}
39
39
40QVariant AccountsServiceDBusAdaptor::getUserProperty(const QString &user, const QString &interface, const QString &property)
40QVariant AccountsServiceDBusAdaptor::getUserProperty(const QString &user, const QString &interface, const QString &property)
41{
41{
42 QDBusInterface *iface = getUserInterface(user);
42 QDBusInterface *iface = getUserInterface(user);
43 if (iface != nullptr && iface->isValid()) {
43 if (iface != nullptr && iface->isValid()) {
44− QDBusMessage answer = iface->call("Get", interface, property);
44+ QDBusReply<QVariant> answer = iface->call("Get", interface, property);
45− if (answer.type() == QDBusMessage::ReplyMessage) {
45+ if (answer.isValid()) {
46− return answer.arguments()[0].value<QDBusVariant>().variant();
46+ return answer;
47 }
47 }
48 }
48 }
49 return QVariant();
49 return QVariant();
50}
50}
51
51
52−QDBusPendingReply<QDBusVariant> AccountsServiceDBusAdaptor::getUserPropertyAsync(const QString &user, const QString &interface, const QString &property)
52+QDBusPendingReply<QVariant> AccountsServiceDBusAdaptor::getUserPropertyAsync(const QString &user, const QString &interface, const QString &property)
53{
53{
54 QDBusInterface *iface = getUserInterface(user);
54 QDBusInterface *iface = getUserInterface(user);
55 if (iface != nullptr && iface->isValid()) {
55 if (iface != nullptr && iface->isValid()) {
@@ -116,9 +116,9 @@ QDBusInterface *AccountsServiceDBusAdaptor::getUserInterface(const QString &user
116{
116{
117 QDBusInterface *iface = m_users.value(user);
117 QDBusInterface *iface = m_users.value(user);
118 if (iface == nullptr && m_accountsManager->isValid()) {
118 if (iface == nullptr && m_accountsManager->isValid()) {
119− QDBusMessage answer = m_accountsManager->call("FindUserByName", user);
119+ QDBusReply<QDBusObjectPath> answer = m_accountsManager->asyncCall("FindUserByName", user);
120− if (answer.type() == QDBusMessage::ReplyMessage) {
120+ if (answer.isValid()) {
121− QString path = answer.arguments()[0].value<QDBusObjectPath>().path();
121+ const QString path = answer.value().path();
122
122
123 iface = new QDBusInterface("org.freedesktop.Accounts",
123 iface = new QDBusInterface("org.freedesktop.Accounts",
124 path,
124 path,
@@ -148,6 +148,8 @@ QDBusInterface *AccountsServiceDBusAdaptor::getUserInterface(const QString &user
148 SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
148 SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
149
149
150 m_users.insert(user, iface);
150 m_users.insert(user, iface);
151+ } else {
152+ qWarning() << "Couldn't get user interface" << answer.error().name() << answer.error().message();
151 }
153 }
152 }
154 }
153 return iface;
155 return iface;
plugins/AccountsService/AccountsServiceDBusAdaptor.h+3−2
@@ -33,13 +33,14 @@ class AccountsServiceDBusAdaptor: public QObject, public QDBusContext
33
33
34public:
34public:
35 explicit AccountsServiceDBusAdaptor(QObject *parent = 0);
35 explicit AccountsServiceDBusAdaptor(QObject *parent = 0);
36+ ~AccountsServiceDBusAdaptor() = default;
36
37
37 Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &interface, const QString &property);
38 Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &interface, const QString &property);
38− Q_INVOKABLE QDBusPendingReply<QDBusVariant> getUserPropertyAsync(const QString &user, const QString &interface, const QString &property);
39+ Q_INVOKABLE QDBusPendingReply<QVariant> getUserPropertyAsync(const QString &user, const QString &interface, const QString &property);
39
40
40 template <typename T>
41 template <typename T>
41 inline T getUserProperty(const QString &user, const QString &interface, const QString &property) {
42 inline T getUserProperty(const QString &user, const QString &interface, const QString &property) {
42− QVariant variant = getUserProperty(user, interface, property);
43+ const QVariant variant = getUserProperty(user, interface, property);
43 if (variant.isValid() && variant.canConvert<QDBusArgument>()) {
44 if (variant.isValid() && variant.canConvert<QDBusArgument>()) {
44 return qdbus_cast<T>(variant.value<QDBusArgument>());
45 return qdbus_cast<T>(variant.value<QDBusArgument>());
45 }
46 }
plugins/Lights/Lights.cpp+1−1
@@ -71,7 +71,7 @@ void Lights::setColor(const QColor &color)
71 if (m_color != color) {
71 if (m_color != color) {
72 m_color = color;
72 m_color = color;
73 Q_EMIT colorChanged(m_color);
73 Q_EMIT colorChanged(m_color);
74− // FIXME: update the collor if the light is already on
74+ // FIXME: update the color if the light is already on
75 }
75 }
76}
76}
77
77
plugins/Powerd/Powerd.cpp+33−28
@@ -18,54 +18,49 @@
18
18
19#include "Powerd.h"
19#include "Powerd.h"
20#include <QDBusPendingCall>
20#include <QDBusPendingCall>
21+#include <QDBusConnection>
21
22
22−void autoBrightnessChanged(GSettings *settings, const gchar *key, QDBusInterface *unityScreen)
23+void autoBrightnessChanged(GSettings *settings, const gchar *key, Powerd * instance)
23{
24{
24− bool value = g_settings_get_boolean(settings, key);
25+ const bool value = g_settings_get_boolean(settings, key);
25− unityScreen->asyncCall("userAutobrightnessEnable", QVariant(value));
26+ instance->performAsyncCall("userAutobrightnessEnable", {value});
26}
27}
27
28
28−void activityTimeoutChanged(GSettings *settings, const gchar *key, QDBusInterface *unityScreen)
29+void activityTimeoutChanged(GSettings *settings, const gchar *key, Powerd * instance)
29{
30{
30− int value = g_settings_get_uint(settings, key);
31+ const int value = g_settings_get_int(settings, key);
31− unityScreen->asyncCall("setInactivityTimeouts", QVariant(value), QVariant(-1));
32+ instance->performAsyncCall("setInactivityTimeouts", {value, -1});
32}
33}
33
34
34−void dimTimeoutChanged(GSettings *settings, const gchar *key, QDBusInterface *unityScreen)
35+void dimTimeoutChanged(GSettings *settings, const gchar *key, Powerd * instance)
35{
36{
36− int value = g_settings_get_uint(settings, key);
37+ const int value = g_settings_get_int(settings, key);
37− unityScreen->asyncCall("setInactivityTimeouts", QVariant(-1), QVariant(value));
38+ instance->performAsyncCall("setInactivityTimeouts", {-1, value});
38}
39}
39
40
40Powerd::Powerd(QObject* parent)
41Powerd::Powerd(QObject* parent)
41 : QObject(parent),
42 : QObject(parent),
42− unityScreen(nullptr),
43 cachedStatus(Status::On)
43 cachedStatus(Status::On)
44{
44{
45− unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
46− "/com/canonical/Unity/Screen",
47− "com.canonical.Unity.Screen",
48− QDBusConnection::SM_BUSNAME(), this);
45+ QDBusConnection::SM_BUSNAME().connect("com.canonical.Unity.Screen",
49−
50− unityScreen->connection().connect("com.canonical.Unity.Screen",
51− "/com/canonical/Unity/Screen",
46+ "/com/canonical/Unity/Screen",
52− "com.canonical.Unity.Screen",
47+ "com.canonical.Unity.Screen",
53− "DisplayPowerStateChange",
48+ "DisplayPowerStateChange",
54− this,
49+ this,
55− SLOT(handleDisplayPowerStateChange(int, int)));
50+ SLOT(handleDisplayPowerStateChange(int, int)));
56
51
57 systemSettings = g_settings_new("com.ubuntu.touch.system");
52 systemSettings = g_settings_new("com.ubuntu.touch.system");
58− g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), unityScreen);
53+ g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), this);
59− g_signal_connect(systemSettings, "changed::activity-timeout", G_CALLBACK(activityTimeoutChanged), unityScreen);
54+ g_signal_connect(systemSettings, "changed::activity-timeout", G_CALLBACK(activityTimeoutChanged), this);
60− g_signal_connect(systemSettings, "changed::dim-timeout", G_CALLBACK(dimTimeoutChanged), unityScreen);
55+ g_signal_connect(systemSettings, "changed::dim-timeout", G_CALLBACK(dimTimeoutChanged), this);
61− autoBrightnessChanged(systemSettings, "auto-brightness", unityScreen);
56+ autoBrightnessChanged(systemSettings, "auto-brightness", this);
62− activityTimeoutChanged(systemSettings, "activity-timeout", unityScreen);
57+ activityTimeoutChanged(systemSettings, "activity-timeout", this);
63− dimTimeoutChanged(systemSettings, "dim-timeout", unityScreen);
58+ dimTimeoutChanged(systemSettings, "dim-timeout", this);
64}
59}
65
60
66Powerd::~Powerd()
61Powerd::~Powerd()
67{
62{
68− g_signal_handlers_disconnect_by_data(systemSettings, unityScreen);
63+ g_signal_handlers_disconnect_by_data(systemSettings, this);
69 g_object_unref(systemSettings);
64 g_object_unref(systemSettings);
70}
65}
71
66
@@ -81,3 +76,13 @@ void Powerd::handleDisplayPowerStateChange(int status, int reason)
81 Q_EMIT statusChanged((DisplayStateChangeReason)reason);
76 Q_EMIT statusChanged((DisplayStateChangeReason)reason);
82 }
77 }
83}
78}
79+
80+void Powerd::performAsyncCall(const QString &method, const QVariantList &args)
81+{
82+ QDBusMessage msg = QDBusMessage::createMethodCall("com.canonical.Unity.Screen",
83+ "/com/canonical/Unity/Screen",
84+ "com.canonical.Unity.Screen",
85+ method);
86+ msg.setArguments(args);
87+ QDBusConnection::SM_BUSNAME().asyncCall(msg);
88+}
plugins/Powerd/Powerd.h+4−3
@@ -21,8 +21,7 @@
21#define UNITY_POWERD_H
21#define UNITY_POWERD_H
22
22
23#include <gio/gio.h>
23#include <gio/gio.h>
24−#include <QtCore/QObject>
24+#include <QObject>
25−#include <QtDBus/QDBusInterface>
26
25
27class Powerd: public QObject
26class Powerd: public QObject
28{
27{
@@ -30,6 +29,7 @@ class Powerd: public QObject
30 Q_ENUMS(Status)
29 Q_ENUMS(Status)
31 Q_ENUMS(DisplayStateChangeReason)
30 Q_ENUMS(DisplayStateChangeReason)
32 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
31 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
32+ Q_DISABLE_COPY(Powerd)
33
33
34public:
34public:
35 enum DisplayStateChangeReason {
35 enum DisplayStateChangeReason {
@@ -49,6 +49,8 @@ public:
49
49
50 Status status() const;
50 Status status() const;
51
51
52+ void performAsyncCall(const QString &method, const QVariantList &args);
53+
52Q_SIGNALS:
54Q_SIGNALS:
53 void statusChanged(DisplayStateChangeReason reason);
55 void statusChanged(DisplayStateChangeReason reason);
54
56
@@ -56,7 +58,6 @@ private Q_SLOTS:
56 void handleDisplayPowerStateChange(int status, int reason);
58 void handleDisplayPowerStateChange(int status, int reason);
57
59
58private:
60private:
59− QDBusInterface *unityScreen;
60 GSettings *systemSettings;
61 GSettings *systemSettings;
61 Status cachedStatus;
62 Status cachedStatus;
62};
63};
plugins/Ubuntu/SystemImage/SystemImage.cpp+7−8
@@ -16,19 +16,18 @@
16
16
17#include "SystemImage.h"
17#include "SystemImage.h"
18#include <QDBusConnection>
18#include <QDBusConnection>
19−#include <QDBusInterface>
19+#include <QDBusPendingCall>
20
20
21SystemImage::SystemImage(QObject *parent)
21SystemImage::SystemImage(QObject *parent)
22− : QObject(parent),
22+ : QObject(parent)
23− m_interface(new QDBusInterface("com.canonical.SystemImage",
24− "/Service",
25− "com.canonical.SystemImage",
26− QDBusConnection::systemBus(),
27− this))
28{
23{
29}
24}
30
25
31void SystemImage::factoryReset()
26void SystemImage::factoryReset()
32{
27{
28+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.canonical.SystemImage",
29+ "/Service",
30+ "com.canonical.SystemImage",
33− m_interface->call("FactoryReset");
31+ "FactoryReset");
32+ QDBusConnection::systemBus().asyncCall(msg);
34}
33}
plugins/Ubuntu/SystemImage/SystemImage.h+1−5
@@ -19,8 +19,6 @@
19
19
20#include <QObject>
20#include <QObject>
21
21
22−class QDBusInterface;
23−
24class SystemImage : public QObject
22class SystemImage : public QObject
25{
23{
26 Q_OBJECT
24 Q_OBJECT
@@ -28,11 +26,9 @@ class SystemImage : public QObject
28
26
29public:
27public:
30 explicit SystemImage(QObject *parent = 0);
28 explicit SystemImage(QObject *parent = 0);
29+ ~SystemImage() = default;
31
30
32 Q_INVOKABLE void factoryReset();
31 Q_INVOKABLE void factoryReset();
33−
34−private:
35− QDBusInterface *m_interface;
36};
32};
37
33
38#endif // SYSTEMIMAGE_H
34#endif // SYSTEMIMAGE_H
plugins/Unity/Connectivity/Connectivity.cpp+5−5
@@ -16,7 +16,6 @@
16
16
17#include "Connectivity.h"
17#include "Connectivity.h"
18#include <QDBusConnection>
18#include <QDBusConnection>
19−#include <QDBusInterface>
20#include <QDBusPendingCall>
19#include <QDBusPendingCall>
21
20
22Connectivity::Connectivity(QObject *parent)
21Connectivity::Connectivity(QObject *parent)
@@ -26,8 +25,9 @@ Connectivity::Connectivity(QObject *parent)
26
25
27void Connectivity::unlockAllModems()
26void Connectivity::unlockAllModems()
28{
27{
29− QDBusInterface iface("com.ubuntu.connectivity1",
28+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.ubuntu.connectivity1",
30− "/com/ubuntu/connectivity1/Private",
29+ "/com/ubuntu/connectivity1/Private",
31− "com.ubuntu.connectivity1.Private");
30+ "com.ubuntu.connectivity1.Private",
32− iface.asyncCall("UnlockAllModems");
31+ "UnlockAllModems");
32+ QDBusConnection::sessionBus().asyncCall(msg);
33}
33}
plugins/Unity/Connectivity/Connectivity.h+1
@@ -26,6 +26,7 @@ class Connectivity : public QObject
26
26
27public:
27public:
28 explicit Connectivity(QObject *parent = 0);
28 explicit Connectivity(QObject *parent = 0);
29+ ~Connectivity() = default;
29
30
30 Q_INVOKABLE void unlockAllModems();
31 Q_INVOKABLE void unlockAllModems();
31};
32};
plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.h+1−1
@@ -36,4 +36,4 @@ public Q_SLOTS:
36
36
37};
37};
38
38
39−#endif // DBUSUNITYSESSIONSERVICE_H
39+#endif // DBUSDASHCOMMUNICATORSERVICE_H
plugins/Unity/DashCommunicator/plugin.cpp+1
@@ -25,6 +25,7 @@
25
25
26void DashCommunicatorPlugin::registerTypes(const char *uri)
26void DashCommunicatorPlugin::registerTypes(const char *uri)
27{
27{
28+ // @uri Unity.DashCommunicator
28 Q_ASSERT(uri == QStringLiteral("Unity.DashCommunicator"));
29 Q_ASSERT(uri == QStringLiteral("Unity.DashCommunicator"));
29 qmlRegisterType<DashCommunicatorService>(uri, 0, 1, "DashCommunicatorService");
30 qmlRegisterType<DashCommunicatorService>(uri, 0, 1, "DashCommunicatorService");
30 qmlRegisterType<DashCommunicator>(uri, 0, 1, "DashCommunicator");
31 qmlRegisterType<DashCommunicator>(uri, 0, 1, "DashCommunicator");
plugins/Unity/Launcher/dbusinterface.cpp−4
@@ -32,10 +32,6 @@ DBusInterface::DBusInterface(LauncherModel *parent):
32{
32{
33}
33}
34
34
35−DBusInterface::~DBusInterface()
36−{
37−}
38−
39QString DBusInterface::introspect(const QString &path) const
35QString DBusInterface::introspect(const QString &path) const
40{
36{
41 /* This case we should just list the nodes */
37 /* This case we should just list the nodes */
plugins/Unity/Launcher/dbusinterface.h+1−1
@@ -27,7 +27,7 @@ class DBusInterface: public UnityDBusVirtualObject
27 Q_OBJECT
27 Q_OBJECT
28public:
28public:
29 DBusInterface(LauncherModel *parent);
29 DBusInterface(LauncherModel *parent);
30− ~DBusInterface();
30+ ~DBusInterface() = default;
31
31
32 // QDBusVirtualObject implementaition
32 // QDBusVirtualObject implementaition
33 QString introspect (const QString &path) const override;
33 QString introspect (const QString &path) const override;
plugins/Unity/Session/dbusunitysessionservice.cpp+47−55
@@ -18,77 +18,69 @@
18#include "dbusunitysessionservice.h"
18#include "dbusunitysessionservice.h"
19
19
20// Qt
20// Qt
21−#include <QDBusConnection>
21+#include <QDBusPendingCall>
22−#include <QDBusInterface>
23
22
24DBusUnitySessionService::DBusUnitySessionService()
23DBusUnitySessionService::DBusUnitySessionService()
25 : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
24 : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
26{
25{
27}
26}
28
27
29−DBusUnitySessionService::~DBusUnitySessionService()
30−{
31−}
32−
33void DBusUnitySessionService::Logout()
28void DBusUnitySessionService::Logout()
34{
29{
30+ // TODO ask the apps to quit and then emit the signal
35− Q_EMIT logoutReady();
31+ Q_EMIT logoutReady();
36}
32}
37
33
38void DBusUnitySessionService::EndSession()
34void DBusUnitySessionService::EndSession()
39{
35{
40− QDBusConnection connection = QDBusConnection::sessionBus();
36+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.ubuntu.Upstart",
41− QDBusInterface iface1 ("com.ubuntu.Upstart",
42− "/com/ubuntu/Upstart",
37+ "/com/ubuntu/Upstart",
43− "com.ubuntu.Upstart0_6",
38+ "com.ubuntu.Upstart0_6",
44− connection);
45−
46− iface1.call("EndSession");
39+ "EndSession");
40+ QDBusConnection::sessionBus().asyncCall(msg);
47}
41}
48
42
49void DBusUnitySessionService::RequestLogout()
43void DBusUnitySessionService::RequestLogout()
50{
44{
51− Q_EMIT logoutRequested(false);
45+ Q_EMIT logoutRequested(false);
52}
46}
53
47
54void DBusUnitySessionService::Reboot()
48void DBusUnitySessionService::Reboot()
55{
49{
56− QDBusConnection connection = QDBusConnection::systemBus();
50+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.login1",
57− QDBusInterface iface1 ("org.freedesktop.login1",
58− "/org/freedesktop/login1",
51+ "/org/freedesktop/login1",
59− "org.freedesktop.login1.Manager",
52+ "org.freedesktop.login1.Manager",
60− connection);
61−
62− iface1.call("Reboot", false);
53+ "Reboot");
54+ msg << false;
55+ QDBusConnection::systemBus().asyncCall(msg);
63}
56}
64
57
65void DBusUnitySessionService::RequestReboot()
58void DBusUnitySessionService::RequestReboot()
66{
59{
67− Q_EMIT rebootRequested(false);
60+ Q_EMIT rebootRequested(false);
68}
61}
69
62
70void DBusUnitySessionService::Shutdown()
63void DBusUnitySessionService::Shutdown()
71{
64{
72− QDBusConnection connection = QDBusConnection::systemBus();
65+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.login1",
73− QDBusInterface iface1 ("org.freedesktop.login1",
74− "/org/freedesktop/login1",
66+ "/org/freedesktop/login1",
75− "org.freedesktop.login1.Manager",
67+ "org.freedesktop.login1.Manager",
76− connection);
77−
78− iface1.call("PowerOff", false);
68+ "PowerOff");
69+ msg << false;
70+ QDBusConnection::systemBus().asyncCall(msg);
79}
71}
80
72
81void DBusUnitySessionService::RequestShutdown()
73void DBusUnitySessionService::RequestShutdown()
82{
74{
83− Q_EMIT shutdownRequested(false);
75+ Q_EMIT shutdownRequested(false);
84}
76}
85
77
86enum class Action : unsigned
78enum class Action : unsigned
87{
79{
88− LOGOUT = 0,
80+ LOGOUT = 0,
89− SHUTDOWN,
81+ SHUTDOWN,
90− REBOOT,
82+ REBOOT,
91− NONE
83+ NONE
92};
84};
93
85
94DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
86DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
@@ -96,38 +88,38 @@ DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
96{
88{
97}
89}
98
90
99−DBusGnomeSessionManagerWrapper::~DBusGnomeSessionManagerWrapper()
91+void DBusGnomeSessionManagerWrapper::performAsyncCall(const QString &method)
100{
92{
93+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.canonical.Unity",
94+ "/com/canonical/Unity/Session",
95+ "com.canonical.Unity.Session",
96+ method);
97+ QDBusConnection::sessionBus().asyncCall(msg);
101}
98}
102
99
103void DBusGnomeSessionManagerWrapper::Open(const unsigned type, const unsigned arg_1, const unsigned max_wait, const QList<QDBusObjectPath> &inhibitors)
100void DBusGnomeSessionManagerWrapper::Open(const unsigned type, const unsigned arg_1, const unsigned max_wait, const QList<QDBusObjectPath> &inhibitors)
104{
101{
105− Q_UNUSED(arg_1);
102+ Q_UNUSED(arg_1);
106− Q_UNUSED(max_wait);
103+ Q_UNUSED(max_wait);
107− Q_UNUSED(inhibitors);
104+ Q_UNUSED(inhibitors);
108−
109− QDBusConnection connection = QDBusConnection::sessionBus();
110− QDBusInterface iface1 ("com.canonical.Unity",
111− "/com/canonical/Unity/Session",
112− "com.canonical.Unity.Session",
113− connection);
114
105
115− Action action = (Action)type;
106+ const Action action = (Action)type;
116
107
117− switch (action)
108+ switch (action)
118− {
109+ {
119 case Action::LOGOUT:
110 case Action::LOGOUT:
120− iface1.call("RequestLogout");
111+ performAsyncCall("RequestLogout");
121− break;
112+ break;
122
113
123 case Action::REBOOT:
114 case Action::REBOOT:
124− iface1.call("RequestShutdown");
115+ performAsyncCall("RequestReboot");
125− break;
116+ break;
126
117
127 case Action::SHUTDOWN:
118 case Action::SHUTDOWN:
119+ performAsyncCall("RequestShutdown");
128− break;
120+ break;
129
121
130 default:
122 default:
131− break;
123+ break;
132− }
124+ }
133}
125}
plugins/Unity/Session/dbusunitysessionservice.h+11−8
@@ -38,7 +38,7 @@ class DBusUnitySessionService : public UnityDBusObject
38
38
39public:
39public:
40 DBusUnitySessionService();
40 DBusUnitySessionService();
41− ~DBusUnitySessionService();
41+ ~DBusUnitySessionService() = default;
42
42
43 // For use in QML. Javascript doesn't accept functions beginning with capital letters
43 // For use in QML. Javascript doesn't accept functions beginning with capital letters
44 Q_INVOKABLE void logout() { Logout(); }
44 Q_INVOKABLE void logout() { Logout(); }
@@ -90,7 +90,7 @@ public Q_SLOTS:
90 /**
90 /**
91 * Logout the system.
91 * Logout the system.
92 *
92 *
93− * This method directly logout the system without user's confirmation.
93+ * This method directly logs out the system without user's confirmation.
94 * Ordinary applications should avoid calling this method. Please call
94 * Ordinary applications should avoid calling this method. Please call
95 * RequestLogout() to ask the user to decide logout or not.
95 * RequestLogout() to ask the user to decide logout or not.
96 */
96 */
@@ -99,7 +99,7 @@ public Q_SLOTS:
99 /**
99 /**
100 * Reboot the system.
100 * Reboot the system.
101 *
101 *
102− * This method directly reboot the system without user's confirmation.
102+ * This method directly reboots the system without user's confirmation.
103 * Ordinary applications should avoid calling this method. Please call
103 * Ordinary applications should avoid calling this method. Please call
104 * RequestReboot() to ask the user to decide reboot or not.
104 * RequestReboot() to ask the user to decide reboot or not.
105 */
105 */
@@ -108,7 +108,7 @@ public Q_SLOTS:
108 /**
108 /**
109 * Shutdown the system.
109 * Shutdown the system.
110 *
110 *
111− * This method directly shutdown the system without user's confirmation.
111+ * This method directly shuts down the system without user's confirmation.
112 * Ordinary applications should avoid calling this method. Please call
112 * Ordinary applications should avoid calling this method. Please call
113 * RequestShutdown() to ask the user to decide shutdown or not.
113 * RequestShutdown() to ask the user to decide shutdown or not.
114 */
114 */
@@ -117,7 +117,7 @@ public Q_SLOTS:
117 /**
117 /**
118 * Issue a logout request.
118 * Issue a logout request.
119 *
119 *
120− * This method emit the logoutRequested signal to the shell with a boolean
120+ * This method emits the logoutRequested signal to the shell with a boolean
121 * which indicates if there's any inhibitors. The shell should receive
121 * which indicates if there's any inhibitors. The shell should receive
122 * this signal and display a dialog to ask the user to confirm the logout
122 * this signal and display a dialog to ask the user to confirm the logout
123 * action. If confirmed, shell can call Logout() method to logout.
123 * action. If confirmed, shell can call Logout() method to logout.
@@ -127,7 +127,7 @@ public Q_SLOTS:
127 /**
127 /**
128 * Issue a reboot request.
128 * Issue a reboot request.
129 *
129 *
130− * This method emit the rebootRequested signal to the shell with a boolean
130+ * This method emist the rebootRequested signal to the shell with a boolean
131 * which indicates if there's any inhibitors. The shell should receive
131 * which indicates if there's any inhibitors. The shell should receive
132 * this signal and display a dialog to ask the user to confirm the reboot
132 * this signal and display a dialog to ask the user to confirm the reboot
133 * action. If confirmed, shell can call Reboot() method to reboot
133 * action. If confirmed, shell can call Reboot() method to reboot
@@ -137,7 +137,7 @@ public Q_SLOTS:
137 /**
137 /**
138 * Issue a shutdown request.
138 * Issue a shutdown request.
139 *
139 *
140− * This method emit the shutdownRequested signal to the shell with a
140+ * This method emits the shutdownRequested signal to the shell with a
141 * boolean which indicates if there's any inhibitors.
141 * boolean which indicates if there's any inhibitors.
142 * The shell should receive
142 * The shell should receive
143 * this signal and display a dialog to ask the user to confirm the reboot
143 * this signal and display a dialog to ask the user to confirm the reboot
@@ -161,9 +161,12 @@ class DBusGnomeSessionManagerWrapper : public UnityDBusObject
161
161
162public:
162public:
163 DBusGnomeSessionManagerWrapper();
163 DBusGnomeSessionManagerWrapper();
164− ~DBusGnomeSessionManagerWrapper();
164+ ~DBusGnomeSessionManagerWrapper() = default;
165
165
166public Q_SLOTS:
166public Q_SLOTS:
167 Q_SCRIPTABLE void Open(const unsigned int type, const unsigned int arg_1, const unsigned int max_wait, const QList<QDBusObjectPath> &inhibitors);
167 Q_SCRIPTABLE void Open(const unsigned int type, const unsigned int arg_1, const unsigned int max_wait, const QList<QDBusObjectPath> &inhibitors);
168+
169+private:
170+ void performAsyncCall(const QString &method);
168};
171};
169#endif // DBUSUNITYSESSIONSERVICE_H
172#endif // DBUSUNITYSESSIONSERVICE_H
plugins/Wizard/System.cpp+13−9
@@ -16,7 +16,9 @@
16
16
17#include "System.h"
17#include "System.h"
18
18
19−#include <QDBusInterface>
19+#include <QDBusPendingCall>
20+#include <QDBusMessage>
21+#include <QDBusConnection>
20#include <QDBusMetaType>
22#include <QDBusMetaType>
21#include <QDir>
23#include <QDir>
22#include <QFile>
24#include <QFile>
@@ -65,21 +67,23 @@ void System::setWizardEnabled(bool enabled)
65void System::setSessionVariable(const QString &variable, const QString &value)
67void System::setSessionVariable(const QString &variable, const QString &value)
66{
68{
67 // We need to update both upstart's and DBus's environment
69 // We need to update both upstart's and DBus's environment
68− QProcess::execute(QString("initctl set-env --global %1=%2").arg(variable, value));
70+ QProcess::startDetached(QStringLiteral("initctl set-env --global %1=%2").arg(variable, value));
69−
70− QDBusInterface iface("org.freedesktop.DBus",
71− "/org/freedesktop/DBus",
72− "org.freedesktop.DBus",
73− QDBusConnection::sessionBus());
74
71
75 QMap<QString,QString> valueMap;
72 QMap<QString,QString> valueMap;
76 valueMap.insert(variable, value);
73 valueMap.insert(variable, value);
74+
75+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.DBus",
76+ "/org/freedesktop/DBus",
77+ "org.freedesktop.DBus",
77− iface.call("UpdateActivationEnvironment", QVariant::fromValue(valueMap));
78+ "UpdateActivationEnvironment");
79+
80+ msg << QVariant::fromValue(valueMap);
81+ QDBusConnection::sessionBus().asyncCall(msg);
78}
82}
79
83
80void System::updateSessionLanguage(const QString &locale)
84void System::updateSessionLanguage(const QString &locale)
81{
85{
82− QString language = locale.split(".")[0];
86+ const QString language = locale.split(".")[0];
83
87
84 setSessionVariable("LANGUAGE", language);
88 setSessionVariable("LANGUAGE", language);
85 setSessionVariable("LANG", locale);
89 setSessionVariable("LANG", locale);
tests/plugins/AccountsService/client.cpp+10−20
@@ -94,8 +94,7 @@ private Q_SLOTS:
94
94
95 void testGetSetService()
95 void testGetSetService()
96 {
96 {
97− AccountsService session;
97+ AccountsService session(this, QTest::currentTestFunction());
98− session.setUser(QTest::currentTestFunction());
99
98
100 QCOMPARE(session.demoEdges(), false);
99 QCOMPARE(session.demoEdges(), false);
101 session.setDemoEdges(true);
100 session.setDemoEdges(true);
@@ -112,8 +111,7 @@ private Q_SLOTS:
112
111
113 void testAsynchornousChangeForDemoEdges()
112 void testAsynchornousChangeForDemoEdges()
114 {
113 {
115− AccountsService session;
114+ AccountsService session(this, QTest::currentTestFunction());
116− session.setUser(QTest::currentTestFunction());
117
115
118 QCOMPARE(session.demoEdges(), false);
116 QCOMPARE(session.demoEdges(), false);
119 ASSERT_DBUS_CALL(m_userInterface->call("Set",
117 ASSERT_DBUS_CALL(m_userInterface->call("Set",
@@ -125,8 +123,7 @@ private Q_SLOTS:
125
123
126 void testAsynchornousChangeForFailedLogins()
124 void testAsynchornousChangeForFailedLogins()
127 {
125 {
128− AccountsService session;
126+ AccountsService session(this, QTest::currentTestFunction());
129− session.setUser(QTest::currentTestFunction());
130
127
131 QCOMPARE(session.failedLogins(), (uint)0);
128 QCOMPARE(session.failedLogins(), (uint)0);
132 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
129 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
@@ -138,8 +135,7 @@ private Q_SLOTS:
138
135
139 void testAsynchornousChangeForStatsWelcomeScreen()
136 void testAsynchornousChangeForStatsWelcomeScreen()
140 {
137 {
141− AccountsService session;
138+ AccountsService session(this, QTest::currentTestFunction());
142− session.setUser(QTest::currentTestFunction());
143
139
144 QCOMPARE(session.statsWelcomeScreen(), true);
140 QCOMPARE(session.statsWelcomeScreen(), true);
145 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
141 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
@@ -151,8 +147,7 @@ private Q_SLOTS:
151
147
152 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
148 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
153 {
149 {
154− AccountsService session;
150+ AccountsService session(this, QTest::currentTestFunction());
155− session.setUser(QTest::currentTestFunction());
156
151
157 QCOMPARE(session.enableLauncherWhileLocked(), true);
152 QCOMPARE(session.enableLauncherWhileLocked(), true);
158 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
153 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
@@ -164,8 +159,7 @@ private Q_SLOTS:
164
159
165 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
160 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
166 {
161 {
167− AccountsService session;
162+ AccountsService session(this, QTest::currentTestFunction());
168− session.setUser(QTest::currentTestFunction());
169
163
170 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
164 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
171 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
165 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
@@ -177,8 +171,7 @@ private Q_SLOTS:
177
171
178 void testAsynchornousChangeForStatsPasswordDisplayHint()
172 void testAsynchornousChangeForStatsPasswordDisplayHint()
179 {
173 {
180− AccountsService session;
174+ AccountsService session(this, QTest::currentTestFunction());
181− session.setUser(QTest::currentTestFunction());
182
175
183 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
176 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
184 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
177 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
@@ -190,8 +183,7 @@ private Q_SLOTS:
190
183
191 void testAsynchornousChangeForStatsLicenseAccepted()
184 void testAsynchornousChangeForStatsLicenseAccepted()
192 {
185 {
193− AccountsService session;
186+ AccountsService session(this, QTest::currentTestFunction());
194− session.setUser(QTest::currentTestFunction());
195
187
196 QCOMPARE(session.hereEnabled(), false);
188 QCOMPARE(session.hereEnabled(), false);
197 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
189 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
@@ -203,8 +195,7 @@ private Q_SLOTS:
203
195
204 void testAsynchornousChangeForLicenseBasePath()
196 void testAsynchornousChangeForLicenseBasePath()
205 {
197 {
206− AccountsService session;
198+ AccountsService session(this, QTest::currentTestFunction());
207− session.setUser(QTest::currentTestFunction());
208
199
209 QCOMPARE(session.hereLicensePath(), QString());
200 QCOMPARE(session.hereLicensePath(), QString());
210 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
201 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
@@ -216,8 +207,7 @@ private Q_SLOTS:
216
207
217 void testAsynchornousChangeForStatsBackgroundFile()
208 void testAsynchornousChangeForStatsBackgroundFile()
218 {
209 {
219− AccountsService session;
210+ AccountsService session(this, QTest::currentTestFunction());
220− session.setUser(QTest::currentTestFunction());
221
211
222 QCOMPARE(session.backgroundFile(), QString());
212 QCOMPARE(session.backgroundFile(), QString());
223 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
213 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
tests/plugins/Unity/Session/sessionbackendtest.cpp+27−40
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013-2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
15 *
15 *
16 * Authors:
16 * Authors:
17 * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
17 * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
18+ * Lukáš Tinkl <lukas.tinkl@canonical.com>
18 */
19 */
19
20
20#include <QtTest>
21#include <QtTest>
@@ -49,17 +50,22 @@ private Q_SLOTS:
49
50
50 void testUnitySessionLogoutRequested_data() {
51 void testUnitySessionLogoutRequested_data() {
51 QTest::addColumn<QString>("method");
52 QTest::addColumn<QString>("method");
53+ QTest::addColumn<QString>("signal");
52
54
53− QTest::newRow("Logout") << "RequestLogout";
55+ QTest::newRow("Logout") << "RequestLogout" << "logoutRequested(bool)";
56+ QTest::newRow("Reboot") << "RequestReboot" << "rebootRequested(bool)";
57+ QTest::newRow("Shutdown") << "RequestShutdown" << "shutdownRequested(bool)";
54 }
58 }
55
59
56 void testUnitySessionLogoutRequested() {
60 void testUnitySessionLogoutRequested() {
57 QFETCH(QString, method);
61 QFETCH(QString, method);
62+ QFETCH(QString, signal);
58
63
59 DBusUnitySessionService dbusUnitySessionService;
64 DBusUnitySessionService dbusUnitySessionService;
60 QCoreApplication::processEvents(); // to let the service register on DBus
65 QCoreApplication::processEvents(); // to let the service register on DBus
61
66
67+ // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
62− QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
68+ QSignalSpy spy(&dbusUnitySessionService, signal.prepend(QSIGNAL_CODE).toLocal8Bit().constData());
63
69
64 QDBusReply<void> reply = dbusUnitySession->call(method);
70 QDBusReply<void> reply = dbusUnitySession->call(method);
65 QCOMPARE(reply.isValid(), true);
71 QCOMPARE(reply.isValid(), true);
@@ -67,51 +73,34 @@ private Q_SLOTS:
67 QCOMPARE(spy.count(), 1);
73 QCOMPARE(spy.count(), 1);
68 }
74 }
69
75
70− void testGnomeSessionWrapperLogoutRequested() {
76+ void testGnomeSessionWrapper_data() {
71− DBusUnitySessionService dbusUnitySessionService;
77+ QTest::addColumn<uint>("method");
72− QCoreApplication::processEvents(); // to let the service register on DBus
78+ QTest::addColumn<QString>("signal");
73−
74− // Spy on the logoutRequested signal on the /com/canonical/Unity/Session object
75− // as proof we are actually calling the actual method.
76− QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
77
79
78− DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
80+ QTest::newRow("Logout") << (uint)Action::LOGOUT << "logoutRequested(bool)";
79− QCoreApplication::processEvents(); // to let the service register on DBus
81+ QTest::newRow("Shutdown") << (unsigned)Action::SHUTDOWN << "shutdownRequested(bool)";
80−
82+ QTest::newRow("Reboot") << (unsigned)Action::REBOOT << "rebootRequested(bool)";
81− QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
82− "/org/gnome/SessionManager/EndSessionDialog",
83− "org.gnome.SessionManager.EndSessionDialog",
84− QDBusConnection::sessionBus());
85−
86− QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
87−
88− // Set the QVariant as a QList<QDBusObjectPath> type
89− QDbusList var;
90− QVariant inhibitors;
91− inhibitors.setValue(var);
92−
93− QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::LOGOUT, (unsigned)0, (unsigned)0, inhibitors);
94− QCOMPARE(reply.isValid(), true);
95−
96− // Make sure we see the signal being emitted.
97− QCOMPARE(spy.count(), 1);
98 }
83 }
99
84
100− void testGnomeSessionWrapperShutdownRequested() {
85+ void testGnomeSessionWrapper() {
86+ QFETCH(uint, method);
87+ QFETCH(QString, signal);
88+
101 DBusUnitySessionService dbusUnitySessionService;
89 DBusUnitySessionService dbusUnitySessionService;
102 QCoreApplication::processEvents(); // to let the service register on DBus
90 QCoreApplication::processEvents(); // to let the service register on DBus
103
91
104− // Spy on the shutdownRequested signal on the /com/canonical/Unity/Session object
92+ // Spy on the given signal on the /com/canonical/Unity/Session object
105 // as proof we are actually calling the actual method.
93 // as proof we are actually calling the actual method.
94+ // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
106− QSignalSpy spy(&dbusUnitySessionService, SIGNAL(shutdownRequested(bool)));
95+ QSignalSpy spy(&dbusUnitySessionService, signal.prepend(QSIGNAL_CODE).toLocal8Bit().constData());
107
96
108 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
97 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
109 QCoreApplication::processEvents(); // to let the service register on DBus
98 QCoreApplication::processEvents(); // to let the service register on DBus
110
99
111− QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
100+ QDBusInterface dbusGnomeSessionWrapper("com.canonical.Unity",
112− "/org/gnome/SessionManager/EndSessionDialog",
101+ "/org/gnome/SessionManager/EndSessionDialog",
113− "org.gnome.SessionManager.EndSessionDialog",
102+ "org.gnome.SessionManager.EndSessionDialog",
114− QDBusConnection::sessionBus());
103+ QDBusConnection::sessionBus());
115
104
116 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
105 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
117
106
@@ -120,9 +109,7 @@ private Q_SLOTS:
120 QVariant inhibitors;
109 QVariant inhibitors;
121 inhibitors.setValue(var);
110 inhibitors.setValue(var);
122
111
123− // * Reboot action translates to the shutdown signal due to some weird idiosyncracy
124− // in the indicator-session/Unity interaction. *
125− QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::REBOOT, (unsigned)0, (unsigned)0, inhibitors);
112+ QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", method, (unsigned)0, (unsigned)0, inhibitors);
126 QCOMPARE(reply.isValid(), true);
113 QCOMPARE(reply.isValid(), true);
127
114
128 // Make sure we see the signal being emitted.
115 // Make sure we see the signal being emitted.