Merge lp:~lukas-kde/unity8/asyncDbusCalls into lp:unity8

Proposed by Lukáš Tinkl on 2015-06-18
Status: Merged
Approved by: Michael Zanetti on 2015-07-03
Approved revision: 1804
Merged at revision: 1864
Proposed branch: lp:~lukas-kde/unity8/asyncDbusCalls
Merge into: lp:unity8
Prerequisite: lp:~lukas-kde/unity8/highdpi-mousetouchadaptor
Diff against target: 1038 lines (+180/-218)
18 files modified
plugins/AccountsService/AccountsService.cpp (+31/-42)
plugins/AccountsService/AccountsService.h (+4/-3)
plugins/AccountsService/AccountsServiceDBusAdaptor.cpp (+13/-11)
plugins/AccountsService/AccountsServiceDBusAdaptor.h (+3/-2)
plugins/Lights/Lights.cpp (+1/-1)
plugins/Ubuntu/SystemImage/SystemImage.cpp (+7/-8)
plugins/Ubuntu/SystemImage/SystemImage.h (+1/-5)
plugins/Unity/Connectivity/Connectivity.cpp (+5/-5)
plugins/Unity/Connectivity/Connectivity.h (+1/-0)
plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.h (+1/-1)
plugins/Unity/DashCommunicator/plugin.cpp (+1/-0)
plugins/Unity/Launcher/dbusinterface.cpp (+0/-4)
plugins/Unity/Launcher/dbusinterface.h (+1/-1)
plugins/Unity/Session/dbusunitysessionservice.cpp (+49/-57)
plugins/Unity/Session/dbusunitysessionservice.h (+11/-8)
plugins/Wizard/System.cpp (+13/-9)
tests/plugins/AccountsService/client.cpp (+10/-20)
tests/plugins/Unity/Session/sessionbackendtest.cpp (+28/-41)
To merge this branch: bzr merge lp:~lukas-kde/unity8/asyncDbusCalls
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration 2015-06-18 Needs Fixing on 2015-07-15
Michael Zanetti (community) 2015-06-18 Approve on 2015-07-03
Review via email: mp+262322@code.launchpad.net

This proposal supersedes a proposal from 2015-06-12.

Commit Message

Avoid sync DBUS calls

Description of the Change

Perform DBUS calls asynchronously; extended the DBUS UnitySession tests to cover all of reboot/logout/shutdown

* Are there any related MPs required for this MP to build/function as expected? Please list.

No

 * Did you perform an exploratory manual test run of your code change and any related functionality?

Yes

 * Did you make sure that your branch does not contain spurious tags?

Yes

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

N/A

 * If you changed the UI, has there been a design review?

N/A

 * Did you have a look at the warnings when running tests? Can they be reduced?

To post a comment you must log in.
Daniel d'Andrada (dandrader) wrote : Posted in a previous version of this proposal

"""
878 - * This method emit the rebootRequested signal to the shell with a boolean
879 + * This method emist the rebootRequested signal to the shell with a boolean
"""

s/emist/emits

Daniel d'Andrada (dandrader) wrote : Posted in a previous version of this proposal

You have to either add lp:~lukas-kde/unity8/highdpi-mousetouchadaptor as a prerequisite or remove its commit from this branch.

Lukáš Tinkl (lukas-kde) wrote : Posted in a previous version of this proposal

> """
> 878 - * This method emit the rebootRequested signal to the shell with
> a boolean
> 879 + * This method emist the rebootRequested signal to the shell with
> a boolean
> """
>
> s/emist/emits

Fixed

Lukáš Tinkl (lukas-kde) wrote :

Done, resubmitted with the prereq branch

Lukáš Tinkl (lukas-kde) wrote :

Should be good to go

Michael Zanetti (mzanetti) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?

yes

 * Did CI run pass? If not, please explain why.

yes

 * Did you make sure that the branch does not contain spurious tags?

yes

review: Approve
Michael Zanetti (mzanetti) wrote :

for some reason this prevents the phone from suspending the screen. Pulled out from silo.

review: Needs Fixing
Lukáš Tinkl (lukas-kde) wrote :

Should be fixed now, verifiable from silo 048

Michael Zanetti (mzanetti) wrote :

