- use DataContainer::connectVisualization

- add internalUpdateSource so that we can automate the call to checkForUpdates

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=711719
This commit is contained in:
Aaron J. Seigo 2007-09-12 17:04:21 +00:00
parent 8415f49e55
commit 705e4d9148
2 changed files with 26 additions and 19 deletions

View File

@ -76,7 +76,7 @@ class DataEngine::Private
DataContainer* s = new DataContainer(engine);
s->setObjectName(sourceName);
sources.insert(sourceName, s);
connect(s, SIGNAL(requestUpdate(QString)), engine, SLOT(updateSource(QString)));
connect(s, SIGNAL(requestUpdate(QString)), engine, SLOT(internalUpdateSource(QString)));
if (limit > 0) {
trimQueue();
@ -86,27 +86,19 @@ class DataEngine::Private
return s;
}
void connectSource(const DataContainer* s, QObject* visualization, uint updateInterval)
void connectSource(DataContainer* s, QObject* visualization, uint updateInterval)
{
connect(visualization, SIGNAL(destroyed(QObject*)),
s, SLOT(disconnectVisualization(QObject*)), Qt::QueuedConnection);
if (updateInterval > 0) {
// never more frequently than allowed, never more than 20 times per second
uint min = qMax(50, minUpdateFreq); // for qMin below
updateInterval = qMax(min, updateInterval);
if (updateInterval < 1) {
connect(s, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
} else {
// never more frequently than allowed
uint min = minUpdateFreq; // for qMin below
updateInterval = qMin(min, updateInterval);
// never more than 20 times per second, and align on the 50ms
// align on the 50ms
updateInterval = updateInterval - (updateInterval % 50);
connect(s->signalRelay(visualization, updateInterval),
SIGNAL(updated(QString,Plasma::DataEngine::Data)),
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
}
s->connectVisualization(visualization, updateInterval);
QMetaObject::invokeMethod(visualization, "updated",
Q_ARG(QString, s->objectName()),
Q_ARG(Plasma::DataEngine::Data, s->data()));
@ -124,7 +116,7 @@ class DataEngine::Private
// now we have a source; since it was created on demand, assume
// it should be removed when not used
connect(s, SIGNAL(unused(QString)), engine, SLOT(removeSource(QString)));
connect(s, SIGNAL(requestUpdate(QString)), engine, SLOT(updateSource(QString)));
connect(s, SIGNAL(requestUpdate(QString)), engine, SLOT(internalUpdateSource(QString)));
}
}
}
@ -195,7 +187,7 @@ void DataEngine::connectSource(const QString& source, QObject* visualization, ui
void DataEngine::connectAllSources(QObject* visualization, uint updateInterval) const
{
foreach (const DataContainer* s, d->sources) {
foreach (DataContainer* s, d->sources) {
d->connectSource(s, visualization, updateInterval);
}
}
@ -234,6 +226,13 @@ void DataEngine::startInit()
init();
}
void DataEngine::internalUpdateSource(const QString& source)
{
if (updateSource(source)) {
d->queueUpdate();
}
}
void DataEngine::init()
{
// kDebug() << "DataEngine::init() called ";

View File

@ -106,6 +106,9 @@ class PLASMA_EXPORT DataEngine : public QObject
* The data is a QHash of QVariants keyed by QString names, allowing
* one data source to provide sets of related data.
*
* This method may be called multiple times for the same visualization
* without side-effects. This can be useful to change the updateInterval.
*
* @param visualization the object to connect the data source to
* @param updateInterval the frequency, in milliseconds, with which to signal updates;
* a value of 0 (the default) means to update only
@ -371,6 +374,11 @@ class PLASMA_EXPORT DataEngine : public QObject
**/
void startInit();
/**
* @internal
**/
void internalUpdateSource(const QString& source);
private:
class Private;
Private* const d;