Fixed an issue with an object being deleted too early.

svn path=/trunk/KDE/kdelibs/; revision=1158360
This commit is contained in:
Brian David Pritchett 2010-08-02 16:00:47 +00:00
parent e8cabacbb4
commit df52b374e9
3 changed files with 33 additions and 8 deletions

View File

@ -190,13 +190,19 @@ void DataContainer::store()
if (!needsToBeStored()){
return;
}
DataEngine* de = getDataEngine();
if (de == NULL) {
return;
}
setNeedsToBeStored(false);
Storage* store = new Storage(de->name(), 0);
KConfigGroup op = store->operationDescription("save");
if (d->store == NULL) {
d->store = new Storage(de->name(), 0);
}
KConfigGroup op = d->store->operationDescription("save");
op.writeEntry("source", objectName());
DataEngine::Data dataToStore = data();
DataEngine::Data::const_iterator it = dataToStore.constBegin();
@ -213,13 +219,21 @@ void DataContainer::store()
op.writeEntry("data", b.toBase64());
}
++it;
ServiceJob* job = store->startOperationCall(op);
job->start();
if (d->store == NULL) {
d->store = new Storage(de->name(), 0);
}
ServiceJob* job = d->store->startOperationCall(op);
d->storeCount++;
connect(job, "finished(KJob*)", this, "storeJobFinished(KJob*)");
}
}
//FIXME: this may result in the service being deleted before the jobs ... resulting in the
//jobs potentially being terminated prematurely
store->deleteLater();
void DataContainer::storeJobFinished(KJob* job)
{
d->storeCount--;
if (d->storeCount == 0) {
d->store->deleteLater();
}
}
void DataContainer::retrieve()

View File

@ -259,6 +259,12 @@ class PLASMA_EXPORT DataContainer : public QObject
*/
void populateFromStoredData(KJob *job);
/**
* Deletes the store member of DataContainerPrivate if
* there are no more references to it.
*/
void storeJobFinished(KJob *job);
private:
friend class SignalRelay;
DataContainerPrivate *const d;

View File

@ -23,6 +23,7 @@
#include <QtCore/QTimerEvent>
#include <QtCore/QTime>
#include "servicejob.h"
#include "storage_p.h"
namespace Plasma
{
@ -36,7 +37,9 @@ public:
: dirty(false),
cached(false),
enableStorage(false),
isStored(true)
isStored(true),
store(NULL),
storeCount(0)
{}
SignalRelay *signalRelay(const DataContainer *dc, QObject *visualization,
@ -50,10 +53,12 @@ public:
QMap<QObject *, SignalRelay *> relayObjects;
QMap<uint, SignalRelay *> relays;
QTime updateTs;
Storage* store;
bool dirty : 1;
bool cached : 1;
bool enableStorage : 1;
bool isStored : 1;
int storeCount;
};
class SignalRelay : public QObject