on xenial help sign in
make it threaded
0929203Michael Zanetti
plugins/Unity/DashCommunicator/CMakeLists.txt+1
@@ -8,6 +8,7 @@ set(QMLDASHCOMMUNICATORPLUGIN_SRC
8 dbusdashcommunicatorservice.cpp
8 dbusdashcommunicatorservice.cpp
9 dashcommunicatorservice.cpp
9 dashcommunicatorservice.cpp
10 dashcommunicator.cpp
10 dashcommunicator.cpp
11+ dashconnection.cpp
11)
12)
12
13
13add_library(DashCommunicator-qml MODULE
14add_library(DashCommunicator-qml MODULE
plugins/Unity/DashCommunicator/dashcommunicator.cpp+16−10
@@ -15,32 +15,38 @@
15 */
15 */
16
16
17#include "dashcommunicator.h"
17#include "dashcommunicator.h"
18−
18+#include "dashconnection.h"
19
19
20#include <QObject>
20#include <QObject>
21−#include <QDBusConnection>
22−#include <QDBusConnectionInterface>
23−#include <QDBusInterface>
24−#include <QDebug>
25−#include <QDBusPendingCall>
26
21
27DashCommunicator::DashCommunicator(QObject *parent):
22DashCommunicator::DashCommunicator(QObject *parent):
28 QThread(parent),
23 QThread(parent),
29− m_dashService(nullptr)
24+ m_dashConnection(nullptr),
25+ m_created(false)
30{
26{
31 start();
27 start();
32}
28}
33
29
34void DashCommunicator::setCurrentScope(const QString &scopeId, bool animate, bool isSwipe)
30void DashCommunicator::setCurrentScope(const QString &scopeId, bool animate, bool isSwipe)
35{
31{
36− m_dashService->dbusInterface()->asyncCall("SetCurrentScope", scopeId, animate, isSwipe);
32+ m_mutex.lock();
33+ if (m_created) {
34+ QMetaObject::invokeMethod(m_dashConnection, "setCurrentScope",
35+ Q_ARG(QString, scopeId),
36+ Q_ARG(bool, animate),
37+ Q_ARG(bool, isSwipe));
38+ }
39+ m_mutex.unlock();
37}
40}
38
41
39void DashCommunicator::run()
42void DashCommunicator::run()
40{
43{
41− m_dashService = new AbstractDBusServiceMonitor("com.canonical.UnityDash",
44+ m_dashConnection = new DashConnection("com.canonical.UnityDash",
42 "/com/canonical/UnityDash",
45 "/com/canonical/UnityDash",
43− "", AbstractDBusServiceMonitor::SessionBus, this);
46+ "", this);
47+ m_mutex.lock();
48+ m_created = true;
49+ m_mutex.unlock();
44
50
45 exec();
51 exec();
46}
52}
plugins/Unity/DashCommunicator/dashcommunicator.h+5−3
@@ -19,9 +19,9 @@
19
19
20// Qt
20// Qt
21#include <QThread>
21#include <QThread>
22+#include <QMutex>
22
23
23−// local
24+class DashConnection;
24−#include "abstractdbusservicemonitor.h"
25
25
26class DashCommunicator: public QThread
26class DashCommunicator: public QThread
27{
27{
@@ -37,7 +37,9 @@ protected:
37 void run() override;
37 void run() override;
38
38
39private:
39private:
40− AbstractDBusServiceMonitor *m_dashService;
40+ DashConnection *m_dashConnection;
41+ bool m_created;
42+ QMutex m_mutex;
41};
43};
42
44
43#endif
45#endif