on xenial help sign in
Convert DashCommunicator to use AbstractDBusServiceMonitor
commit200453ad448aa770e59981fbd03b3657dc37f180 authorGerry Boland <gerry.boland@canonical.com> dateFri 5 Sep 2014, 12:55 (12 years ago) parent0996017
3 files changed+25−21
plugins/Unity/DashCommunicator/CMakeLists.txt+7−2 plugins/Unity/DashCommunicator/dashcommunicator.cpp+11−15 plugins/Unity/DashCommunicator/dashcommunicator.h+7−4
plugins/Unity/DashCommunicator/CMakeLists.txt+7−2
@@ -1,5 +1,6 @@
11include_directories(
22 ${CMAKE_CURRENT_SOURCE_DIR}
3+ ${libunity8-private_SOURCE_DIR}
34)
45
56set(QMLDASHCOMMUNICATORPLUGIN_SRC
@@ -7,13 +8,17 @@ set(QMLDASHCOMMUNICATORPLUGIN_SRC
78 dbusdashcommunicatorservice.cpp
89 dashcommunicatorservice.cpp
910 dashcommunicator.cpp
10− )
11+)
1112
1213add_library(DashCommunicator-qml MODULE
1314 ${QMLDASHCOMMUNICATORPLUGIN_SRC}
14− )
15+)
1516
1617qt5_use_modules(DashCommunicator-qml DBus Qml)
1718
19+target_link_libraries(DashCommunicator-qml
20+ unity8-private
21+)
22+
1823# export the qmldir and qmltypes files
1924add_unity8_plugin(Unity.DashCommunicator 0.1 Unity/DashCommunicator TARGETS DashCommunicator-qml)
plugins/Unity/DashCommunicator/dashcommunicator.cpp+11−15
@@ -16,28 +16,24 @@
1616
1717#include "dashcommunicator.h"
1818
19−#include <QObject>
2019#include <QDBusConnection>
20+#include <QDBusConnectionInterface>
2121#include <QDBusInterface>
2222#include <QDebug>
2323
24−DashCommunicator::DashCommunicator(QObject *parent):
25− QObject(parent)
24+DashCommunicator::DashCommunicator(QObject *parent)
25+ : AbstractDBusServiceMonitor("com.canonical.UnityDash",
26+ "/com/canonical/UnityDash",
27+ "", parent)
2628{
2729}
2830
29−DashCommunicator::~DashCommunicator()
30−{
31−}
32−
33−
3431void DashCommunicator::setCurrentScope(const QString &scopeId, bool animate, bool reset)
3532{
36− QDBusConnection connection = QDBusConnection::sessionBus();
37− QDBusInterface dashIface ("com.canonical.UnityDash",
38− "/com/canonical/UnityDash",
39− "",
40− connection);
41−
42− dashIface.call("SetCurrentScope", scopeId, animate, reset);
33+ if (dbusInterface() == nullptr) {
34+ qDebug() << "DashCommunicator - setCurrentScope failed as Dash DBus interface not available";
35+ return;
36+ } else {
37+ dbusInterface()->asyncCall("SetCurrentScope", scopeId, animate, reset);
38+ }
4339}
plugins/Unity/DashCommunicator/dashcommunicator.h+7−4
@@ -17,16 +17,19 @@
1717#ifndef DASHCOMMUNICATOR_H
1818#define DASHCOMMUNICATOR_H
1919
20+// Qt
2021#include <QObject>
2122
22−class DashCommunicator: public QObject
23+// local
24+#include "abstractdbusservicemonitor.h"
25+
26+class DashCommunicator: public AbstractDBusServiceMonitor
2327{
2428 Q_OBJECT
25− Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.DashCommunicator")
2629
2730public:
28− DashCommunicator(QObject *parent = 0);
29− ~DashCommunicator();
31+ explicit DashCommunicator(QObject *parent = 0);
32+ ~DashCommunicator() = default;
3033
3134public Q_SLOTS:
3235 void setCurrentScope(const QString &scopeId, bool animate, bool reset);