diff options
-rw-r--r-- | common/resourceconfig.cpp | 9 | ||||
-rw-r--r-- | common/resourceconfig.h | 1 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 8 | ||||
-rw-r--r-- | examples/client/main.cpp | 35 |
4 files changed, 43 insertions, 10 deletions
diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index 3554b76..a0f39a8 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp | |||
@@ -33,6 +33,15 @@ static QSharedPointer<QSettings> getResourceConfig(const QByteArray &identifier) | |||
33 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/" + identifier, QSettings::IniFormat); | 33 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/" + identifier, QSettings::IniFormat); |
34 | } | 34 | } |
35 | 35 | ||
36 | QByteArray ResourceConfig::newIdentifier(const QByteArray &type) | ||
37 | { | ||
38 | auto settings = getSettings(); | ||
39 | const auto counter = settings->value("instanceCounter", 0).toInt() + 1; | ||
40 | const QByteArray identifier = type + ".instance" + QByteArray::number(counter); | ||
41 | settings->setValue("instanceCounter", counter); | ||
42 | settings->sync(); | ||
43 | return identifier; | ||
44 | } | ||
36 | 45 | ||
37 | void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type) | 46 | void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type) |
38 | { | 47 | { |
diff --git a/common/resourceconfig.h b/common/resourceconfig.h index fec9f56..cc9cb94 100644 --- a/common/resourceconfig.h +++ b/common/resourceconfig.h | |||
@@ -28,6 +28,7 @@ class ResourceConfig | |||
28 | { | 28 | { |
29 | public: | 29 | public: |
30 | static QMap<QByteArray, QByteArray> getResources(); | 30 | static QMap<QByteArray, QByteArray> getResources(); |
31 | static QByteArray newIdentifier(const QByteArray &type); | ||
31 | static void addResource(const QByteArray &identifier, const QByteArray &type); | 32 | static void addResource(const QByteArray &identifier, const QByteArray &type); |
32 | static void removeResource(const QByteArray &identifier); | 33 | static void removeResource(const QByteArray &identifier); |
33 | static void clear(); | 34 | static void clear(); |
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 367704a..df52538 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -20,6 +20,9 @@ | |||
20 | 20 | ||
21 | #include "resourceconfig.h" | 21 | #include "resourceconfig.h" |
22 | #include "query.h" | 22 | #include "query.h" |
23 | #include "definitions.h" | ||
24 | #include "storage.h" | ||
25 | #include <QDir> | ||
23 | 26 | ||
24 | ResourceFacade::ResourceFacade(const QByteArray &) | 27 | ResourceFacade::ResourceFacade(const QByteArray &) |
25 | : Akonadi2::StoreFacade<Akonadi2::ApplicationDomain::AkonadiResource>() | 28 | : Akonadi2::StoreFacade<Akonadi2::ApplicationDomain::AkonadiResource>() |
@@ -35,8 +38,9 @@ ResourceFacade::~ResourceFacade() | |||
35 | KAsync::Job<void> ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) | 38 | KAsync::Job<void> ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) |
36 | { | 39 | { |
37 | return KAsync::start<void>([resource, this]() { | 40 | return KAsync::start<void>([resource, this]() { |
38 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); | ||
39 | const QByteArray type = resource.getProperty("type").toByteArray(); | 41 | const QByteArray type = resource.getProperty("type").toByteArray(); |
42 | //It is currently a requirement that the resource starts with the type | ||
43 | const QByteArray identifier = ResourceConfig::newIdentifier(type); | ||
40 | ResourceConfig::addResource(identifier, type); | 44 | ResourceConfig::addResource(identifier, type); |
41 | auto changedProperties = resource.changedProperties(); | 45 | auto changedProperties = resource.changedProperties(); |
42 | changedProperties.removeOne("identifier"); | 46 | changedProperties.removeOne("identifier"); |
@@ -57,7 +61,7 @@ KAsync::Job<void> ResourceFacade::modify(const Akonadi2::ApplicationDomain::Akon | |||
57 | return KAsync::start<void>([resource, this]() { | 61 | return KAsync::start<void>([resource, this]() { |
58 | const QByteArray identifier = resource.identifier(); | 62 | const QByteArray identifier = resource.identifier(); |
59 | if (identifier.isEmpty()) { | 63 | if (identifier.isEmpty()) { |
60 | Warning() << "We need an \"identifier\" property to identify the resource to configure"; | 64 | Warning() << "We need an \"identifier\" property to identify the resource to configure."; |
61 | return; | 65 | return; |
62 | } | 66 | } |
63 | auto changedProperties = resource.changedProperties(); | 67 | auto changedProperties = resource.changedProperties(); |
diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 81bcc11..946557f 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp | |||
@@ -335,8 +335,15 @@ int main(int argc, char *argv[]) | |||
335 | } else if (command == "create") { | 335 | } else if (command == "create") { |
336 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 336 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); |
337 | auto &store = getStore(type); | 337 | auto &store = getStore(type); |
338 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 338 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; |
339 | auto object = store.getObject(resource); | 339 | if (type == "resource") { |
340 | auto resourceType = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
341 | object = store.getObject(""); | ||
342 | object->setProperty("type", resourceType); | ||
343 | } else { | ||
344 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
345 | object = store.getObject(resource); | ||
346 | } | ||
340 | auto map = consumeMap(args); | 347 | auto map = consumeMap(args); |
341 | for (auto i = map.begin(); i != map.end(); ++i) { | 348 | for (auto i = map.begin(); i != map.end(); ++i) { |
342 | object->setProperty(i.key().toLatin1(), i.value()); | 349 | object->setProperty(i.key().toLatin1(), i.value()); |
@@ -349,9 +356,15 @@ int main(int argc, char *argv[]) | |||
349 | } else if (command == "modify") { | 356 | } else if (command == "modify") { |
350 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 357 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); |
351 | auto &store = getStore(type); | 358 | auto &store = getStore(type); |
352 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 359 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; |
353 | auto identifier = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 360 | if (type == "resource") { |
354 | auto object = store.getObject(resource, identifier); | 361 | auto identifier = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); |
362 | object = store.getObject("", identifier); | ||
363 | } else { | ||
364 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
365 | auto identifier = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
366 | object = store.getObject(resource, identifier); | ||
367 | } | ||
355 | auto map = consumeMap(args); | 368 | auto map = consumeMap(args); |
356 | for (auto i = map.begin(); i != map.end(); ++i) { | 369 | for (auto i = map.begin(); i != map.end(); ++i) { |
357 | object->setProperty(i.key().toLatin1(), i.value()); | 370 | object->setProperty(i.key().toLatin1(), i.value()); |
@@ -364,9 +377,15 @@ int main(int argc, char *argv[]) | |||
364 | } else if (command == "remove") { | 377 | } else if (command == "remove") { |
365 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 378 | auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); |
366 | auto &store = getStore(type); | 379 | auto &store = getStore(type); |
367 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 380 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; |
368 | auto identifier = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | 381 | if (type == "resource") { |
369 | auto object = store.getObject(resource, identifier); | 382 | auto identifier = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); |
383 | object = store.getObject("", identifier); | ||
384 | } else { | ||
385 | auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
386 | auto identifier = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); | ||
387 | object = store.getObject(resource, identifier); | ||
388 | } | ||
370 | auto result = store.remove(*object).exec(); | 389 | auto result = store.remove(*object).exec(); |
371 | result.waitForFinished(); | 390 | result.waitForFinished(); |
372 | if (result.errorCode()) { | 391 | if (result.errorCode()) { |