ok. reapproving as per previous review (only reverts since then)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/AccountsService/AccountsService.cpp'
2--- plugins/AccountsService/AccountsService.cpp 2015-04-17 16:39:32 +0000
3+++ plugins/AccountsService/AccountsService.cpp 2015-07-02 19:12:53 +0000
4@@ -23,10 +23,9 @@
5 #include <QStringList>
6 #include <QDebug>
7
8-AccountsService::AccountsService(QObject* parent)
9- : QObject(parent),
10+AccountsService::AccountsService(QObject* parent, const QString &user)
11+ : QObject(parent),
12 m_service(new AccountsServiceDBusAdaptor(this)),
13- m_user(""),
14 m_demoEdges(false),
15 m_enableLauncherWhileLocked(false),
16 m_enableIndicatorsWhileLocked(false),
17@@ -36,12 +35,10 @@
18 m_hereEnabled(false),
19 m_hereLicensePath() // null means not set yet
20 {
21- connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
22- this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
23- connect(m_service, SIGNAL(maybeChanged(const QString &)),
24- this, SLOT(maybeChanged(const QString &)));
25+ connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
26+ connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
27
28- setUser(qgetenv("USER"));
29+ setUser(!user.isEmpty() ? user : QString::fromUtf8(qgetenv("USER")));
30 }
31
32 QString AccountsService::user() const
33@@ -173,19 +170,18 @@
34 connect(watcher, &QDBusPendingCallWatcher::finished,
35 this, [this](QDBusPendingCallWatcher* watcher) {
36
37- QDBusPendingReply<QDBusVariant> reply = *watcher;
38+ QDBusPendingReply<QVariant> reply = *watcher;
39+ watcher->deleteLater();
40 if (reply.isError()) {
41 qWarning() << "Failed to get 'EnableLauncherWhileLocked' property - " << reply.error().message();
42- watcher->deleteLater();
43 return;
44 }
45
46- auto enableLauncherWhileLocked = reply.value().variant().toBool();
47+ const bool enableLauncherWhileLocked = reply.value().toBool();
48 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
49 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
50 Q_EMIT enableLauncherWhileLockedChanged();
51 }
52- watcher->deleteLater();
53 });
54 if (!async) {
55 watcher->waitForFinished();
56@@ -203,19 +199,18 @@
57 connect(watcher, &QDBusPendingCallWatcher::finished,
58 this, [this](QDBusPendingCallWatcher* watcher) {
59
60- QDBusPendingReply<QDBusVariant> reply = *watcher;
61+ QDBusPendingReply<QVariant> reply = *watcher;
62+ watcher->deleteLater();
63 if (reply.isError()) {
64 qWarning() << "Failed to get 'EnableIndicatorsWhileLocked' property - " << reply.error().message();
65- watcher->deleteLater();
66 return;
67 }
68
69- auto enableIndicatorsWhileLocked = reply.value().variant().toBool();
70+ const bool enableIndicatorsWhileLocked = reply.value().toBool();
71 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
72 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
73 Q_EMIT enableIndicatorsWhileLockedChanged();
74 }
75- watcher->deleteLater();
76 });
77 if (!async) {
78 watcher->waitForFinished();
79@@ -233,19 +228,18 @@
80 connect(watcher, &QDBusPendingCallWatcher::finished,
81 this, [this](QDBusPendingCallWatcher* watcher) {
82
83- QDBusPendingReply<QDBusVariant> reply = *watcher;
84+ QDBusPendingReply<QVariant> reply = *watcher;
85+ watcher->deleteLater();
86 if (reply.isError()) {
87 qWarning() << "Failed to get 'BackgroundFile' property - " << reply.error().message();
88- watcher->deleteLater();
89 return;
90 }
91
92- auto backgroundFile = reply.value().variant().toString();
93+ const QString backgroundFile = reply.value().toString();
94 if (m_backgroundFile != backgroundFile) {
95 m_backgroundFile = backgroundFile;
96 Q_EMIT backgroundFileChanged();
97 }
98- watcher->deleteLater();
99 });
100 if (!async) {
101 watcher->waitForFinished();
102@@ -263,19 +257,18 @@
103 connect(watcher, &QDBusPendingCallWatcher::finished,
104 this, [this](QDBusPendingCallWatcher* watcher) {
105
106- QDBusPendingReply<QDBusVariant> reply = *watcher;
107+ QDBusPendingReply<QVariant> reply = *watcher;
108+ watcher->deleteLater();
109 if (reply.isError()) {
110 qWarning() << "Failed to get 'StatsWelcomeScreen' property - " << reply.error().message();
111- watcher->deleteLater();
112 return;
113 }
114
115- auto statsWelcomeScreen = reply.value().variant().toBool();
116+ const bool statsWelcomeScreen = reply.value().toBool();
117 if (m_statsWelcomeScreen != statsWelcomeScreen) {
118 m_statsWelcomeScreen = statsWelcomeScreen;
119 Q_EMIT statsWelcomeScreenChanged();
120 }
121- watcher->deleteLater();
122 });
123 if (!async) {
124 watcher->waitForFinished();
125@@ -293,19 +286,18 @@
126 connect(watcher, &QDBusPendingCallWatcher::finished,
127 this, [this](QDBusPendingCallWatcher* watcher) {
128
129- QDBusPendingReply<QDBusVariant> reply = *watcher;
130+ QDBusPendingReply<QVariant> reply = *watcher;
131+ watcher->deleteLater();
132 if (reply.isError()) {
133 qWarning() << "Failed to get 'PasswordDisplayHint' property - " << reply.error().message();
134- watcher->deleteLater();
135 return;
136 }
137
138- PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().variant().toInt();
139+ const PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)reply.value().toInt();
140 if (m_passwordDisplayHint != passwordDisplayHint) {
141 m_passwordDisplayHint = passwordDisplayHint;
142 Q_EMIT passwordDisplayHintChanged();
143 }
144- watcher->deleteLater();
145 });
146 if (!async) {
147 watcher->waitForFinished();
148@@ -323,19 +315,18 @@
149 connect(watcher, &QDBusPendingCallWatcher::finished,
150 this, [this](QDBusPendingCallWatcher* watcher) {
151
152- QDBusPendingReply<QDBusVariant> reply = *watcher;
153+ QDBusPendingReply<QVariant> reply = *watcher;
154+ watcher->deleteLater();
155 if (reply.isError()) {
156 qWarning() << "Failed to get 'FailedLogins' property - " << reply.error().message();
157- watcher->deleteLater();
158 return;
159 }
160
161- uint failedLogins = reply.value().variant().toUInt();
162+ const uint failedLogins = reply.value().toUInt();
163 if (m_failedLogins != failedLogins) {
164 m_failedLogins = failedLogins;
165 Q_EMIT failedLoginsChanged();
166 }
167- watcher->deleteLater();
168 });
169 if (!async) {
170 watcher->waitForFinished();
171@@ -353,19 +344,18 @@
172 connect(watcher, &QDBusPendingCallWatcher::finished,
173 this, [this](QDBusPendingCallWatcher* watcher) {
174
175- QDBusPendingReply<QDBusVariant> reply = *watcher;
176+ QDBusPendingReply<QVariant> reply = *watcher;
177+ watcher->deleteLater();
178 if (reply.isError()) {
179 qWarning() << "Failed to get 'LicenseAccepted' property - " << reply.error().message();
180- watcher->deleteLater();
181 return;
182 }
183
184- auto hereEnabled = reply.value().variant().toBool();
185+ const bool hereEnabled = reply.value().toBool();
186 if (m_hereEnabled != hereEnabled) {
187 m_hereEnabled = hereEnabled;
188 Q_EMIT hereEnabledChanged();
189 }
190- watcher->deleteLater();
191 });
192 if (!async) {
193 watcher->waitForFinished();
194@@ -383,14 +373,14 @@
195 connect(watcher, &QDBusPendingCallWatcher::finished,
196 this, [this](QDBusPendingCallWatcher* watcher) {
197
198- QDBusPendingReply<QDBusVariant> reply = *watcher;
199+ QDBusPendingReply<QVariant> reply = *watcher;
200+ watcher->deleteLater();
201 if (reply.isError()) {
202 qWarning() << "Failed to get 'LicenseBasePath' property - " << reply.error().message();
203- watcher->deleteLater();
204 return;
205 }
206
207- auto hereLicensePath = reply.value().variant().toString();
208+ QString hereLicensePath = reply.value().toString();
209 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
210 hereLicensePath = "";
211
212@@ -398,7 +388,6 @@
213 m_hereLicensePath = hereLicensePath;
214 Q_EMIT hereLicensePathChanged();
215 }
216- watcher->deleteLater();
217 });
218 if (!async) {
219 watcher->waitForFinished();
220@@ -421,7 +410,7 @@
221 }
222 }
223
224-void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
225+void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
226 {
227 if (m_user != user) {
228 return;
229@@ -459,7 +448,7 @@
230 }
231 }
232
233-void AccountsService::maybeChanged(const QString &user)
234+void AccountsService::onMaybeChanged(const QString &user)
235 {
236 if (m_user != user) {
237 return;
238
239=== modified file 'plugins/AccountsService/AccountsService.h'
240--- plugins/AccountsService/AccountsService.h 2015-04-09 16:20:15 +0000
241+++ plugins/AccountsService/AccountsService.h 2015-07-02 19:12:53 +0000
242@@ -72,7 +72,8 @@
243 Numeric,
244 };
245
246- explicit AccountsService(QObject *parent = 0);
247+ explicit AccountsService(QObject *parent = 0, const QString & user = QString());
248+ ~AccountsService() = default;
249
250 QString user() const;
251 void setUser(const QString &user);
252@@ -103,8 +104,8 @@
253 void hereLicensePathChanged();
254
255 private Q_SLOTS:
256- void propertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
257- void maybeChanged(const QString &user);
258+ void onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
259+ void onMaybeChanged(const QString &user);
260
261 private:
262 void updateDemoEdges(bool async = true);
263
264=== modified file 'plugins/AccountsService/AccountsServiceDBusAdaptor.cpp'
265--- plugins/AccountsService/AccountsServiceDBusAdaptor.cpp 2015-04-10 10:22:18 +0000
266+++ plugins/AccountsService/AccountsServiceDBusAdaptor.cpp 2015-07-02 19:12:53 +0000
267@@ -21,35 +21,35 @@
268 #include <QDBusConnectionInterface>
269 #include <QDBusMessage>
270 #include <QDBusVariant>
271+#include <QDebug>
272
273 AccountsServiceDBusAdaptor::AccountsServiceDBusAdaptor(QObject* parent)
274 : QObject(parent),
275 m_accountsManager(nullptr),
276- m_users(),
277 m_ignoreNextChanged(false)
278 {
279 QDBusConnection connection = QDBusConnection::SM_BUSNAME();
280 QDBusConnectionInterface *interface = connection.interface();
281 interface->startService("org.freedesktop.Accounts");
282 m_accountsManager = new QDBusInterface("org.freedesktop.Accounts",
283- "/org/freedesktop/Accounts",
284- "org.freedesktop.Accounts",
285- connection, this);
286+ "/org/freedesktop/Accounts",
287+ "org.freedesktop.Accounts",
288+ connection, this);
289 }
290
291 QVariant AccountsServiceDBusAdaptor::getUserProperty(const QString &user, const QString &interface, const QString &property)
292 {
293 QDBusInterface *iface = getUserInterface(user);
294 if (iface != nullptr && iface->isValid()) {
295- QDBusMessage answer = iface->call("Get", interface, property);
296- if (answer.type() == QDBusMessage::ReplyMessage) {
297- return answer.arguments()[0].value<QDBusVariant>().variant();
298+ QDBusReply<QVariant> answer = iface->call("Get", interface, property);
299+ if (answer.isValid()) {
300+ return answer;
301 }
302 }
303 return QVariant();
304 }
305
306-QDBusPendingReply<QDBusVariant> AccountsServiceDBusAdaptor::getUserPropertyAsync(const QString &user, const QString &interface, const QString &property)
307+QDBusPendingReply<QVariant> AccountsServiceDBusAdaptor::getUserPropertyAsync(const QString &user, const QString &interface, const QString &property)
308 {
309 QDBusInterface *iface = getUserInterface(user);
310 if (iface != nullptr && iface->isValid()) {
311@@ -116,9 +116,9 @@
312 {
313 QDBusInterface *iface = m_users.value(user);
314 if (iface == nullptr && m_accountsManager->isValid()) {
315- QDBusMessage answer = m_accountsManager->call("FindUserByName", user);
316- if (answer.type() == QDBusMessage::ReplyMessage) {
317- QString path = answer.arguments()[0].value<QDBusObjectPath>().path();
318+ QDBusReply<QDBusObjectPath> answer = m_accountsManager->asyncCall("FindUserByName", user);
319+ if (answer.isValid()) {
320+ const QString path = answer.value().path();
321
322 iface = new QDBusInterface("org.freedesktop.Accounts",
323 path,
324@@ -148,6 +148,8 @@
325 SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
326
327 m_users.insert(user, iface);
328+ } else {
329+ qWarning() << "Couldn't get user interface" << answer.error().name() << answer.error().message();
330 }
331 }
332 return iface;
333
334=== modified file 'plugins/AccountsService/AccountsServiceDBusAdaptor.h'
335--- plugins/AccountsService/AccountsServiceDBusAdaptor.h 2015-04-10 10:22:18 +0000
336+++ plugins/AccountsService/AccountsServiceDBusAdaptor.h 2015-07-02 19:12:53 +0000
337@@ -33,13 +33,14 @@
338
339 public:
340 explicit AccountsServiceDBusAdaptor(QObject *parent = 0);
341+ ~AccountsServiceDBusAdaptor() = default;
342
343 Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &interface, const QString &property);
344- Q_INVOKABLE QDBusPendingReply<QDBusVariant> getUserPropertyAsync(const QString &user, const QString &interface, const QString &property);
345+ Q_INVOKABLE QDBusPendingReply<QVariant> getUserPropertyAsync(const QString &user, const QString &interface, const QString &property);
346
347 template <typename T>
348 inline T getUserProperty(const QString &user, const QString &interface, const QString &property) {
349- QVariant variant = getUserProperty(user, interface, property);
350+ const QVariant variant = getUserProperty(user, interface, property);
351 if (variant.isValid() && variant.canConvert<QDBusArgument>()) {
352 return qdbus_cast<T>(variant.value<QDBusArgument>());
353 }
354
355=== modified file 'plugins/Lights/Lights.cpp'
356--- plugins/Lights/Lights.cpp 2014-12-12 14:16:10 +0000
357+++ plugins/Lights/Lights.cpp 2015-07-02 19:12:53 +0000
358@@ -71,7 +71,7 @@
359 if (m_color != color) {
360 m_color = color;
361 Q_EMIT colorChanged(m_color);
362- // FIXME: update the collor if the light is already on
363+ // FIXME: update the color if the light is already on
364 }
365 }
366
367
368=== modified file 'plugins/Ubuntu/SystemImage/SystemImage.cpp'
369--- plugins/Ubuntu/SystemImage/SystemImage.cpp 2014-07-30 11:08:29 +0000
370+++ plugins/Ubuntu/SystemImage/SystemImage.cpp 2015-07-02 19:12:53 +0000
371@@ -16,19 +16,18 @@
372
373 #include "SystemImage.h"
374 #include <QDBusConnection>
375-#include <QDBusInterface>
376+#include <QDBusPendingCall>
377
378 SystemImage::SystemImage(QObject *parent)
379- : QObject(parent),
380- m_interface(new QDBusInterface("com.canonical.SystemImage",
381- "/Service",
382- "com.canonical.SystemImage",
383- QDBusConnection::systemBus(),
384- this))
385+ : QObject(parent)
386 {
387 }
388
389 void SystemImage::factoryReset()
390 {
391- m_interface->call("FactoryReset");
392+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.canonical.SystemImage",
393+ "/Service",
394+ "com.canonical.SystemImage",
395+ "FactoryReset");
396+ QDBusConnection::systemBus().asyncCall(msg);
397 }
398
399=== modified file 'plugins/Ubuntu/SystemImage/SystemImage.h'
400--- plugins/Ubuntu/SystemImage/SystemImage.h 2014-07-30 11:08:29 +0000
401+++ plugins/Ubuntu/SystemImage/SystemImage.h 2015-07-02 19:12:53 +0000
402@@ -19,8 +19,6 @@
403
404 #include <QObject>
405
406-class QDBusInterface;
407-
408 class SystemImage : public QObject
409 {
410 Q_OBJECT
411@@ -28,11 +26,9 @@
412
413 public:
414 explicit SystemImage(QObject *parent = 0);
415+ ~SystemImage() = default;
416
417 Q_INVOKABLE void factoryReset();
418-
419-private:
420- QDBusInterface *m_interface;
421 };
422
423 #endif // SYSTEMIMAGE_H
424
425=== modified file 'plugins/Unity/Connectivity/Connectivity.cpp'
426--- plugins/Unity/Connectivity/Connectivity.cpp 2014-08-20 17:14:55 +0000
427+++ plugins/Unity/Connectivity/Connectivity.cpp 2015-07-02 19:12:53 +0000
428@@ -16,7 +16,6 @@
429
430 #include "Connectivity.h"
431 #include <QDBusConnection>
432-#include <QDBusInterface>
433 #include <QDBusPendingCall>
434
435 Connectivity::Connectivity(QObject *parent)
436@@ -26,8 +25,9 @@
437
438 void Connectivity::unlockAllModems()
439 {
440- QDBusInterface iface("com.ubuntu.connectivity1",
441- "/com/ubuntu/connectivity1/Private",
442- "com.ubuntu.connectivity1.Private");
443- iface.asyncCall("UnlockAllModems");
444+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.ubuntu.connectivity1",
445+ "/com/ubuntu/connectivity1/Private",
446+ "com.ubuntu.connectivity1.Private",
447+ "UnlockAllModems");
448+ QDBusConnection::sessionBus().asyncCall(msg);
449 }
450
451=== modified file 'plugins/Unity/Connectivity/Connectivity.h'
452--- plugins/Unity/Connectivity/Connectivity.h 2014-08-20 17:14:55 +0000
453+++ plugins/Unity/Connectivity/Connectivity.h 2015-07-02 19:12:53 +0000
454@@ -26,6 +26,7 @@
455
456 public:
457 explicit Connectivity(QObject *parent = 0);
458+ ~Connectivity() = default;
459
460 Q_INVOKABLE void unlockAllModems();
461 };
462
463=== modified file 'plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.h'
464--- plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.h 2014-10-30 21:43:18 +0000
465+++ plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.h 2015-07-02 19:12:53 +0000
466@@ -36,4 +36,4 @@
467
468 };
469
470-#endif // DBUSUNITYSESSIONSERVICE_H
471+#endif // DBUSDASHCOMMUNICATORSERVICE_H
472
473=== modified file 'plugins/Unity/DashCommunicator/plugin.cpp'
474--- plugins/Unity/DashCommunicator/plugin.cpp 2014-07-24 16:02:27 +0000
475+++ plugins/Unity/DashCommunicator/plugin.cpp 2015-07-02 19:12:53 +0000
476@@ -25,6 +25,7 @@
477
478 void DashCommunicatorPlugin::registerTypes(const char *uri)
479 {
480+ // @uri Unity.DashCommunicator
481 Q_ASSERT(uri == QStringLiteral("Unity.DashCommunicator"));
482 qmlRegisterType<DashCommunicatorService>(uri, 0, 1, "DashCommunicatorService");
483 qmlRegisterType<DashCommunicator>(uri, 0, 1, "DashCommunicator");
484
485=== modified file 'plugins/Unity/Launcher/dbusinterface.cpp'
486--- plugins/Unity/Launcher/dbusinterface.cpp 2014-11-04 12:53:23 +0000
487+++ plugins/Unity/Launcher/dbusinterface.cpp 2015-07-02 19:12:53 +0000
488@@ -32,10 +32,6 @@
489 {
490 }
491
492-DBusInterface::~DBusInterface()
493-{
494-}
495-
496 QString DBusInterface::introspect(const QString &path) const
497 {
498 /* This case we should just list the nodes */
499
500=== modified file 'plugins/Unity/Launcher/dbusinterface.h'
501--- plugins/Unity/Launcher/dbusinterface.h 2014-10-09 15:00:32 +0000
502+++ plugins/Unity/Launcher/dbusinterface.h 2015-07-02 19:12:53 +0000
503@@ -27,7 +27,7 @@
504 Q_OBJECT
505 public:
506 DBusInterface(LauncherModel *parent);
507- ~DBusInterface();
508+ ~DBusInterface() = default;
509
510 // QDBusVirtualObject implementaition
511 QString introspect (const QString &path) const override;
512
513=== modified file 'plugins/Unity/Session/dbusunitysessionservice.cpp'
514--- plugins/Unity/Session/dbusunitysessionservice.cpp 2015-03-02 12:11:03 +0000
515+++ plugins/Unity/Session/dbusunitysessionservice.cpp 2015-07-02 19:12:53 +0000
516@@ -18,77 +18,69 @@
517 #include "dbusunitysessionservice.h"
518
519 // Qt
520-#include <QDBusConnection>
521-#include <QDBusInterface>
522+#include <QDBusPendingCall>
523
524 DBusUnitySessionService::DBusUnitySessionService()
525 : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
526 {
527 }
528
529-DBusUnitySessionService::~DBusUnitySessionService()
530-{
531-}
532-
533 void DBusUnitySessionService::Logout()
534 {
535- Q_EMIT logoutReady();
536+ // TODO ask the apps to quit and then emit the signal
537+ Q_EMIT logoutReady();
538 }
539
540 void DBusUnitySessionService::EndSession()
541 {
542- QDBusConnection connection = QDBusConnection::sessionBus();
543- QDBusInterface iface1 ("com.ubuntu.Upstart",
544- "/com/ubuntu/Upstart",
545- "com.ubuntu.Upstart0_6",
546- connection);
547-
548- iface1.call("EndSession");
549+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.ubuntu.Upstart",
550+ "/com/ubuntu/Upstart",
551+ "com.ubuntu.Upstart0_6",
552+ "EndSession");
553+ QDBusConnection::sessionBus().asyncCall(msg);
554 }
555
556 void DBusUnitySessionService::RequestLogout()
557 {
558- Q_EMIT logoutRequested(false);
559+ Q_EMIT logoutRequested(false);
560 }
561
562 void DBusUnitySessionService::Reboot()
563 {
564- QDBusConnection connection = QDBusConnection::systemBus();
565- QDBusInterface iface1 ("org.freedesktop.login1",
566- "/org/freedesktop/login1",
567- "org.freedesktop.login1.Manager",
568- connection);
569-
570- iface1.call("Reboot", false);
571+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.login1",
572+ "/org/freedesktop/login1",
573+ "org.freedesktop.login1.Manager",
574+ "Reboot");
575+ msg << false;
576+ QDBusConnection::systemBus().asyncCall(msg);
577 }
578
579 void DBusUnitySessionService::RequestReboot()
580 {
581- Q_EMIT rebootRequested(false);
582+ Q_EMIT rebootRequested(false);
583 }
584
585 void DBusUnitySessionService::Shutdown()
586 {
587- QDBusConnection connection = QDBusConnection::systemBus();
588- QDBusInterface iface1 ("org.freedesktop.login1",
589- "/org/freedesktop/login1",
590- "org.freedesktop.login1.Manager",
591- connection);
592-
593- iface1.call("PowerOff", false);
594+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.login1",
595+ "/org/freedesktop/login1",
596+ "org.freedesktop.login1.Manager",
597+ "PowerOff");
598+ msg << false;
599+ QDBusConnection::systemBus().asyncCall(msg);
600 }
601
602 void DBusUnitySessionService::RequestShutdown()
603 {
604- Q_EMIT shutdownRequested(false);
605+ Q_EMIT shutdownRequested(false);
606 }
607
608 enum class Action : unsigned
609 {
610- LOGOUT = 0,
611- SHUTDOWN,
612- REBOOT,
613- NONE
614+ LOGOUT = 0,
615+ SHUTDOWN,
616+ REBOOT,
617+ NONE
618 };
619
620 DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
621@@ -96,38 +88,38 @@
622 {
623 }
624
625-DBusGnomeSessionManagerWrapper::~DBusGnomeSessionManagerWrapper()
626+void DBusGnomeSessionManagerWrapper::performAsyncCall(const QString &method)
627 {
628+ const QDBusMessage msg = QDBusMessage::createMethodCall("com.canonical.Unity",
629+ "/com/canonical/Unity/Session",
630+ "com.canonical.Unity.Session",
631+ method);
632+ QDBusConnection::sessionBus().asyncCall(msg);
633 }
634
635 void DBusGnomeSessionManagerWrapper::Open(const unsigned type, const unsigned arg_1, const unsigned max_wait, const QList<QDBusObjectPath> &inhibitors)
636 {
637- Q_UNUSED(arg_1);
638- Q_UNUSED(max_wait);
639- Q_UNUSED(inhibitors);
640-
641- QDBusConnection connection = QDBusConnection::sessionBus();
642- QDBusInterface iface1 ("com.canonical.Unity",
643- "/com/canonical/Unity/Session",
644- "com.canonical.Unity.Session",
645- connection);
646-
647- Action action = (Action)type;
648-
649- switch (action)
650- {
651+ Q_UNUSED(arg_1);
652+ Q_UNUSED(max_wait);
653+ Q_UNUSED(inhibitors);
654+
655+ const Action action = (Action)type;
656+
657+ switch (action)
658+ {
659 case Action::LOGOUT:
660- iface1.call("RequestLogout");
661- break;
662+ performAsyncCall("RequestLogout");
663+ break;
664
665 case Action::REBOOT:
666- iface1.call("RequestShutdown");
667- break;
668+ performAsyncCall("RequestReboot");
669+ break;
670
671 case Action::SHUTDOWN:
672- break;
673+ performAsyncCall("RequestShutdown");
674+ break;
675
676 default:
677- break;
678- }
679+ break;
680+ }
681 }
682
683=== modified file 'plugins/Unity/Session/dbusunitysessionservice.h'
684--- plugins/Unity/Session/dbusunitysessionservice.h 2015-03-02 12:11:03 +0000
685+++ plugins/Unity/Session/dbusunitysessionservice.h 2015-07-02 19:12:53 +0000
686@@ -38,7 +38,7 @@
687
688 public:
689 DBusUnitySessionService();
690- ~DBusUnitySessionService();
691+ ~DBusUnitySessionService() = default;
692
693 // For use in QML. Javascript doesn't accept functions beginning with capital letters
694 Q_INVOKABLE void logout() { Logout(); }
695@@ -90,7 +90,7 @@
696 /**
697 * Logout the system.
698 *
699- * This method directly logout the system without user's confirmation.
700+ * This method directly logs out the system without user's confirmation.
701 * Ordinary applications should avoid calling this method. Please call
702 * RequestLogout() to ask the user to decide logout or not.
703 */
704@@ -99,7 +99,7 @@
705 /**
706 * Reboot the system.
707 *
708- * This method directly reboot the system without user's confirmation.
709+ * This method directly reboots the system without user's confirmation.
710 * Ordinary applications should avoid calling this method. Please call
711 * RequestReboot() to ask the user to decide reboot or not.
712 */
713@@ -108,7 +108,7 @@
714 /**
715 * Shutdown the system.
716 *
717- * This method directly shutdown the system without user's confirmation.
718+ * This method directly shuts down the system without user's confirmation.
719 * Ordinary applications should avoid calling this method. Please call
720 * RequestShutdown() to ask the user to decide shutdown or not.
721 */
722@@ -117,7 +117,7 @@
723 /**
724 * Issue a logout request.
725 *
726- * This method emit the logoutRequested signal to the shell with a boolean
727+ * This method emits the logoutRequested signal to the shell with a boolean
728 * which indicates if there's any inhibitors. The shell should receive
729 * this signal and display a dialog to ask the user to confirm the logout
730 * action. If confirmed, shell can call Logout() method to logout.
731@@ -127,7 +127,7 @@
732 /**
733 * Issue a reboot request.
734 *
735- * This method emit the rebootRequested signal to the shell with a boolean
736+ * This method emits the rebootRequested signal to the shell with a boolean
737 * which indicates if there's any inhibitors. The shell should receive
738 * this signal and display a dialog to ask the user to confirm the reboot
739 * action. If confirmed, shell can call Reboot() method to reboot
740@@ -137,7 +137,7 @@
741 /**
742 * Issue a shutdown request.
743 *
744- * This method emit the shutdownRequested signal to the shell with a
745+ * This method emits the shutdownRequested signal to the shell with a
746 * boolean which indicates if there's any inhibitors.
747 * The shell should receive
748 * this signal and display a dialog to ask the user to confirm the reboot
749@@ -161,9 +161,12 @@
750
751 public:
752 DBusGnomeSessionManagerWrapper();
753- ~DBusGnomeSessionManagerWrapper();
754+ ~DBusGnomeSessionManagerWrapper() = default;
755
756 public Q_SLOTS:
757 Q_SCRIPTABLE void Open(const unsigned int type, const unsigned int arg_1, const unsigned int max_wait, const QList<QDBusObjectPath> &inhibitors);
758+
759+private:
760+ void performAsyncCall(const QString &method);
761 };
762 #endif // DBUSUNITYSESSIONSERVICE_H
763
764=== modified file 'plugins/Wizard/System.cpp'
765--- plugins/Wizard/System.cpp 2014-11-19 17:43:09 +0000
766+++ plugins/Wizard/System.cpp 2015-07-02 19:12:53 +0000
767@@ -16,7 +16,9 @@
768
769 #include "System.h"
770
771-#include <QDBusInterface>
772+#include <QDBusPendingCall>
773+#include <QDBusMessage>
774+#include <QDBusConnection>
775 #include <QDBusMetaType>
776 #include <QDir>
777 #include <QFile>
778@@ -65,21 +67,23 @@
779 void System::setSessionVariable(const QString &variable, const QString &value)
780 {
781 // We need to update both upstart's and DBus's environment
782- QProcess::execute(QString("initctl set-env --global %1=%2").arg(variable, value));
783-
784- QDBusInterface iface("org.freedesktop.DBus",
785- "/org/freedesktop/DBus",
786- "org.freedesktop.DBus",
787- QDBusConnection::sessionBus());
788+ QProcess::startDetached(QStringLiteral("initctl set-env --global %1=%2").arg(variable, value));
789
790 QMap<QString,QString> valueMap;
791 valueMap.insert(variable, value);
792- iface.call("UpdateActivationEnvironment", QVariant::fromValue(valueMap));
793+
794+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.DBus",
795+ "/org/freedesktop/DBus",
796+ "org.freedesktop.DBus",
797+ "UpdateActivationEnvironment");
798+
799+ msg << QVariant::fromValue(valueMap);
800+ QDBusConnection::sessionBus().asyncCall(msg);
801 }
802
803 void System::updateSessionLanguage(const QString &locale)
804 {
805- QString language = locale.split(".")[0];
806+ const QString language = locale.split(".")[0];
807
808 setSessionVariable("LANGUAGE", language);
809 setSessionVariable("LANG", locale);
810
811=== modified file 'tests/plugins/AccountsService/client.cpp'
812--- tests/plugins/AccountsService/client.cpp 2015-04-17 16:44:28 +0000
813+++ tests/plugins/AccountsService/client.cpp 2015-07-02 19:12:53 +0000
814@@ -94,8 +94,7 @@
815
816 void testGetSetService()
817 {
818- AccountsService session;
819- session.setUser(QTest::currentTestFunction());
820+ AccountsService session(this, QTest::currentTestFunction());
821
822 QCOMPARE(session.demoEdges(), false);
823 session.setDemoEdges(true);
824@@ -112,8 +111,7 @@
825
826 void testAsynchornousChangeForDemoEdges()
827 {
828- AccountsService session;
829- session.setUser(QTest::currentTestFunction());
830+ AccountsService session(this, QTest::currentTestFunction());
831
832 QCOMPARE(session.demoEdges(), false);
833 ASSERT_DBUS_CALL(m_userInterface->call("Set",
834@@ -125,8 +123,7 @@
835
836 void testAsynchornousChangeForFailedLogins()
837 {
838- AccountsService session;
839- session.setUser(QTest::currentTestFunction());
840+ AccountsService session(this, QTest::currentTestFunction());
841
842 QCOMPARE(session.failedLogins(), (uint)0);
843 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
844@@ -138,8 +135,7 @@
845
846 void testAsynchornousChangeForStatsWelcomeScreen()
847 {
848- AccountsService session;
849- session.setUser(QTest::currentTestFunction());
850+ AccountsService session(this, QTest::currentTestFunction());
851
852 QCOMPARE(session.statsWelcomeScreen(), true);
853 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
854@@ -151,8 +147,7 @@
855
856 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
857 {
858- AccountsService session;
859- session.setUser(QTest::currentTestFunction());
860+ AccountsService session(this, QTest::currentTestFunction());
861
862 QCOMPARE(session.enableLauncherWhileLocked(), true);
863 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
864@@ -164,8 +159,7 @@
865
866 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
867 {
868- AccountsService session;
869- session.setUser(QTest::currentTestFunction());
870+ AccountsService session(this, QTest::currentTestFunction());
871
872 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
873 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
874@@ -177,8 +171,7 @@
875
876 void testAsynchornousChangeForStatsPasswordDisplayHint()
877 {
878- AccountsService session;
879- session.setUser(QTest::currentTestFunction());
880+ AccountsService session(this, QTest::currentTestFunction());
881
882 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
883 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
884@@ -190,8 +183,7 @@
885
886 void testAsynchornousChangeForStatsLicenseAccepted()
887 {
888- AccountsService session;
889- session.setUser(QTest::currentTestFunction());
890+ AccountsService session(this, QTest::currentTestFunction());
891
892 QCOMPARE(session.hereEnabled(), false);
893 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
894@@ -203,8 +195,7 @@
895
896 void testAsynchornousChangeForLicenseBasePath()
897 {
898- AccountsService session;
899- session.setUser(QTest::currentTestFunction());
900+ AccountsService session(this, QTest::currentTestFunction());
901
902 QCOMPARE(session.hereLicensePath(), QString());
903 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
904@@ -216,8 +207,7 @@
905
906 void testAsynchornousChangeForStatsBackgroundFile()
907 {
908- AccountsService session;
909- session.setUser(QTest::currentTestFunction());
910+ AccountsService session(this, QTest::currentTestFunction());
911
912 QCOMPARE(session.backgroundFile(), QString());
913 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
914
915=== modified file 'tests/plugins/Unity/Session/sessionbackendtest.cpp'
916--- tests/plugins/Unity/Session/sessionbackendtest.cpp 2015-02-03 10:52:07 +0000
917+++ tests/plugins/Unity/Session/sessionbackendtest.cpp 2015-07-02 19:12:53 +0000
918@@ -1,5 +1,5 @@
919 /*
920- * Copyright 2013 Canonical Ltd.
921+ * Copyright 2013-2015 Canonical Ltd.
922 *
923 * This program is free software; you can redistribute it and/or modify
924 * it under the terms of the GNU Lesser General Public License as published by
925@@ -15,6 +15,7 @@
926 *
927 * Authors:
928 * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
929+ * Lukáš Tinkl <lukas.tinkl@canonical.com>
930 */
931
932 #include <QtTest>
933@@ -49,17 +50,22 @@
934
935 void testUnitySessionLogoutRequested_data() {
936 QTest::addColumn<QString>("method");
937+ QTest::addColumn<QString>("signal");
938
939- QTest::newRow("Logout") << "RequestLogout";
940+ QTest::newRow("Logout") << "RequestLogout" << "logoutRequested(bool)";
941+ QTest::newRow("Reboot") << "RequestReboot" << "rebootRequested(bool)";
942+ QTest::newRow("Shutdown") << "RequestShutdown" << "shutdownRequested(bool)";
943 }
944
945 void testUnitySessionLogoutRequested() {
946 QFETCH(QString, method);
947+ QFETCH(QString, signal);
948
949 DBusUnitySessionService dbusUnitySessionService;
950 QCoreApplication::processEvents(); // to let the service register on DBus
951
952- QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
953+ // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
954+ QSignalSpy spy(&dbusUnitySessionService, signal.prepend(QSIGNAL_CODE).toLocal8Bit().constData());
955
956 QDBusReply<void> reply = dbusUnitySession->call(method);
957 QCOMPARE(reply.isValid(), true);
958@@ -67,51 +73,34 @@
959 QCOMPARE(spy.count(), 1);
960 }
961
962- void testGnomeSessionWrapperLogoutRequested() {
963- DBusUnitySessionService dbusUnitySessionService;
964- QCoreApplication::processEvents(); // to let the service register on DBus
965-
966- // Spy on the logoutRequested signal on the /com/canonical/Unity/Session object
967- // as proof we are actually calling the actual method.
968- QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
969-
970- DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
971- QCoreApplication::processEvents(); // to let the service register on DBus
972-
973- QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
974- "/org/gnome/SessionManager/EndSessionDialog",
975- "org.gnome.SessionManager.EndSessionDialog",
976- QDBusConnection::sessionBus());
977-
978- QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
979-
980- // Set the QVariant as a QList<QDBusObjectPath> type
981- QDbusList var;
982- QVariant inhibitors;
983- inhibitors.setValue(var);
984-
985- QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::LOGOUT, (unsigned)0, (unsigned)0, inhibitors);
986- QCOMPARE(reply.isValid(), true);
987-
988- // Make sure we see the signal being emitted.
989- QCOMPARE(spy.count(), 1);
990+ void testGnomeSessionWrapper_data() {
991+ QTest::addColumn<uint>("method");
992+ QTest::addColumn<QString>("signal");
993+
994+ QTest::newRow("Logout") << (uint)Action::LOGOUT << "logoutRequested(bool)";
995+ QTest::newRow("Shutdown") << (unsigned)Action::SHUTDOWN << "shutdownRequested(bool)";
996+ QTest::newRow("Reboot") << (unsigned)Action::REBOOT << "rebootRequested(bool)";
997 }
998
999- void testGnomeSessionWrapperShutdownRequested() {
1000+ void testGnomeSessionWrapper() {
1001+ QFETCH(uint, method);
1002+ QFETCH(QString, signal);
1003+
1004 DBusUnitySessionService dbusUnitySessionService;
1005 QCoreApplication::processEvents(); // to let the service register on DBus
1006
1007- // Spy on the shutdownRequested signal on the /com/canonical/Unity/Session object
1008+ // Spy on the given signal on the /com/canonical/Unity/Session object
1009 // as proof we are actually calling the actual method.
1010- QSignalSpy spy(&dbusUnitySessionService, SIGNAL(shutdownRequested(bool)));
1011+ // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
1012+ QSignalSpy spy(&dbusUnitySessionService, signal.prepend(QSIGNAL_CODE).toLocal8Bit().constData());
1013
1014 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
1015 QCoreApplication::processEvents(); // to let the service register on DBus
1016
1017- QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
1018- "/org/gnome/SessionManager/EndSessionDialog",
1019- "org.gnome.SessionManager.EndSessionDialog",
1020- QDBusConnection::sessionBus());
1021+ QDBusInterface dbusGnomeSessionWrapper("com.canonical.Unity",
1022+ "/org/gnome/SessionManager/EndSessionDialog",
1023+ "org.gnome.SessionManager.EndSessionDialog",
1024+ QDBusConnection::sessionBus());
1025
1026 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
1027
1028@@ -120,9 +109,7 @@
1029 QVariant inhibitors;
1030 inhibitors.setValue(var);
1031
1032- // * Reboot action translates to the shutdown signal due to some weird idiosyncracy
1033- // in the indicator-session/Unity interaction. *
1034- QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::REBOOT, (unsigned)0, (unsigned)0, inhibitors);
1035+ QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", method, (unsigned)0, (unsigned)0, inhibitors);
1036 QCOMPARE(reply.isValid(), true);
1037
1038 // Make sure we see the signal being emitted.

Subscribers

People subscribed via source and target branches