on xenial help sign in
Add common DBus object classes to libunity8-private
commitae64e24d8708b746d469c83d967458346718a8be authorMichael Terry <michael.terry@canonical.com> dateThu 9 Oct 2014, 10:53 (12 years ago) parentf4fcd19
25 files changed+313−163
plugins/LightDM/CMakeLists.txt+2 plugins/LightDM/DBusGreeter.cpp+3−24 plugins/LightDM/DBusGreeter.h+3−5 plugins/LightDM/DBusGreeterList.cpp+3−24 plugins/LightDM/DBusGreeterList.h+3−5 plugins/LightDM/Greeter.cpp−21 plugins/LightDM/Greeter.h−1 plugins/LightDM/plugin.cpp+8−1 plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.cpp+1−11 plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.h+2−3 plugins/Unity/Launcher/CMakeLists.txt+5−1 plugins/Unity/Launcher/dbusinterface.cpp+3−42 plugins/Unity/Launcher/dbusinterface.h+2−6 plugins/Unity/Session/CMakeLists.txt+5−1 plugins/Unity/Session/dbusunitysessionservice.cpp+2−14 plugins/Unity/Session/dbusunitysessionservice.h+2−3 src/libunity8-private/CMakeLists.txt+2 src/libunity8-private/unitydbusobject.cpp+82 src/libunity8-private/unitydbusobject.h+46 src/libunity8-private/unitydbusvirtualobject.cpp+79 src/libunity8-private/unitydbusvirtualobject.h+47 tests/mocks/LightDM/CMakeLists.txt+2 tests/plugins/LightDM/CMakeLists.txt+2 tests/plugins/Unity/Launcher/CMakeLists.txt+5−1 tests/plugins/Unity/Session/CMakeLists.txt+4
plugins/LightDM/CMakeLists.txt+2
@@ -10,6 +10,7 @@ include_directories(
1010 ${CMAKE_SOURCE_DIR}/plugins/Utils
1111 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM
1212 #${LIBLIGHTDM_INCLUDE_DIRS}
13+ ${libunity8-private_SOURCE_DIR}
1314 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
1415)
1516
@@ -28,6 +29,7 @@ add_library(LightDM-qml MODULE
2829
2930target_link_libraries(LightDM-qml
3031 MockLightDM-demo
32+ unity8-private
3133# TODO: Once we split out a separate greeter process, uncomment these lines
3234# ${LIBLIGHTDM_LDFLAGS}
3335 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
plugins/LightDM/DBusGreeter.cpp+3−24
@@ -20,11 +20,9 @@
2020#include <QDBusMessage>
2121#include <QStringList>
2222
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)
23+DBusGreeter::DBusGreeter(Greeter *greeter, const QString &path)
24+ : UnityDBusObject(path, "com.canonical.UnityGreeter", greeter),
25+ m_greeter(greeter)
2826{
2927 connect(m_greeter, SIGNAL(isActiveChanged()), this, SLOT(isActiveChangedHandler()));
3028}
@@ -49,22 +47,3 @@ void DBusGreeter::isActiveChangedHandler()
4947 notifyPropertyChanged("IsActive", isActive());
5048 Q_EMIT isActiveChanged();
5149}
52−
53−// Manually emit a PropertiesChanged signal over DBus, because QtDBus
54−// doesn't do it for us on Q_PROPERTIES, oddly enough.
55−void DBusGreeter::notifyPropertyChanged(const QString& propertyName, const QVariant &value)
56−{
57− QDBusMessage message;
58− QVariantMap changedProps;
59−
60− changedProps.insert(propertyName, value);
61−
62− message = QDBusMessage::createSignal(m_path,
63− "org.freedesktop.DBus.Properties",
64− "PropertiesChanged");
65− message << "com.canonical.UnityGreeter";
66− message << changedProps;
67− message << QStringList();
68−
69− m_connection.send(message);
70−}
plugins/LightDM/DBusGreeter.h+3−5
@@ -17,6 +17,7 @@
1717#ifndef UNITY_DBUSGREETER_H
1818#define UNITY_DBUSGREETER_H
1919
20+#include "unitydbusobject.h"
2021#include <QDBusConnection>
2122#include <QObject>
2223
@@ -25,7 +26,7 @@ class Greeter;
2526/** This is an internal class used to talk with the indicators.
2627 */
2728
28−class DBusGreeter : public QObject
29+class DBusGreeter : public UnityDBusObject
2930{
3031 Q_OBJECT
3132 Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter")
@@ -33,7 +34,7 @@ class DBusGreeter : public QObject
3334 Q_PROPERTY(bool IsActive READ isActive NOTIFY isActiveChanged) // since 14.10
3435
3536public:
36− explicit DBusGreeter(Greeter *greeter, const QDBusConnection &connection, const QString &path);
37+ explicit DBusGreeter(Greeter *greeter, const QString &path);
3738
3839 bool isActive() const;
3940 Q_SCRIPTABLE void ShowGreeter(); // temporary, until we split the greeter again
@@ -44,12 +45,9 @@ Q_SIGNALS:
4445
4546private Q_SLOTS:
4647 void isActiveChangedHandler();
47− void notifyPropertyChanged(const QString &propertyName, const QVariant &value);
4848
4949private:
5050 Greeter *m_greeter;
51− QDBusConnection m_connection;
52− QString m_path;
5351};
5452
5553#endif
plugins/LightDM/DBusGreeterList.cpp+3−24
@@ -20,11 +20,9 @@
2020#include <QDBusMessage>
2121#include <QStringList>
2222
23−DBusGreeterList::DBusGreeterList(Greeter *greeter, const QDBusConnection &connection, const QString &path)
24− : QObject(greeter),
25− m_greeter(greeter),
26− m_connection(connection),
27− m_path(path)
23+DBusGreeterList::DBusGreeterList(Greeter *greeter, const QString &path)
24+ : UnityDBusObject(path, "com.canonical.UnityGreeter", greeter),
25+ m_greeter(greeter)
2826{
2927 connect(m_greeter, SIGNAL(authenticationUserChanged(const QString &)), this, SLOT(authenticationUserChangedHandler(const QString &)));
3028 connect(m_greeter, SIGNAL(promptlessChanged()), this, SLOT(promptlessChangedHandler()));
@@ -56,22 +54,3 @@ void DBusGreeterList::promptlessChangedHandler()
5654 notifyPropertyChanged("EntryIsLocked", entryIsLocked());
5755 Q_EMIT entryIsLockedChanged();
5856}
59−
60−// Manually emit a PropertiesChanged signal over DBus, because QtDBus
61−// doesn't do it for us on Q_PROPERTIES, oddly enough.
62−void DBusGreeterList::notifyPropertyChanged(const QString& propertyName, const QVariant &value)
63−{
64− QDBusMessage message;
65− QVariantMap changedProps;
66−
67− changedProps.insert(propertyName, value);
68−
69− message = QDBusMessage::createSignal(m_path,
70− "org.freedesktop.DBus.Properties",
71− "PropertiesChanged");
72− message << "com.canonical.UnityGreeter.List";
73− message << changedProps;
74− message << QStringList();
75−
76− m_connection.send(message);
77−}
plugins/LightDM/DBusGreeterList.h+3−5
@@ -17,6 +17,7 @@
1717#ifndef UNITY_DBUSGREETERLIST_H
1818#define UNITY_DBUSGREETERLIST_H
1919
20+#include "unitydbusobject.h"
2021#include <QDBusConnection>
2122#include <QObject>
2223
@@ -25,7 +26,7 @@ class Greeter;
2526/** This is an internal class used to talk with the indicators.
2627 */
2728
28−class DBusGreeterList : public QObject
29+class DBusGreeterList : public UnityDBusObject
2930{
3031 Q_OBJECT
3132 Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter.List")
@@ -34,7 +35,7 @@ class DBusGreeterList : public QObject
3435 Q_PROPERTY(bool EntryIsLocked READ entryIsLocked NOTIFY entryIsLockedChanged) // since 14.04
3536
3637public:
37− explicit DBusGreeterList(Greeter *greeter, const QDBusConnection &connection, const QString &path);
38+ explicit DBusGreeterList(Greeter *greeter, const QString &path);
3839
3940 Q_SCRIPTABLE void SetActiveEntry(const QString &entry); // since 13.04
4041 Q_SCRIPTABLE QString GetActiveEntry() const; // since 13.10
@@ -49,12 +50,9 @@ Q_SIGNALS:
4950private Q_SLOTS:
5051 void authenticationUserChangedHandler(const QString &user);
5152 void promptlessChangedHandler();
52− void notifyPropertyChanged(const QString &propertyName, const QVariant &value);
5353
5454private:
5555 Greeter *m_greeter;
56− QDBusConnection m_connection;
57− QString m_path;
5856};
5957
6058#endif
plugins/LightDM/Greeter.cpp−21
@@ -16,17 +16,9 @@
1616 * Author: Michael Terry <michael.terry@canonical.com>
1717 */
1818
19−#include "DBusGreeter.h"
20−#include "DBusGreeterList.h"
2119#include "Greeter.h"
2220#include <libintl.h>
2321#include <QLightDM/Greeter>
24−#include <QTimer>
25−
26−static const char* GREETER_DBUS_PATH = "/";
27−static const char* GREETER_LIST_DBUS_PATH = "/list";
28−static const char* GREETER_DBUS_SERVICE = "com.canonical.UnityGreeter";
29−
3022
3123class GreeterPrivate
3224{
@@ -69,9 +61,6 @@ Greeter::Greeter(QObject* parent)
6961 this, SLOT(authenticationCompleteFilter()));
7062
7163 d->m_greeter->connectSync();
72−
73− // Use a zero-timer to let Qml finish loading before we announce on DBus
74− QTimer::singleShot(0, this, SLOT(registerDBus()));
7564}
7665
7766bool Greeter::isActive() const
@@ -165,13 +154,3 @@ void Greeter::authenticationCompleteFilter()
165154 Q_EMIT isAuthenticatedChanged();
166155 Q_EMIT authenticationComplete();
167156}
168−
169−void Greeter::registerDBus()
170−{
171− QDBusConnection connection = QDBusConnection::sessionBus();
172− DBusGreeter *root = new DBusGreeter(this, connection, GREETER_DBUS_PATH);
173− connection.registerObject(GREETER_DBUS_PATH, root, QDBusConnection::ExportScriptableContents);
174− DBusGreeterList *list = new DBusGreeterList(this, connection, GREETER_LIST_DBUS_PATH);
175− connection.registerObject(GREETER_LIST_DBUS_PATH, list, QDBusConnection::ExportScriptableContents);
176− connection.registerService(GREETER_DBUS_SERVICE);
177−}
plugins/LightDM/Greeter.h−1
@@ -77,7 +77,6 @@ private Q_SLOTS:
7777 void showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type);
7878 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
7979 void authenticationCompleteFilter();
80− void registerDBus();
8180};
8281
8382#endif
plugins/LightDM/plugin.cpp+8−1
@@ -18,6 +18,8 @@
1818 */
1919
2020#include "plugin.h"
21+#include "DBusGreeter.h"
22+#include "DBusGreeterList.h"
2123#include "Greeter.h"
2224#include "UsersModel.h"
2325#include <libusermetricsoutput/ColorTheme.h>
@@ -32,7 +34,12 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3234{
3335 Q_UNUSED(engine)
3436 Q_UNUSED(scriptEngine)
35− return new Greeter();
37+
38+ Greeter *greeter = new Greeter();
39+ new DBusGreeter(greeter, "/");
40+ new DBusGreeterList(greeter, "/list");
41+
42+ return greeter;
3643}
3744
3845static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.cpp+1−11
@@ -22,10 +22,8 @@
2222#include <QTimer>
2323
2424DBusDashCommunicatorService::DBusDashCommunicatorService(QObject *parent):
25− QObject(parent)
25+ UnityDBusObject("/com/canonical/UnityDash", "com.canonical.UnityDash", parent)
2626{
27− // Use a zero-timer to let Qml finish loading before we announce on DBus
28− QTimer::singleShot(0, this, SLOT(registerDBus()));
2927}
3028
3129DBusDashCommunicatorService::~DBusDashCommunicatorService()
@@ -36,11 +34,3 @@ void DBusDashCommunicatorService::SetCurrentScope(const QString &scopeId, bool a
3634{
3735 Q_EMIT setCurrentScopeRequested(scopeId, animate, isSwipe);
3836}
39−
40−void DBusDashCommunicatorService::registerDBus()
41−{
42− QDBusConnection connection = QDBusConnection::sessionBus();
43−
44− connection.registerService("com.canonical.UnityDash");
45− connection.registerObject("/com/canonical/UnityDash", this, QDBusConnection::ExportScriptableSlots);
46−}
plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.h+2−3
@@ -17,9 +17,10 @@
1717#ifndef DBUSDASHCOMMUNICATORSERVICE_H
1818#define DBUSDASHCOMMUNICATORSERVICE_H
1919
20+#include "unitydbusobject.h"
2021#include <QObject>
2122
22−class DBusDashCommunicatorService: public QObject
23+class DBusDashCommunicatorService: public UnityDBusObject
2324{
2425 Q_OBJECT
2526 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.DashCommunicator")
@@ -34,8 +35,6 @@ Q_SIGNALS:
3435public Q_SLOTS:
3536 Q_SCRIPTABLE void SetCurrentScope(const QString &scopeId, bool animate, bool isSwipe);
3637
37−private Q_SLOTS:
38− void registerDBus();
3938};
4039
4140#endif // DBUSUNITYSESSIONSERVICE_H
plugins/Unity/Launcher/CMakeLists.txt+5−1
@@ -9,6 +9,7 @@ include_directories(
99 ${CMAKE_CURRENT_SOURCE_DIR}
1010 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
1111 ${GSETTINGS_QT_INCLUDE_DIRS}
12+ ${libunity8-private_SOURCE_DIR}
1213)
1314
1415set(QMLLAUNCHERPLUGIN_SRC
@@ -30,7 +31,10 @@ add_library(UnityLauncher-qml MODULE
3031 ${QMLLAUNCHERPLUGIN_SRC}
3132 )
3233
33−target_link_libraries(UnityLauncher-qml ${GSETTINGS_QT_LDFLAGS})
34+target_link_libraries(UnityLauncher-qml
35+ unity8-private
36+ ${GSETTINGS_QT_LDFLAGS}
37+ )
3438
3539qt5_use_modules(UnityLauncher-qml DBus Qml Gui)
3640
plugins/Unity/Launcher/dbusinterface.cpp+3−42
@@ -28,19 +28,13 @@
2828#include <QTimer>
2929
3030DBusInterface::DBusInterface(LauncherModel *parent):
31− QDBusVirtualObject(parent),
31+ UnityDBusVirtualObject("/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher", parent),
3232 m_launcherModel(parent)
3333{
34− // Use a zero-timer to let Qml finish loading before we announce on DBus
35− QTimer::singleShot(0, this, SLOT(registerDBus()));
3634}
3735
3836DBusInterface::~DBusInterface()
3937{
40− /* Remove oursevles from DBus */
41− QDBusConnection con = QDBusConnection::sessionBus();
42− con.unregisterService("com.canonical.Unity.Launcher");
43− con.unregisterObject("/com/canonical/Unity/Launcher");
4438}
4539
4640QString DBusInterface::introspect(const QString &path) const
@@ -181,13 +175,13 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
181175 int newCount = message.arguments()[2].toInt();
182176 if (!item || newCount != item->count()) {
183177 Q_EMIT countChanged(appid, newCount);
184− emitPropChangedDbus(appid, "count", QVariant(newCount));
178+ notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "count", QVariant(newCount));
185179 }
186180 } else if (message.arguments()[1].toString() == "countVisible") {
187181 bool newVisible = message.arguments()[2].toBool();
188182 if (!item || newVisible != item->countVisible()) {
189183 Q_EMIT countVisibleChanged(appid, newVisible);
190− emitPropChangedDbus(appid, "countVisible", newVisible);
184+ notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "countVisible", newVisible);
191185 }
192186 }
193187 } else if (message.member() == "GetAll") {
@@ -204,36 +198,3 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
204198 QDBusMessage reply = message.createReply(retval);
205199 return connection.send(reply);
206200}
207−
208−void DBusInterface::emitPropChangedDbus(const QString& appId, const QString& property, const QVariant &value)
209−{
210− QString path("/com/canonical/Unity/Launcher/");
211− path.append(encodeAppId(appId));
212−
213− QDBusMessage message = QDBusMessage::createSignal(path, "org.freedesktop.DBus.Properties", "PropertiesChanged");
214−
215− QList<QVariant> arguments;
216− QVariantHash changedprops;
217− changedprops[property] = QVariant::fromValue(QDBusVariant(value));
218− QVariantList deletedprops;
219−
220− arguments.append(changedprops);
221− arguments.append(deletedprops);
222−
223− message.setArguments(arguments);
224−
225− QDBusConnection con = QDBusConnection::sessionBus();
226− con.send(message);
227−}
228−
229−void DBusInterface::registerDBus()
230−{
231− /* Set up ourselves on DBus */
232− QDBusConnection con = QDBusConnection::sessionBus();
233− if (!con.registerService("com.canonical.Unity.Launcher")) {
234− qWarning() << "Unable to register launcher name";
235− }
236− if (!con.registerVirtualObject("/com/canonical/Unity/Launcher", this, QDBusConnection::VirtualObjectRegisterOption::SubPath)) {
237− qWarning() << "Unable to register launcher object";
238− }
239−}
plugins/Unity/Launcher/dbusinterface.h+2−6
@@ -18,12 +18,13 @@
1818 */
1919
2020#include "launcheritem.h"
21+#include "unitydbusvirtualobject.h"
2122
2223#include <QDBusVirtualObject>
2324
2425class LauncherModel;
2526
26−class DBusInterface: public QDBusVirtualObject
27+class DBusInterface: public UnityDBusVirtualObject
2728{
2829 Q_OBJECT
2930public:
@@ -43,10 +44,5 @@ private:
4344 static QString decodeAppId(const QString& path);
4445 static QString encodeAppId(const QString& appId);
4546
46− void emitPropChangedDbus(const QString& appId, const QString& property, const QVariant &value);
47−
4847 LauncherModel *m_launcherModel;
49−
50−private Q_SLOTS:
51− void registerDBus();
5248};
plugins/Unity/Session/CMakeLists.txt+5−1
@@ -5,6 +5,7 @@ pkg_search_module(GIO REQUIRED gio-2.0)
55include_directories(
66 ${CMAKE_CURRENT_SOURCE_DIR}
77 ${GIO_INCLUDE_DIRS}
8+ ${libunity8-private_SOURCE_DIR}
89)
910
1011set(QMLSESSIONPLUGIN_SRC
@@ -18,7 +19,10 @@ add_library(UnitySession-qml MODULE
1819 )
1920
2021qt5_use_modules(UnitySession-qml DBus Qml)
21−target_link_libraries(UnitySession-qml ${GIO_LDFLAGS})
22+target_link_libraries(UnitySession-qml
23+ unity8-private
24+ ${GIO_LDFLAGS}
25+ )
2226
2327# export the qmldir and qmltypes files
2428add_unity8_plugin(Unity.Session 0.1 Unity/Session TARGETS UnitySession-qml)
plugins/Unity/Session/dbusunitysessionservice.cpp+2−14
@@ -22,10 +22,9 @@
2222#include <QDBusInterface>
2323#include <QTimer>
2424
25−DBusUnitySessionService::DBusUnitySessionService() : QObject()
25+DBusUnitySessionService::DBusUnitySessionService()
26+ : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
2627{
27− // Use a zero-timer to let Qml finish loading before we announce on DBus
28− QTimer::singleShot(0, this, SLOT(registerDBus()));
2928}
3029
3130DBusUnitySessionService::~DBusUnitySessionService()
@@ -73,14 +72,3 @@ void DBusUnitySessionService::RequestShutdown()
7372{
7473 Q_EMIT shutdownRequested(false);
7574}
76−
77−void DBusUnitySessionService::registerDBus()
78−{
79− QDBusConnection connection = QDBusConnection::sessionBus();
80−
81− connection.registerService("com.canonical.Unity");
82− connection.registerObject("/com/canonical/Unity/Session", this,
83− QDBusConnection::ExportScriptableSignals
84− | QDBusConnection::ExportScriptableSlots
85− | QDBusConnection::ExportScriptableInvokables);
86−}
plugins/Unity/Session/dbusunitysessionservice.h+2−3
@@ -17,6 +17,7 @@
1717#ifndef DBUSUNITYSESSIONSERVICE_H
1818#define DBUSUNITYSESSIONSERVICE_H
1919
20+#include "unitydbusobject.h"
2021#include <QObject>
2122
2223/**
@@ -26,7 +27,7 @@
2627 * com.canonical.Unity.Session interface provides public methods
2728 * and signals to handle Logout/Reboot/Shutdown.
2829 */
29−class DBusUnitySessionService : public QObject
30+class DBusUnitySessionService : public UnityDBusObject
3031{
3132 Q_OBJECT
3233 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Session")
@@ -134,8 +135,6 @@ public Q_SLOTS:
134135 */
135136 Q_SCRIPTABLE void RequestShutdown();
136137
137−private Q_SLOTS:
138− void registerDBus();
139138};
140139
141140#endif // DBUSUNITYSESSIONSERVICE_H
src/libunity8-private/CMakeLists.txt+2
@@ -6,6 +6,8 @@ project(lib${LIB_NAME})
66
77set(lib${LIB_NAME}_SRCS
88 abstractdbusservicemonitor.cpp
9+ unitydbusobject.cpp
10+ unitydbusvirtualobject.cpp
911 )
1012
1113add_library(${LIB_NAME} SHARED
src/libunity8-private/unitydbusobject.cppnew file+82
@@ -0,0 +1,82 @@
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 "unitydbusobject.h"
18+
19+#include <QDebug>
20+#include <QDBusMessage>
21+#include <QMetaClassInfo>
22+#include <QTimer>
23+
24+UnityDBusObject::UnityDBusObject(const QString &path, const QString &service, QObject *parent)
25+ : QObject(parent)
26+ , m_connection(QDBusConnection::sessionBus())
27+ , m_path(path)
28+ , m_service(service)
29+{
30+ // Use a zero-timer to let Qml finish loading before we announce on DBus
31+ QTimer::singleShot(0, this, SLOT(registerObject()));
32+}
33+
34+UnityDBusObject::~UnityDBusObject()
35+{
36+ // Leave service in place because multiple objects may be registered with
37+ // the same service. But we know we own the object path and can unregister it.
38+ m_connection.unregisterObject(path());
39+}
40+
41+QDBusConnection UnityDBusObject::connection() const
42+{
43+ return m_connection;
44+}
45+
46+QString UnityDBusObject::path() const
47+{
48+ return m_path;
49+}
50+
51+// Manually emit a PropertiesChanged signal over DBus, because QtDBus
52+// doesn't do it for us on Q_PROPERTIES, oddly enough.
53+void UnityDBusObject::notifyPropertyChanged(const QString& propertyName, const QVariant &value)
54+{
55+ QDBusMessage message;
56+ QString interface;
57+ QVariantMap changedProps;
58+
59+ interface = metaObject()->classInfo(metaObject()->indexOfClassInfo("D-Bus Interface")).value();
60+ changedProps.insert(propertyName, value);
61+
62+ message = QDBusMessage::createSignal(path(),
63+ "org.freedesktop.DBus.Properties",
64+ "PropertiesChanged");
65+ message << interface;
66+ message << changedProps;
67+ message << QStringList();
68+
69+ connection().send(message);
70+}
71+
72+void UnityDBusObject::registerObject()
73+{
74+ if (!m_connection.registerObject(m_path, this, QDBusConnection::ExportScriptableContents)) {
75+ qWarning() << "Unable to register DBus object" << m_path;
76+ }
77+ if (!m_service.isEmpty()) {
78+ if (!m_connection.registerService(m_service)) {
79+ qWarning() << "Unable to register DBus service" << m_service;
80+ }
81+ }
82+}
src/libunity8-private/unitydbusobject.hnew file+46
@@ -0,0 +1,46 @@
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 UNITYDBUSOBJECT_H
18+#define UNITYDBUSOBJECT_H
19+
20+#include <QDBusConnection>
21+#include <QObject>
22+
23+class Q_DECL_EXPORT UnityDBusObject : public QObject
24+{
25+ Q_OBJECT
26+
27+public:
28+ explicit UnityDBusObject(const QString &path, const QString &service = QString(), QObject *parent = 0);
29+ ~UnityDBusObject();
30+
31+ QDBusConnection connection() const;
32+ QString path() const;
33+
34+protected:
35+ void notifyPropertyChanged(const QString& propertyName, const QVariant &value);
36+
37+private Q_SLOTS:
38+ void registerObject();
39+
40+private:
41+ QDBusConnection m_connection;
42+ QString m_path;
43+ QString m_service;
44+};
45+
46+#endif // UNITYDBUSOBJECT_H
src/libunity8-private/unitydbusvirtualobject.cppnew file+79
@@ -0,0 +1,79 @@
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 "unitydbusvirtualobject.h"
18+
19+#include <QDebug>
20+#include <QDBusMessage>
21+#include <QTimer>
22+
23+UnityDBusVirtualObject::UnityDBusVirtualObject(const QString &path, const QString &service, QObject *parent)
24+ : QDBusVirtualObject(parent)
25+ , m_connection(QDBusConnection::sessionBus())
26+ , m_path(path)
27+ , m_service(service)
28+{
29+ // Use a zero-timer to let Qml finish loading before we announce on DBus
30+ QTimer::singleShot(0, this, SLOT(registerObject()));
31+}
32+
33+UnityDBusVirtualObject::~UnityDBusVirtualObject()
34+{
35+ // Leave service in place because multiple objects may be registered with
36+ // the same service. But we know we own the object path and can unregister it.
37+ m_connection.unregisterObject(path());
38+}
39+
40+QDBusConnection UnityDBusVirtualObject::connection() const
41+{
42+ return m_connection;
43+}
44+
45+QString UnityDBusVirtualObject::path() const
46+{
47+ return m_path;
48+}
49+
50+// Manually emit a PropertiesChanged signal over DBus, because QtDBus
51+// doesn't do it for us on Q_PROPERTIES, oddly enough.
52+void UnityDBusVirtualObject::notifyPropertyChanged(const QString& interface, const QString& node, const QString& propertyName, const QVariant &value)
53+{
54+ QDBusMessage message;
55+ QVariantMap changedProps;
56+
57+ changedProps.insert(propertyName, value);
58+
59+ message = QDBusMessage::createSignal(path() + "/" + node,
60+ "org.freedesktop.DBus.Properties",
61+ "PropertiesChanged");
62+ message << interface;
63+ message << changedProps;
64+ message << QStringList();
65+
66+ connection().send(message);
67+}
68+
69+void UnityDBusVirtualObject::registerObject()
70+{
71+ if (!m_connection.registerVirtualObject(m_path, this, QDBusConnection::VirtualObjectRegisterOption::SubPath)) {
72+ qWarning() << "Unable to register DBus object" << m_path;
73+ }
74+ if (!m_service.isEmpty()) {
75+ if (!m_connection.registerService(m_service)) {
76+ qWarning() << "Unable to register DBus service" << m_service;
77+ }
78+ }
79+}
src/libunity8-private/unitydbusvirtualobject.hnew file+47
@@ -0,0 +1,47 @@
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 UNITYDBUSVIRTUALOBJECT_H
18+#define UNITYDBUSVIRTUALOBJECT_H
19+
20+#include <QDBusConnection>
21+#include <QDBusVirtualObject>
22+#include <QObject>
23+
24+class Q_DECL_EXPORT UnityDBusVirtualObject : public QDBusVirtualObject
25+{
26+ Q_OBJECT
27+
28+public:
29+ explicit UnityDBusVirtualObject(const QString &path, const QString &service = QString(), QObject *parent = 0);
30+ ~UnityDBusVirtualObject();
31+
32+ QDBusConnection connection() const;
33+ QString path() const;
34+
35+protected:
36+ void notifyPropertyChanged(const QString& interface, const QString& node, const QString& propertyName, const QVariant &value);
37+
38+private Q_SLOTS:
39+ void registerObject();
40+
41+private:
42+ QDBusConnection m_connection;
43+ QString m_path;
44+ QString m_service;
45+};
46+
47+#endif // UNITYDBUSVIRTUALOBJECT_H
tests/mocks/LightDM/CMakeLists.txt+2
@@ -15,6 +15,7 @@ include_directories(
1515 ${CMAKE_CURRENT_BINARY_DIR}
1616 ${CMAKE_SOURCE_DIR}/plugins/Utils
1717 ${CMAKE_SOURCE_DIR}/tests/mocks/libusermetrics
18+ ${libunity8-private_SOURCE_DIR}
1819)
1920
2021set(QMLPLUGIN_SRC
@@ -40,6 +41,7 @@ target_link_libraries(MockLightDM-qml
4041 -llightdm-qt5-2
4142 -L${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics
4243 -lusermetricsoutput
44+ unity8-private
4345 )
4446
4547qt5_use_modules(MockLightDM-qml DBus Gui Qml)
tests/plugins/LightDM/CMakeLists.txt+2
@@ -11,12 +11,14 @@ include_directories(
1111 ${CMAKE_SOURCE_DIR}/plugins/LightDM
1212 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM
1313 ${LIBLIGHTDM_INCLUDE_DIRS}
14+ ${libunity8-private_SOURCE_DIR}
1415 )
1516
1617add_dependencies(test-lightdm-dbus MockLightDM-full)
1718target_link_libraries(test-lightdm-dbus
1819 -L${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full
1920 -llightdm-qt5-2
21+ unity8-private
2022 )
2123
2224add_definitions(-DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
tests/plugins/Unity/Launcher/CMakeLists.txt+5−1
@@ -7,6 +7,7 @@ include_directories(
77 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
88 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
99 ${GSETTINGS_QT_INCLUDE_DIRS}
10+ ${libunity8-private_SOURCE_DIR}
1011 )
1112
1213add_definitions(-DSM_BUSNAME=sessionBus)
@@ -34,7 +35,10 @@ add_executable(launchermodeltestExec
3435 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
3536 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
3637 )
37−target_link_libraries(launchermodeltestExec ${GSETTINGS_QT_LDFLAGS})
38+target_link_libraries(launchermodeltestExec
39+ unity8-private
40+ ${GSETTINGS_QT_LDFLAGS}
41+ )
3842qt5_use_modules(launchermodeltestExec Test Core DBus Xml Gui)
3943
4044# copy .desktop files into build directory for shadow builds
tests/plugins/Unity/Session/CMakeLists.txt+4
@@ -1,6 +1,7 @@
11include_directories(
22 ${CMAKE_CURRENT_BINARY_DIR}
33 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session
4+ ${libunity8-private_SOURCE_DIR}
45)
56
67add_definitions(-DSM_BUSNAME=sessionBus)
@@ -17,4 +18,7 @@ add_executable(sessionbackendtestExec
1718 sessionbackendtest.cpp
1819 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session/dbusunitysessionservice.cpp
1920)
21+target_link_libraries(sessionbackendtestExec
22+ unity8-private
23+ )
2024qt5_use_modules(sessionbackendtestExec Test Core Qml DBus)