From 9250bd82b49f8cf755af19bc54edccaee24eaa55 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Thu, 24 Apr 2008 20:16:21 +0000 Subject: [PATCH] put sourceLimit back in, add an accessor as well. used by akonadi svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800769 --- dataengine.cpp | 20 ++++++++++++++++++++ dataengine.h | 17 +++++++++++++++++ scripting/dataenginescript.cpp | 7 +++++++ scripting/dataenginescript.h | 1 + 4 files changed, 45 insertions(+) diff --git a/dataengine.cpp b/dataengine.cpp index 52bb65eb3..215dee67b 100644 --- a/dataengine.cpp +++ b/dataengine.cpp @@ -418,6 +418,26 @@ void DataEngine::addSource(DataContainer* source) emit sourceAdded(source->objectName()); } +void DataEngine::setSourceLimit(uint limit) +{ + if (d->limit == limit) { + return; + } + + d->limit = limit; + + if (d->limit > 0) { + d->trimQueue(); + } else { + d->sourceQueue.clear(); + } +} + +uint DataEngine::sourceLimit() const +{ + return d->limit; +} + void DataEngine::setMinimumPollingInterval(int minimumMs) { d->minPollingInterval = minimumMs; diff --git a/dataengine.h b/dataengine.h index 5b4fc27e9..5e462aeaf 100644 --- a/dataengine.h +++ b/dataengine.h @@ -196,6 +196,14 @@ class PLASMA_EXPORT DataEngine : public QObject */ bool isEmpty() const; + /** + * Returns the maximum number of sources this DataEngine will list + * at any given time. + * + * @return the maximum number of sources; zero means no limit. + */ + uint sourceLimit() const; + /** * @return the name of the icon for this data engine; and empty string * is returned if there is no associated icon. @@ -307,6 +315,15 @@ class PLASMA_EXPORT DataEngine : public QObject **/ void addSource(DataContainer* source); + /** + * Sets an upper limit on the number of data sources to keep in this engine. + * If the limit is exceeded, then the oldest data source, as defined by last + * update, is dropped. + * + * @param limit the maximum number of sources to keep active + **/ + void setSourceLimit(uint limit); + /** * Sets the minimum amount of time, in milliseconds, that must pass between * successive updates of data. This can help prevent too many updates happening diff --git a/scripting/dataenginescript.cpp b/scripting/dataenginescript.cpp index 701ad8c37..c2ff49046 100644 --- a/scripting/dataenginescript.cpp +++ b/scripting/dataenginescript.cpp @@ -92,6 +92,13 @@ void DataEngineScript::removeData(const QString& source, const QString& key) } } +void DataEngineScript::setSourceLimit(uint limit) +{ + if (d->dataEngine) { + d->dataEngine->setSourceLimit(limit); + } +} + void DataEngineScript::setMinimumPollingInterval(int minimumMs) { if (d->dataEngine) { diff --git a/scripting/dataenginescript.h b/scripting/dataenginescript.h index 13c85eb80..4d42bd4af 100644 --- a/scripting/dataenginescript.h +++ b/scripting/dataenginescript.h @@ -80,6 +80,7 @@ protected: void setData(const QString &source, const QVariant &value); void clearData(const QString& source); void removeData(const QString& source, const QString& key); + void setSourceLimit(uint limit); void setMinimumPollingInterval(int minimumMs); int minimumPollingInterval() const; void setPollingInterval(uint frequency);