on xenial help sign in
make the dashcommunicator async
commit2d99d78aebf65a670480f845854220caf30848d1 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 18 Sep 2014, 11:06 (12 years ago) parentbd05eec
4 files changed+114−8
plugins/Unity/DashCommunicator/CMakeLists.txt+4 plugins/Unity/DashCommunicator/dashcommunicator.cpp+80−8 plugins/Unity/DashCommunicator/dashcommunicator.h+29 qml/Shell.qml+1
plugins/Unity/DashCommunicator/CMakeLists.txt+4
@@ -1,3 +1,6 @@
1+include(FindPkgConfig)
2+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=3)
3+
14include_directories(
25 ${CMAKE_CURRENT_SOURCE_DIR}
36)
@@ -7,6 +10,7 @@ set(QMLDASHCOMMUNICATORPLUGIN_SRC
710 dbusdashcommunicatorservice.cpp
811 dashcommunicatorservice.cpp
912 dashcommunicator.cpp
13+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
1014 )
1115
1216add_library(DashCommunicator-qml MODULE
plugins/Unity/DashCommunicator/dashcommunicator.cpp+80−8
@@ -16,13 +16,22 @@
1616
1717#include "dashcommunicator.h"
1818
19+#include <unity/shell/application/ApplicationInfoInterface.h>
20+#include <unity/shell/application/ApplicationManagerInterface.h>
21+
1922#include <QObject>
2023#include <QDBusConnection>
2124#include <QDBusInterface>
2225#include <QDebug>
26+#include <QDBusPendingCall>
27+
28+using namespace unity::shell::application;
2329
2430DashCommunicator::DashCommunicator(QObject *parent):
25− QObject(parent)
31+ QObject(parent),
32+ m_dashInterface(nullptr),
33+ m_applicationManager(nullptr),
34+ m_dash(nullptr)
2635{
2736}
2837
@@ -30,14 +39,77 @@ DashCommunicator::~DashCommunicator()
3039{
3140}
3241
33−
3442void DashCommunicator::setCurrentScope(const QString &scopeId, bool animate, bool isSwipe)
3543{
36− QDBusConnection connection = QDBusConnection::sessionBus();
37− QDBusInterface dashIface ("com.canonical.UnityDash",
38− "/com/canonical/UnityDash",
39− "",
40− connection);
44+ // Connection not up... Try to connect
45+ if (!m_dashInterface || !m_dashInterface->isValid()) {
46+ connectToDash();
47+ }
48+
49+ if (m_dashInterface && m_dashInterface->isValid()) {
50+ m_dashInterface->asyncCall("SetCurrentScope", scopeId, animate, isSwipe);
51+ }
52+}
53+
54+void DashCommunicator::connectToDash()
55+{
56+ if (m_dashInterface) {
57+ m_dashInterface->deleteLater();
58+ m_dashInterface = nullptr;
59+ }
60+
61+ if (m_applicationManager) {
62+ ApplicationInfoInterface *dash = m_applicationManager->findApplication("unity8-dash");
63+ if (dash && dash->state() == ApplicationInfoInterface::Running) {
64+ QDBusConnection connection = QDBusConnection::sessionBus();
65+ m_dashInterface = new QDBusInterface("com.canonical.UnityDash",
66+ "/com/canonical/UnityDash",
67+ "",
68+ connection);
69+ } else {
70+ qWarning() << "Dash is suspended or not running. Can't connect.";
71+ }
72+ }
73+}
74+
75+unity::shell::application::ApplicationManagerInterface* DashCommunicator::applicationManager() const
76+{
77+ return m_applicationManager;
78+}
79+
80+void DashCommunicator::setApplicationManager(unity::shell::application::ApplicationManagerInterface *appManager)
81+{
82+ if (m_applicationManager != appManager) {
83+ m_applicationManager = appManager;
84+ Q_EMIT applicationManagerChanged();
85+
86+ connect(m_applicationManager, &unity::shell::application::ApplicationManagerInterface::applicationAdded, this, &DashCommunicator::applicationAdded);
87+ connect(m_applicationManager, &unity::shell::application::ApplicationManagerInterface::applicationRemoved, this, &DashCommunicator::applicationRemoved);
88+
89+ if (m_applicationManager->findApplication("unity8-dash")) {
90+ applicationAdded("unity8-dash");
91+ }
92+ }
93+}
94+
95+void DashCommunicator::applicationAdded(const QString &appId)
96+{
97+ if (appId != "unity8-dash") {
98+ return;
99+ }
100+ ApplicationInfoInterface *app = m_applicationManager->findApplication(appId);
101+ if (!app) {
102+ qWarning() << "DashCommunicator received an applicationAdded signal for dash, but there's no dash!";
103+ return;
104+ }
105+ connectToDash();
106+}
41107
42− dashIface.call("SetCurrentScope", scopeId, animate, isSwipe);
108+void DashCommunicator::applicationRemoved(const QString &appId)
109+{
110+ if (appId != "unity8-dash") {
111+ return;
112+ }
113+ m_dashInterface->deleteLater();
114+ m_dashInterface = nullptr;
43115}
plugins/Unity/DashCommunicator/dashcommunicator.h+29
@@ -19,17 +19,46 @@
1919
2020#include <QObject>
2121
22+class QDBusInterface;
23+
24+namespace unity {
25+namespace shell {
26+namespace application {
27+class ApplicationManagerInterface;
28+class ApplicationInfoInterface;
29+}
30+}
31+}
32+
2233class DashCommunicator: public QObject
2334{
2435 Q_OBJECT
2536 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.DashCommunicator")
2637
38+ Q_PROPERTY(unity::shell::application::ApplicationManagerInterface* applicationManager
39+ READ applicationManager WRITE setApplicationManager NOTIFY applicationManagerChanged)
2740public:
2841 DashCommunicator(QObject *parent = 0);
2942 ~DashCommunicator();
3043
44+ unity::shell::application::ApplicationManagerInterface* applicationManager() const;
45+ void setApplicationManager(unity::shell::application::ApplicationManagerInterface *appManager);
46+
47+Q_SIGNALS:
48+ void applicationManagerChanged();
49+
3150public Q_SLOTS:
3251 void setCurrentScope(const QString &scopeId, bool animate, bool isSwipe);
52+
53+private Q_SLOTS:
54+ void connectToDash();
55+ void applicationAdded(const QString &appId);
56+ void applicationRemoved(const QString &appId);
57+
58+private:
59+ QDBusInterface *m_dashInterface;
60+ unity::shell::application::ApplicationManagerInterface* m_applicationManager;
61+ unity::shell::application::ApplicationInfoInterface* m_dash;
3362};
3463
3564#endif
qml/Shell.qml+1
@@ -103,6 +103,7 @@ Item {
103103 DashCommunicator {
104104 id: dash
105105 objectName: "dashCommunicator"
106+ applicationManager: ApplicationManager
106107 }
107108
108109 WindowKeysFilter {