Merge lp:~mterry/unity8/show-greeter-dbus into lp:unity8

Proposed by Michael Terry
Status: Superseded
Proposed branch: lp:~mterry/unity8/show-greeter-dbus
Merge into: lp:unity8
Diff against target: 395 lines (+207/-1)
11 files modified
plugins/LightDM/CMakeLists.txt (+1/-0)
plugins/LightDM/DBusGreeter.cpp (+65/-0)
plugins/LightDM/DBusGreeter.h (+55/-0)
plugins/LightDM/Greeter.cpp (+17/-0)
plugins/LightDM/Greeter.h (+5/-0)
plugins/LightDM/plugin.cpp (+3/-0)
qml/Shell.qml (+11/-0)
tests/mocks/LightDM/CMakeLists.txt (+1/-0)
tests/plugins/LightDM/CMakeLists.txt (+1/-1)
tests/plugins/LightDM/dbus.cpp (+40/-0)
tests/qmltests/tst_Shell.qml (+8/-0)
To merge this branch: bzr merge lp:~mterry/unity8/show-greeter-dbus
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+224941@code.launchpad.net

This proposal has been superseded by a proposal from 2014-06-29.

Commit message

Allow the session to bring up the greeter/lockscreen over DBus. The emergency dialer will need this support in order to cancel bringing it up.

Description of the change

Allow the session to bring up the greeter/lockscreen over DBus. The emergency dialer will need this support in order to cancel bringing it up.

== Checklist ==

 * 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?
 - NA

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

To post a comment you must log in.
lp:~mterry/unity8/show-greeter-dbus updated
981. By Michael Terry

