on xenial help sign in
Expose a new greeter DBus property, IsActive, which tells apps and indicators when the integrated-greeter screen is active. Useful for switching UI modes when the screen is locked.
f5dd6b4Michael Terry
plugins/LightDM/CMakeLists.txt+1
@@ -15,6 +15,7 @@ include_directories(
15
15
16set(QMLPLUGIN_SRC
16set(QMLPLUGIN_SRC
17 ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
17 ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
18+ DBusGreeter.cpp
18 DBusGreeterList.cpp
19 DBusGreeterList.cpp
19 Greeter.cpp
20 Greeter.cpp
20 plugin.cpp
21 plugin.cpp
plugins/LightDM/DBusGreeter.cppnew file+60
@@ -0,0 +1,60 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "DBusGreeter.h"
18+#include "Greeter.h"
19+
20+#include <QDBusMessage>
21+#include <QStringList>
22+
23+DBusGreeter::DBusGreeter(Greeter *greeter, const QDBusConnection &connection, const QString &path)
24+ : QObject(greeter),
25+ m_greeter(greeter),
26+ m_connection(connection),
27+ m_path(path)
28+{
29+ connect(m_greeter, SIGNAL(isActiveChanged()), this, SLOT(isActiveChangedHandler()));
30+}
31+
32+bool DBusGreeter::isActive() const
33+{
34+ return m_greeter->isActive();
35+}
36+
37+void DBusGreeter::isActiveChangedHandler()
38+{
39+ notifyPropertyChanged("IsActive", isActive());
40+ Q_EMIT isActiveChanged();
41+}
42+
43+// Manually emit a PropertiesChanged signal over DBus, because QtDBus
44+// doesn't do it for us on Q_PROPERTIES, oddly enough.
45+void DBusGreeter::notifyPropertyChanged(const QString& propertyName, const QVariant &value)
46+{
47+ QDBusMessage message;
48+ QVariantMap changedProps;
49+
50+ changedProps.insert(propertyName, value);
51+
52+ message = QDBusMessage::createSignal(m_path,
53+ "org.freedesktop.DBus.Properties",
54+ "PropertiesChanged");
55+ message << "com.canonical.UnityGreeter";
56+ message << changedProps;
57+ message << QStringList();
58+
59+ m_connection.send(message);
60+}
plugins/LightDM/DBusGreeter.hnew file+54
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef UNITY_DBUSGREETER_H
18+#define UNITY_DBUSGREETER_H
19+
20+#include <QDBusConnection>
21+#include <QObject>
22+
23+class Greeter;
24+class QDBusInterface;
25+
26+/** This is an internal class used to talk with the indicators.
27+ */
28+
29+class DBusGreeter : public QObject
30+{
31+ Q_OBJECT
32+ Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter")
33+
34+ Q_PROPERTY(bool IsActive READ isActive NOTIFY isActiveChanged) // since 14.10
35+
36+public:
37+ explicit DBusGreeter(Greeter *greeter, const QDBusConnection &connection, const QString &path);
38+
39+ bool isActive() const;
40+
41+Q_SIGNALS:
42+ void isActiveChanged();
43+
44+private Q_SLOTS:
45+ void isActiveChangedHandler();
46+ void notifyPropertyChanged(const QString &propertyName, const QVariant &value);
47+
48+private:
49+ Greeter *m_greeter;
50+ QDBusConnection m_connection;
51+ QString m_path;
52+};
53+
54+#endif
plugins/LightDM/Greeter.cpp+17
@@ -25,6 +25,7 @@ public:
25 explicit GreeterPrivate(Greeter *parent);
25 explicit GreeterPrivate(Greeter *parent);
26
26
27 QLightDM::Greeter *m_greeter;
27 QLightDM::Greeter *m_greeter;
28+ bool m_active;
28 bool wasPrompted;
29 bool wasPrompted;
29 bool promptless;
30 bool promptless;
30
31
@@ -38,6 +39,7 @@ private:
38
39
39GreeterPrivate::GreeterPrivate(Greeter* parent)
40GreeterPrivate::GreeterPrivate(Greeter* parent)
40 : m_greeter(new QLightDM::Greeter(parent)),
41 : m_greeter(new QLightDM::Greeter(parent)),
42+ m_active(false),
41 wasPrompted(false),
43 wasPrompted(false),
42 promptless(false),
44 promptless(false),
43 q_ptr(parent)
45 q_ptr(parent)
@@ -60,6 +62,21 @@ Greeter::Greeter(QObject* parent)
60 d->m_greeter->connectSync();
62 d->m_greeter->connectSync();
61}
63}
62
64
65+bool Greeter::isActive() const
66+{
67+ Q_D(const Greeter);
68+ return d->m_active;
69+}
70+
71+void Greeter::setIsActive(bool active)
72+{
73+ Q_D(Greeter);
74+ if (d->m_active != active) {
75+ d->m_active = active;
76+ Q_EMIT isActiveChanged();
77+ }
78+}
79+
63bool Greeter::isAuthenticated() const
80bool Greeter::isAuthenticated() const
64{
81{
65 Q_D(const Greeter);
82 Q_D(const Greeter);
plugins/LightDM/Greeter.h+4
@@ -34,6 +34,7 @@ class Greeter : public QObject
34{
34{
35 Q_OBJECT
35 Q_OBJECT
36
36
37+ Q_PROPERTY(bool active READ isActive WRITE setIsActive NOTIFY isActiveChanged)
37 Q_PROPERTY(bool authenticated READ isAuthenticated)
38 Q_PROPERTY(bool authenticated READ isAuthenticated)
38 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
39 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
39 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
40 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
@@ -41,6 +42,7 @@ class Greeter : public QObject
41public:
42public:
42 explicit Greeter(QObject* parent=0);
43 explicit Greeter(QObject* parent=0);
43
44
45+ bool isActive() const;
44 bool isAuthenticated() const;
46 bool isAuthenticated() const;
45 QString authenticationUser() const;
47 QString authenticationUser() const;
46 bool promptless() const;
48 bool promptless() const;
@@ -49,12 +51,14 @@ public Q_SLOTS:
49 void authenticate(const QString &username=QString());
51 void authenticate(const QString &username=QString());
50 void respond(const QString &response);
52 void respond(const QString &response);
51 bool startSessionSync(const QString &session=QString());
53 bool startSessionSync(const QString &session=QString());
54+ void setIsActive(bool isActive);
52
55
53Q_SIGNALS:
56Q_SIGNALS:
54 void showMessage(const QString &text, bool isError);
57 void showMessage(const QString &text, bool isError);
55 void showPrompt(const QString &text, bool isSecret);
58 void showPrompt(const QString &text, bool isSecret);
56 void authenticationComplete();
59 void authenticationComplete();
57 void authenticationUserChanged(const QString &user);
60 void authenticationUserChanged(const QString &user);
61+ void isActiveChanged();
58 void promptlessChanged();
62 void promptlessChanged();
59
63
60 // This signal is emitted by external agents like indicators, and the UI
64 // This signal is emitted by external agents like indicators, and the UI
plugins/LightDM/plugin.cpp+3
@@ -18,6 +18,7 @@
18 */
18 */
19
19
20#include "plugin.h"
20#include "plugin.h"
21+#include "DBusGreeter.h"
21#include "DBusGreeterList.h"
22#include "DBusGreeterList.h"
22#include "Greeter.h"
23#include "Greeter.h"
23#include "UsersModel.h"
24#include "UsersModel.h"
@@ -39,6 +40,8 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
39
40
40 Greeter *greeter = new Greeter();
41 Greeter *greeter = new Greeter();
41 QDBusConnection connection = QDBusConnection::sessionBus();
42 QDBusConnection connection = QDBusConnection::sessionBus();
43+ DBusGreeter *root = new DBusGreeter(greeter, connection, "/");
44+ connection.registerObject("/", root, QDBusConnection::ExportScriptableContents);
42 DBusGreeterList *list = new DBusGreeterList(greeter, connection, GREETER_LIST_DBUS_PATH);
45 DBusGreeterList *list = new DBusGreeterList(greeter, connection, GREETER_LIST_DBUS_PATH);
43 connection.registerObject(GREETER_LIST_DBUS_PATH, list, QDBusConnection::ExportScriptableContents);
46 connection.registerObject(GREETER_LIST_DBUS_PATH, list, QDBusConnection::ExportScriptableContents);
44 connection.registerService(GREETER_DBUS_SERVICE);
47 connection.registerService(GREETER_DBUS_SERVICE);
qml/Shell.qml+6
@@ -373,6 +373,12 @@ FocusScope {
373 }
373 }
374 }
374 }
375
375
376+ Binding {
377+ target: LightDM.Greeter
378+ property: "active"
379+ value: greeter.shown || lockscreen.shown
380+ }
381+
376 Rectangle {
382 Rectangle {
377 anchors.fill: parent
383 anchors.fill: parent
378 color: "black"
384 color: "black"
tests/mocks/LightDM/CMakeLists.txt+1
@@ -18,6 +18,7 @@ include_directories(
18)
18)
19
19
20set(QMLPLUGIN_SRC
20set(QMLPLUGIN_SRC
21+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeter.cpp
21 ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
22 ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
22 ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
23 ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
23 ${CMAKE_SOURCE_DIR}/plugins/LightDM/plugin.cpp
24 ${CMAKE_SOURCE_DIR}/plugins/LightDM/plugin.cpp
tests/plugins/LightDM/CMakeLists.txt+1−1
@@ -19,7 +19,7 @@ target_link_libraries(test-lightdm-dbus
19
19
20add_definitions(-DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
20add_definitions(-DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
21
21
22−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)
22+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)
23add_dependencies(testLightDMDBus test-lightdm-dbus)
23add_dependencies(testLightDMDBus test-lightdm-dbus)
24
24
25add_dependencies(qmluitests testLightDMDBus)
25add_dependencies(qmluitests testLightDMDBus)
tests/plugins/LightDM/dbus.cpp+33
@@ -38,6 +38,13 @@ private Q_SLOTS:
38 // SIGNAL method, because QtDBus doesn't know about PropertiesChanged.
38 // SIGNAL method, because QtDBus doesn't know about PropertiesChanged.
39 // So we connect the hard way for the benefit of any tests that want
39 // So we connect the hard way for the benefit of any tests that want
40 // to watch.
40 // to watch.
41+ QDBusConnection::sessionBus().connect(
42+ "com.canonical.UnityGreeter",
43+ "/",
44+ "org.freedesktop.DBus.Properties",
45+ "PropertiesChanged",
46+ this,
47+ SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
41 QDBusConnection::sessionBus().connect(
48 QDBusConnection::sessionBus().connect(
42 "com.canonical.UnityGreeter",
49 "com.canonical.UnityGreeter",
43 "/list",
50 "/list",
@@ -57,6 +64,12 @@ private Q_SLOTS:
57 view->show();
64 view->show();
58 QTest::qWaitForWindowExposed(view);
65 QTest::qWaitForWindowExposed(view);
59
66
67+ dbusMain = new QDBusInterface("com.canonical.UnityGreeter",
68+ "/",
69+ "com.canonical.UnityGreeter",
70+ QDBusConnection::sessionBus(), view);
71+ QVERIFY(dbusMain->isValid());
72+
60 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
73 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
61 "/list",
74 "/list",
62 "com.canonical.UnityGreeter.List",
75 "com.canonical.UnityGreeter.List",
@@ -155,9 +168,29 @@ private Q_SLOTS:
155 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
168 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
156 }
169 }
157
170
171+ void testIsActive()
172+ {
173+ QVERIFY(!greeter->isActive());
174+ QVERIFY(!dbusMain->property("IsActive").toBool());
175+
176+ QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
177+ greeter->setIsActive(true);
178+ spy.wait();
179+
180+ QVERIFY(greeter->isActive());
181+ QVERIFY(dbusMain->property("IsActive").toBool());
182+
183+ QCOMPARE(spy.count(), 1);
184+ QList<QVariant> arguments = spy.takeFirst();
185+ QCOMPARE(arguments.at(0).toString(), QString("com.canonical.UnityGreeter"));
186+ QVERIFY(arguments.at(1).toMap().contains("IsActive"));
187+ QVERIFY(arguments.at(1).toMap()["IsActive"].toBool());
188+ }
189+
158private:
190private:
159 QQuickView *view;
191 QQuickView *view;
160 Greeter *greeter;
192 Greeter *greeter;
193+ QDBusInterface *dbusMain;
161 QDBusInterface *dbusList;
194 QDBusInterface *dbusList;
162};
195};
163
196