on xenial help sign in
Convert DashCommunicator to use AbstractDBusServiceMonitor
200453aGerry Boland
plugins/Unity/DashCommunicator/CMakeLists.txt+7−2
@@ -1,5 +1,6 @@
1include_directories(
1include_directories(
2 ${CMAKE_CURRENT_SOURCE_DIR}
2 ${CMAKE_CURRENT_SOURCE_DIR}
3+ ${libunity8-private_SOURCE_DIR}
3)
4)
4
5
5set(QMLDASHCOMMUNICATORPLUGIN_SRC
6set(QMLDASHCOMMUNICATORPLUGIN_SRC
@@ -7,13 +8,17 @@ set(QMLDASHCOMMUNICATORPLUGIN_SRC
7 dbusdashcommunicatorservice.cpp
8 dbusdashcommunicatorservice.cpp
8 dashcommunicatorservice.cpp
9 dashcommunicatorservice.cpp
9 dashcommunicator.cpp
10 dashcommunicator.cpp
10− )
11+)
11
12
12add_library(DashCommunicator-qml MODULE
13add_library(DashCommunicator-qml MODULE
13 ${QMLDASHCOMMUNICATORPLUGIN_SRC}
14 ${QMLDASHCOMMUNICATORPLUGIN_SRC}
14− )
15+)
15
16
16qt5_use_modules(DashCommunicator-qml DBus Qml)
17qt5_use_modules(DashCommunicator-qml DBus Qml)
17
18
19+target_link_libraries(DashCommunicator-qml
20+ unity8-private
21+)
22+
18# export the qmldir and qmltypes files
23# export the qmldir and qmltypes files
19add_unity8_plugin(Unity.DashCommunicator 0.1 Unity/DashCommunicator TARGETS DashCommunicator-qml)
24add_unity8_plugin(Unity.DashCommunicator 0.1 Unity/DashCommunicator TARGETS DashCommunicator-qml)
plugins/Unity/DashCommunicator/dashcommunicator.cpp+11−15
@@ -16,28 +16,24 @@
16
16
17#include "dashcommunicator.h"
17#include "dashcommunicator.h"
18
18
19−#include <QObject>
20#include <QDBusConnection>
19#include <QDBusConnection>
20+#include <QDBusConnectionInterface>
21#include <QDBusInterface>
21#include <QDBusInterface>
22#include <QDebug>
22#include <QDebug>
23
23
24−DashCommunicator::DashCommunicator(QObject *parent):
24+DashCommunicator::DashCommunicator(QObject *parent)
25+ : AbstractDBusServiceMonitor("com.canonical.UnityDash",
26+ "/com/canonical/UnityDash",
25− QObject(parent)
27+ "", parent)
26{
28{
27}
29}
28
30
29−DashCommunicator::~DashCommunicator()
30−{
31−}
32−
33−
34void DashCommunicator::setCurrentScope(const QString &scopeId, bool animate, bool reset)
31void DashCommunicator::setCurrentScope(const QString &scopeId, bool animate, bool reset)
35{
32{
36− QDBusConnection connection = QDBusConnection::sessionBus();
33+ if (dbusInterface() == nullptr) {
37− QDBusInterface dashIface ("com.canonical.UnityDash",
34+ qDebug() << "DashCommunicator - setCurrentScope failed as Dash DBus interface not available";
38− "/com/canonical/UnityDash",
35+ return;
39− "",
36+ } else {
40− connection);
41−
42− dashIface.call("SetCurrentScope", scopeId, animate, reset);
37+ dbusInterface()->asyncCall("SetCurrentScope", scopeId, animate, reset);
38+ }
43}
39}
plugins/Unity/DashCommunicator/dashcommunicator.h+7−4
@@ -17,16 +17,19 @@
17#ifndef DASHCOMMUNICATOR_H
17#ifndef DASHCOMMUNICATOR_H
18#define DASHCOMMUNICATOR_H
18#define DASHCOMMUNICATOR_H
19
19
20+// Qt
20#include <QObject>
21#include <QObject>
21
22
23+// local
24+#include "abstractdbusservicemonitor.h"
25+
22−class DashCommunicator: public QObject
26+class DashCommunicator: public AbstractDBusServiceMonitor
23{
27{
24 Q_OBJECT
28 Q_OBJECT
25− Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.DashCommunicator")
26
29
27public:
30public:
28− DashCommunicator(QObject *parent = 0);
31+ explicit DashCommunicator(QObject *parent = 0);
29− ~DashCommunicator();
32+ ~DashCommunicator() = default;
30
33
31public Q_SLOTS:
34public Q_SLOTS:
32 void setCurrentScope(const QString &scopeId, bool animate, bool reset);
35 void setCurrentScope(const QString &scopeId, bool animate, bool reset);