diff options
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 2c6eabc..63b3126 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -18,8 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | #include "resourcefacade.h" | 19 | #include "resourcefacade.h" |
20 | 20 | ||
21 | #include <QSettings> | 21 | #include "resourceconfig.h" |
22 | #include <QStandardPaths> | ||
23 | 22 | ||
24 | ResourceFacade::ResourceFacade(const QByteArray &) | 23 | ResourceFacade::ResourceFacade(const QByteArray &) |
25 | : Akonadi2::StoreFacade<Akonadi2::ApplicationDomain::AkonadiResource>() | 24 | : Akonadi2::StoreFacade<Akonadi2::ApplicationDomain::AkonadiResource>() |
@@ -32,25 +31,12 @@ ResourceFacade::~ResourceFacade() | |||
32 | 31 | ||
33 | } | 32 | } |
34 | 33 | ||
35 | static QSharedPointer<QSettings> getSettings() | ||
36 | { | ||
37 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/resources.ini", QSettings::IniFormat); | ||
38 | } | ||
39 | |||
40 | KAsync::Job<void> ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) | 34 | KAsync::Job<void> ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) |
41 | { | 35 | { |
42 | return KAsync::start<void>([resource, this]() { | 36 | return KAsync::start<void>([resource, this]() { |
43 | auto settings = getSettings(); | ||
44 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); | 37 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); |
45 | const QByteArray type = resource.getProperty("type").toByteArray(); | 38 | const QByteArray type = resource.getProperty("type").toByteArray(); |
46 | 39 | ResourceConfig::addResource(identifier, type); | |
47 | settings->beginGroup("resources"); | ||
48 | settings->setValue(identifier, type); | ||
49 | settings->endGroup(); | ||
50 | settings->beginGroup(identifier); | ||
51 | //Add some settings? | ||
52 | settings->endGroup(); | ||
53 | settings->sync(); | ||
54 | }); | 40 | }); |
55 | } | 41 | } |
56 | 42 | ||
@@ -62,30 +48,20 @@ KAsync::Job<void> ResourceFacade::modify(const Akonadi2::ApplicationDomain::Akon | |||
62 | KAsync::Job<void> ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) | 48 | KAsync::Job<void> ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) |
63 | { | 49 | { |
64 | return KAsync::start<void>([resource, this]() { | 50 | return KAsync::start<void>([resource, this]() { |
65 | auto settings = getSettings(); | ||
66 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); | 51 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); |
67 | 52 | ResourceConfig::removeResource(identifier); | |
68 | settings->beginGroup("resources"); | ||
69 | settings->remove(identifier); | ||
70 | settings->endGroup(); | ||
71 | settings->sync(); | ||
72 | }); | 53 | }); |
73 | } | 54 | } |
74 | 55 | ||
75 | KAsync::Job<void> ResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) | 56 | KAsync::Job<void> ResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) |
76 | { | 57 | { |
77 | return KAsync::start<void>([query, resultProvider]() { | 58 | return KAsync::start<void>([query, resultProvider]() { |
78 | auto settings = getSettings(); | 59 | for (const auto &res : ResourceConfig::getResources()) { |
79 | settings->beginGroup("resources"); | ||
80 | for (const auto &identifier : settings->childKeys()) { | ||
81 | const auto type = settings->value(identifier).toByteArray(); | ||
82 | auto resource = Akonadi2::ApplicationDomain::AkonadiResource::Ptr::create(); | 60 | auto resource = Akonadi2::ApplicationDomain::AkonadiResource::Ptr::create(); |
83 | resource->setProperty("identifier", identifier); | 61 | resource->setProperty("identifier", res.first); |
84 | resource->setProperty("type", type); | 62 | resource->setProperty("type", res.second); |
85 | resultProvider->add(resource); | 63 | resultProvider->add(resource); |
86 | } | 64 | } |
87 | settings->endGroup(); | ||
88 | |||
89 | //TODO initialResultSetComplete should be implicit | 65 | //TODO initialResultSetComplete should be implicit |
90 | resultProvider->initialResultSetComplete(); | 66 | resultProvider->initialResultSetComplete(); |
91 | resultProvider->complete(); | 67 | resultProvider->complete(); |