delay usage checks so quite disconnect/reconnects don't result in unecessary loss of data
(only to reload it again immediately thereafter...)
This commit is contained in:
parent
97743420a0
commit
176d4b896b
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
};
|
||||
|
||||
|
@ -20,11 +20,13 @@
|
||||
#ifndef PLASMA_DATACONTAINER_P_H
|
||||
#define PLASMA_DATACONTAINER_P_H
|
||||
|
||||
#include <QtCore/QTimerEvent>
|
||||
#include <QtCore/QTime>
|
||||
#include "servicejob.h"
|
||||
#include "storage_p.h"
|
||||
|
||||
#include <QtCore/QTimerEvent>
|
||||
#include <QtCore/QTime>
|
||||
#include <QtCore/QBasicTimer>
|
||||
|
||||
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<QObject *, SignalRelay *> relayObjects;
|
||||
QMap<uint, SignalRelay *> 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
|
||||
|
Loading…
Reference in New Issue
Block a user