Merge from is-active

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/LightDM/CMakeLists.txt'
2--- plugins/LightDM/CMakeLists.txt 2014-06-11 15:36:51 +0000
3+++ plugins/LightDM/CMakeLists.txt 2014-06-29 22:42:44 +0000
4@@ -15,6 +15,7 @@
5
6 set(QMLPLUGIN_SRC
7 ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
8+ DBusGreeter.cpp
9 DBusGreeterList.cpp
10 Greeter.cpp
11 plugin.cpp
12
13=== added file 'plugins/LightDM/DBusGreeter.cpp'
14--- plugins/LightDM/DBusGreeter.cpp 1970-01-01 00:00:00 +0000
15+++ plugins/LightDM/DBusGreeter.cpp 2014-06-29 22:42:44 +0000
16@@ -0,0 +1,65 @@
17+/*
18+ * Copyright (C) 2014 Canonical, Ltd.
19+ *
20+ * This program is free software; you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License as published by
22+ * the Free Software Foundation; version 3.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ */
32+
33+#include "DBusGreeter.h"
34+#include "Greeter.h"
35+
36+#include <QDBusMessage>
37+#include <QStringList>
38+
39+DBusGreeter::DBusGreeter(Greeter *greeter, const QDBusConnection &connection, const QString &path)
40+ : QObject(greeter),
41+ m_greeter(greeter),
42+ m_connection(connection),
43+ m_path(path)
44+{
45+ connect(m_greeter, SIGNAL(isActiveChanged()), this, SLOT(isActiveChangedHandler()));
46+}
47+
48+bool DBusGreeter::isActive() const
49+{
50+ return m_greeter->isActive();
51+}
52+
53+void DBusGreeter::ShowGreeter()
54+{
55+ return Q_EMIT m_greeter->showGreeter();
56+}
57+
58+void DBusGreeter::isActiveChangedHandler()
59+{
60+ notifyPropertyChanged("IsActive", isActive());
61+ Q_EMIT isActiveChanged();
62+}
63+
64+// Manually emit a PropertiesChanged signal over DBus, because QtDBus
65+// doesn't do it for us on Q_PROPERTIES, oddly enough.
66+void DBusGreeter::notifyPropertyChanged(const QString& propertyName, const QVariant &value)
67+{
68+ QDBusMessage message;
69+ QVariantMap changedProps;
70+
71+ changedProps.insert(propertyName, value);
72+
73+ message = QDBusMessage::createSignal(m_path,
74+ "org.freedesktop.DBus.Properties",
75+ "PropertiesChanged");
76+ message << "com.canonical.UnityGreeter";
77+ message << changedProps;
78+ message << QStringList();
79+
80+ m_connection.send(message);
81+}
82
83=== added file 'plugins/LightDM/DBusGreeter.h'
84--- plugins/LightDM/DBusGreeter.h 1970-01-01 00:00:00 +0000
85+++ plugins/LightDM/DBusGreeter.h 2014-06-29 22:42:44 +0000
86@@ -0,0 +1,55 @@
87+/*
88+ * Copyright (C) 2014 Canonical, Ltd.
89+ *
90+ * This program is free software; you can redistribute it and/or modify
91+ * it under the terms of the GNU General Public License as published by
92+ * the Free Software Foundation; version 3.
93+ *
94+ * This program is distributed in the hope that it will be useful,
95+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
96+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97+ * GNU General Public License for more details.
98+ *
99+ * You should have received a copy of the GNU General Public License
100+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
101+ */
102+
103+#ifndef UNITY_DBUSGREETER_H
104+#define UNITY_DBUSGREETER_H
105+
106+#include <QDBusConnection>
107+#include <QObject>
108+
109+class Greeter;
110+class QDBusInterface;
111+
112+/** This is an internal class used to talk with the indicators.
113+ */
114+
115+class DBusGreeter : public QObject
116+{
117+ Q_OBJECT
118+ Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter")
119+
120+ Q_PROPERTY(bool IsActive READ isActive NOTIFY isActiveChanged) // since 14.10
121+
122+public:
123+ explicit DBusGreeter(Greeter *greeter, const QDBusConnection &connection, const QString &path);
124+
125+ bool isActive() const;
126+ Q_SCRIPTABLE void ShowGreeter(); // temporary, until we split the greeter again
127+
128+Q_SIGNALS:
129+ void isActiveChanged();
130+
131+private Q_SLOTS:
132+ void isActiveChangedHandler();
133+ void notifyPropertyChanged(const QString &propertyName, const QVariant &value);
134+
135+private:
136+ Greeter *m_greeter;
137+ QDBusConnection m_connection;
138+ QString m_path;
139+};
140+
141+#endif
142
143=== modified file 'plugins/LightDM/Greeter.cpp'
144--- plugins/LightDM/Greeter.cpp 2014-06-11 15:36:51 +0000
145+++ plugins/LightDM/Greeter.cpp 2014-06-29 22:42:44 +0000
146@@ -25,6 +25,7 @@
147 explicit GreeterPrivate(Greeter *parent);
148
149 QLightDM::Greeter *m_greeter;
150+ bool m_active;
151 bool wasPrompted;
152 bool promptless;
153
154@@ -38,6 +39,7 @@
155
156 GreeterPrivate::GreeterPrivate(Greeter* parent)
157 : m_greeter(new QLightDM::Greeter(parent)),
158+ m_active(false),
159 wasPrompted(false),
160 promptless(false),
161 q_ptr(parent)
162@@ -60,6 +62,21 @@
163 d->m_greeter->connectSync();
164 }
165
166+bool Greeter::isActive() const
167+{
168+ Q_D(const Greeter);
169+ return d->m_active;
170+}
171+
172+void Greeter::setIsActive(bool active)
173+{
174+ Q_D(Greeter);
175+ if (d->m_active != active) {
176+ d->m_active = active;
177+ Q_EMIT isActiveChanged();
178+ }
179+}
180+
181 bool Greeter::isAuthenticated() const
182 {
183 Q_D(const Greeter);
184
185=== modified file 'plugins/LightDM/Greeter.h'
186--- plugins/LightDM/Greeter.h 2014-06-11 15:36:51 +0000
187+++ plugins/LightDM/Greeter.h 2014-06-29 22:42:44 +0000
188@@ -34,6 +34,7 @@
189 {
190 Q_OBJECT
191
192+ Q_PROPERTY(bool active READ isActive WRITE setIsActive NOTIFY isActiveChanged)
193 Q_PROPERTY(bool authenticated READ isAuthenticated)
194 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
195 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
196@@ -41,6 +42,7 @@
197 public:
198 explicit Greeter(QObject* parent=0);
199
200+ bool isActive() const;
201 bool isAuthenticated() const;
202 QString authenticationUser() const;
203 bool promptless() const;
204@@ -49,13 +51,16 @@
205 void authenticate(const QString &username=QString());
206 void respond(const QString &response);
207 bool startSessionSync(const QString &session=QString());
208+ void setIsActive(bool isActive);
209
210 Q_SIGNALS:
211 void showMessage(const QString &text, bool isError);
212 void showPrompt(const QString &text, bool isSecret);
213 void authenticationComplete();
214 void authenticationUserChanged(const QString &user);
215+ void isActiveChanged();
216 void promptlessChanged();
217+ void showGreeter();
218
219 // This signal is emitted by external agents like indicators, and the UI
220 // should switch to this user if possible.
221
222=== modified file 'plugins/LightDM/plugin.cpp'
223--- plugins/LightDM/plugin.cpp 2014-06-11 15:36:51 +0000
224+++ plugins/LightDM/plugin.cpp 2014-06-29 22:42:44 +0000
225@@ -18,6 +18,7 @@
226 */
227
228 #include "plugin.h"
229+#include "DBusGreeter.h"
230 #include "DBusGreeterList.h"
231 #include "Greeter.h"
232 #include "UsersModel.h"
233@@ -39,6 +40,8 @@
234
235 Greeter *greeter = new Greeter();
236 QDBusConnection connection = QDBusConnection::sessionBus();
237+ DBusGreeter *root = new DBusGreeter(greeter, connection, "/");
238+ connection.registerObject("/", root, QDBusConnection::ExportScriptableContents);
239 DBusGreeterList *list = new DBusGreeterList(greeter, connection, GREETER_LIST_DBUS_PATH);
240 connection.registerObject(GREETER_LIST_DBUS_PATH, list, QDBusConnection::ExportScriptableContents);
241 connection.registerService(GREETER_DBUS_SERVICE);
242
243=== modified file 'qml/Shell.qml'
244--- qml/Shell.qml 2014-06-24 16:27:07 +0000
245+++ qml/Shell.qml 2014-06-29 22:42:44 +0000
246@@ -348,6 +348,8 @@
247 Connections {
248 target: LightDM.Greeter
249
250+ onShowGreeter: greeter.show()
251+
252 onShowPrompt: {
253 if (LightDM.Users.count == 1) {
254 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
255@@ -373,6 +375,12 @@
256 }
257 }
258
259+ Binding {
260+ target: LightDM.Greeter
261+ property: "active"
262+ value: greeter.shown || lockscreen.shown
263+ }
264+
265 Rectangle {
266 anchors.fill: parent
267 color: "black"
268@@ -412,6 +420,9 @@
269 onShownChanged: {
270 if (shown) {
271 lockscreen.reset();
272+ if (!LightDM.Greeter.promptless) {
273+ lockscreen.show();
274+ }
275 // If there is only one user, we start authenticating with that one here.
276 // If there are more users, the Greeter will handle that
277 if (LightDM.Users.count == 1) {
278
279=== modified file 'tests/mocks/LightDM/CMakeLists.txt'
280--- tests/mocks/LightDM/CMakeLists.txt 2014-06-11 15:36:51 +0000
281+++ tests/mocks/LightDM/CMakeLists.txt 2014-06-29 22:42:44 +0000
282@@ -18,6 +18,7 @@
283 )
284
285 set(QMLPLUGIN_SRC
286+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeter.cpp
287 ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
288 ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
289 ${CMAKE_SOURCE_DIR}/plugins/LightDM/plugin.cpp
290
291=== modified file 'tests/plugins/LightDM/CMakeLists.txt'
292--- tests/plugins/LightDM/CMakeLists.txt 2014-06-11 15:36:51 +0000
293+++ tests/plugins/LightDM/CMakeLists.txt 2014-06-29 22:42:44 +0000
294@@ -19,7 +19,7 @@
295
296 add_definitions(-DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
297
298-add_custom_target(testLightDMDBus dbus-launch env QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/tests/mocks LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full ${CMAKE_CURRENT_BINARY_DIR}/test-lightdm-dbus)
299+add_custom_target(testLightDMDBus xvfb-run --server-args "-screen 0 1024x768x24" --auto-servernum dbus-launch env QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/tests/mocks LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full ${CMAKE_CURRENT_BINARY_DIR}/test-lightdm-dbus)
300 add_dependencies(testLightDMDBus test-lightdm-dbus)
301
302 add_dependencies(qmluitests testLightDMDBus)
303
304=== modified file 'tests/plugins/LightDM/dbus.cpp'
305--- tests/plugins/LightDM/dbus.cpp 2013-12-03 16:55:03 +0000
306+++ tests/plugins/LightDM/dbus.cpp 2014-06-29 22:42:44 +0000
307@@ -40,6 +40,13 @@
308 // to watch.
309 QDBusConnection::sessionBus().connect(
310 "com.canonical.UnityGreeter",
311+ "/",
312+ "org.freedesktop.DBus.Properties",
313+ "PropertiesChanged",
314+ this,
315+ SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
316+ QDBusConnection::sessionBus().connect(
317+ "com.canonical.UnityGreeter",
318 "/list",
319 "org.freedesktop.DBus.Properties",
320 "PropertiesChanged",
321@@ -57,6 +64,12 @@
322 view->show();
323 QTest::qWaitForWindowExposed(view);
324
325+ dbusMain = new QDBusInterface("com.canonical.UnityGreeter",
326+ "/",
327+ "com.canonical.UnityGreeter",
328+ QDBusConnection::sessionBus(), view);
329+ QVERIFY(dbusMain->isValid());
330+
331 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
332 "/list",
333 "com.canonical.UnityGreeter.List",
334@@ -155,9 +168,36 @@
335 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
336 }
337
338+ void testIsActive()
339+ {
340+ QVERIFY(!greeter->isActive());
341+ QVERIFY(!dbusMain->property("IsActive").toBool());
342+
343+ QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
344+ greeter->setIsActive(true);
345+ spy.wait();
346+
347+ QVERIFY(greeter->isActive());
348+ QVERIFY(dbusMain->property("IsActive").toBool());
349+
350+ QCOMPARE(spy.count(), 1);
351+ QList<QVariant> arguments = spy.takeFirst();
352+ QCOMPARE(arguments.at(0).toString(), QString("com.canonical.UnityGreeter"));
353+ QVERIFY(arguments.at(1).toMap().contains("IsActive"));
354+ QVERIFY(arguments.at(1).toMap()["IsActive"].toBool());
355+ }
356+
357+ void testShowGreeter()
358+ {
359+ // Just confirm the call exists and doesn't fail
360+ QDBusReply<void> reply = dbusMain->call("ShowGreeter");
361+ QVERIFY(reply.isValid());
362+ }
363+
364 private:
365 QQuickView *view;
366 Greeter *greeter;
367+ QDBusInterface *dbusMain;
368 QDBusInterface *dbusList;
369 };
370
371
372=== modified file 'tests/qmltests/tst_Shell.qml'
373--- tests/qmltests/tst_Shell.qml 2014-06-17 03:52:58 +0000
374+++ tests/qmltests/tst_Shell.qml 2014-06-29 22:42:44 +0000
375@@ -20,6 +20,7 @@
376 import QtQuick 2.0
377 import QtTest 1.0
378 import GSettings 1.0
379+import LightDM 0.1 as LightDM
380 import Unity.Application 0.1
381 import Unity.Test 0.1 as UT
382 import Powerd 0.1
383@@ -556,5 +557,12 @@
384 tryCompare(greeter, "showProgress", 0)
385 waitUntilApplicationWindowIsFullyVisible()
386 }
387+
388+ function test_showGreeterDBusCall() {
389+ var greeter = findChild(shell, "greeter")
390+ tryCompare(greeter, "showProgress", 0)
391+ LightDM.Greeter.showGreeter()
392+ tryCompare(greeter, "showProgress", 1)
393+ }
394 }
395 }

Subscribers

People subscribed via source and target branches