Added akonadi storage plugin loading.

svn path=/trunk/KDE/kdelibs/; revision=1164453
This commit is contained in:
Brian David Pritchett 2010-08-16 19:02:03 +00:00
parent a2d0e31e23
commit 4fdf87b54f
2 changed files with 48 additions and 38 deletions

View File

@ -19,6 +19,7 @@
#include "datacontainer.h"
#include "private/datacontainer_p.h"
#include "private/storage_p.h"
#include "pluginloader.h"
#include <kdebug.h>
@ -198,36 +199,43 @@ void DataContainer::store()
setNeedsToBeStored(false);
if (d->store == NULL) {
d->store = new Storage(de->name(), 0);
if (!d->store) {
QVariantList args;
args.insert(0, de->name());
d->store = PluginLoader::pluginLoader()->loadService("akonadi_storage_plugin", args, 0);
if (!d->store) {
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();
while (it != dataToStore.constEnd() && dataToStore.constEnd() == data().constEnd()) {
QVariant v = it.value();
if ((it.value().type() == QVariant::String) || (it.value().type() == QVariant::Int)) {
op.writeEntry("key", it.key());
op.writeEntry("data", it.value());
} else {
QByteArray b;
QDataStream ds(&b, QIODevice::WriteOnly);
ds << it.value();
op.writeEntry("key", "base64-" + it.key());
op.writeEntry("data", b.toBase64());
}
++it;
if (d->store == NULL) {
QByteArray b;
QDataStream ds(&b, QIODevice::WriteOnly);
ds << it.value();
op.writeEntry("key", it.key());
op.writeEntry("data", b.toBase64());
}
++it;
if (!d->store) {
QVariantList args;
args.insert(0, de->name());
d->store = PluginLoader::pluginLoader()->loadService("plasma_storage_akonadi", args, 0);
if (!d->store) {
d->store = new Storage(de->name(), 0);
}
ServiceJob* job = d->store->startOperationCall(op);
d->storeCount++;
connect(job, SIGNAL(finished(KJob*)), this, SLOT(storeJobFinished(KJob*)));
}
ServiceJob* job = d->store->startOperationCall(op);
d->storeCount++;
connect(job, SIGNAL(finished(KJob*)), this, SLOT(storeJobFinished(KJob*)));
}
void DataContainerPrivate::storeJobFinished(KJob* )
{
--storeCount;
@ -243,10 +251,17 @@ void DataContainer::retrieve()
if (de == NULL) {
return;
}
Storage* store = new Storage(de->name(), 0);
KConfigGroup retrieveGroup = store->operationDescription("retrieve");
if (!d->store) {
QVariantList args;
args.insert(0, de->name());
d->store = PluginLoader::pluginLoader()->loadService("plasma_storage_akonadi", args, 0);
if (!d->store) {
d->store = new Storage(de->name(), 0);
}
}
KConfigGroup retrieveGroup = d->store->operationDescription("retrieve");
retrieveGroup.writeEntry("source", objectName());
ServiceJob* retrieveJob = store->startOperationCall(retrieveGroup);
ServiceJob* retrieveJob = d->store->startOperationCall(retrieveGroup);
connect(retrieveJob, SIGNAL(result(KJob*)), this,
SLOT(populateFromStoredData(KJob*)));
}
@ -261,27 +276,22 @@ void DataContainerPrivate::populateFromStoredData(KJob *job)
ServiceJob* ret = dynamic_cast<ServiceJob*>(job);
QHash<QString, QVariant> h = ret->result().toHash();
foreach (QString key, h.keys()) {
if (key.startsWith("base64-")) {
QByteArray b = QByteArray::fromBase64(h[key].toString().toAscii());
QDataStream ds(&b, QIODevice::ReadOnly);
QVariant v(ds);
key.remove(0, 7);
dataToInsert.insert(key, v);
} else {
dataToInsert.insert(key, h[key]);
}
QByteArray b = QByteArray::fromBase64(h[key].toString().toAscii());
QDataStream ds(&b, QIODevice::ReadOnly);
QVariant v(ds);
key.remove(0, 7);
dataToInsert.insert(key, v);
}
if (!(data.isEmpty()))
//Do not fill the source with old stored
//data if it is already populated with new data.
if (data.isEmpty())
{
//Do not fill the source with old stored
//data if it is already populated with new data.
return;
data = dataToInsert;
// dirty = true;
// q->checkForUpdate();
}
data = dataToInsert;
dirty = true;
q->checkForUpdate();
}
void DataContainer::disconnectVisualization(QObject *visualization)

View File

@ -35,7 +35,7 @@ class DataContainerPrivate
public:
DataContainerPrivate(DataContainer *container)
: q(container),
store(NULL),
store(0),
dirty(false),
cached(false),
enableStorage(false),
@ -66,7 +66,7 @@ public:
QMap<QObject *, SignalRelay *> relayObjects;
QMap<uint, SignalRelay *> relays;
QTime updateTs;
Storage* store;
Service* store;
bool dirty : 1;
bool cached : 1;
bool enableStorage : 1;