~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to applets/opendesktop/sourcewatchlist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mto: (0.4.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: james.westby@ubuntu.com-20100525095014-e3cebfkdenjrx3xg
Tags: upstream-4.4.80
Import upstream version 4.4.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of KDE.
3
 
 
4
 
    Copyright (c) 2009 Eckhart Wörner <ewoerner@kde.org>
5
 
 
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.
10
 
 
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.
15
 
 
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,
19
 
    USA.
20
 
*/
21
 
 
22
 
#include "sourcewatchlist.h"
23
 
 
24
 
 
25
 
using namespace Plasma;
26
 
 
27
 
SourceWatchList::SourceWatchList(DataEngine* engine, QObject* parent)
28
 
    : QObject(parent),
29
 
      m_engine(engine),
30
 
      m_updateInterval(0)
31
 
{
32
 
}
33
 
 
34
 
 
35
 
bool SourceWatchList::contains(const QString& key) const
36
 
{
37
 
    return m_data.contains(key);
38
 
}
39
 
 
40
 
 
41
 
QString SourceWatchList::query() const
42
 
{
43
 
    return m_query;
44
 
}
45
 
 
46
 
 
47
 
void SourceWatchList::setQuery(const QString& query)
48
 
{
49
 
    if (query != m_query) {
50
 
        if (!m_query.isEmpty()) {
51
 
            m_engine->disconnectSource(m_query, this);
52
 
        }
53
 
        dataUpdated(m_query, DataEngine::Data());
54
 
        m_query = query;
55
 
        if (!m_query.isEmpty()) {
56
 
            m_engine->connectSource(m_query, this, m_updateInterval);
57
 
        }
58
 
    }
59
 
}
60
 
 
61
 
 
62
 
void SourceWatchList::setUpdateInterval(uint updateInterval)
63
 
{
64
 
    m_updateInterval = updateInterval;
65
 
    if (!m_query.isEmpty()) {
66
 
        m_engine->connectSource(m_query, this, m_updateInterval);
67
 
    }
68
 
}
69
 
 
70
 
 
71
 
QVariant SourceWatchList::value(const QString& id) const
72
 
{
73
 
    return m_data.value(id);
74
 
}
75
 
 
76
 
 
77
 
void SourceWatchList::dataUpdated(const QString& source, const Plasma::DataEngine::Data& data)
78
 
{
79
 
    Q_UNUSED(source)
80
 
 
81
 
    const QSet<QString> oldKeys = QSet<QString>::fromList(m_data.keys());
82
 
    const QSet<QString> newKeys = QSet<QString>::fromList(data.keys());
83
 
    m_data = data;
84
 
    QSet<QString> addedKeys = QSet<QString>(newKeys).subtract(oldKeys);
85
 
    QSet<QString> removedKeys = QSet<QString>(oldKeys).subtract(newKeys);
86
 
    if (!removedKeys.isEmpty()) {
87
 
        emit keysRemoved(removedKeys);
88
 
    }
89
 
    if (!addedKeys.isEmpty()) {
90
 
        emit keysAdded(addedKeys);
91
 
    }
92
 
}
93
 
 
94
 
 
95
 
#include "sourcewatchlist.moc"