summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-08 09:57:40 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-08 09:57:40 +0200
commitc0a8d67cde03e33bf21e0f186f85d4c89c7ff572 (patch)
tree26e5ee4213faf334bc57f2fd9243bcbbee2a83de
parent228a3380328535f30fcb187cae7db2415ec2d314 (diff)
downloadsink-c0a8d67cde03e33bf21e0f186f85d4c89c7ff572.tar.gz
sink-c0a8d67cde03e33bf21e0f186f85d4c89c7ff572.zip
Extracted resource config
-rw-r--r--common/CMakeLists.txt1
-rw-r--r--common/resourceconfig.cpp62
-rw-r--r--common/resourceconfig.h32
-rw-r--r--common/resourcefacade.cpp36
-rw-r--r--tests/clientapitest.cpp9
5 files changed, 110 insertions, 30 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 58c7ea0..56ae59b 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -27,6 +27,7 @@ set(command_SRCS
27 messagequeue.cpp 27 messagequeue.cpp
28 index.cpp 28 index.cpp
29 resourcefacade.cpp 29 resourcefacade.cpp
30 resourceconfig.cpp
30 domain/applicationdomaintype.cpp 31 domain/applicationdomaintype.cpp
31 domain/event.cpp 32 domain/event.cpp
32 ${storage_SRCS}) 33 ${storage_SRCS})
diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp
new file mode 100644
index 0000000..1f8fcda
--- /dev/null
+++ b/common/resourceconfig.cpp
@@ -0,0 +1,62 @@
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 "resourceconfig.h"
20
21#include <QSettings>
22#include <QSharedPointer>
23#include <QStandardPaths>
24
25static QSharedPointer<QSettings> getSettings()
26{
27 return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/resources.ini", QSettings::IniFormat);
28}
29
30void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type)
31{
32 auto settings = getSettings();
33 settings->beginGroup("resources");
34 settings->setValue(QString::fromLatin1(identifier), type);
35 settings->endGroup();
36 // settings->beginGroup(identifier);
37 // //Add some settings?
38 // settings->endGroup();
39 settings->sync();
40}
41
42void ResourceConfig::removeResource(const QByteArray &identifier)
43{
44 auto settings = getSettings();
45 settings->beginGroup("resources");
46 settings->remove(QString::fromLatin1(identifier));
47 settings->endGroup();
48 settings->sync();
49}
50
51QList<QPair<QByteArray, QByteArray> > ResourceConfig::getResources()
52{
53 QList<QPair<QByteArray, QByteArray> > resources;
54 auto settings = getSettings();
55 settings->beginGroup("resources");
56 for (const auto &identifier : settings->childKeys()) {
57 const auto type = settings->value(identifier).toByteArray();
58 resources << qMakePair<QByteArray, QByteArray>(identifier.toLatin1(), type);
59 }
60 settings->endGroup();
61 return resources;
62}
diff --git a/common/resourceconfig.h b/common/resourceconfig.h
new file mode 100644
index 0000000..eda870f
--- /dev/null
+++ b/common/resourceconfig.h
@@ -0,0 +1,32 @@
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
20#pragma once
21
22#include <QList>
23#include <QByteArray>
24#include <QPair>
25
26class ResourceConfig
27{
28public:
29 static QList<QPair<QByteArray, QByteArray> > getResources();
30 static void addResource(const QByteArray &identifier, const QByteArray &type);
31 static void removeResource(const QByteArray &identifier);
32};
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
24ResourceFacade::ResourceFacade(const QByteArray &) 23ResourceFacade::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
35static QSharedPointer<QSettings> getSettings()
36{
37 return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/resources.ini", QSettings::IniFormat);
38}
39
40KAsync::Job<void> ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) 34KAsync::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
62KAsync::Job<void> ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) 48KAsync::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
75KAsync::Job<void> ResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) 56KAsync::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();
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index e7db0d0..5eb16da 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -190,6 +190,15 @@ private Q_SLOTS:
190 result.exec(); 190 result.exec();
191 QCOMPARE(result.size(), 1); 191 QCOMPARE(result.size(), 1);
192 } 192 }
193
194 Akonadi2::Store::remove(res, "resourceconfig");
195 {
196 Akonadi2::Query query;
197 query.resources << "resourceconfig";
198 async::SyncListResult<Akonadi2::ApplicationDomain::AkonadiResource::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::AkonadiResource>(query));
199 result.exec();
200 QCOMPARE(result.size(), 0);
201 }
193 } 202 }
194 203
195}; 204};