Fixed an issue with an object being deleted too early.
svn path=/trunk/KDE/kdelibs/; revision=1158360
This commit is contained in:
parent
e8cabacbb4
commit
df52b374e9
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user