diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-08 09:19:43 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-08 09:19:43 +0200 |
commit | 228a3380328535f30fcb187cae7db2415ec2d314 (patch) | |
tree | c5aff9f889ac41aa5f79bd5d144f2c94a8298edc /common/resourcefacade.cpp | |
parent | 12a87e1d6d5c0e4b5a5aacbfa880678629321c1d (diff) | |
download | sink-228a3380328535f30fcb187cae7db2415ec2d314.tar.gz sink-228a3380328535f30fcb187cae7db2415ec2d314.zip |
We can add resources.
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp new file mode 100644 index 0000000..2c6eabc --- /dev/null +++ b/common/resourcefacade.cpp | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | #include "resourcefacade.h" | ||
20 | |||
21 | #include <QSettings> | ||
22 | #include <QStandardPaths> | ||
23 | |||
24 | ResourceFacade::ResourceFacade(const QByteArray &) | ||
25 | : Akonadi2::StoreFacade<Akonadi2::ApplicationDomain::AkonadiResource>() | ||
26 | { | ||
27 | |||
28 | } | ||
29 | |||
30 | ResourceFacade::~ResourceFacade() | ||
31 | { | ||
32 | |||
33 | } | ||
34 | |||
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) | ||
41 | { | ||
42 | return KAsync::start<void>([resource, this]() { | ||
43 | auto settings = getSettings(); | ||
44 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); | ||
45 | const QByteArray type = resource.getProperty("type").toByteArray(); | ||
46 | |||
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 | }); | ||
55 | } | ||
56 | |||
57 | KAsync::Job<void> ResourceFacade::modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) | ||
58 | { | ||
59 | return KAsync::null<void>(); | ||
60 | } | ||
61 | |||
62 | KAsync::Job<void> ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) | ||
63 | { | ||
64 | return KAsync::start<void>([resource, this]() { | ||
65 | auto settings = getSettings(); | ||
66 | const QByteArray identifier = resource.getProperty("identifier").toByteArray(); | ||
67 | |||
68 | settings->beginGroup("resources"); | ||
69 | settings->remove(identifier); | ||
70 | settings->endGroup(); | ||
71 | settings->sync(); | ||
72 | }); | ||
73 | } | ||
74 | |||
75 | KAsync::Job<void> ResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) | ||
76 | { | ||
77 | return KAsync::start<void>([query, resultProvider]() { | ||
78 | auto settings = getSettings(); | ||
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(); | ||
83 | resource->setProperty("identifier", identifier); | ||
84 | resource->setProperty("type", type); | ||
85 | resultProvider->add(resource); | ||
86 | } | ||
87 | settings->endGroup(); | ||
88 | |||
89 | //TODO initialResultSetComplete should be implicit | ||
90 | resultProvider->initialResultSetComplete(); | ||
91 | resultProvider->complete(); | ||
92 | }); | ||
93 | } | ||
94 | |||