diff --git a/datacontainer.cpp b/datacontainer.cpp index 663c7ca97..84b345c74 100644 --- a/datacontainer.cpp +++ b/datacontainer.cpp @@ -31,8 +31,6 @@ DataContainer::DataContainer(QObject *parent) : QObject(parent), d(new DataContainerPrivate(this)) { - d->storageTimer = new QTimer(this); - QObject::connect(d->storageTimer, SIGNAL(timeout()), this, SLOT(store())); } DataContainer::~DataContainer() @@ -61,7 +59,7 @@ void DataContainer::setData(const QString &key, const QVariant &value) //setData() since the last time it was stored. This //gives us only one singleShot timer. if (isStorageEnabled() || !needsToBeStored()) { - d->storageTimer->start(180000); + d->storageTimer.start(180000, this); } setNeedsToBeStored(true); @@ -330,11 +328,22 @@ void DataContainer::setNeedsUpdate(bool update) void DataContainer::checkUsage() { - if (d->relays.count() < 1 && - receivers(SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data))) < 1) { - // DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED! - kDebug() << objectName() << "is unused"; - emit becameUnused(objectName()); + if (!d->checkUsageTimer.isActive()) { + d->checkUsageTimer.start(10, this); + } +} + +void DataContainer::timerEvent(QTimerEvent * event) +{ + if (event->timerId() == d->checkUsageTimer.timerId()) { + if (d->relays.count() < 1 && + receivers(SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data))) < 1) { + // DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED! + kDebug() << objectName() << "is unused"; + emit becameUnused(objectName()); + } + } else if (event->timerId() == d->storageTimer.timerId()) { + d->store(); } } diff --git a/datacontainer.h b/datacontainer.h index 746be5e40..3c196c10e 100644 --- a/datacontainer.h +++ b/datacontainer.h @@ -245,6 +245,11 @@ class PLASMA_EXPORT DataContainer : public QObject **/ void checkUsage(); + /** + * @reimp from QObject + */ + void timerEvent(QTimerEvent * event); + private: friend class SignalRelay; friend class DataContainerPrivate; @@ -253,7 +258,6 @@ class PLASMA_EXPORT DataContainer : public QObject Q_PRIVATE_SLOT(d, void storeJobFinished(KJob *job)) Q_PRIVATE_SLOT(d, void populateFromStoredData(KJob *job)) - Q_PRIVATE_SLOT(d, void store()) Q_PRIVATE_SLOT(d, void retrieve()) }; diff --git a/private/datacontainer_p.h b/private/datacontainer_p.h index 59054d624..a3e1f00a8 100644 --- a/private/datacontainer_p.h +++ b/private/datacontainer_p.h @@ -20,11 +20,13 @@ #ifndef PLASMA_DATACONTAINER_P_H #define PLASMA_DATACONTAINER_P_H -#include -#include #include "servicejob.h" #include "storage_p.h" +#include +#include +#include + class QTimer; namespace Plasma @@ -38,11 +40,11 @@ public: DataContainerPrivate(DataContainer *container) : q(container), storage(NULL), + storageCount(0), dirty(false), cached(false), enableStorage(false), - isStored(true), - storageCount(0) + isStored(true) { } @@ -71,14 +73,15 @@ public: DataEngine::Data data; QMap relayObjects; QMap relays; - QTimer *storageTimer; QTime updateTs; Storage* storage; + QBasicTimer storageTimer; + QBasicTimer checkUsageTimer; + int storageCount; bool dirty : 1; bool cached : 1; bool enableStorage : 1; bool isStored : 1; - int storageCount; }; class SignalRelay : public QObject