use variant maps instead of configgroups
services operationdescriptions are now QVariantMaps
This commit is contained in:
parent
aa8ed30fda
commit
b0530820ec
@ -38,8 +38,8 @@ void StorageTest::initTestCase()
|
|||||||
void StorageTest::store()
|
void StorageTest::store()
|
||||||
{
|
{
|
||||||
Storage storage;
|
Storage storage;
|
||||||
KConfigGroup op = storage.operationDescription("save");
|
QVariantMap op = storage.operationDescription("save");
|
||||||
op.writeEntry("group", "Test");
|
op["group"] = "Test";
|
||||||
Plasma::ServiceJob *job = storage.startOperationCall(op);
|
Plasma::ServiceJob *job = storage.startOperationCall(op);
|
||||||
StorageJob *storageJob = qobject_cast<StorageJob *>(job);
|
StorageJob *storageJob = qobject_cast<StorageJob *>(job);
|
||||||
|
|
||||||
@ -54,8 +54,8 @@ void StorageTest::store()
|
|||||||
void StorageTest::retrieve()
|
void StorageTest::retrieve()
|
||||||
{
|
{
|
||||||
Storage storage;
|
Storage storage;
|
||||||
KConfigGroup op = storage.operationDescription("retrieve");
|
QVariantMap op = storage.operationDescription("retrieve");
|
||||||
op.writeEntry("group", "Test");
|
op["group"] = "Test";
|
||||||
Plasma::ServiceJob *job = storage.startOperationCall(op);
|
Plasma::ServiceJob *job = storage.startOperationCall(op);
|
||||||
StorageJob *storageJob = qobject_cast<StorageJob *>(job);
|
StorageJob *storageJob = qobject_cast<StorageJob *>(job);
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ void StorageTest::retrieve()
|
|||||||
void StorageTest::deleteEntry()
|
void StorageTest::deleteEntry()
|
||||||
{
|
{
|
||||||
Storage storage;
|
Storage storage;
|
||||||
KConfigGroup op = storage.operationDescription("delete");
|
QVariantMap op = storage.operationDescription("delete");
|
||||||
op.writeEntry("group", "Test");
|
op["group"] = "Test";
|
||||||
Plasma::ServiceJob *job = storage.startOperationCall(op);
|
Plasma::ServiceJob *job = storage.startOperationCall(op);
|
||||||
StorageJob *storageJob = qobject_cast<StorageJob *>(job);
|
StorageJob *storageJob = qobject_cast<StorageJob *>(job);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ void StorageTest::deleteEntry()
|
|||||||
}
|
}
|
||||||
|
|
||||||
op = storage.operationDescription("retrieve");
|
op = storage.operationDescription("retrieve");
|
||||||
op.writeEntry("group", "Test");
|
op["group"] = "Test";
|
||||||
job = storage.startOperationCall(op);
|
job = storage.startOperationCall(op);
|
||||||
storageJob = qobject_cast<StorageJob *>(job);
|
storageJob = qobject_cast<StorageJob *>(job);
|
||||||
|
|
||||||
|
@ -201,8 +201,8 @@ void DataContainerPrivate::store()
|
|||||||
storage = new Storage(q);
|
storage = new Storage(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
KConfigGroup op = storage->operationDescription("save");
|
QVariantMap op = storage->operationDescription("save");
|
||||||
op.writeEntry("group", q->objectName());
|
op["group"] = q->objectName();
|
||||||
StorageJob *job = static_cast<StorageJob *>(storage->startOperationCall(op));
|
StorageJob *job = static_cast<StorageJob *>(storage->startOperationCall(op));
|
||||||
job->setData(data);
|
job->setData(data);
|
||||||
storageCount++;
|
storageCount++;
|
||||||
@ -229,8 +229,8 @@ void DataContainerPrivate::retrieve()
|
|||||||
storage = new Storage(q);
|
storage = new Storage(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
KConfigGroup retrieveGroup = storage->operationDescription("retrieve");
|
QVariantMap retrieveGroup = storage->operationDescription("retrieve");
|
||||||
retrieveGroup.writeEntry("group", q->objectName());
|
retrieveGroup["group"] = q->objectName();
|
||||||
ServiceJob* retrieveJob = storage->startOperationCall(retrieveGroup);
|
ServiceJob* retrieveJob = storage->startOperationCall(retrieveGroup);
|
||||||
QObject::connect(retrieveJob, SIGNAL(result(KJob*)), q,
|
QObject::connect(retrieveJob, SIGNAL(result(KJob*)), q,
|
||||||
SLOT(populateFromStoredData(KJob*)));
|
SLOT(populateFromStoredData(KJob*)));
|
||||||
@ -255,9 +255,9 @@ void DataContainerPrivate::populateFromStoredData(KJob *job)
|
|||||||
q->forceImmediateUpdate();
|
q->forceImmediateUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
KConfigGroup expireGroup = storage->operationDescription("expire");
|
QVariantMap expireGroup = storage->operationDescription("expire");
|
||||||
//expire things older than 4 days
|
//expire things older than 4 days
|
||||||
expireGroup.writeEntry("age", 345600);
|
expireGroup["age"] = 345600;
|
||||||
storage->startOperationCall(expireGroup);
|
storage->startOperationCall(expireGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +67,8 @@ void DataEngineConsumerPrivate::slotServiceReady(Plasma::Service *plasmoidServic
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
kDebug() << "requesting dataengine!";
|
kDebug() << "requesting dataengine!";
|
||||||
#endif
|
#endif
|
||||||
KConfigGroup op = plasmoidService->operationDescription("DataEngine");
|
QVariantMap op = plasmoidService->operationDescription("DataEngine");
|
||||||
op.writeEntry("EngineName", engineNameForService.value(plasmoidService));
|
op["EngineName"] = engineNameForService.value(plasmoidService);
|
||||||
plasmoidService->startOperationCall(op);
|
plasmoidService->startOperationCall(op);
|
||||||
connect(plasmoidService, SIGNAL(finished(Plasma::ServiceJob*)),
|
connect(plasmoidService, SIGNAL(finished(Plasma::ServiceJob*)),
|
||||||
this, SLOT(slotJobFinished(Plasma::ServiceJob*)));
|
this, SLOT(slotJobFinished(Plasma::ServiceJob*)));
|
||||||
|
@ -45,7 +45,7 @@ class NullServiceJob : public ServiceJob
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NullServiceJob(const QString &destination, const QString &operation, QObject *parent)
|
NullServiceJob(const QString &destination, const QString &operation, QObject *parent)
|
||||||
: ServiceJob(destination, operation, QHash<QString, QVariant>(), parent)
|
: ServiceJob(destination, operation, QVariantMap(), parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public:
|
|||||||
setName("NullService");
|
setName("NullService");
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceJob *createJob(const QString &operation, QHash<QString, QVariant> &)
|
ServiceJob *createJob(const QString &operation, QVariantMap &)
|
||||||
{
|
{
|
||||||
return new NullServiceJob(destination(), operation, this);
|
return new NullServiceJob(destination(), operation, this);
|
||||||
}
|
}
|
||||||
@ -77,7 +77,6 @@ class ServicePrivate
|
|||||||
public:
|
public:
|
||||||
ServicePrivate(Service *service)
|
ServicePrivate(Service *service)
|
||||||
: q(service),
|
: q(service),
|
||||||
config(0),
|
|
||||||
dummyConfig(0),
|
dummyConfig(0),
|
||||||
publicService(0)
|
publicService(0)
|
||||||
{
|
{
|
||||||
@ -85,7 +84,6 @@ public:
|
|||||||
|
|
||||||
~ServicePrivate()
|
~ServicePrivate()
|
||||||
{
|
{
|
||||||
delete config;
|
|
||||||
delete dummyConfig;
|
delete dummyConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +97,7 @@ public:
|
|||||||
QString destination;
|
QString destination;
|
||||||
QString name;
|
QString name;
|
||||||
QString resourcename;
|
QString resourcename;
|
||||||
ConfigLoader *config;
|
QMap<QString, QVariantMap> operationsMap;
|
||||||
KConfig *dummyConfig;
|
KConfig *dummyConfig;
|
||||||
DNSSD::PublicService *publicService;
|
DNSSD::PublicService *publicService;
|
||||||
QMultiHash<QWidget *, QString> associatedWidgets;
|
QMultiHash<QWidget *, QString> associatedWidgets;
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
ServiceJobPrivate(ServiceJob *owner,
|
ServiceJobPrivate(ServiceJob *owner,
|
||||||
const QString &dest,
|
const QString &dest,
|
||||||
const QString &op,
|
const QString &op,
|
||||||
const QHash<QString, QVariant> ¶ms);
|
const QVariantMap ¶ms);
|
||||||
|
|
||||||
void preventAutoStart();
|
void preventAutoStart();
|
||||||
void autoStart();
|
void autoStart();
|
||||||
@ -42,7 +42,7 @@ public:
|
|||||||
ServiceJob *q;
|
ServiceJob *q;
|
||||||
QString destination;
|
QString destination;
|
||||||
QString operation;
|
QString operation;
|
||||||
QHash<QString, QVariant> parameters;
|
QVariantMap parameters;
|
||||||
QVariant result;
|
QVariant result;
|
||||||
bool m_allowAutoStart;
|
bool m_allowAutoStart;
|
||||||
};
|
};
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
StorageJob::StorageJob(const QString& destination,
|
StorageJob::StorageJob(const QString& destination,
|
||||||
const QString& operation,
|
const QString& operation,
|
||||||
const QHash<QString, QVariant>& parameters,
|
const QVariantMap& parameters,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
: ServiceJob(destination, operation, parameters, parent),
|
: ServiceJob(destination, operation, parameters, parent),
|
||||||
m_clientName(destination)
|
m_clientName(destination)
|
||||||
@ -77,7 +77,7 @@ QString StorageJob::clientName() const
|
|||||||
void StorageJob::start()
|
void StorageJob::start()
|
||||||
{
|
{
|
||||||
//FIXME: QHASH
|
//FIXME: QHASH
|
||||||
QHash<QString, QVariant> params = parameters();
|
QVariantMap params = parameters();
|
||||||
|
|
||||||
QString valueGroup = params["group"].toString();
|
QString valueGroup = params["group"].toString();
|
||||||
if (valueGroup.isEmpty()) {
|
if (valueGroup.isEmpty()) {
|
||||||
@ -86,13 +86,13 @@ void StorageJob::start()
|
|||||||
|
|
||||||
QWeakPointer<StorageJob> me(this);
|
QWeakPointer<StorageJob> me(this);
|
||||||
if (operationName() == "save") {
|
if (operationName() == "save") {
|
||||||
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "save", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantHash&, params));
|
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "save", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap&, params));
|
||||||
} else if (operationName() == "retrieve") {
|
} else if (operationName() == "retrieve") {
|
||||||
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "retrieve", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantHash&, params));
|
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "retrieve", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap&, params));
|
||||||
} else if (operationName() == "delete") {
|
} else if (operationName() == "delete") {
|
||||||
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "deleteEntry", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantHash&, params));
|
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "deleteEntry", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap&, params));
|
||||||
} else if (operationName() == "expire") {
|
} else if (operationName() == "expire") {
|
||||||
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "expire", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantHash&, params));
|
QMetaObject::invokeMethod(Plasma::StorageThread::self(), "expire", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap&, params));
|
||||||
} else {
|
} else {
|
||||||
setError(true);
|
setError(true);
|
||||||
setResult(false);
|
setResult(false);
|
||||||
@ -109,7 +109,7 @@ void StorageJob::resultSlot(StorageJob *job, const QVariant &result)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::ServiceJob* Storage::createJob(const QString &operation, QHash<QString, QVariant> ¶meters)
|
Plasma::ServiceJob* Storage::createJob(const QString &operation, QVariantMap ¶meters)
|
||||||
{
|
{
|
||||||
if (m_clientName.isEmpty()) {
|
if (m_clientName.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -37,7 +37,7 @@ class StorageJob : public Plasma::ServiceJob
|
|||||||
public:
|
public:
|
||||||
StorageJob(const QString& destination,
|
StorageJob(const QString& destination,
|
||||||
const QString& operation,
|
const QString& operation,
|
||||||
const QHash<QString, QVariant>& parameters,
|
const QVariantMap& parameters,
|
||||||
QObject *parent = 0);
|
QObject *parent = 0);
|
||||||
~StorageJob();
|
~StorageJob();
|
||||||
void setData(const QVariantHash &data);
|
void setData(const QVariantHash &data);
|
||||||
@ -66,7 +66,7 @@ public:
|
|||||||
~Storage();
|
~Storage();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Plasma::ServiceJob* createJob(const QString &operation, QHash<QString, QVariant> ¶meters);
|
Plasma::ServiceJob* createJob(const QString &operation, QVariantMap ¶meters);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_clientName;
|
QString m_clientName;
|
||||||
|
@ -52,9 +52,10 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
void addItem();
|
void addItem();
|
||||||
|
const QMap<QString, QVariantMap> &groupsMap() const;
|
||||||
|
|
||||||
//private:
|
private:
|
||||||
QVariantMap m_map;
|
QMap<QString, QVariantMap> m_groupsMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ConfigLoaderHandlerMap::addItem()
|
void ConfigLoaderHandlerMap::addItem()
|
||||||
@ -73,53 +74,50 @@ void ConfigLoaderHandlerMap::addItem()
|
|||||||
setKey(name());
|
setKey(name());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap map;
|
if (!m_groupsMap.contains(currentGroup())) {
|
||||||
if (m_map.contains(currentGroup())) {
|
m_groupsMap[currentGroup()] = QVariantMap();
|
||||||
map = m_map[currentGroup()].value<QVariantMap>();
|
|
||||||
} else {
|
|
||||||
m_map[currentGroup()] = QVariantMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (type() == "bool") {
|
if (type() == "bool") {
|
||||||
bool defaultVal = defaultValue().toLower() == "true";
|
bool defaultVal = defaultValue().toLower() == "true";
|
||||||
map[key()] = defaultVal;
|
m_groupsMap[currentGroup()][key()] = defaultVal;
|
||||||
} else if (type() == "color") {
|
} else if (type() == "color") {
|
||||||
map[key()] = QColor(defaultValue());
|
m_groupsMap[currentGroup()][key()] = QColor(defaultValue());
|
||||||
} else if (type() == "datetime") {
|
} else if (type() == "datetime") {
|
||||||
map[key()] = QDateTime::fromString(defaultValue());
|
m_groupsMap[currentGroup()][key()] = QDateTime::fromString(defaultValue());
|
||||||
} else if (type() == "enum") {
|
} else if (type() == "enum") {
|
||||||
key() = (key().isEmpty()) ? name() : key();
|
key() = (key().isEmpty()) ? name() : key();
|
||||||
map[key()] = defaultValue().toUInt();
|
m_groupsMap[currentGroup()][key()] = defaultValue().toUInt();
|
||||||
} else if (type() == "font") {
|
} else if (type() == "font") {
|
||||||
map[key()] = QFont(defaultValue());
|
m_groupsMap[currentGroup()][key()] = QFont(defaultValue());
|
||||||
} else if (type() == "int") {
|
} else if (type() == "int") {
|
||||||
map[key()] = defaultValue().toInt();
|
m_groupsMap[currentGroup()][key()] = defaultValue().toInt();
|
||||||
} else if (type() == "password") {
|
} else if (type() == "password") {
|
||||||
map[key()] = defaultValue();
|
m_groupsMap[currentGroup()][key()] = defaultValue();
|
||||||
} else if (type() == "path") {
|
} else if (type() == "path") {
|
||||||
map[key()] = defaultValue();
|
m_groupsMap[currentGroup()][key()] = defaultValue();
|
||||||
} else if (type() == "string") {
|
} else if (type() == "string") {
|
||||||
map[key()] = defaultValue();
|
m_groupsMap[currentGroup()][key()] = defaultValue();
|
||||||
} else if (type() == "stringlist") {
|
} else if (type() == "stringlist") {
|
||||||
//FIXME: the split() is naive and will break on lists with ,'s in them
|
//FIXME: the split() is naive and will break on lists with ,'s in them
|
||||||
map[key()] = defaultValue().split(',');
|
m_groupsMap[currentGroup()][key()] = defaultValue().split(',');
|
||||||
} else if (type() == "uint") {
|
} else if (type() == "uint") {
|
||||||
map[key()] = defaultValue().toUInt();
|
m_groupsMap[currentGroup()][key()] = defaultValue().toUInt();
|
||||||
} else if (type() == "url") {
|
} else if (type() == "url") {
|
||||||
setKey((key().isEmpty()) ? name() : key());
|
setKey((key().isEmpty()) ? name() : key());
|
||||||
map[key()] = QUrl::fromUserInput(defaultValue());
|
m_groupsMap[currentGroup()][key()] = QUrl::fromUserInput(defaultValue());
|
||||||
} else if (type() == "double") {
|
} else if (type() == "double") {
|
||||||
map[key()] = defaultValue().toDouble();
|
m_groupsMap[currentGroup()][key()] = defaultValue().toDouble();
|
||||||
} else if (type() == "intlist") {
|
} else if (type() == "intlist") {
|
||||||
QStringList tmpList = defaultValue().split(',');
|
QStringList tmpList = defaultValue().split(',');
|
||||||
QList<int> defaultList;
|
QList<int> defaultList;
|
||||||
foreach (const QString &tmp, tmpList) {
|
foreach (const QString &tmp, tmpList) {
|
||||||
defaultList.append(tmp.toInt());
|
defaultList.append(tmp.toInt());
|
||||||
}
|
}
|
||||||
map[key()] = QVariant::fromValue(defaultList);
|
m_groupsMap[currentGroup()][key()] = QVariant::fromValue(defaultList);
|
||||||
} else if (type() == "longlong") {
|
} else if (type() == "longlong") {
|
||||||
map[key()] = defaultValue().toLongLong();
|
m_groupsMap[currentGroup()][key()] = defaultValue().toLongLong();
|
||||||
} else if (type() == "point") {
|
} else if (type() == "point") {
|
||||||
QPoint defaultPoint;
|
QPoint defaultPoint;
|
||||||
QStringList tmpList = defaultValue().split(',');
|
QStringList tmpList = defaultValue().split(',');
|
||||||
@ -127,7 +125,7 @@ void ConfigLoaderHandlerMap::addItem()
|
|||||||
defaultPoint.setX(tmpList[0].toInt());
|
defaultPoint.setX(tmpList[0].toInt());
|
||||||
defaultPoint.setY(tmpList[1].toInt());
|
defaultPoint.setY(tmpList[1].toInt());
|
||||||
}
|
}
|
||||||
map[key()] = defaultPoint;
|
m_groupsMap[currentGroup()][key()] = defaultPoint;
|
||||||
} else if (type() == "rect") {
|
} else if (type() == "rect") {
|
||||||
QRect defaultRect;
|
QRect defaultRect;
|
||||||
QStringList tmpList = defaultValue().split(',');
|
QStringList tmpList = defaultValue().split(',');
|
||||||
@ -135,7 +133,7 @@ void ConfigLoaderHandlerMap::addItem()
|
|||||||
defaultRect.setCoords(tmpList[0].toInt(), tmpList[1].toInt(),
|
defaultRect.setCoords(tmpList[0].toInt(), tmpList[1].toInt(),
|
||||||
tmpList[2].toInt(), tmpList[3].toInt());
|
tmpList[2].toInt(), tmpList[3].toInt());
|
||||||
}
|
}
|
||||||
map[key()] = tmpList;
|
m_groupsMap[currentGroup()][key()] = tmpList;
|
||||||
} else if (type() == "size") {
|
} else if (type() == "size") {
|
||||||
QSize defaultSize;
|
QSize defaultSize;
|
||||||
QStringList tmpList = defaultValue().split(',');
|
QStringList tmpList = defaultValue().split(',');
|
||||||
@ -143,20 +141,21 @@ void ConfigLoaderHandlerMap::addItem()
|
|||||||
defaultSize.setWidth(tmpList[0].toInt());
|
defaultSize.setWidth(tmpList[0].toInt());
|
||||||
defaultSize.setHeight(tmpList[1].toInt());
|
defaultSize.setHeight(tmpList[1].toInt());
|
||||||
}
|
}
|
||||||
map[key()] = tmpList;
|
m_groupsMap[currentGroup()][key()] = tmpList;
|
||||||
} else if (type() == "ulonglong") {
|
} else if (type() == "ulonglong") {
|
||||||
map[key()] = defaultValue().toULongLong();
|
m_groupsMap[currentGroup()][key()] = defaultValue().toULongLong();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_map[currentGroup()] = map;
|
const QMap<QString, QVariantMap> &ConfigLoaderHandlerMap::groupsMap() const
|
||||||
|
{
|
||||||
|
return m_groupsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
Service::Service(QObject *parent)
|
Service::Service(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
d(new ServicePrivate(this))
|
d(new ServicePrivate(this))
|
||||||
{
|
{
|
||||||
ConfigLoaderPrivate *cl = new ConfigLoaderPrivate;
|
|
||||||
ConfigLoaderHandlerMap map(0, cl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Service::Service(QObject *parent, const QVariantList &args)
|
Service::Service(QObject *parent, const QVariantList &args)
|
||||||
@ -164,8 +163,6 @@ Service::Service(QObject *parent, const QVariantList &args)
|
|||||||
d(new ServicePrivate(this))
|
d(new ServicePrivate(this))
|
||||||
{
|
{
|
||||||
Q_UNUSED(args)
|
Q_UNUSED(args)
|
||||||
ConfigLoaderPrivate *cl = new ConfigLoaderPrivate;
|
|
||||||
ConfigLoaderHandlerMap map(0, cl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Service::~Service()
|
Service::~Service()
|
||||||
@ -204,38 +201,35 @@ QString Service::destination() const
|
|||||||
|
|
||||||
QStringList Service::operationNames() const
|
QStringList Service::operationNames() const
|
||||||
{
|
{
|
||||||
if (!d->config) {
|
if (!d->operationsMap.keys().isEmpty()) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
kDebug() << "No valid operations scheme has been registered";
|
kDebug() << "No valid operations scheme has been registered";
|
||||||
#endif
|
#endif
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return d->config->groupList();
|
return d->operationsMap.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
KConfigGroup Service::operationDescription(const QString &operationName)
|
QVariantMap Service::operationDescription(const QString &operationName)
|
||||||
{
|
{
|
||||||
if (!d->config) {
|
if (!d->operationsMap.keys().isEmpty()) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
kDebug() << "No valid operations scheme has been registered";
|
kDebug() << "No valid operations scheme has been registered";
|
||||||
#endif
|
#endif
|
||||||
return d->dummyGroup();
|
return QVariantMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
d->config->writeConfig();
|
|
||||||
KConfigGroup params(d->config->config(), operationName);
|
|
||||||
//kDebug() << "operation" << operationName
|
//kDebug() << "operation" << operationName
|
||||||
// << "requested, has keys" << params.keyList() << "from"
|
// << "requested, has keys" << d->operationsMap.keys();
|
||||||
// << d->config->config()->name();
|
return d->operationsMap.value(operationName);
|
||||||
return params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, QVariant> Service::parametersFromDescription(const KConfigGroup &description)
|
/*QHash<QString, QVariant> Service::parametersFromDescription(const KConfigGroup &description)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> params;
|
QHash<QString, QVariant> params;
|
||||||
|
|
||||||
if (!d->config || !description.isValid()) {
|
if (!d->operationsMap.keys().isEmpty() || !description.isValid()) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,30 +242,30 @@ QHash<QString, QVariant> Service::parametersFromDescription(const KConfigGroup &
|
|||||||
}
|
}
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
ServiceJob *Service::startOperationCall(const KConfigGroup &description, QObject *parent)
|
ServiceJob *Service::startOperationCall(const QVariantMap &description, QObject *parent)
|
||||||
{
|
{
|
||||||
// TODO: nested groups?
|
// TODO: nested groups?
|
||||||
ServiceJob *job = 0;
|
ServiceJob *job = 0;
|
||||||
const QString op = description.isValid() ? description.name() : QString();
|
const QString op = !description.isEmpty() ? description.value("_name").toString() : QString();
|
||||||
|
|
||||||
if (!d->config) {
|
if (!d->operationsMap.keys().isEmpty()) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
kDebug() << "No valid operations scheme has been registered";
|
kDebug() << "No valid operations scheme has been registered";
|
||||||
#endif
|
#endif
|
||||||
} else if (!op.isEmpty() && d->config->hasGroup(op)) {
|
} else if (!op.isEmpty() && d->operationsMap.contains(op)) {
|
||||||
if (d->disabledOperations.contains(op)) {
|
if (d->disabledOperations.contains(op)) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
kDebug() << "Operation" << op << "is disabled";
|
kDebug() << "Operation" << op << "is disabled";
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
QHash<QString, QVariant> params = parametersFromDescription(description);
|
QVariantMap map = description;
|
||||||
job = createJob(op, params);
|
job = createJob(op, map);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
kDebug() << op << "is not a valid group; valid groups are:" << d->config->groupList();
|
kDebug() << op << "is not a valid group; valid groups are:" << d->operationsMap->keys();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,8 +313,7 @@ void Service::setName(const QString &name)
|
|||||||
d->name = name;
|
d->name = name;
|
||||||
|
|
||||||
// now reset the config, which may be based on our name
|
// now reset the config, which may be based on our name
|
||||||
delete d->config;
|
d->operationsMap.clear();
|
||||||
d->config = 0;
|
|
||||||
|
|
||||||
delete d->dummyConfig;
|
delete d->dummyConfig;
|
||||||
d->dummyConfig = 0;
|
d->dummyConfig = 0;
|
||||||
@ -332,7 +325,7 @@ void Service::setName(const QString &name)
|
|||||||
|
|
||||||
void Service::setOperationEnabled(const QString &operation, bool enable)
|
void Service::setOperationEnabled(const QString &operation, bool enable)
|
||||||
{
|
{
|
||||||
if (!d->config || !d->config->hasGroup(operation)) {
|
if (!d->operationsMap.keys().isEmpty() || !d->operationsMap.contains(operation)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,19 +358,25 @@ void Service::setOperationEnabled(const QString &operation, bool enable)
|
|||||||
|
|
||||||
bool Service::isOperationEnabled(const QString &operation) const
|
bool Service::isOperationEnabled(const QString &operation) const
|
||||||
{
|
{
|
||||||
return d->config && d->config->hasGroup(operation) && !d->disabledOperations.contains(operation);
|
return d->operationsMap.contains(operation) && !d->disabledOperations.contains(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::setOperationsScheme(QIODevice *xml)
|
void Service::setOperationsScheme(QIODevice *xml)
|
||||||
{
|
{
|
||||||
delete d->config;
|
d->operationsMap.clear();
|
||||||
|
|
||||||
delete d->dummyConfig;
|
delete d->dummyConfig;
|
||||||
d->dummyConfig = 0;
|
d->dummyConfig = 0;
|
||||||
|
|
||||||
KSharedConfigPtr c = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
ConfigLoaderPrivate *configLoaderPrivate = new ConfigLoaderPrivate;
|
||||||
d->config = new ConfigLoader(c, xml, this);
|
configLoaderPrivate->setWriteDefaults(true);
|
||||||
d->config->d->setWriteDefaults(true);
|
ConfigLoaderHandlerMap configLoaderHandler(0, configLoaderPrivate);
|
||||||
|
QXmlInputSource source(xml);
|
||||||
|
QXmlSimpleReader reader;
|
||||||
|
reader.setContentHandler(&configLoaderHandler);
|
||||||
|
reader.parse(&source, false);
|
||||||
|
d->operationsMap = configLoaderHandler.groupsMap();
|
||||||
|
delete configLoaderPrivate;
|
||||||
|
|
||||||
emit operationsChanged();
|
emit operationsChanged();
|
||||||
|
|
||||||
@ -385,7 +384,7 @@ void Service::setOperationsScheme(QIODevice *xml)
|
|||||||
QHashIterator<QWidget *, QString> it(d->associatedWidgets);
|
QHashIterator<QWidget *, QString> it(d->associatedWidgets);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
it.key()->setEnabled(d->config->hasGroup(it.value()));
|
it.key()->setEnabled(d->operationsMap.contains(it.value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,14 +392,14 @@ void Service::setOperationsScheme(QIODevice *xml)
|
|||||||
QHashIterator<QQuickItem *, QString> it(d->associatedItems);
|
QHashIterator<QQuickItem *, QString> it(d->associatedItems);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
it.key()->setEnabled(d->config->hasGroup(it.value()));
|
it.key()->setEnabled(d->operationsMap.contains(it.value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::registerOperationsScheme()
|
void Service::registerOperationsScheme()
|
||||||
{
|
{
|
||||||
if (d->config) {
|
if (!d->operationsMap.keys().isEmpty()) {
|
||||||
// we've already done our job. let's go home.
|
// we've already done our job. let's go home.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ public:
|
|||||||
* @param operationName the operation to retrieve parameters for
|
* @param operationName the operation to retrieve parameters for
|
||||||
* @return KConfigGroup containing the parameters
|
* @return KConfigGroup containing the parameters
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE KConfigGroup operationDescription(const QString &operationName);
|
Q_INVOKABLE QVariantMap operationDescription(const QString &operationName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to create a ServiceJob which is associated with a given
|
* Called to create a ServiceJob which is associated with a given
|
||||||
@ -135,7 +135,7 @@ public:
|
|||||||
* @return a started ServiceJob; the consumer may connect to relevant
|
* @return a started ServiceJob; the consumer may connect to relevant
|
||||||
* signals before returning to the event loop
|
* signals before returning to the event loop
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE ServiceJob *startOperationCall(const KConfigGroup &description, QObject *parent = 0);
|
Q_INVOKABLE ServiceJob *startOperationCall(const QVariantMap &description, QObject *parent = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query to find if an operation is enabled or not.
|
* Query to find if an operation is enabled or not.
|
||||||
@ -177,7 +177,7 @@ public:
|
|||||||
* @param description the configuration values to turn into the parameter map
|
* @param description the configuration values to turn into the parameter map
|
||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE QHash<QString, QVariant> parametersFromDescription(const KConfigGroup &description);
|
/*Q_INVOKABLE QVariantMap parametersFromDescription(const KConfigGroup &description);*/
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
@ -213,7 +213,7 @@ protected:
|
|||||||
* @return a ServiceJob that can be started and monitored by the consumer
|
* @return a ServiceJob that can be started and monitored by the consumer
|
||||||
*/
|
*/
|
||||||
virtual ServiceJob *createJob(const QString &operation,
|
virtual ServiceJob *createJob(const QString &operation,
|
||||||
QHash<QString, QVariant> ¶meters) = 0;
|
QVariantMap ¶meters) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default this is based on the file in plasma/services/name.operations, but can be
|
* By default this is based on the file in plasma/services/name.operations, but can be
|
||||||
|
@ -27,7 +27,7 @@ namespace Plasma
|
|||||||
{
|
{
|
||||||
|
|
||||||
ServiceJobPrivate::ServiceJobPrivate(ServiceJob *owner, const QString &dest,
|
ServiceJobPrivate::ServiceJobPrivate(ServiceJob *owner, const QString &dest,
|
||||||
const QString &op, const QHash<QString, QVariant> ¶ms)
|
const QString &op, const QVariantMap ¶ms)
|
||||||
: q(owner),
|
: q(owner),
|
||||||
destination(dest),
|
destination(dest),
|
||||||
operation(op),
|
operation(op),
|
||||||
@ -56,7 +56,7 @@ void ServiceJobPrivate::autoStart()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServiceJob::ServiceJob(const QString &destination, const QString &operation,
|
ServiceJob::ServiceJob(const QString &destination, const QString &operation,
|
||||||
const QHash<QString, QVariant> ¶meters, QObject *parent)
|
const QVariantMap ¶meters, QObject *parent)
|
||||||
: KJob(parent),
|
: KJob(parent),
|
||||||
d(new ServiceJobPrivate(this, destination, operation, parameters))
|
d(new ServiceJobPrivate(this, destination, operation, parameters))
|
||||||
{
|
{
|
||||||
@ -78,7 +78,7 @@ QString ServiceJob::operationName() const
|
|||||||
return d->operation;
|
return d->operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, QVariant> ServiceJob::parameters() const
|
QVariantMap ServiceJob::parameters() const
|
||||||
{
|
{
|
||||||
return d->parameters;
|
return d->parameters;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
* @param parent the parent object for this service
|
* @param parent the parent object for this service
|
||||||
*/
|
*/
|
||||||
ServiceJob(const QString &destination, const QString &operation,
|
ServiceJob(const QString &destination, const QString &operation,
|
||||||
const QHash<QString, QVariant> ¶meters, QObject *parent = 0);
|
const QVariantMap ¶meters, QObject *parent = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
@ -88,7 +88,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @return the parameters for the operation
|
* @return the parameters for the operation
|
||||||
*/
|
*/
|
||||||
QHash<QString, QVariant> parameters() const;
|
QVariantMap parameters() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result of the operation
|
* Returns the result of the operation
|
||||||
|
Loading…
Reference in New Issue
Block a user