~ubuntu-branches/ubuntu/wily/unity-2d/wily

« back to all changes in this revision

Viewing changes to panel/applets/homebutton/homebuttonapplet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-08-25 18:16:57 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20110825181657-opb29rqsxae3i98f
Tags: 4.2.0-0ubuntu1
* New upstream release:
  - [panel] application menus do not appear on first hover after dismissal
    (lp: #825262)
  - [dash] Lens icons badly scaled (lp: #825368)
  - [panel] indicators are shifted offscreen to the right (lp: #827673)
  - [panel] scrubbing from system indicators to menubar should be possible
    (lp: #706903)
  - [launcher] Closed applications don't get their launcher counts cleared
    (lp: #767367)
  - [dash] selected item should not be underlined but use the same 
    treatment as unity (lp: #817456)
  - [dash] categories should be collapsed by default (lp: #827214)
  - [dash] Ratings filter (lp: #831855)
  - [dash] Multirange filter (lp: #831856)
  - [dash] ToggleButton filter (lp: #831857)
  - [dash] Icon size must be bigger to match the mockups (lp: #831858)
  - [dash] "Refine search" right margin should be 15 pixels (lp: #832058)
  - [dash] "Refine search" should be "Filter results" (lp: #832060)
  - [dash] Font sizes should match new design (lp: #832114)
  - [panel] Glitch: application menu appearing when pressing the BFB 
    (lp: #825060)
  - [panel] Glitch: application menus are quickly opened after a drag gesture
    (lp: #825267)
  - [dash] File thumbnails aspect ratio is not respected (lp: #832204)
* debian/control: require current the current versions of nux and unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of unity-2d
 
3
 *
 
4
 * Copyright 2010 Canonical Ltd.
 
5
 *
 
6
 * Authors:
 
7
 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
 
8
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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/>.
 
20
 */
 
21
 
 
22
// Self
 
23
#include "homebuttonapplet.h"
 
24
 
 
25
// Local
 
26
#include <debug_p.h>
 
27
 
 
28
// libunity-2d
 
29
#include <launcherclient.h>
 
30
 
 
31
// Qt
 
32
#include <QHBoxLayout>
 
33
#include <QDBusInterface>
 
34
#include <QDBusServiceWatcher>
 
35
#include <QDBusConnectionInterface>
 
36
 
 
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";
 
40
 
 
41
HomeButtonApplet::HomeButtonApplet(Unity2dPanel* panel)
 
42
: Unity2d::PanelApplet(panel)
 
43
, m_button(new HomeButton)
 
44
, m_dashInterface(NULL)
 
45
, m_launcherClient(new LauncherClient(this))
 
46
{
 
47
    connect(m_button, SIGNAL(clicked()), SLOT(toggleDash()));
 
48
 
 
49
    QHBoxLayout* layout = new QHBoxLayout(this);
 
50
    layout->setMargin(0);
 
51
    layout->addWidget(m_button);
 
52
 
 
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) {
 
60
        connectToDash();
 
61
    } else {
 
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()));
 
67
    }
 
68
}
 
69
 
 
70
void HomeButtonApplet::connectToDash()
 
71
{
 
72
    if (m_dashInterface != NULL) {
 
73
        return;
 
74
    }
 
75
 
 
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)));
 
79
 
 
80
    /* Immediately update the home button with the current state of the dash */
 
81
    m_button->setChecked(m_dashInterface->property("active").toBool());
 
82
}
 
83
 
 
84
void HomeButtonApplet::toggleDash()
 
85
{
 
86
    if (m_dashInterface == NULL || !m_dashInterface->isValid()) {
 
87
        connectToDash();
 
88
    }
 
89
 
 
90
    bool dashActive = m_dashInterface->property("active").toBool();
 
91
 
 
92
    if (dashActive) {
 
93
        m_dashInterface->setProperty("active", false);
 
94
    } else {
 
95
        /* Call com.canonical.Unity2d.Dash.activateHome (will set com.canonical.Unity2d.Dash.active to true */
 
96
        m_dashInterface->call(QDBus::Block, "activateHome");
 
97
    }
 
98
}
 
99
 
 
100
void HomeButtonApplet::enterEvent(QEvent* event)
 
101
{
 
102
    QWidget::enterEvent(event);
 
103
    m_launcherClient->beginForceVisible();
 
104
}
 
105
 
 
106
void HomeButtonApplet::leaveEvent(QEvent* event)
 
107
{
 
108
    QWidget::leaveEvent(event);
 
109
    m_launcherClient->endForceVisible();
 
110
}
 
111
 
 
112
#include "homebuttonapplet.moc"