Merge lp:~townsend/unity8/fix-lp1392187 into lp:unity8

Proposed by Christopher Townsend
Status: Merged
Approved by: Albert Astals Cid
Approved revision: 1580
Merged at revision: 1648
Proposed branch: lp:~townsend/unity8/fix-lp1392187
Merge into: lp:unity8
Diff against target: 260 lines (+156/-17)
4 files modified
plugins/Unity/Session/dbusunitysessionservice.cpp (+49/-0)
plugins/Unity/Session/dbusunitysessionservice.h (+20/-3)
plugins/Unity/Session/plugin.cpp (+1/-0)
tests/plugins/Unity/Session/sessionbackendtest.cpp (+86/-14)
To merge this branch: bzr merge lp:~townsend/unity8/fix-lp1392187
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+248358@code.launchpad.net

Commit message

Add a wrapper for handling the /org/gnome/SessionManager/EndSessionDialog DBus object used by indicator-session. This allows indicator-session to properly talk to the Unity 8 session management functions.

Description of the change

In the Action handler section, a "Reboot" action translates to a shutdown due to how indicator-session interacts with Unity.

* Are there any related MPs required for this MP to build/function as expected?
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

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

Can you please explain a bit more because a Reboot turns into a Shutdown?

review: Needs Information
Revision history for this message
Christopher Townsend (townsend) wrote :

Hey Albert,

I will try to explain, but I'm not privy to the original reason behind this:)

