diff options
-rw-r--r-- | common/resourceconfig.cpp | 29 | ||||
-rw-r--r-- | common/resourceconfig.h | 3 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 30 |
3 files changed, 61 insertions, 1 deletions
diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index ec72fb9..99e111e 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp | |||
@@ -21,12 +21,19 @@ | |||
21 | #include <QSettings> | 21 | #include <QSettings> |
22 | #include <QSharedPointer> | 22 | #include <QSharedPointer> |
23 | #include <QStandardPaths> | 23 | #include <QStandardPaths> |
24 | #include <QFile> | ||
24 | 25 | ||
25 | static QSharedPointer<QSettings> getSettings() | 26 | static QSharedPointer<QSettings> getSettings() |
26 | { | 27 | { |
27 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/resources.ini", QSettings::IniFormat); | 28 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/resources.ini", QSettings::IniFormat); |
28 | } | 29 | } |
29 | 30 | ||
31 | static QSharedPointer<QSettings> getResourceConfig(const QByteArray &identifier) | ||
32 | { | ||
33 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/" + identifier, QSettings::IniFormat); | ||
34 | } | ||
35 | |||
36 | |||
30 | void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type) | 37 | void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type) |
31 | { | 38 | { |
32 | auto settings = getSettings(); | 39 | auto settings = getSettings(); |
@@ -44,6 +51,7 @@ void ResourceConfig::removeResource(const QByteArray &identifier) | |||
44 | settings->remove(""); | 51 | settings->remove(""); |
45 | settings->endGroup(); | 52 | settings->endGroup(); |
46 | settings->sync(); | 53 | settings->sync(); |
54 | QFile::remove(getResourceConfig(identifier)->fileName()); | ||
47 | } | 55 | } |
48 | 56 | ||
49 | QMap<QByteArray, QByteArray> ResourceConfig::getResources() | 57 | QMap<QByteArray, QByteArray> ResourceConfig::getResources() |
@@ -65,3 +73,24 @@ void ResourceConfig::clear() | |||
65 | settings->clear(); | 73 | settings->clear(); |
66 | settings->sync(); | 74 | settings->sync(); |
67 | } | 75 | } |
76 | |||
77 | void ResourceConfig::configureResource(const QByteArray &identifier, const QMap<QByteArray, QVariant> &configuration) | ||
78 | { | ||
79 | auto config = getResourceConfig(identifier); | ||
80 | config->clear(); | ||
81 | for (const auto &key : configuration.keys()) { | ||
82 | config->setValue(key, configuration.value(key)); | ||
83 | } | ||
84 | config->sync(); | ||
85 | } | ||
86 | |||
87 | QMap<QByteArray, QVariant> ResourceConfig::getConfiguration(const QByteArray &identifier) | ||
88 | { | ||
89 | QMap<QByteArray, QVariant> configuration; | ||
90 | auto config = getResourceConfig(identifier); | ||
91 | for (const auto &key : config->allKeys()) { | ||
92 | configuration.insert(key.toLatin1(), config->value(key)); | ||
93 | } | ||
94 | return configuration; | ||
95 | } | ||
96 | |||
diff --git a/common/resourceconfig.h b/common/resourceconfig.h index e1ba2bc..fec9f56 100644 --- a/common/resourceconfig.h +++ b/common/resourceconfig.h | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include <QList> | 22 | #include <QList> |
23 | #include <QByteArray> | 23 | #include <QByteArray> |
24 | #include <QVariant> | ||
24 | #include <QMap> | 25 | #include <QMap> |
25 | 26 | ||
26 | class ResourceConfig | 27 | class ResourceConfig |
@@ -30,4 +31,6 @@ public: | |||
30 | static void addResource(const QByteArray &identifier, const QByteArray &type); | 31 | static void addResource(const QByteArray &identifier, const QByteArray &type); |
31 | static void removeResource(const QByteArray &identifier); | 32 | static void removeResource(const QByteArray &identifier); |
32 | static void clear(); | 33 | static void clear(); |
34 | static void configureResource(const QByteArray &identifier, const QMap<QByteArray, QVariant> &configuration); | ||
35 | static QMap<QByteArray, QVariant> getConfiguration(const QByteArray &identifier); | ||
33 | }; | 36 | }; |
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) |