diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/resourceconfig.cpp | 9 | ||||
-rw-r--r-- | common/resourceconfig.h | 1 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 8 |
3 files changed, 16 insertions, 2 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(); |