on xenial help sign in
First pass at IsActive property for DBus
92b45e3Michael 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+16
@@ -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
@@ -60,6 +61,21 @@ Greeter::Greeter(QObject* parent)
60 d->m_greeter->connectSync();
61 d->m_greeter->connectSync();
61}
62}
62
63
64+bool Greeter::isActive() const
65+{
66+ Q_D(const Greeter);
67+ return d->m_active;
68+}
69+
70+void Greeter::setIsActive(bool active)
71+{
72+ Q_D(Greeter);
73+ if (d->m_active != active) {
74+ d->m_active = active;
75+ Q_EMIT isActiveChanged();
76+ }
77+}
78+
63bool Greeter::isAuthenticated() const
79bool Greeter::isAuthenticated() const
64{
80{
65 Q_D(const Greeter);
81 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+2
@@ -323,6 +323,8 @@ FocusScope {
323 Connections {
323 Connections {
324 target: LightDM.Greeter
324 target: LightDM.Greeter
325
325
326+ isActive: greeterWrapper.showProgress !== 0
327+
326 onShowPrompt: {
328 onShowPrompt: {
327 if (LightDM.Users.count == 1) {
329 if (LightDM.Users.count == 1) {
328 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
330 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
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