2
* This file is part of unity-2d
4
* Copyright 2010 Canonical Ltd.
7
* - Aurélien Gâteau <aurelien.gateau@canonical.com>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; version 3.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "homebuttonapplet.h"
29
#include <launcherclient.h>
32
#include <QHBoxLayout>
33
#include <QDBusInterface>
34
#include <QDBusServiceWatcher>
35
#include <QDBusConnectionInterface>
37
static const char* DBUS_SERVICE = "com.canonical.Unity2d.Dash";
38
static const char* DBUS_PATH = "/Dash";
39
static const char* DBUS_IFACE = "com.canonical.Unity2d.Dash";
41
HomeButtonApplet::HomeButtonApplet(Unity2dPanel* panel)
42
: Unity2d::PanelApplet(panel)
43
, m_button(new HomeButton)
44
, m_dashInterface(NULL)
45
, m_launcherClient(new LauncherClient(this))
47
connect(m_button, SIGNAL(clicked()), SLOT(toggleDash()));
49
QHBoxLayout* layout = new QHBoxLayout(this);
51
layout->addWidget(m_button);
53
/* Check if the dash is already up and running by asking the bus instead of
54
trying to create an instance of the interface. Creating an instance
55
will cause DBUS to activate the dash and we don't want this to happen, especially
56
during startup where the dash is started with a delay. */
57
QDBusConnectionInterface* sessionBusIFace = QDBusConnection::sessionBus().interface();
58
QDBusReply<bool> reply = sessionBusIFace->isServiceRegistered(DBUS_SERVICE);
59
if (reply.isValid() && reply.value() == true) {
62
/* If the dash is not running, setup a notification so that we can
63
connect to it later when it comes up */
64
QDBusServiceWatcher* serviceWatcher = new QDBusServiceWatcher(DBUS_SERVICE, QDBusConnection::sessionBus(),
65
QDBusServiceWatcher::WatchForRegistration, this);
66
connect(serviceWatcher, SIGNAL(serviceRegistered(QString)), SLOT(connectToDash()));
70
void HomeButtonApplet::connectToDash()
72
if (m_dashInterface != NULL) {
76
m_dashInterface = new QDBusInterface(DBUS_SERVICE, DBUS_PATH, DBUS_IFACE,
77
QDBusConnection::sessionBus(), this);
78
m_button->connect(m_dashInterface, SIGNAL(activeChanged(bool)), SLOT(setChecked(bool)));
80
/* Immediately update the home button with the current state of the dash */
81
m_button->setChecked(m_dashInterface->property("active").toBool());
84
void HomeButtonApplet::toggleDash()
86
if (m_dashInterface == NULL || !m_dashInterface->isValid()) {
90
bool dashActive = m_dashInterface->property("active").toBool();
93
m_dashInterface->setProperty("active", false);
95
/* Call com.canonical.Unity2d.Dash.activateHome (will set com.canonical.Unity2d.Dash.active to true */
96
m_dashInterface->call(QDBus::Block, "activateHome");
100
void HomeButtonApplet::enterEvent(QEvent* event)
102
QWidget::enterEvent(event);
103
m_launcherClient->beginForceVisible();
106
void HomeButtonApplet::leaveEvent(QEvent* event)
108
QWidget::leaveEvent(event);
109
m_launcherClient->endForceVisible();
112
#include "homebuttonapplet.moc"