In Unity (7) land and indicator-session, a Reboot request from indicator-session is supposed to bring up a dialogue that asks the user if they want to either Reboot or Shutdown. This is what my other MP is supposed to fix (https://code.launchpad.net/~townsend/unity8/fix-lp1416074/+merge/248364).

The actual Shutdown request is when you press the power button and a dialogue is brought up that asks the user if they want to Lock, Logout, Reboot, or Shutdown the system.

So that said, the Reboot method is overloaded by the dialogue in that Reboot will either Reboot or Shutdown. This MP only fixes a part of that and the other MP I referenced fixes the other part.

I hope this explains it for you. If not, please ping me and we can hash it out.

Thanks for looking at this!

Revision history for this message
Albert Astals Cid (aacid) wrote :

Ok, this branch together with https://code.launchpad.net/~townsend/unity8/fix-lp1416074/+merge/248364 makes more sense, let's wait until that one is ready for merging

lp:~townsend/unity8/fix-lp1392187 updated
1580. By Christopher Townsend

Merge trunk.

Revision history for this message
Albert Astals Cid (aacid) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Yes, it does fix the bugs in the desktop and can't find any difference on the phone

 * Did CI run pass?
Known broken tests.

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

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/Unity/Session/dbusunitysessionservice.cpp'
2--- plugins/Unity/Session/dbusunitysessionservice.cpp 2014-10-09 15:00:32 +0000
3+++ plugins/Unity/Session/dbusunitysessionservice.cpp 2015-02-25 13:48:45 +0000
4@@ -71,3 +71,52 @@
5 {
6 Q_EMIT shutdownRequested(false);
7 }
8+
9+enum class Action : unsigned
10+{
11+ LOGOUT = 0,
12+ SHUTDOWN,
13+ REBOOT,
14+ NONE
15+};
16+
17+DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
18+ : UnityDBusObject("/org/gnome/SessionManager/EndSessionDialog", "com.canonical.Unity")
19+{
20+}
21+
22+DBusGnomeSessionManagerWrapper::~DBusGnomeSessionManagerWrapper()
23+{
24+}
25+
26+void DBusGnomeSessionManagerWrapper::Open(const unsigned type, const unsigned arg_1, const unsigned max_wait, const QList<QDBusObjectPath> &inhibitors)
27+{
28+ Q_UNUSED(arg_1);
29+ Q_UNUSED(max_wait);
30+ Q_UNUSED(inhibitors);
31+
32+ QDBusConnection connection = QDBusConnection::sessionBus();
33+ QDBusInterface iface1 ("com.canonical.Unity",
34+ "/com/canonical/Unity/Session",
35+ "com.canonical.Unity.Session",
36+ connection);
37+
38+ Action action = (Action)type;
39+
40+ switch (action)
41+ {
42+ case Action::LOGOUT:
43+ iface1.call("RequestLogout");
44+ break;
45+
46+ case Action::REBOOT:
47+ iface1.call("RequestShutdown");
48+ break;
49+
50+ case Action::SHUTDOWN:
51+ break;
52+
53+ default:
54+ break;
55+ }
56+}
57
58=== modified file 'plugins/Unity/Session/dbusunitysessionservice.h'
59--- plugins/Unity/Session/dbusunitysessionservice.h 2014-12-11 13:41:26 +0000
60+++ plugins/Unity/Session/dbusunitysessionservice.h 2015-02-25 13:48:45 +0000
61@@ -17,8 +17,13 @@
62 #ifndef DBUSUNITYSESSIONSERVICE_H
63 #define DBUSUNITYSESSIONSERVICE_H
64
65+#include <QDBusObjectPath>
66+
67 #include "unitydbusobject.h"
68
69+typedef QList<QDBusObjectPath> QDbusList;
70+Q_DECLARE_METATYPE(QList<QDBusObjectPath>)
71+
72 /**
73 * DBusUnitySessionService provides com.canonical.Unity.Session dbus
74 * interface.
75@@ -49,7 +54,7 @@
76 * @param have_inhibitors if there are any special running applications
77 * which inhibit the logout.
78 */
79- void logoutRequested(bool have_inhibitors);
80+ Q_SCRIPTABLE void logoutRequested(bool have_inhibitors);
81
82 /**
83 * rebootRequested signal
84@@ -59,7 +64,7 @@
85 * @param have_inhibitors if there are any special running applications
86 * which inhibit the reboot.
87 */
88- void rebootRequested(bool have_inhibitors);
89+ Q_SCRIPTABLE void rebootRequested(bool have_inhibitors);
90
91 /**
92 * shutdownRequested signal
93@@ -69,7 +74,7 @@
94 * @param have_inhibitors if there are any special running applications
95 * which inhibit the shutdown.
96 */
97- void shutdownRequested(bool have_inhibitors);
98+ Q_SCRIPTABLE void shutdownRequested(bool have_inhibitors);
99
100
101 /**
102@@ -141,4 +146,16 @@
103
104 };
105
106+class DBusGnomeSessionManagerWrapper : public UnityDBusObject
107+{
108+ Q_OBJECT
109+ Q_CLASSINFO("D-Bus Interface", "org.gnome.SessionManager.EndSessionDialog")
110+
111+public:
112+ DBusGnomeSessionManagerWrapper();
113+ ~DBusGnomeSessionManagerWrapper();
114+
115+public Q_SLOTS:
116+ Q_SCRIPTABLE void Open(const unsigned int type, const unsigned int arg_1, const unsigned int max_wait, const QList<QDBusObjectPath> &inhibitors);
117+};
118 #endif // DBUSUNITYSESSIONSERVICE_H
119
120=== modified file 'plugins/Unity/Session/plugin.cpp'
121--- plugins/Unity/Session/plugin.cpp 2014-08-26 23:33:17 +0000
122+++ plugins/Unity/Session/plugin.cpp 2015-02-25 13:48:45 +0000
123@@ -26,6 +26,7 @@
124
125 static QObject *dbusunitysessionservice_provider(QQmlEngine */*engine*/, QJSEngine */*jsEngine*/)
126 {
127+ new DBusGnomeSessionManagerWrapper();
128 return new DBusUnitySessionService();
129 }
130
131
132=== modified file 'tests/plugins/Unity/Session/sessionbackendtest.cpp'
133--- tests/plugins/Unity/Session/sessionbackendtest.cpp 2014-10-08 13:34:21 +0000
134+++ tests/plugins/Unity/Session/sessionbackendtest.cpp 2015-02-25 13:48:45 +0000
135@@ -26,6 +26,14 @@
136
137 #include "dbusunitysessionservice.h"
138
139+enum class Action : unsigned
140+{
141+ LOGOUT = 0,
142+ SHUTDOWN,
143+ REBOOT,
144+ NONE
145+};
146+
147 class SessionBackendTest : public QObject
148 {
149 Q_OBJECT
150@@ -33,32 +41,96 @@
151 private Q_SLOTS:
152
153 void initTestCase() {
154+ dbusUnitySession = new QDBusInterface ("com.canonical.Unity",
155+ "/com/canonical/Unity/Session",
156+ "com.canonical.Unity.Session",
157+ QDBusConnection::sessionBus());
158 }
159
160- void testDbusIfaceMethods_data() {
161+ void testUnitySessionLogoutRequested_data() {
162 QTest::addColumn<QString>("method");
163
164 QTest::newRow("Logout") << "RequestLogout";
165 }
166
167- void testDbusIfaceMethods() {
168+ void testUnitySessionLogoutRequested() {
169 QFETCH(QString, method);
170
171 DBusUnitySessionService dbusUnitySessionService;
172 QCoreApplication::processEvents(); // to let the service register on DBus
173
174- QDBusConnection con = QDBusConnection::sessionBus();
175- QDBusInterface interface ("com.canonical.Unity",
176- "/com/canonical/Unity/Session",
177- "com.canonical.Unity.Session",
178- con);
179- QDBusReply<void> reply;
180-
181- QCOMPARE(interface.isValid(), true);
182- reply = interface.call(method);
183- QCOMPARE(reply.isValid(), true);
184-
185- }
186+ QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
187+
188+ QDBusReply<void> reply = dbusUnitySession->call(method);
189+ QCOMPARE(reply.isValid(), true);
190+
191+ QCOMPARE(spy.count(), 1);
192+ }
193+
194+ void testGnomeSessionWrapperLogoutRequested() {
195+ DBusUnitySessionService dbusUnitySessionService;
196+ QCoreApplication::processEvents(); // to let the service register on DBus
197+
198+ // Spy on the logoutRequested signal on the /com/canonical/Unity/Session object
199+ // as proof we are actually calling the actual method.
200+ QSignalSpy spy(&dbusUnitySessionService, SIGNAL(logoutRequested(bool)));
201+
202+ DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
203+ QCoreApplication::processEvents(); // to let the service register on DBus
204+
205+ QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
206+ "/org/gnome/SessionManager/EndSessionDialog",
207+ "org.gnome.SessionManager.EndSessionDialog",
208+ QDBusConnection::sessionBus());
209+
210+ QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
211+
212+ // Set the QVariant as a QList<QDBusObjectPath> type
213+ QDbusList var;
214+ QVariant inhibitors;
215+ inhibitors.setValue(var);
216+
217+ QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::LOGOUT, (unsigned)0, (unsigned)0, inhibitors);
218+ QCOMPARE(reply.isValid(), true);
219+
220+ // Make sure we see the signal being emitted.
221+ QCOMPARE(spy.count(), 1);
222+ }
223+
224+ void testGnomeSessionWrapperShutdownRequested() {
225+ DBusUnitySessionService dbusUnitySessionService;
226+ QCoreApplication::processEvents(); // to let the service register on DBus
227+
228+ // Spy on the shutdownRequested signal on the /com/canonical/Unity/Session object
229+ // as proof we are actually calling the actual method.
230+ QSignalSpy spy(&dbusUnitySessionService, SIGNAL(shutdownRequested(bool)));
231+
232+ DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
233+ QCoreApplication::processEvents(); // to let the service register on DBus
234+
235+ QDBusInterface dbusGnomeSessionWrapper ("com.canonical.Unity",
236+ "/org/gnome/SessionManager/EndSessionDialog",
237+ "org.gnome.SessionManager.EndSessionDialog",
238+ QDBusConnection::sessionBus());
239+
240+ QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
241+
242+ // Set the QVariant as a QList<QDBusObjectPath> type
243+ QDbusList var;
244+ QVariant inhibitors;
245+ inhibitors.setValue(var);
246+
247+ // * Reboot action translates to the shutdown signal due to some weird idiosyncracy
248+ // in the indicator-session/Unity interaction. *
249+ QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", (unsigned)Action::REBOOT, (unsigned)0, (unsigned)0, inhibitors);
250+ QCOMPARE(reply.isValid(), true);
251+
252+ // Make sure we see the signal being emitted.
253+ QCOMPARE(spy.count(), 1);
254+ }
255+
256+private:
257+ QDBusInterface *dbusUnitySession;
258 };
259
260 QTEST_GUILESS_MAIN(SessionBackendTest)

Subscribers

People subscribed via source and target branches