~jbicha/unity-2d/fix-launcher-quicklist-naming-lp949636

« back to all changes in this revision

Viewing changes to panel/applets/appname/appnameapplet.cpp

  • Committer: Aurelien Gateau
  • Date: 2010-10-06 13:52:55 UTC
  • Revision ID: aurelien.gateau@canonical.com-20101006135255-j4gsdm7k3grh0ydh
Merged in panel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of unity-qt
 
3
 *
 
4
 * Copyright 2010 Canonical Ltd.
 
5
 *
 
6
 * Authors:
 
7
 * - Aurélien Gâteau <aurelien.gateau@canonical.com>
 
8
 *
 
9
 * License: GPL v3
 
10
 */
 
11
// Self
 
12
#include "appnameapplet.h"
 
13
 
 
14
// Local
 
15
 
 
16
// Bamf
 
17
#include <bamf-application.h>
 
18
#include <bamf-matcher.h>
 
19
 
 
20
// Qt
 
21
#include <QHBoxLayout>
 
22
#include <QLabel>
 
23
 
 
24
namespace UnityQt
 
25
{
 
26
 
 
27
struct AppNameAppletPrivate
 
28
{
 
29
    QLabel* m_label;
 
30
};
 
31
 
 
32
AppNameApplet::AppNameApplet()
 
33
: d(new AppNameAppletPrivate)
 
34
{
 
35
    d->m_label = new QLabel;
 
36
 
 
37
    QHBoxLayout* layout = new QHBoxLayout(this);
 
38
    layout->setMargin(0);
 
39
    layout->addWidget(d->m_label);
 
40
 
 
41
    connect(&BamfMatcher::get_default(), SIGNAL(ActiveApplicationChanged(BamfApplication*, BamfApplication*)), SLOT(updateLabel()));
 
42
    updateLabel();
 
43
}
 
44
 
 
45
AppNameApplet::~AppNameApplet()
 
46
{
 
47
    delete d;
 
48
}
 
49
 
 
50
void AppNameApplet::updateLabel()
 
51
{
 
52
    BamfApplication* app = BamfMatcher::get_default().active_application();
 
53
    if (app) {
 
54
        d->m_label->setText(app->name());
 
55
    } else {
 
56
        d->m_label->setText(QString());
 
57
    }
 
58
    adjustSize();
 
59
}
 
60
 
 
61
} // namespace
 
62
 
 
63
APPLET_MAIN(UnityQt::AppNameApplet)
 
64
 
 
65
#include "appnameapplet.moc"