diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-15 13:42:28 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-15 13:42:28 +0100 |
commit | c1a43cf6dabe29bc15186f8062ceeeee4ae77993 (patch) | |
tree | 4eba8082876b6b9c04443bbbbb7b2179fc18bd52 /common/resourcefacade.cpp | |
parent | ef492409892eedb85d7555002eebebe3f046b873 (diff) | |
download | sink-c1a43cf6dabe29bc15186f8062ceeeee4ae77993.tar.gz sink-c1a43cf6dabe29bc15186f8062ceeeee4ae77993.zip |
A simple resource configuration mechanism
We simply write all properties we don't know to a config file.
Resources can pick up configurations as they are started.
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index a00bab5..89d072c 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -38,12 +38,40 @@ KAsync::Job<void> ResourceFacade::create(const Akonadi2::ApplicationDomain::Akon | |||
38 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); | 38 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); |
39 | const QByteArray type = resource.getProperty("type").toByteArray(); | 39 | const QByteArray type = resource.getProperty("type").toByteArray(); |
40 | ResourceConfig::addResource(identifier, type); | 40 | ResourceConfig::addResource(identifier, type); |
41 | auto changedProperties = resource.changedProperties(); | ||
42 | changedProperties.removeOne("identifier"); | ||
43 | changedProperties.removeOne("type"); | ||
44 | if (!changedProperties.isEmpty()) { | ||
45 | //We have some configuration values | ||
46 | QMap<QByteArray, QVariant> configurationValues; | ||
47 | for (const auto &property : changedProperties) { | ||
48 | configurationValues.insert(property, resource.getProperty(property)); | ||
49 | } | ||
50 | ResourceConfig::configureResource(identifier, configurationValues); | ||
51 | } | ||
41 | }); | 52 | }); |
42 | } | 53 | } |
43 | 54 | ||
44 | KAsync::Job<void> ResourceFacade::modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) | 55 | KAsync::Job<void> ResourceFacade::modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) |
45 | { | 56 | { |
46 | return KAsync::null<void>(); | 57 | return KAsync::start<void>([resource, this]() { |
58 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); | ||
59 | if (identifier.isEmpty()) { | ||
60 | Warning() << "We need an \"identifier\" property to identify the resource to configure"; | ||
61 | return; | ||
62 | } | ||
63 | auto changedProperties = resource.changedProperties(); | ||
64 | changedProperties.removeOne("identifier"); | ||
65 | changedProperties.removeOne("type"); | ||
66 | if (!changedProperties.isEmpty()) { | ||
67 | //We have some configuration values | ||
68 | QMap<QByteArray, QVariant> configurationValues; | ||
69 | for (const auto &property : changedProperties) { | ||
70 | configurationValues.insert(property, resource.getProperty(property)); | ||
71 | } | ||
72 | ResourceConfig::configureResource(identifier, configurationValues); | ||
73 | } | ||
74 | }); | ||
47 | } | 75 | } |
48 | 76 | ||
49 | KAsync::Job<void> ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) | 77 | KAsync::Job<void> ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) |