2006-12-17 00:04:44 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2006-12-17 00:04:44 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-08-06 13:20:02 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2006-12-17 00:04:44 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2007-05-21 16:28:03 +02:00
|
|
|
#include "dataengine.h"
|
|
|
|
|
2007-05-28 07:43:54 +02:00
|
|
|
#include <QQueue>
|
2007-05-19 10:38:46 +02:00
|
|
|
#include <QTimer>
|
2007-10-06 00:21:25 +02:00
|
|
|
#include <QTime>
|
2007-09-11 02:49:51 +02:00
|
|
|
#include <QTimerEvent>
|
2007-03-01 09:22:38 +01:00
|
|
|
#include <QVariant>
|
2007-03-01 00:35:26 +01:00
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
#include <KDebug>
|
|
|
|
|
2007-07-23 02:22:16 +02:00
|
|
|
#include "datacontainer.h"
|
2007-03-01 00:35:26 +01:00
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2006-12-17 00:04:44 +01:00
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
class DataEngine::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private(DataEngine* e)
|
2007-05-28 07:43:54 +02:00
|
|
|
: engine(e),
|
2007-09-11 02:49:51 +02:00
|
|
|
ref(0),
|
|
|
|
updateTimerId(0),
|
2007-09-16 18:28:16 +02:00
|
|
|
minUpdateInterval(-1),
|
2007-06-03 00:23:26 +02:00
|
|
|
limit(0),
|
|
|
|
valid(true)
|
2007-05-19 10:38:46 +02:00
|
|
|
{
|
|
|
|
updateTimer = new QTimer(engine);
|
|
|
|
updateTimer->setSingleShot(true);
|
2007-09-11 02:49:51 +02:00
|
|
|
updateTimestamp.start();
|
2007-05-19 10:38:46 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* source(const QString& sourceName, bool createWhenMissing = true)
|
2007-05-19 10:38:46 +02:00
|
|
|
{
|
2007-06-10 06:03:50 +02:00
|
|
|
DataEngine::SourceDict::const_iterator it = sources.find(sourceName);
|
2007-05-19 10:38:46 +02:00
|
|
|
if (it != sources.constEnd()) {
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* s = it.value();
|
2007-05-28 07:43:54 +02:00
|
|
|
if (limit > 0) {
|
2007-07-23 02:22:16 +02:00
|
|
|
QQueue<DataContainer*>::iterator it = sourceQueue.begin();
|
2007-05-28 07:43:54 +02:00
|
|
|
while (it != sourceQueue.end()) {
|
|
|
|
if (*it == s) {
|
|
|
|
sourceQueue.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
sourceQueue.enqueue(s);
|
|
|
|
}
|
2007-05-19 10:38:46 +02:00
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
|
2007-06-10 06:03:50 +02:00
|
|
|
if (!createWhenMissing) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
/*kDebug() << "DataEngine " << engine->objectName()
|
2007-07-23 02:22:16 +02:00
|
|
|
<< ": could not find DataContainer " << sourceName
|
2007-06-10 07:39:27 +02:00
|
|
|
<< ", creating" << endl;*/
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* s = new DataContainer(engine);
|
2007-05-27 09:59:17 +02:00
|
|
|
s->setObjectName(sourceName);
|
2007-05-19 10:38:46 +02:00
|
|
|
sources.insert(sourceName, s);
|
2007-09-13 22:34:17 +02:00
|
|
|
connect(s, SIGNAL(requestUpdate(DataContainer*)), engine, SLOT(internalUpdateSource(DataContainer*)));
|
2007-05-28 07:43:54 +02:00
|
|
|
|
|
|
|
if (limit > 0) {
|
|
|
|
trimQueue();
|
|
|
|
sourceQueue.enqueue(s);
|
|
|
|
}
|
2007-06-13 06:56:49 +02:00
|
|
|
emit engine->newSource(sourceName);
|
2007-05-19 10:38:46 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2007-11-07 07:10:57 +01:00
|
|
|
void connectSource(DataContainer* s, QObject* visualization, uint updateInterval,
|
|
|
|
Plasma::IntervalAlignment align, bool immediateCall = true)
|
2007-09-11 02:49:51 +02:00
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "connect source called with interval" << updateInterval;
|
2007-09-12 19:04:21 +02:00
|
|
|
if (updateInterval > 0) {
|
|
|
|
// never more frequently than allowed, never more than 20 times per second
|
2007-09-16 18:28:16 +02:00
|
|
|
uint min = qMax(50, minUpdateInterval); // for qMin below
|
2007-09-12 19:04:21 +02:00
|
|
|
updateInterval = qMax(min, updateInterval);
|
2007-09-11 02:49:51 +02:00
|
|
|
|
2007-09-12 19:04:21 +02:00
|
|
|
// align on the 50ms
|
|
|
|
updateInterval = updateInterval - (updateInterval % 50);
|
2007-09-11 02:49:51 +02:00
|
|
|
}
|
|
|
|
|
2007-09-12 19:53:54 +02:00
|
|
|
s->connectVisualization(visualization, updateInterval, align);
|
2007-09-12 19:04:21 +02:00
|
|
|
|
2007-11-07 07:10:57 +01:00
|
|
|
if (immediateCall) {
|
|
|
|
QMetaObject::invokeMethod(visualization, "dataUpdated",
|
|
|
|
Q_ARG(QString, s->objectName()),
|
|
|
|
Q_ARG(Plasma::DataEngine::Data, s->data()));
|
|
|
|
}
|
2007-09-11 02:49:51 +02:00
|
|
|
}
|
|
|
|
|
2007-11-07 07:10:57 +01:00
|
|
|
DataContainer* requestSource(const QString& sourceName, bool* newSource = 0)
|
2007-08-11 10:19:20 +02:00
|
|
|
{
|
2007-11-07 07:10:57 +01:00
|
|
|
if (newSource) {
|
|
|
|
*newSource = false;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "requesting source " << sourceName;
|
2007-08-11 10:19:20 +02:00
|
|
|
DataContainer* s = source(sourceName, false);
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
// we didn't find a data source, so give the engine an opportunity to make one
|
2008-01-08 02:25:09 +01:00
|
|
|
/*kDebug() << "DataEngine " << engine->objectName()
|
2007-09-13 22:34:17 +02:00
|
|
|
<< ": could not find DataContainer " << sourceName
|
|
|
|
<< " will create on request" << endl;*/
|
2007-08-11 10:19:20 +02:00
|
|
|
if (engine->sourceRequested(sourceName)) {
|
|
|
|
s = source(sourceName, false);
|
|
|
|
if (s) {
|
|
|
|
// now we have a source; since it was created on demand, assume
|
|
|
|
// it should be removed when not used
|
2007-11-07 07:10:57 +01:00
|
|
|
if (newSource) {
|
|
|
|
*newSource = true;
|
|
|
|
}
|
2007-08-11 10:19:20 +02:00
|
|
|
connect(s, SIGNAL(unused(QString)), engine, SLOT(removeSource(QString)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-13 22:34:17 +02:00
|
|
|
|
2007-08-11 10:19:20 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2007-05-28 07:43:54 +02:00
|
|
|
void trimQueue()
|
|
|
|
{
|
2007-09-13 22:34:17 +02:00
|
|
|
uint queueCount = sourceQueue.count();
|
|
|
|
while (queueCount >= limit) {
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* punted = sourceQueue.dequeue();
|
2007-06-11 23:10:44 +02:00
|
|
|
engine->removeSource(punted->objectName());
|
2007-05-28 07:43:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
void queueUpdate()
|
|
|
|
{
|
|
|
|
if (updateTimer->isActive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateTimer->start(0);
|
|
|
|
}
|
|
|
|
|
2007-09-11 02:49:51 +02:00
|
|
|
DataEngine* engine;
|
2007-08-27 19:27:27 +02:00
|
|
|
int ref;
|
2007-09-11 02:49:51 +02:00
|
|
|
int updateTimerId;
|
2007-09-16 18:28:16 +02:00
|
|
|
int minUpdateInterval;
|
2007-09-11 02:49:51 +02:00
|
|
|
QTime updateTimestamp;
|
2007-06-10 06:03:50 +02:00
|
|
|
DataEngine::SourceDict sources;
|
2007-07-23 02:22:16 +02:00
|
|
|
QQueue<DataContainer*> sourceQueue;
|
2007-05-19 10:38:46 +02:00
|
|
|
QTimer* updateTimer;
|
2007-05-23 09:13:00 +02:00
|
|
|
QString icon;
|
2007-05-28 07:43:54 +02:00
|
|
|
uint limit;
|
2007-06-03 00:23:26 +02:00
|
|
|
bool valid;
|
2007-05-19 10:38:46 +02:00
|
|
|
};
|
2007-03-01 00:35:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
DataEngine::DataEngine(QObject* parent)
|
2007-05-19 10:38:46 +02:00
|
|
|
: QObject(parent),
|
|
|
|
d(new Private(this))
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2007-05-19 10:38:46 +02:00
|
|
|
connect(d->updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdates()));
|
2007-05-23 09:13:00 +02:00
|
|
|
//FIXME: we should delay this call; to when is the question.
|
2007-06-19 09:17:50 +02:00
|
|
|
//Update DataEngine::init() api docu when fixed
|
2007-07-02 12:16:39 +02:00
|
|
|
QTimer::singleShot(0, this, SLOT(startInit()));
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DataEngine::~DataEngine()
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << objectName() << ": bye bye birdy! ";
|
2007-05-19 10:38:46 +02:00
|
|
|
delete d;
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-06-13 06:56:49 +02:00
|
|
|
QStringList DataEngine::sources() const
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2007-05-19 10:38:46 +02:00
|
|
|
return d->sources.keys();
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-09-12 19:53:54 +02:00
|
|
|
void DataEngine::connectSource(const QString& source, QObject* visualization,
|
|
|
|
uint updateInterval, Plasma::IntervalAlignment intervalAlignment) const
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "connectSource" << source;
|
2007-11-07 07:10:57 +01:00
|
|
|
bool newSource;
|
|
|
|
DataContainer* s = d->requestSource(source, &newSource);
|
2007-06-10 07:39:27 +02:00
|
|
|
|
2007-09-13 22:34:17 +02:00
|
|
|
if (s) {
|
2007-11-08 04:37:57 +01:00
|
|
|
// we suppress the immediate invocation of dataUpdated here if the source was prexisting and they
|
|
|
|
// don't request delayed updates (we want to do an immediate update in that case so they
|
|
|
|
// don't have to wait for the first time out)
|
|
|
|
d->connectSource(s, visualization, updateInterval, intervalAlignment, !newSource || updateInterval > 0);
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << " ==> source connected";
|
2007-06-10 06:03:50 +02:00
|
|
|
}
|
2007-09-11 02:49:51 +02:00
|
|
|
}
|
|
|
|
|
2007-09-12 19:53:54 +02:00
|
|
|
void DataEngine::connectAllSources(QObject* visualization, uint updateInterval,
|
|
|
|
Plasma::IntervalAlignment intervalAlignment) const
|
2007-09-11 02:49:51 +02:00
|
|
|
{
|
2007-09-12 19:04:21 +02:00
|
|
|
foreach (DataContainer* s, d->sources) {
|
2007-09-12 19:53:54 +02:00
|
|
|
d->connectSource(s, visualization, updateInterval, intervalAlignment);
|
2007-09-11 02:49:51 +02:00
|
|
|
}
|
2007-05-28 07:43:54 +02:00
|
|
|
}
|
|
|
|
|
2007-06-10 07:39:27 +02:00
|
|
|
void DataEngine::disconnectSource(const QString& source, QObject* visualization) const
|
|
|
|
{
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* s = d->source(source, false);
|
2007-06-10 07:39:27 +02:00
|
|
|
|
2007-09-13 22:34:17 +02:00
|
|
|
if (s) {
|
|
|
|
s->disconnectVisualization(visualization);
|
2007-06-10 07:39:27 +02:00
|
|
|
}
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-08-29 04:57:04 +02:00
|
|
|
DataContainer* DataEngine::containerForSource(const QString &source)
|
|
|
|
{
|
2007-11-15 07:32:54 +01:00
|
|
|
return d->source(source, false);
|
2007-08-29 04:57:04 +02:00
|
|
|
}
|
|
|
|
|
2007-05-23 10:27:09 +02:00
|
|
|
DataEngine::Data DataEngine::query(const QString& source) const
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2007-08-11 10:19:20 +02:00
|
|
|
DataContainer* s = d->requestSource(source);
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
return DataEngine::Data();
|
|
|
|
}
|
2007-03-01 00:35:26 +01:00
|
|
|
|
2007-09-02 00:23:03 +02:00
|
|
|
DataEngine::Data data = s->data();
|
|
|
|
s->checkUsage();
|
|
|
|
return data;
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-07-02 12:16:39 +02:00
|
|
|
void DataEngine::startInit()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2007-09-13 22:34:17 +02:00
|
|
|
void DataEngine::internalUpdateSource(DataContainer* source)
|
2007-09-12 19:04:21 +02:00
|
|
|
{
|
2007-09-16 18:28:16 +02:00
|
|
|
if (d->minUpdateInterval > 0 &&
|
|
|
|
source->timeSinceLastUpdate() < d->minUpdateInterval) {
|
2007-09-13 22:34:17 +02:00
|
|
|
// skip updating this source; it's been too soon
|
|
|
|
//TODO: should we queue an update in this case? return to this
|
|
|
|
// once we see the results in real world usage
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "internal update source is delaying" << source->timeSinceLastUpdate() << d->minUpdateInterval;
|
2007-09-13 22:34:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateSource(source->objectName())) {
|
2007-09-12 19:04:21 +02:00
|
|
|
d->queueUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-01 00:35:26 +01:00
|
|
|
void DataEngine::init()
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
// kDebug() << "DataEngine::init() called ";
|
2007-05-19 10:38:46 +02:00
|
|
|
// default implementation does nothing. this is for engines that have to
|
|
|
|
// start things in motion external to themselves before they can work
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-06-13 06:56:49 +02:00
|
|
|
bool DataEngine::sourceRequested(const QString &name)
|
2007-06-10 06:03:50 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(name)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-09-11 02:49:51 +02:00
|
|
|
bool DataEngine::updateSource(const QString& source)
|
|
|
|
{
|
|
|
|
Q_UNUSED(source);
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "updateSource source" << endl;
|
2007-09-11 02:49:51 +02:00
|
|
|
return false; //TODO: should this be true to trigger, even needless, updates on every tick?
|
|
|
|
}
|
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
void DataEngine::setData(const QString& source, const QVariant& value)
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2007-05-19 10:38:46 +02:00
|
|
|
setData(source, source, value);
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
void DataEngine::setData(const QString& source, const QString& key, const QVariant& value)
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* s = d->source(source);
|
2007-05-19 10:38:46 +02:00
|
|
|
s->setData(key, value);
|
|
|
|
d->queueUpdate();
|
2007-07-09 11:33:15 +02:00
|
|
|
}
|
|
|
|
|
2007-07-17 20:08:57 +02:00
|
|
|
void DataEngine::setData(const QString &source, const Data &data)
|
|
|
|
{
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer *s = d->source(source);
|
2007-07-17 20:08:57 +02:00
|
|
|
Data::const_iterator it = data.constBegin();
|
|
|
|
while (it != data.constEnd()) {
|
|
|
|
s->setData(it.key(), it.value());
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
d->queueUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-09 11:33:15 +02:00
|
|
|
void DataEngine::clearData(const QString& source)
|
|
|
|
{
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* s = d->source(source, false);
|
2007-07-09 11:33:15 +02:00
|
|
|
if (s) {
|
|
|
|
s->clearData();
|
|
|
|
d->queueUpdate();
|
|
|
|
}
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-06-17 19:38:54 +02:00
|
|
|
void DataEngine::removeData(const QString& source, const QString& key)
|
|
|
|
{
|
2007-07-23 02:22:16 +02:00
|
|
|
DataContainer* s = d->source(source, false);
|
2007-06-17 19:38:54 +02:00
|
|
|
if (s) {
|
|
|
|
s->setData(key, QVariant());
|
|
|
|
d->queueUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-23 02:22:16 +02:00
|
|
|
void DataEngine::addSource(DataContainer* source)
|
2007-05-23 08:38:44 +02:00
|
|
|
{
|
2007-06-10 06:03:50 +02:00
|
|
|
SourceDict::const_iterator it = d->sources.find(source->objectName());
|
2007-05-23 08:38:44 +02:00
|
|
|
if (it != d->sources.constEnd()) {
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "source named \"" << source->objectName() << "\" already exists.";
|
2007-05-23 08:38:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-27 09:59:17 +02:00
|
|
|
d->sources.insert(source->objectName(), source);
|
2007-06-13 06:56:49 +02:00
|
|
|
emit newSource(source->objectName());
|
2007-05-23 08:38:44 +02:00
|
|
|
}
|
|
|
|
|
2007-05-28 07:43:54 +02:00
|
|
|
void DataEngine::setSourceLimit(uint limit)
|
|
|
|
{
|
|
|
|
if (d->limit == limit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->limit = limit;
|
|
|
|
|
|
|
|
if (d->limit > 0) {
|
|
|
|
d->trimQueue();
|
|
|
|
} else {
|
|
|
|
d->sourceQueue.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 02:49:51 +02:00
|
|
|
void DataEngine::setMinimumUpdateInterval(int minimumMs)
|
|
|
|
{
|
2007-09-16 18:28:16 +02:00
|
|
|
d->minUpdateInterval = minimumMs;
|
2007-09-11 02:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int DataEngine::minimumUpdateInterval() const
|
|
|
|
{
|
2007-09-16 18:28:16 +02:00
|
|
|
return d->minUpdateInterval;
|
2007-09-11 02:49:51 +02:00
|
|
|
}
|
|
|
|
|
2007-09-16 18:25:59 +02:00
|
|
|
void DataEngine::setUpdateInterval(uint frequency)
|
2007-09-11 02:49:51 +02:00
|
|
|
{
|
|
|
|
killTimer(d->updateTimerId);
|
|
|
|
d->updateTimerId = 0;
|
|
|
|
|
|
|
|
if (frequency > 0) {
|
|
|
|
d->updateTimerId = startTimer(frequency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
NOTE: This is not implemented to prevent having to store the value internally.
|
|
|
|
When there is a good use case for needing access to this value, we can
|
|
|
|
add another member to the Private class and add this method.
|
|
|
|
|
|
|
|
void DataEngine::updateInterval()
|
|
|
|
{
|
|
|
|
return d->updateInterval;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2007-06-11 23:10:44 +02:00
|
|
|
void DataEngine::removeSource(const QString& source)
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "removing source " << source;
|
2007-06-10 06:03:50 +02:00
|
|
|
SourceDict::iterator it = d->sources.find(source);
|
2007-05-19 10:38:46 +02:00
|
|
|
if (it != d->sources.end()) {
|
2007-06-13 06:56:49 +02:00
|
|
|
emit sourceRemoved(it.key());
|
2007-09-02 00:23:03 +02:00
|
|
|
it.value()->deleteLater();
|
2007-05-19 10:38:46 +02:00
|
|
|
d->sources.erase(it);
|
|
|
|
}
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-06-13 06:56:49 +02:00
|
|
|
void DataEngine::clearSources()
|
2007-03-01 00:35:26 +01:00
|
|
|
{
|
2007-07-23 02:22:16 +02:00
|
|
|
QMutableHashIterator<QString, Plasma::DataContainer*> it(d->sources);
|
2007-05-19 10:38:46 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2007-06-13 06:56:49 +02:00
|
|
|
emit sourceRemoved(it.key());
|
2007-05-19 10:38:46 +02:00
|
|
|
delete it.value();
|
|
|
|
it.remove();
|
|
|
|
}
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataEngine::ref()
|
|
|
|
{
|
2007-08-27 19:27:27 +02:00
|
|
|
--d->ref;
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataEngine::deref()
|
|
|
|
{
|
2007-08-27 19:27:27 +02:00
|
|
|
++d->ref;
|
2007-03-01 00:35:26 +01:00
|
|
|
}
|
|
|
|
|
2007-05-23 10:27:09 +02:00
|
|
|
bool DataEngine::isUsed() const
|
2006-12-17 00:04:44 +01:00
|
|
|
{
|
2007-05-19 10:38:46 +02:00
|
|
|
return d->ref != 0;
|
|
|
|
}
|
|
|
|
|
2007-06-03 00:23:26 +02:00
|
|
|
bool DataEngine::isValid() const
|
|
|
|
{
|
|
|
|
return d->valid;
|
|
|
|
}
|
|
|
|
|
2007-11-18 02:32:11 +01:00
|
|
|
bool DataEngine::isEmpty() const
|
|
|
|
{
|
2007-11-19 17:37:46 +01:00
|
|
|
return d->sources.isEmpty();
|
2007-11-18 02:32:11 +01:00
|
|
|
}
|
|
|
|
|
2007-06-04 18:11:55 +02:00
|
|
|
void DataEngine::setValid(bool valid)
|
2007-06-03 00:23:26 +02:00
|
|
|
{
|
|
|
|
d->valid = valid;
|
|
|
|
}
|
|
|
|
|
2007-06-10 06:03:50 +02:00
|
|
|
DataEngine::SourceDict DataEngine::sourceDict() const
|
|
|
|
{
|
|
|
|
return d->sources;
|
|
|
|
}
|
|
|
|
|
2007-09-11 02:49:51 +02:00
|
|
|
void DataEngine::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (event->timerId() != d->updateTimerId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
|
|
|
|
// if the freq update is less than 0, don't bother
|
2007-09-16 18:28:16 +02:00
|
|
|
if (d->minUpdateInterval < 0) {
|
2007-09-11 02:49:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-16 18:28:16 +02:00
|
|
|
// minUpdateInterval
|
|
|
|
if (d->updateTimestamp.elapsed() < d->minUpdateInterval) {
|
2007-09-11 02:49:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->updateTimestamp.restart();
|
|
|
|
QHashIterator<QString, Plasma::DataContainer*> it(d->sources);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
updateSource(it.key());
|
|
|
|
}
|
|
|
|
checkForUpdates();
|
|
|
|
}
|
|
|
|
|
2007-05-23 09:13:00 +02:00
|
|
|
void DataEngine::setIcon(const QString& icon)
|
|
|
|
{
|
|
|
|
d->icon = icon;
|
|
|
|
}
|
|
|
|
|
2007-05-23 10:27:09 +02:00
|
|
|
QString DataEngine::icon() const
|
2007-05-23 09:13:00 +02:00
|
|
|
{
|
|
|
|
return d->icon;
|
|
|
|
}
|
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
void DataEngine::checkForUpdates()
|
|
|
|
{
|
2007-07-23 02:22:16 +02:00
|
|
|
QHashIterator<QString, Plasma::DataContainer*> it(d->sources);
|
2007-05-19 10:38:46 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
it.value()->checkForUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
2007-05-19 10:38:46 +02:00
|
|
|
#include "dataengine.moc"
|