summaryrefslogtreecommitdiffstats
path: root/framework/settings
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-25 16:40:54 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-25 16:40:54 +0100
commitfed67ae13d4b9c109449f6077cea328913a8548e (patch)
tree057d19f9412b2120df749259d393b18c1d5cfb24 /framework/settings
parent0aba0c3fc68712383774263d0906f8e996e1e9c0 (diff)
downloadkube-fed67ae13d4b9c109449f6077cea328913a8548e.tar.gz
kube-fed67ae13d4b9c109449f6077cea328913a8548e.zip
An overly basic settings framework.
and a settings view to mess around.
Diffstat (limited to 'framework/settings')
-rw-r--r--framework/settings/CMakeLists.txt13
-rw-r--r--framework/settings/qmldir2
-rw-r--r--framework/settings/settings.cpp147
-rw-r--r--framework/settings/settings.h89
-rw-r--r--framework/settings/settingsplugin.cpp16
5 files changed, 253 insertions, 14 deletions
diff --git a/framework/settings/CMakeLists.txt b/framework/settings/CMakeLists.txt
index 77268ab9..15ab7584 100644
--- a/framework/settings/CMakeLists.txt
+++ b/framework/settings/CMakeLists.txt
@@ -1,15 +1,16 @@
1set(settingsplugin_SRCS 1set(settingsplugin_SRCS
2 settingsplugin.cpp 2 settingsplugin.cpp
3 maildir_resource.cpp 3 # maildir_resource.cpp
4 resourcelistmodel.cpp 4 # resourcelistmodel.cpp
5 resourcescontroller.cpp 5 # resourcescontroller.cpp
6 settings.cpp
6) 7)
7 8
8add_library(settingsplugin SHARED ${settingsplugin_SRCS}) 9add_library(settingsplugin SHARED ${settingsplugin_SRCS})
9 10
10qt5_use_modules(settingsplugin Core Quick Qml) 11qt5_use_modules(settingsplugin Core Quick Qml)
11 12
12target_link_libraries(settingsplugin sink) 13target_link_libraries(settingsplugin)
13 14
14install(TARGETS settingsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/sink/settings) 15install(TARGETS settingsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/settings)
15install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/sink/settings) 16install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/settings)
diff --git a/framework/settings/qmldir b/framework/settings/qmldir
index 1740f29a..7b756aea 100644
--- a/framework/settings/qmldir
+++ b/framework/settings/qmldir
@@ -1,3 +1,3 @@
1module org.kde.sink.settings 1module org.kde.kube.settings
2 2
3plugin settingsplugin 3plugin settingsplugin
diff --git a/framework/settings/settings.cpp b/framework/settings/settings.cpp
new file mode 100644
index 00000000..a4e28190
--- /dev/null
+++ b/framework/settings/settings.cpp
@@ -0,0 +1,147 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "settings.h"
20
21#include <QDebug>
22#include <QStandardPaths>
23#include <QMetaObject>
24#include <QMetaProperty>
25
26using namespace Kube;
27
28Settings::Settings(QObject *parent)
29 : QObject(parent)
30{
31
32}
33
34Settings::Settings(const QByteArray &id, QObject *parent)
35 : QObject(parent),
36 mIdentifier(id)
37{
38 load();
39}
40
41Settings::Settings(const Settings &other)
42 : QObject(other.parent()),
43 mIdentifier(other.mIdentifier)
44{
45 load();
46}
47
48Settings::~Settings()
49{
50 // save();
51}
52
53QSharedPointer<QSettings> Settings::getSettings()
54{
55 return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QString("/kube/%1.ini").arg(QString::fromLatin1(mIdentifier)), QSettings::IniFormat);
56}
57
58void Settings::save()
59{
60 qWarning() << "Saving" << mIdentifier;
61 auto settings = getSettings();
62 for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) {
63 const auto p = metaObject()->property(i).name();
64 qWarning() << "setting " << p << property(p);
65 settings->setValue(p, property(p));
66 }
67 settings->sync();
68}
69
70void Settings::load()
71{
72 qWarning() << "loading" << mIdentifier;
73 for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) {
74 auto p = metaObject()->property(i).name();
75 setProperty(p, QVariant());
76 }
77 auto settings = getSettings();
78 for (const auto &p : settings->allKeys()) {
79 qWarning() << "loading " << p << settings->value(p);
80 setProperty(p.toLatin1(), settings->value(p));
81 }
82}
83
84void Settings::setIdentifier(const QByteArray &id)
85{
86 mIdentifier = id;
87 load();
88}
89
90QByteArray Settings::identifier() const
91{
92 return mIdentifier;
93}
94
95ApplicationContext::ApplicationContext()
96 : Settings("applicationcontext")
97{
98
99}
100
101Account ApplicationContext::currentAccount() const
102{
103 return Account(property("currentAccountId").toByteArray());
104}
105
106Account::Account(const QByteArray &identifier)
107 : Settings("account." + identifier)
108{
109
110}
111
112Identity Account::primaryIdentity() const
113{
114 return Identity(property("primaryIdentityId").toByteArray());
115}
116
117Identity::Identity(const QByteArray &identifier)
118 : Settings("identity." + identifier)
119{
120
121}
122
123Transport Identity::transport() const
124{
125 return Transport(property("transportId").toByteArray());
126}
127
128Transport::Transport(const QByteArray &identifier)
129 : Settings("transport." + identifier)
130{
131
132}
133
134QByteArray Transport::username() const
135{
136 return property("username").toByteArray();
137}
138
139QByteArray Transport::password() const
140{
141 return property("password").toByteArray();
142}
143
144QByteArray Transport::server() const
145{
146 return property("server").toByteArray();
147}
diff --git a/framework/settings/settings.h b/framework/settings/settings.h
new file mode 100644
index 00000000..bfee55cb
--- /dev/null
+++ b/framework/settings/settings.h
@@ -0,0 +1,89 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#pragma once
20
21#include <QObject>
22#include <QByteArray>
23#include <QSettings>
24#include <QSharedPointer>
25
26namespace Kube {
27
28class Settings : public QObject {
29 Q_OBJECT
30 Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier)
31public:
32 Settings(QObject *parent = 0);
33 Settings(const QByteArray &id, QObject *parent = 0);
34 virtual ~Settings();
35 Settings(const Settings&);
36
37 void setIdentifier(const QByteArray &id);
38 QByteArray identifier() const;
39
40 Q_INVOKABLE void save();
41private:
42 void load();
43 QSharedPointer<QSettings> getSettings();
44 QByteArray mIdentifier;
45};
46
47class Account;
48class Identity;
49class Transport;
50
51class ApplicationContext : public Settings
52{
53 Q_OBJECT
54public:
55 ApplicationContext();
56 Account currentAccount() const;
57
58};
59
60class Account : public Settings
61{
62 Q_OBJECT
63public:
64 Account(const QByteArray &identifier);
65 Identity primaryIdentity() const;
66};
67
68class Identity : public Settings
69{
70 Q_OBJECT
71public:
72 Identity(const QByteArray &identifier);
73 Transport transport() const;
74};
75
76class Transport : public Settings
77{
78 Q_OBJECT
79public:
80 Transport(const QByteArray &identifier);
81 QByteArray username() const;
82 QByteArray password() const;
83 QByteArray server() const;
84};
85
86}
87
88Q_DECLARE_METATYPE(Kube::Settings*);
89
diff --git a/framework/settings/settingsplugin.cpp b/framework/settings/settingsplugin.cpp
index ca670583..a1888669 100644
--- a/framework/settings/settingsplugin.cpp
+++ b/framework/settings/settingsplugin.cpp
@@ -1,16 +1,18 @@
1#include "settingsplugin.h" 1#include "settingsplugin.h"
2 2
3#include "resourcescontroller.h" 3// #include "resourcescontroller.h"
4#include "resourcelistmodel.h" 4// #include "resourcelistmodel.h"
5#include "maildir_resource.h" 5// #include "maildir_resource.h"
6#include "settings.h"
6 7
7#include <QtQml> 8#include <QtQml>
8 9
9void SettingsPlugin::registerTypes (const char *uri) 10void SettingsPlugin::registerTypes (const char *uri)
10{ 11{
11 Q_ASSERT(uri == QLatin1String("org.kde.sink.settings")); 12 Q_ASSERT(uri == QLatin1String("org.kde.kube.settings"));
12 13
13 qmlRegisterType<ResourceListModel>(); 14 // qmlRegisterType<ResourceListModel>();
14 qmlRegisterType<ResourcesController>(uri, 1, 0, "Resources"); 15 // qmlRegisterType<ResourcesController>(uri, 1, 0, "Resources");
15 qmlRegisterType<MaildirResouceController>(uri, 1, 0, "Maildir"); 16 // qmlRegisterType<MaildirResouceController>(uri, 1, 0, "Maildir");
17 qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings");
16} 18}