2
* Copyright 2010 Chani Armitage <chani@kde.org>
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
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
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.
20
#include "activitylist.h"
23
#include "plasmaapp.h"
24
#include "kactivitycontroller.h"
28
#include <Plasma/Containment>
29
#include <Plasma/Corona>
32
#include <KServiceTypeTrader>
34
ActivityList::ActivityList(Plasma::Location location, QGraphicsItem *parent)
35
: AbstractIconList(location, parent),
36
m_activityController(new KActivityController(this)),
37
m_scheduleHideOnAdd(0)
39
QStringList activities = m_activityController->listActivities();
40
foreach (const QString &activity, activities) {
41
createActivityIcon(activity);
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;
48
KConfig config("plasma-desktoprc");
49
KConfigGroup group(&config, "ActivityManager HiddenTemplates");
51
if (group.readEntry(service->storageId(), false)) continue;
53
createActivityIcon(service->name(), service->icon(), service->storageId());
59
if (m_allAppletsHash.count() == 1) {
60
ActivityIcon *icon = qobject_cast<ActivityIcon*>(m_allAppletsHash.values().first());
62
icon->setClosable(false);
66
//-do something about sorting and filtering (most recent first?)
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 &)));
74
ActivityList::~ActivityList()
78
void ActivityList::createActivityIcon(const QString &id)
80
ActivityIcon *icon = new ActivityIcon(id);
82
m_allAppletsHash.insert(id, icon);
83
connect(icon->activity(), SIGNAL(stateChanged()), this, SLOT(updateClosable()));
86
void ActivityList::createActivityIcon(const QString &name, const QString &iconName, const QString &plugin)
88
ActivityIcon *icon = new ActivityIcon(name, iconName, plugin);
90
connect(icon, SIGNAL(requestsRemoval(bool)),
91
this, SLOT(templateHidden(bool)));
94
m_allAppletsHash.insert("null:" + name, icon);
95
// m_allAppletsHash.insert(id, icon);
96
// connect(icon->activity(), SIGNAL(stateChanged()), this, SLOT(updateClosable()));
100
void AppletsListWidget::appletIconDoubleClicked(AbstractIcon *icon)
102
emit(appletDoubleClicked(static_cast<AppletIconWidget*>(icon)->appletItem()));
106
void ActivityList::updateVisibleIcons()
110
void ActivityList::setSearch(const QString &searchString)
112
foreach (Plasma::AbstractIcon *icon, m_allAppletsHash) {
113
icon->setVisible(icon->name().contains(searchString, Qt::CaseInsensitive));
117
void ActivityList::activityAdded(const QString &id)
121
if (m_allAppletsHash.count() == 1) {
122
ActivityIcon *icon = qobject_cast<ActivityIcon*>(m_allAppletsHash.values().first());
124
icon->setClosable(true);
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;
137
createActivityIcon(id);
141
void ActivityList::activityRemoved(const QString &id)
143
ActivityIcon *icon = qobject_cast<ActivityIcon *>(m_allAppletsHash.take(id));
146
icon->activityRemoved();
149
if (m_allAppletsHash.count() == 1) {
150
ActivityIcon *icon = qobject_cast<ActivityIcon*>(m_allAppletsHash.values().first());
152
icon->setClosable(false);
159
void ActivityList::updateClosable()
161
ActivityIcon * running = 0;
162
bool twoRunning = false;
164
foreach (Plasma::AbstractIcon *i, m_allAppletsHash) {
165
ActivityIcon *icon = qobject_cast<ActivityIcon*>(i);
167
if (icon && icon->activity() && icon->activity()->state() == KActivityInfo::Running) {
169
//found two, no worries
179
foreach (Plasma::AbstractIcon *i, m_allAppletsHash) {
180
qobject_cast < ActivityIcon * > (i)->setClosable(true);
183
} else if (running) {
184
running->setClosable(false);
188
void ActivityList::templateHidden(bool immediate)
190
ActivityIcon * icon = qobject_cast < ActivityIcon * > (sender());
196
m_allAppletsHash.remove(m_allAppletsHash.key(icon));
199
m_scheduleHideOnAdd = icon;