on xenial help sign in
First pass at IsActive property for DBus
commit92b45e38b4df0155017f2ddd9cbb9564eb019043 authorMichael Terry <michael.terry@canonical.com> dateWed 18 Jun 2014, 13:26 (12 years ago) parentcbf1d54
8 files changed+141
plugins/LightDM/CMakeLists.txt+1 plugins/LightDM/DBusGreeter.cpp+60 plugins/LightDM/DBusGreeter.h+54 plugins/LightDM/Greeter.cpp+16 plugins/LightDM/Greeter.h+4 plugins/LightDM/plugin.cpp+3 qml/Shell.qml+2 tests/mocks/LightDM/CMakeLists.txt+1
plugins/LightDM/CMakeLists.txt+1
@@ -15,6 +15,7 @@ include_directories(
1515
1616set(QMLPLUGIN_SRC
1717 ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
18+ DBusGreeter.cpp
1819 DBusGreeterList.cpp
1920 Greeter.cpp
2021 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:
2525 explicit GreeterPrivate(Greeter *parent);
2626
2727 QLightDM::Greeter *m_greeter;
28+ bool m_active;
2829 bool wasPrompted;
2930 bool promptless;
3031
@@ -60,6 +61,21 @@ Greeter::Greeter(QObject* parent)
6061 d->m_greeter->connectSync();
6162}
6263
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+
6379bool Greeter::isAuthenticated() const
6480{
6581 Q_D(const Greeter);
plugins/LightDM/Greeter.h+4
@@ -34,6 +34,7 @@ class Greeter : public QObject
3434{
3535 Q_OBJECT
3636
37+ Q_PROPERTY(bool active READ isActive WRITE setIsActive NOTIFY isActiveChanged)
3738 Q_PROPERTY(bool authenticated READ isAuthenticated)
3839 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
3940 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
@@ -41,6 +42,7 @@ class Greeter : public QObject
4142public:
4243 explicit Greeter(QObject* parent=0);
4344
45+ bool isActive() const;
4446 bool isAuthenticated() const;
4547 QString authenticationUser() const;
4648 bool promptless() const;
@@ -49,12 +51,14 @@ public Q_SLOTS:
4951 void authenticate(const QString &username=QString());
5052 void respond(const QString &response);
5153 bool startSessionSync(const QString &session=QString());
54+ void setIsActive(bool isActive);
5255
5356Q_SIGNALS:
5457 void showMessage(const QString &text, bool isError);
5558 void showPrompt(const QString &text, bool isSecret);
5659 void authenticationComplete();
5760 void authenticationUserChanged(const QString &user);
61+ void isActiveChanged();
5862 void promptlessChanged();
5963
6064 // This signal is emitted by external agents like indicators, and the UI
plugins/LightDM/plugin.cpp+3
@@ -18,6 +18,7 @@
1818 */
1919
2020#include "plugin.h"
21+#include "DBusGreeter.h"
2122#include "DBusGreeterList.h"
2223#include "Greeter.h"
2324#include "UsersModel.h"
@@ -39,6 +40,8 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3940
4041 Greeter *greeter = new Greeter();
4142 QDBusConnection connection = QDBusConnection::sessionBus();
43+ DBusGreeter *root = new DBusGreeter(greeter, connection, "/");
44+ connection.registerObject("/", root, QDBusConnection::ExportScriptableContents);
4245 DBusGreeterList *list = new DBusGreeterList(greeter, connection, GREETER_LIST_DBUS_PATH);
4346 connection.registerObject(GREETER_LIST_DBUS_PATH, list, QDBusConnection::ExportScriptableContents);
4447 connection.registerService(GREETER_DBUS_SERVICE);
qml/Shell.qml+2
@@ -323,6 +323,8 @@ FocusScope {
323323 Connections {
324324 target: LightDM.Greeter
325325
326+ isActive: greeterWrapper.showProgress !== 0
327+
326328 onShowPrompt: {
327329 if (LightDM.Users.count == 1) {
328330 // 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(
1818)
1919
2020set(QMLPLUGIN_SRC
21+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeter.cpp
2122 ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
2223 ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
2324 ${CMAKE_SOURCE_DIR}/plugins/LightDM/plugin.cpp