on xenial help sign in
Add common DBus object classes to libunity8-private
ae64e24Michael Terry
plugins/LightDM/CMakeLists.txt+2
@@ -10,6 +10,7 @@ include_directories(
10 ${CMAKE_SOURCE_DIR}/plugins/Utils
10 ${CMAKE_SOURCE_DIR}/plugins/Utils
11 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM
11 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM
12 #${LIBLIGHTDM_INCLUDE_DIRS}
12 #${LIBLIGHTDM_INCLUDE_DIRS}
13+ ${libunity8-private_SOURCE_DIR}
13 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
14 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
14)
15)
15
16
@@ -28,6 +29,7 @@ add_library(LightDM-qml MODULE
28
29
29target_link_libraries(LightDM-qml
30target_link_libraries(LightDM-qml
30 MockLightDM-demo
31 MockLightDM-demo
32+ unity8-private
31# TODO: Once we split out a separate greeter process, uncomment these lines
33# TODO: Once we split out a separate greeter process, uncomment these lines
32# ${LIBLIGHTDM_LDFLAGS}
34# ${LIBLIGHTDM_LDFLAGS}
33 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
35 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
plugins/LightDM/DBusGreeter.cpp+3−24
@@ -20,11 +20,9 @@
20#include <QDBusMessage>
20#include <QDBusMessage>
21#include <QStringList>
21#include <QStringList>
22
22
23−DBusGreeter::DBusGreeter(Greeter *greeter, const QDBusConnection &connection, const QString &path)
23+DBusGreeter::DBusGreeter(Greeter *greeter, const QString &path)
24− : QObject(greeter),
24+ : UnityDBusObject(path, "com.canonical.UnityGreeter", greeter),
25− m_greeter(greeter),
25+ m_greeter(greeter)
26− m_connection(connection),
27− m_path(path)
28{
26{
29 connect(m_greeter, SIGNAL(isActiveChanged()), this, SLOT(isActiveChangedHandler()));
27 connect(m_greeter, SIGNAL(isActiveChanged()), this, SLOT(isActiveChangedHandler()));
30}
28}
@@ -49,22 +47,3 @@ void DBusGreeter::isActiveChangedHandler()
49 notifyPropertyChanged("IsActive", isActive());
47 notifyPropertyChanged("IsActive", isActive());
50 Q_EMIT isActiveChanged();
48 Q_EMIT isActiveChanged();
51}
49}
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 @@
17#ifndef UNITY_DBUSGREETER_H
17#ifndef UNITY_DBUSGREETER_H
18#define UNITY_DBUSGREETER_H
18#define UNITY_DBUSGREETER_H
19
19
20+#include "unitydbusobject.h"
20#include <QDBusConnection>
21#include <QDBusConnection>
21#include <QObject>
22#include <QObject>
22
23
@@ -25,7 +26,7 @@ class Greeter;
25/** This is an internal class used to talk with the indicators.
26/** This is an internal class used to talk with the indicators.
26 */
27 */
27
28
28−class DBusGreeter : public QObject
29+class DBusGreeter : public UnityDBusObject
29{
30{
30 Q_OBJECT
31 Q_OBJECT
31 Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter")
32 Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter")
@@ -33,7 +34,7 @@ class DBusGreeter : public QObject
33 Q_PROPERTY(bool IsActive READ isActive NOTIFY isActiveChanged) // since 14.10
34 Q_PROPERTY(bool IsActive READ isActive NOTIFY isActiveChanged) // since 14.10
34
35
35public:
36public:
36− explicit DBusGreeter(Greeter *greeter, const QDBusConnection &connection, const QString &path);
37+ explicit DBusGreeter(Greeter *greeter, const QString &path);
37
38
38 bool isActive() const;
39 bool isActive() const;
39 Q_SCRIPTABLE void ShowGreeter(); // temporary, until we split the greeter again
40 Q_SCRIPTABLE void ShowGreeter(); // temporary, until we split the greeter again
@@ -44,12 +45,9 @@ Q_SIGNALS:
44
45
45private Q_SLOTS:
46private Q_SLOTS:
46 void isActiveChangedHandler();
47 void isActiveChangedHandler();
47− void notifyPropertyChanged(const QString &propertyName, const QVariant &value);
48
48
49private:
49private:
50 Greeter *m_greeter;
50 Greeter *m_greeter;
51− QDBusConnection m_connection;
52− QString m_path;
53};
51};
54
52
55#endif
53#endif
plugins/LightDM/DBusGreeterList.cpp+3−24
@@ -20,11 +20,9 @@
20#include <QDBusMessage>
20#include <QDBusMessage>
21#include <QStringList>
21#include <QStringList>
22
22
23−DBusGreeterList::DBusGreeterList(Greeter *greeter, const QDBusConnection &connection, const QString &path)
23+DBusGreeterList::DBusGreeterList(Greeter *greeter, const QString &path)
24− : QObject(greeter),
24+ : UnityDBusObject(path, "com.canonical.UnityGreeter", greeter),
25− m_greeter(greeter),
25+ m_greeter(greeter)
26− m_connection(connection),
27− m_path(path)
28{
26{
29 connect(m_greeter, SIGNAL(authenticationUserChanged(const QString &)), this, SLOT(authenticationUserChangedHandler(const QString &)));
27 connect(m_greeter, SIGNAL(authenticationUserChanged(const QString &)), this, SLOT(authenticationUserChangedHandler(const QString &)));
30 connect(m_greeter, SIGNAL(promptlessChanged()), this, SLOT(promptlessChangedHandler()));
28 connect(m_greeter, SIGNAL(promptlessChanged()), this, SLOT(promptlessChangedHandler()));
@@ -56,22 +54,3 @@ void DBusGreeterList::promptlessChangedHandler()
56 notifyPropertyChanged("EntryIsLocked", entryIsLocked());
54 notifyPropertyChanged("EntryIsLocked", entryIsLocked());
57 Q_EMIT entryIsLockedChanged();
55 Q_EMIT entryIsLockedChanged();
58}
56}
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 @@
17#ifndef UNITY_DBUSGREETERLIST_H
17#ifndef UNITY_DBUSGREETERLIST_H
18#define UNITY_DBUSGREETERLIST_H
18#define UNITY_DBUSGREETERLIST_H
19
19
20+#include "unitydbusobject.h"
20#include <QDBusConnection>
21#include <QDBusConnection>
21#include <QObject>
22#include <QObject>
22
23
@@ -25,7 +26,7 @@ class Greeter;
25/** This is an internal class used to talk with the indicators.
26/** This is an internal class used to talk with the indicators.
26 */
27 */
27
28
28−class DBusGreeterList : public QObject
29+class DBusGreeterList : public UnityDBusObject
29{
30{
30 Q_OBJECT
31 Q_OBJECT
31 Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter.List")
32 Q_CLASSINFO("D-Bus Interface", "com.canonical.UnityGreeter.List")
@@ -34,7 +35,7 @@ class DBusGreeterList : public QObject
34 Q_PROPERTY(bool EntryIsLocked READ entryIsLocked NOTIFY entryIsLockedChanged) // since 14.04
35 Q_PROPERTY(bool EntryIsLocked READ entryIsLocked NOTIFY entryIsLockedChanged) // since 14.04
35
36
36public:
37public:
37− explicit DBusGreeterList(Greeter *greeter, const QDBusConnection &connection, const QString &path);
38+ explicit DBusGreeterList(Greeter *greeter, const QString &path);
38
39
39 Q_SCRIPTABLE void SetActiveEntry(const QString &entry); // since 13.04
40 Q_SCRIPTABLE void SetActiveEntry(const QString &entry); // since 13.04
40 Q_SCRIPTABLE QString GetActiveEntry() const; // since 13.10
41 Q_SCRIPTABLE QString GetActiveEntry() const; // since 13.10
@@ -49,12 +50,9 @@ Q_SIGNALS:
49private Q_SLOTS:
50private Q_SLOTS:
50 void authenticationUserChangedHandler(const QString &user);
51 void authenticationUserChangedHandler(const QString &user);
51 void promptlessChangedHandler();
52 void promptlessChangedHandler();
52− void notifyPropertyChanged(const QString &propertyName, const QVariant &value);
53
53
54private:
54private:
55 Greeter *m_greeter;
55 Greeter *m_greeter;
56− QDBusConnection m_connection;
57− QString m_path;
58};
56};
59
57
60#endif
58#endif
plugins/LightDM/Greeter.cpp−21
@@ -16,17 +16,9 @@
16 * Author: Michael Terry <michael.terry@canonical.com>
16 * Author: Michael Terry <michael.terry@canonical.com>
17 */
17 */
18
18
19−#include "DBusGreeter.h"
20−#include "DBusGreeterList.h"
21#include "Greeter.h"
19#include "Greeter.h"
22#include <libintl.h>
20#include <libintl.h>
23#include <QLightDM/Greeter>
21#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−
30
22
31class GreeterPrivate
23class GreeterPrivate
32{
24{
@@ -69,9 +61,6 @@ Greeter::Greeter(QObject* parent)
69 this, SLOT(authenticationCompleteFilter()));
61 this, SLOT(authenticationCompleteFilter()));
70
62
71 d->m_greeter->connectSync();
63 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()));
75}
64}
76
65
77bool Greeter::isActive() const
66bool Greeter::isActive() const
@@ -165,13 +154,3 @@ void Greeter::authenticationCompleteFilter()
165 Q_EMIT isAuthenticatedChanged();
154 Q_EMIT isAuthenticatedChanged();
166 Q_EMIT authenticationComplete();
155 Q_EMIT authenticationComplete();
167}
156}
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:
77 void showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type);
77 void showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type);
78 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
78 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
79 void authenticationCompleteFilter();
79 void authenticationCompleteFilter();
80− void registerDBus();
81};
80};
82
81
83#endif
82#endif
plugins/LightDM/plugin.cpp+8−1
@@ -18,6 +18,8 @@
18 */
18 */
19
19
20#include "plugin.h"
20#include "plugin.h"
21+#include "DBusGreeter.h"
22+#include "DBusGreeterList.h"
21#include "Greeter.h"
23#include "Greeter.h"
22#include "UsersModel.h"
24#include "UsersModel.h"
23#include <libusermetricsoutput/ColorTheme.h>
25#include <libusermetricsoutput/ColorTheme.h>
@@ -32,7 +34,12 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
32{
34{
33 Q_UNUSED(engine)
35 Q_UNUSED(engine)
34 Q_UNUSED(scriptEngine)
36 Q_UNUSED(scriptEngine)
37+
38+ Greeter *greeter = new Greeter();
39+ new DBusGreeter(greeter, "/");
40+ new DBusGreeterList(greeter, "/list");
41+
35− return new Greeter();
42+ return greeter;
36}
43}
37
44
38static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
45static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
plugins/Unity/DashCommunicator/dbusdashcommunicatorservice.cpp+1−11
@@ -22,10 +22,8 @@
22#include <QTimer>
22#include <QTimer>
23
23
24DBusDashCommunicatorService::DBusDashCommunicatorService(QObject *parent):
24DBusDashCommunicatorService::DBusDashCommunicatorService(QObject *parent):
25− QObject(parent)
25+ UnityDBusObject("/com/canonical/UnityDash", "com.canonical.UnityDash", parent)
26{
26{
27− // Use a zero-timer to let Qml finish loading before we announce on DBus
28− QTimer::singleShot(0, this, SLOT(registerDBus()));
29}
27}
30
28
31DBusDashCommunicatorService::~DBusDashCommunicatorService()
29DBusDashCommunicatorService::~DBusDashCommunicatorService()
@@ -36,11 +34,3 @@ void DBusDashCommunicatorService::SetCurrentScope(const QString &scopeId, bool a
36{
34{
37 Q_EMIT setCurrentScopeRequested(scopeId, animate, isSwipe);
35 Q_EMIT setCurrentScopeRequested(scopeId, animate, isSwipe);
38}
36}
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 @@
17#ifndef DBUSDASHCOMMUNICATORSERVICE_H
17#ifndef DBUSDASHCOMMUNICATORSERVICE_H
18#define DBUSDASHCOMMUNICATORSERVICE_H
18#define DBUSDASHCOMMUNICATORSERVICE_H
19
19
20+#include "unitydbusobject.h"
20#include <QObject>
21#include <QObject>
21
22
22−class DBusDashCommunicatorService: public QObject
23+class DBusDashCommunicatorService: public UnityDBusObject
23{
24{
24 Q_OBJECT
25 Q_OBJECT
25 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.DashCommunicator")
26 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.DashCommunicator")
@@ -34,8 +35,6 @@ Q_SIGNALS:
34public Q_SLOTS:
35public Q_SLOTS:
35 Q_SCRIPTABLE void SetCurrentScope(const QString &scopeId, bool animate, bool isSwipe);
36 Q_SCRIPTABLE void SetCurrentScope(const QString &scopeId, bool animate, bool isSwipe);
36
37
37−private Q_SLOTS:
38− void registerDBus();
39};
38};
40
39
41#endif // DBUSUNITYSESSIONSERVICE_H
40#endif // DBUSUNITYSESSIONSERVICE_H
plugins/Unity/Launcher/CMakeLists.txt+5−1
@@ -9,6 +9,7 @@ include_directories(
9 ${CMAKE_CURRENT_SOURCE_DIR}
9 ${CMAKE_CURRENT_SOURCE_DIR}
10 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
10 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
11 ${GSETTINGS_QT_INCLUDE_DIRS}
11 ${GSETTINGS_QT_INCLUDE_DIRS}
12+ ${libunity8-private_SOURCE_DIR}
12)
13)
13
14
14set(QMLLAUNCHERPLUGIN_SRC
15set(QMLLAUNCHERPLUGIN_SRC
@@ -30,7 +31,10 @@ add_library(UnityLauncher-qml MODULE
30 ${QMLLAUNCHERPLUGIN_SRC}
31 ${QMLLAUNCHERPLUGIN_SRC}
31 )
32 )
32
33
33−target_link_libraries(UnityLauncher-qml ${GSETTINGS_QT_LDFLAGS})
34+target_link_libraries(UnityLauncher-qml
35+ unity8-private
36+ ${GSETTINGS_QT_LDFLAGS}
37+ )
34
38
35qt5_use_modules(UnityLauncher-qml DBus Qml Gui)
39qt5_use_modules(UnityLauncher-qml DBus Qml Gui)
36
40
plugins/Unity/Launcher/dbusinterface.cpp+3−42
@@ -28,19 +28,13 @@
28#include <QTimer>
28#include <QTimer>
29
29
30DBusInterface::DBusInterface(LauncherModel *parent):
30DBusInterface::DBusInterface(LauncherModel *parent):
31− QDBusVirtualObject(parent),
31+ UnityDBusVirtualObject("/com/canonical/Unity/Launcher", "com.canonical.Unity.Launcher", parent),
32 m_launcherModel(parent)
32 m_launcherModel(parent)
33{
33{
34− // Use a zero-timer to let Qml finish loading before we announce on DBus
35− QTimer::singleShot(0, this, SLOT(registerDBus()));
36}
34}
37
35
38DBusInterface::~DBusInterface()
36DBusInterface::~DBusInterface()
39{
37{
40− /* Remove oursevles from DBus */
41− QDBusConnection con = QDBusConnection::sessionBus();
42− con.unregisterService("com.canonical.Unity.Launcher");
43− con.unregisterObject("/com/canonical/Unity/Launcher");
44}
38}
45
39
46QString DBusInterface::introspect(const QString &path) const
40QString DBusInterface::introspect(const QString &path) const
@@ -181,13 +175,13 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
181 int newCount = message.arguments()[2].toInt();
175 int newCount = message.arguments()[2].toInt();
182 if (!item || newCount != item->count()) {
176 if (!item || newCount != item->count()) {
183 Q_EMIT countChanged(appid, newCount);
177 Q_EMIT countChanged(appid, newCount);
184− emitPropChangedDbus(appid, "count", QVariant(newCount));
178+ notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "count", QVariant(newCount));
185 }
179 }
186 } else if (message.arguments()[1].toString() == "countVisible") {
180 } else if (message.arguments()[1].toString() == "countVisible") {
187 bool newVisible = message.arguments()[2].toBool();
181 bool newVisible = message.arguments()[2].toBool();
188 if (!item || newVisible != item->countVisible()) {
182 if (!item || newVisible != item->countVisible()) {
189 Q_EMIT countVisibleChanged(appid, newVisible);
183 Q_EMIT countVisibleChanged(appid, newVisible);
190− emitPropChangedDbus(appid, "countVisible", newVisible);
184+ notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "countVisible", newVisible);
191 }
185 }
192 }
186 }
193 } else if (message.member() == "GetAll") {
187 } else if (message.member() == "GetAll") {
@@ -204,36 +198,3 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
204 QDBusMessage reply = message.createReply(retval);
198 QDBusMessage reply = message.createReply(retval);
205 return connection.send(reply);
199 return connection.send(reply);
206}
200}
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 @@
18 */
18 */
19
19
20#include "launcheritem.h"
20#include "launcheritem.h"
21+#include "unitydbusvirtualobject.h"
21
22
22#include <QDBusVirtualObject>
23#include <QDBusVirtualObject>
23
24
24class LauncherModel;
25class LauncherModel;
25
26
26−class DBusInterface: public QDBusVirtualObject
27+class DBusInterface: public UnityDBusVirtualObject
27{
28{
28 Q_OBJECT
29 Q_OBJECT
29public:
30public:
@@ -43,10 +44,5 @@ private:
43 static QString decodeAppId(const QString& path);
44 static QString decodeAppId(const QString& path);
44 static QString encodeAppId(const QString& appId);
45 static QString encodeAppId(const QString& appId);
45
46
46− void emitPropChangedDbus(const QString& appId, const QString& property, const QVariant &value);
47−
48 LauncherModel *m_launcherModel;
47 LauncherModel *m_launcherModel;
49−
50−private Q_SLOTS:
51− void registerDBus();
52};
48};
plugins/Unity/Session/CMakeLists.txt+5−1
@@ -5,6 +5,7 @@ pkg_search_module(GIO REQUIRED gio-2.0)
5include_directories(
5include_directories(
6 ${CMAKE_CURRENT_SOURCE_DIR}
6 ${CMAKE_CURRENT_SOURCE_DIR}
7 ${GIO_INCLUDE_DIRS}
7 ${GIO_INCLUDE_DIRS}
8+ ${libunity8-private_SOURCE_DIR}
8)
9)
9
10
10set(QMLSESSIONPLUGIN_SRC
11set(QMLSESSIONPLUGIN_SRC
@@ -18,7 +19,10 @@ add_library(UnitySession-qml MODULE
18 )
19 )
19
20
20qt5_use_modules(UnitySession-qml DBus Qml)
21qt5_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+ )
22
26
23# export the qmldir and qmltypes files
27# export the qmldir and qmltypes files
24add_unity8_plugin(Unity.Session 0.1 Unity/Session TARGETS UnitySession-qml)
28add_unity8_plugin(Unity.Session 0.1 Unity/Session TARGETS UnitySession-qml)
plugins/Unity/Session/dbusunitysessionservice.cpp+2−14
@@ -22,10 +22,9 @@
22#include <QDBusInterface>
22#include <QDBusInterface>
23#include <QTimer>
23#include <QTimer>
24
24
25−DBusUnitySessionService::DBusUnitySessionService() : QObject()
25+DBusUnitySessionService::DBusUnitySessionService()
26+ : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
26{
27{
27− // Use a zero-timer to let Qml finish loading before we announce on DBus
28− QTimer::singleShot(0, this, SLOT(registerDBus()));
29}
28}
30
29
31DBusUnitySessionService::~DBusUnitySessionService()
30DBusUnitySessionService::~DBusUnitySessionService()
@@ -73,14 +72,3 @@ void DBusUnitySessionService::RequestShutdown()
73{
72{
74 Q_EMIT shutdownRequested(false);
73 Q_EMIT shutdownRequested(false);
75}
74}
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 @@
17#ifndef DBUSUNITYSESSIONSERVICE_H
17#ifndef DBUSUNITYSESSIONSERVICE_H
18#define DBUSUNITYSESSIONSERVICE_H
18#define DBUSUNITYSESSIONSERVICE_H
19
19
20+#include "unitydbusobject.h"
20#include <QObject>
21#include <QObject>
21
22
22/**
23/**
@@ -26,7 +27,7 @@
26 * com.canonical.Unity.Session interface provides public methods
27 * com.canonical.Unity.Session interface provides public methods
27 * and signals to handle Logout/Reboot/Shutdown.
28 * and signals to handle Logout/Reboot/Shutdown.
28 */
29 */
29−class DBusUnitySessionService : public QObject
30+class DBusUnitySessionService : public UnityDBusObject
30{
31{
31 Q_OBJECT
32 Q_OBJECT
32 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Session")
33 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Session")
@@ -134,8 +135,6 @@ public Q_SLOTS:
134 */
135 */
135 Q_SCRIPTABLE void RequestShutdown();
136 Q_SCRIPTABLE void RequestShutdown();
136
137
137−private Q_SLOTS:
138− void registerDBus();
139};
138};
140
139
141#endif // DBUSUNITYSESSIONSERVICE_H
140#endif // DBUSUNITYSESSIONSERVICE_H
src/libunity8-private/CMakeLists.txt+2
@@ -6,6 +6,8 @@ project(lib${LIB_NAME})
6
6
7set(lib${LIB_NAME}_SRCS
7set(lib${LIB_NAME}_SRCS
8 abstractdbusservicemonitor.cpp
8 abstractdbusservicemonitor.cpp
9+ unitydbusobject.cpp
10+ unitydbusvirtualobject.cpp
9 )
11 )
10
12
11add_library(${LIB_NAME} SHARED
13add_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(
15 ${CMAKE_CURRENT_BINARY_DIR}
15 ${CMAKE_CURRENT_BINARY_DIR}
16 ${CMAKE_SOURCE_DIR}/plugins/Utils
16 ${CMAKE_SOURCE_DIR}/plugins/Utils
17 ${CMAKE_SOURCE_DIR}/tests/mocks/libusermetrics
17 ${CMAKE_SOURCE_DIR}/tests/mocks/libusermetrics
18+ ${libunity8-private_SOURCE_DIR}
18)
19)
19
20
20set(QMLPLUGIN_SRC
21set(QMLPLUGIN_SRC
@@ -40,6 +41,7 @@ target_link_libraries(MockLightDM-qml
40 -llightdm-qt5-2
41 -llightdm-qt5-2
41 -L${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics
42 -L${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics
42 -lusermetricsoutput
43 -lusermetricsoutput
44+ unity8-private
43 )
45 )
44
46
45qt5_use_modules(MockLightDM-qml DBus Gui Qml)
47qt5_use_modules(MockLightDM-qml DBus Gui Qml)
tests/plugins/LightDM/CMakeLists.txt+2
@@ -11,12 +11,14 @@ include_directories(
11 ${CMAKE_SOURCE_DIR}/plugins/LightDM
11 ${CMAKE_SOURCE_DIR}/plugins/LightDM
12 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM
12 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM
13 ${LIBLIGHTDM_INCLUDE_DIRS}
13 ${LIBLIGHTDM_INCLUDE_DIRS}
14+ ${libunity8-private_SOURCE_DIR}
14 )
15 )
15
16
16add_dependencies(test-lightdm-dbus MockLightDM-full)
17add_dependencies(test-lightdm-dbus MockLightDM-full)
17target_link_libraries(test-lightdm-dbus
18target_link_libraries(test-lightdm-dbus
18 -L${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full
19 -L${CMAKE_BINARY_DIR}/tests/mocks/LightDM/full
19 -llightdm-qt5-2
20 -llightdm-qt5-2
21+ unity8-private
20 )
22 )
21
23
22add_definitions(-DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
24add_definitions(-DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
tests/plugins/Unity/Launcher/CMakeLists.txt+5−1
@@ -7,6 +7,7 @@ include_directories(
7 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
7 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
8 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
8 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
9 ${GSETTINGS_QT_INCLUDE_DIRS}
9 ${GSETTINGS_QT_INCLUDE_DIRS}
10+ ${libunity8-private_SOURCE_DIR}
10 )
11 )
11
12
12add_definitions(-DSM_BUSNAME=sessionBus)
13add_definitions(-DSM_BUSNAME=sessionBus)
@@ -34,7 +35,10 @@ add_executable(launchermodeltestExec
34 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
35 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
35 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
36 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
36 )
37 )
37−target_link_libraries(launchermodeltestExec ${GSETTINGS_QT_LDFLAGS})
38+target_link_libraries(launchermodeltestExec
39+ unity8-private
40+ ${GSETTINGS_QT_LDFLAGS}
41+ )
38qt5_use_modules(launchermodeltestExec Test Core DBus Xml Gui)
42qt5_use_modules(launchermodeltestExec Test Core DBus Xml Gui)
39
43
40# copy .desktop files into build directory for shadow builds
44# copy .desktop files into build directory for shadow builds
tests/plugins/Unity/Session/CMakeLists.txt+4
@@ -1,6 +1,7 @@
1include_directories(
1include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}
2 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session
3 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session
4+ ${libunity8-private_SOURCE_DIR}
4)
5)
5
6
6add_definitions(-DSM_BUSNAME=sessionBus)
7add_definitions(-DSM_BUSNAME=sessionBus)
@@ -17,4 +18,7 @@ add_executable(sessionbackendtestExec
17 sessionbackendtest.cpp
18 sessionbackendtest.cpp
18 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session/dbusunitysessionservice.cpp
19 ${CMAKE_SOURCE_DIR}/plugins/Unity/Session/dbusunitysessionservice.cpp
19)
20)
21+target_link_libraries(sessionbackendtestExec
22+ unity8-private
23+ )
20qt5_use_modules(sessionbackendtestExec Test Core Qml DBus)
24qt5_use_modules(sessionbackendtestExec Test Core Qml DBus)