2
This file is part of KDE.
4
Copyright (c) 2009 Eckhart Wörner <ewoerner@kde.org>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22
#include "activitylist.h"
24
#include <QtCore/QtAlgorithms>
26
#include "activitywidget.h"
29
ActivityList::ActivityList(Plasma::DataEngine* engine, QGraphicsWidget* parent)
30
: ScrollWidget(parent),
33
m_updateInterval(10 * 60),
34
m_firstUpdateDone(false)
36
m_container = new QGraphicsWidget(this);
37
m_layout = new QGraphicsLinearLayout(Qt::Vertical, m_container);
38
setWidget(m_container);
42
int ActivityList::limit() const
48
int ActivityList::updateInterval() const
50
return m_updateInterval;
54
void ActivityList::setLimit(int limit)
56
if (limit != m_limit) {
58
dataUpdated("activity", m_engine->query("activity"));
63
void ActivityList::setProvider(const QString& provider) {
64
if (provider != m_provider) {
65
if (!m_provider.isEmpty()) {
66
m_engine->disconnectSource("Activities\\provider:" + m_provider, this);
68
m_provider = provider;
69
if (!m_provider.isEmpty()) {
70
// wait for the data to arrive the first time
71
m_engine->connectSource("Activities\\provider:" + m_provider, this, 1000);
77
void ActivityList::setUpdateInterval(int interval)
79
m_updateInterval = interval;
80
m_engine->connectSource("Activities\\provider:" + m_provider, this, m_updateInterval * 1000);
84
QStringList ActivityList::getDisplayedActivities(const Plasma::DataEngine::Data& data)
86
QStringList result = data.keys();
87
qSort(result.begin(), result.end(), qGreater<QString>());
88
while (result.size() > m_limit) {
95
void ActivityList::dataUpdated(const QString& source, const Plasma::DataEngine::Data& data)
99
if (!m_firstUpdateDone) {
100
if (data.contains("SourceStatus") && data.value("SourceStatus") == "retrieving") {
103
m_engine->connectSource("Activities\\provider:" + m_provider, this, m_updateInterval * 1000);
104
m_firstUpdateDone = true;
108
QStringList displayedActivities = getDisplayedActivities(data);
110
// FIXME: This is still highly inefficient
111
while (m_layout->count()) {
112
ActivityWidget* widget = static_cast<ActivityWidget*>(m_layout->itemAt(0));
113
m_layout->removeAt(0);
114
widget->deleteLater();
117
QStringList::iterator j = displayedActivities.begin();
118
for (int i = 0; i < displayedActivities.size(); ++i, ++j) {
119
if (!data[*j].value<Plasma::DataEngine::Data>().isEmpty()) {
120
ActivityWidget* widget = new ActivityWidget(m_engine, m_container);
121
widget->setActivityData(data[*j].value<Plasma::DataEngine::Data>());
122
m_layout->addItem(widget);
126
// Go to the top of the list
131
#include "activitylist.moc"