on aa536ad help sign in
unity8/plugins/Unity/DashCommunicator/dashcommunicator.cpp
121 lines 4.1 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "dashcommunicator.h"
19#include <unity/shell/application/ApplicationInfoInterface.h>
20#include <unity/shell/application/ApplicationManagerInterface.h>
22#include <QObject>
23#include <QDBusConnection>
24#include <QDBusInterface>
25#include <QDebug>
26#include <QDBusPendingCall>
28using namespace unity::shell::application;
30DashCommunicator::DashCommunicator(QObject *parent):
31 QObject(parent),
32 m_dashInterface(nullptr),
33 m_applicationManager(nullptr),
34 m_dash(nullptr)
38DashCommunicator::~DashCommunicator()
42void DashCommunicator::setCurrentScope(const QString &scopeId, bool animate, bool isSwipe)
44 // Connection not up... Try to connect
45 if (!m_dashInterface || !m_dashInterface->isValid()) {
46 connectToDash();
47 }
49 if (m_dashInterface && m_dashInterface->isValid()) {
50 // Using an async call just in case the Dash would fail to wake up from suspend
51 // We don't want to hang the whole shell waiting for reply.
52 m_dashInterface->asyncCall("SetCurrentScope", scopeId, animate, isSwipe);
53 }
56void DashCommunicator::connectToDash()
58 if (m_dashInterface) {
59 m_dashInterface->deleteLater();
60 m_dashInterface = nullptr;
61 }
63 if (m_applicationManager) {
64 ApplicationInfoInterface *dash = m_applicationManager->findApplication("unity8-dash");
65 // Don't try to connect to the Dash while its suspended, it would hang the shell waiting for a reply.
66 if (dash && dash->state() == ApplicationInfoInterface::Running) {
67 QDBusConnection connection = QDBusConnection::sessionBus();
68 m_dashInterface = new QDBusInterface("com.canonical.UnityDash",
69 "/com/canonical/UnityDash",
70 "",
71 connection);
72 } else {
73 qWarning() << "Dash is suspended or not running. Can't connect.";
74 }
75 }
78unity::shell::application::ApplicationManagerInterface* DashCommunicator::applicationManager() const
80 return m_applicationManager;
83void DashCommunicator::setApplicationManager(unity::shell::application::ApplicationManagerInterface *appManager)
85 if (m_applicationManager != appManager) {
86 m_applicationManager = appManager;
87 Q_EMIT applicationManagerChanged();
89 connect(m_applicationManager, &unity::shell::application::ApplicationManagerInterface::applicationAdded, this, &DashCommunicator::applicationAdded);
90 connect(m_applicationManager, &unity::shell::application::ApplicationManagerInterface::applicationRemoved, this, &DashCommunicator::applicationRemoved);
92 // If the Dash is around already, immediately try to connect
93 if (m_applicationManager->findApplication("unity8-dash")) {
94 connectToDash();
95 }
96 }
99void DashCommunicator::applicationAdded(const QString &appId)
101 if (appId != "unity8-dash") {
102 return;
103 }
104 ApplicationInfoInterface *app = m_applicationManager->findApplication(appId);
105 if (!app) {
106 qWarning() << "DashCommunicator received an applicationAdded signal for the dash, but there's no dash around!";
107 return;
108 }
109 connectToDash();
112void DashCommunicator::applicationRemoved(const QString &appId)
114 if (appId != "unity8-dash") {
115 return;
116 }
117 if (m_dashInterface) {
118 m_dashInterface->deleteLater();
119 m_dashInterface = nullptr;
120 }