~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/desktop/shell/activitymanager/activitylist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2010 Chani Armitage <chani@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library/Lesser General Public License
 
6
 *   version 2, or (at your option) any later version, as published by the
 
7
 *   Free Software Foundation
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library/Lesser General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "activitylist.h"
 
21
 
 
22
#include "activity.h"
 
23
#include "plasmaapp.h"
 
24
#include "kactivitycontroller.h"
 
25
 
 
26
#include <QHash>
 
27
 
 
28
#include <Plasma/Containment>
 
29
#include <Plasma/Corona>
 
30
 
 
31
#include <KService>
 
32
#include <KServiceTypeTrader>
 
33
 
 
34
ActivityList::ActivityList(Plasma::Location location, QGraphicsItem *parent)
 
35
    : AbstractIconList(location, parent),
 
36
      m_activityController(new KActivityController(this)),
 
37
      m_scheduleHideOnAdd(0)
 
38
{
 
39
    QStringList activities = m_activityController->listActivities();
 
40
    foreach (const QString &activity, activities) {
 
41
        createActivityIcon(activity);
 
42
    }
 
43
 
 
44
    KService::List templates = KServiceTypeTrader::self()->query("Plasma/LayoutTemplate");
 
45
    foreach (const KService::Ptr &service, templates) {
 
46
        if (!service->property("X-Plasma-ContainmentLayout-ShowAsExisting", QVariant::Bool).toBool()) continue;
 
47
 
 
48
        KConfig config("plasma-desktoprc");
 
49
        KConfigGroup group(&config, "ActivityManager HiddenTemplates");
 
50
 
 
51
        if (group.readEntry(service->storageId(), false)) continue;
 
52
 
 
53
        createActivityIcon(service->name(), service->icon(), service->storageId());
 
54
    }
 
55
 
 
56
    updateClosable();
 
57
 
 
58
    /*
 
59
    if (m_allAppletsHash.count() == 1) {
 
60
        ActivityIcon *icon = qobject_cast<ActivityIcon*>(m_allAppletsHash.values().first());
 
61
        if (icon) {
 
62
            icon->setClosable(false);
 
63
        }
 
64
    }*/
 
65
    //TODO:
 
66
    //-do something about sorting and filtering (most recent first?)
 
67
 
 
68
    connect(m_activityController, SIGNAL(activityAdded(const QString &)), this, SLOT(activityAdded(const QString &)));
 
69
    connect(m_activityController, SIGNAL(activityRemoved(const QString &)), this, SLOT(activityRemoved(const QString &)));
 
70
 
 
71
    updateList();
 
72
}
 
73
 
 
74
ActivityList::~ActivityList()
 
75
{
 
76
}
 
77
 
 
78
void ActivityList::createActivityIcon(const QString &id)
 
79
{
 
80
    ActivityIcon *icon = new ActivityIcon(id);
 
81
    addIcon(icon);
 
82
    m_allAppletsHash.insert(id, icon);
 
83
    connect(icon->activity(), SIGNAL(stateChanged()), this, SLOT(updateClosable()));
 
84
}
 
85
 
 
86
void ActivityList::createActivityIcon(const QString &name, const QString &iconName, const QString &plugin)
 
87
{
 
88
    ActivityIcon *icon = new ActivityIcon(name, iconName, plugin);
 
89
 
 
90
    connect(icon, SIGNAL(requestsRemoval(bool)),
 
91
            this, SLOT(templateHidden(bool)));
 
92
 
 
93
    addIcon(icon);
 
94
    m_allAppletsHash.insert("null:" + name, icon);
 
95
    // m_allAppletsHash.insert(id, icon);
 
96
    // connect(icon->activity(), SIGNAL(stateChanged()), this, SLOT(updateClosable()));
 
97
}
 
98
 
 
99
/*
 
100
void AppletsListWidget::appletIconDoubleClicked(AbstractIcon *icon)
 
101
{
 
102
    emit(appletDoubleClicked(static_cast<AppletIconWidget*>(icon)->appletItem()));
 
103
}
 
104
*/
 
105
 
 
106
void ActivityList::updateVisibleIcons()
 
107
{
 
108
}
 
109
 
 
110
void ActivityList::setSearch(const QString &searchString)
 
111
{
 
112
    foreach (Plasma::AbstractIcon *icon, m_allAppletsHash) {
 
113
        icon->setVisible(icon->name().contains(searchString, Qt::CaseInsensitive));
 
114
    }
 
115
}
 
116
 
 
117
void ActivityList::activityAdded(const QString &id)
 
118
{
 
119
    //kDebug() << id;
 
120
    /*
 
121
    if (m_allAppletsHash.count() == 1) {
 
122
        ActivityIcon *icon = qobject_cast<ActivityIcon*>(m_allAppletsHash.values().first());
 
123
        if (icon) {
 
124
            icon->setClosable(true);
 
125
        }
 
126
    }
 
127
    */
 
128
 
 
129
    // Syncing removal of template activity andd addition of a
 
130
    // new activity based on it
 
131
    if (m_scheduleHideOnAdd) {
 
132
        hideIcon(m_scheduleHideOnAdd);
 
133
        m_allAppletsHash.remove(m_allAppletsHash.key(m_scheduleHideOnAdd));
 
134
        m_scheduleHideOnAdd = 0;
 
135
    }
 
136
 
 
137
    createActivityIcon(id);
 
138
    updateList();
 
139
}
 
140
 
 
141
void ActivityList::activityRemoved(const QString &id)
 
142
{
 
143
    ActivityIcon *icon = qobject_cast<ActivityIcon *>(m_allAppletsHash.take(id));
 
144
 
 
145
    if (icon) {
 
146
        icon->activityRemoved();
 
147
    }
 
148
/*
 
149
    if (m_allAppletsHash.count() == 1) {
 
150
        ActivityIcon *icon = qobject_cast<ActivityIcon*>(m_allAppletsHash.values().first());
 
151
        if (icon) {
 
152
            icon->setClosable(false);
 
153
        }
 
154
    }
 
155
*/
 
156
    updateList();
 
157
}
 
158
 
 
159
void ActivityList::updateClosable()
 
160
{
 
161
    ActivityIcon * running = 0;
 
162
    bool twoRunning = false;
 
163
 
 
164
    foreach (Plasma::AbstractIcon *i, m_allAppletsHash) {
 
165
        ActivityIcon *icon = qobject_cast<ActivityIcon*>(i);
 
166
 
 
167
        if (icon && icon->activity() && icon->activity()->state() == KActivityInfo::Running) {
 
168
            if (running) {
 
169
                //found two, no worries
 
170
                twoRunning = true;
 
171
                break;
 
172
            } else {
 
173
                running = icon;
 
174
            }
 
175
        }
 
176
    }
 
177
 
 
178
    if (twoRunning) {
 
179
        foreach (Plasma::AbstractIcon *i, m_allAppletsHash) {
 
180
            qobject_cast < ActivityIcon * > (i)->setClosable(true);
 
181
        }
 
182
 
 
183
    } else if (running) {
 
184
        running->setClosable(false);
 
185
    }
 
186
}
 
187
 
 
188
void ActivityList::templateHidden(bool immediate)
 
189
{
 
190
    ActivityIcon * icon = qobject_cast < ActivityIcon * > (sender());
 
191
 
 
192
    if (!icon) return;
 
193
 
 
194
    if (immediate) {
 
195
        hideIcon(icon);
 
196
        m_allAppletsHash.remove(m_allAppletsHash.key(icon));
 
197
 
 
198
    } else {
 
199
        m_scheduleHideOnAdd = icon;
 
200
    }
 
201
}
 
202