summaryrefslogtreecommitdiffstats
path: root/common/resourceconfig.cpp
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 /common/resourceconfig.cpp
parent228a3380328535f30fcb187cae7db2415ec2d314 (diff)
downloadsink-c0a8d67cde03e33bf21e0f186f85d4c89c7ff572.tar.gz
sink-c0a8d67cde03e33bf21e0f186f85d4c89c7ff572.zip
Extracted resource config
Diffstat (limited to 'common/resourceconfig.cpp')
-rw-r--r--common/resourceconfig.cpp62
1 files changed, 62 insertions, 0 deletions
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}