summaryrefslogtreecommitdiffstats
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
parent0aba0c3fc68712383774263d0906f8e996e1e9c0 (diff)
downloadkube-fed67ae13d4b9c109449f6077cea328913a8548e.tar.gz
kube-fed67ae13d4b9c109449f6077cea328913a8548e.zip
An overly basic settings framework.
and a settings view to mess around.
-rw-r--r--applications/kube-mail/package/contents/ui/Settings.qml123
-rw-r--r--applications/kube-mail/package/contents/ui/main.qml15
-rw-r--r--framework/CMakeLists.txt1
-rw-r--r--framework/mail/CMakeLists.txt2
-rw-r--r--framework/mail/composer.cpp15
-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
10 files changed, 404 insertions, 19 deletions
diff --git a/applications/kube-mail/package/contents/ui/Settings.qml b/applications/kube-mail/package/contents/ui/Settings.qml
new file mode 100644
index 00000000..71fcf359
--- /dev/null
+++ b/applications/kube-mail/package/contents/ui/Settings.qml
@@ -0,0 +1,123 @@
1/*
2 * Copyright (C) 2016 Michael Bohlender <michael.bohlender@kdemail.net>
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 3 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, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.4
19import QtQuick.Controls 1.4
20import QtQuick.Layouts 1.1
21
22import org.kde.kube.settings 1.0 as KubeSettings
23
24Rectangle {
25 id: root
26
27 visible: false
28
29 color: colorPalette.border
30
31 opacity: 0.9
32
33 MouseArea {
34 anchors.fill: parent
35
36 onClicked: {
37 root.visible = false
38 }
39 }
40
41 Rectangle {
42 anchors.centerIn: parent
43
44 height: root.height * 0.8
45 width: root.width * 0.8
46
47 color: colorPalette.background
48
49 MouseArea {
50 anchors.fill: parent
51 }
52
53 GridLayout {
54 columns: 2
55 anchors.fill: parent
56 anchors.margins: 10
57 rowSpacing: 10
58 columnSpacing: 10
59
60 Label { text: "Username" }
61 TextField {
62 id: username
63 text: "username"
64 Layout.fillWidth: true
65 }
66
67 Label { text: "Password" }
68 TextField {
69 id: password
70 text: "password"
71 Layout.fillWidth: true
72 }
73
74 Label { text: "Server" }
75 TextField {
76 id: server
77 text: "server"
78 Layout.fillWidth: true
79 }
80
81 KubeSettings.Settings {
82 id: contextSettings
83 identifier: "applicationcontext"
84 property string currentAccountId: "current"
85 }
86 KubeSettings.Settings {
87 id: accountSettings
88 identifier: "account.current"
89 property string primaryIdentity: "current"
90 }
91 KubeSettings.Settings {
92 id: identitySettings
93 identifier: "identity.current"
94 property string transport: "current"
95 }
96 KubeSettings.Settings {
97 id: transportSettings
98 identifier: "transport.current"
99 property alias username: username.text
100 property alias password: password.text
101 property alias server: server.text
102 }
103
104 Item {
105 Layout.columnSpan: 2
106 Layout.fillWidth: true
107 Button {
108 id: button
109 anchors.centerIn: parent
110 text: "Save"
111 onClicked: {
112 contextSettings.save();
113 accountSettings.save();
114 identitySettings.save();
115 transportSettings.save();
116 root.visible = false;
117 }
118 }
119 }
120
121 }
122 }
123}
diff --git a/applications/kube-mail/package/contents/ui/main.qml b/applications/kube-mail/package/contents/ui/main.qml
index 7682a334..191a7434 100644
--- a/applications/kube-mail/package/contents/ui/main.qml
+++ b/applications/kube-mail/package/contents/ui/main.qml
@@ -21,6 +21,7 @@ import QtQuick.Layouts 1.1
21import org.kde.plasma.components 2.0 as PlasmaComponents 21import org.kde.plasma.components 2.0 as PlasmaComponents
22 22
23import org.kde.kube.actions 1.0 as KubeAction 23import org.kde.kube.actions 1.0 as KubeAction
24import org.kde.kube.settings 1.0 as KubeSettings
24 25
25ApplicationWindow { 26ApplicationWindow {
26 id: app 27 id: app
@@ -69,6 +70,14 @@ ApplicationWindow {
69 70
70 PlasmaComponents.ToolButton { 71 PlasmaComponents.ToolButton {
71 height: parent.height 72 height: parent.height
73 text: "Settings"
74 onClicked: {
75 settings.visible = true
76 }
77 }
78
79 PlasmaComponents.ToolButton {
80 height: parent.height
72 iconName: "mail-message-new" 81 iconName: "mail-message-new"
73 text: "Compose" 82 text: "Compose"
74 onClicked: { 83 onClicked: {
@@ -165,6 +174,12 @@ ApplicationWindow {
165 174
166 } 175 }
167 176
177 Settings {
178 id: settings
179
180 anchors.fill: parent
181 }
182
168 FocusComposer { 183 FocusComposer {
169 id: composer 184 id: composer
170 185
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index d8d45af9..1955d709 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -36,5 +36,6 @@ set(SINK_RESOURCE_PLUGINS_PATH ${QT_PLUGIN_INSTALL_DIR}/sink/resources)
36 36
37add_subdirectory(mail) 37add_subdirectory(mail)
38add_subdirectory(actions) 38add_subdirectory(actions)
39add_subdirectory(settings)
39 40
40feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) 41feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt
index 7215427b..54a031cc 100644
--- a/framework/mail/CMakeLists.txt
+++ b/framework/mail/CMakeLists.txt
@@ -24,7 +24,7 @@ add_library(mailplugin SHARED ${mailplugin_SRCS})
24 24
25qt5_use_modules(mailplugin Core Quick Qml) 25qt5_use_modules(mailplugin Core Quick Qml)
26 26
27target_link_libraries(mailplugin actionplugin sink KF5::Otp KF5::Codecs ${CURL_LIBRARIES}) 27target_link_libraries(mailplugin actionplugin settingsplugin sink KF5::Otp KF5::Codecs ${CURL_LIBRARIES})
28 28
29install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) 29install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail)
30install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) 30install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail)
diff --git a/framework/mail/composer.cpp b/framework/mail/composer.cpp
index 1ec56347..4ef112fa 100644
--- a/framework/mail/composer.cpp
+++ b/framework/mail/composer.cpp
@@ -21,6 +21,7 @@
21#include "composer.h" 21#include "composer.h"
22#include <actions/context.h> 22#include <actions/context.h>
23#include <actions/action.h> 23#include <actions/action.h>
24#include <settings/settings.h>
24#include <KMime/Message> 25#include <KMime/Message>
25#include <KCodecs/KEmailAddress> 26#include <KCodecs/KEmailAddress>
26#include <QVariant> 27#include <QVariant>
@@ -127,12 +128,18 @@ void Composer::send()
127 mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); 128 mail->subject(true)->fromUnicodeString(m_subject, "utf-8");
128 mail->setBody(m_body.toUtf8()); 129 mail->setBody(m_body.toUtf8());
129 mail->assemble(); 130 mail->assemble();
131
132 Kube::ApplicationContext settings;
133 auto account = settings.currentAccount();
134 auto identity = account.primaryIdentity();
135 auto transport = identity.transport();
136
130 Kube::Context context; 137 Kube::Context context;
131 context.setProperty("message", QVariant::fromValue(mail)); 138 context.setProperty("message", QVariant::fromValue(mail));
132 //TODO get from somewhere 139
133 context.setProperty("username", QVariant::fromValue(QByteArray("test@test.com"))); 140 context.setProperty("username", transport.username());
134 context.setProperty("password", QVariant::fromValue(QByteArray("pass"))); 141 context.setProperty("password", transport.password());
135 context.setProperty("server", QVariant::fromValue(QByteArray("smtp://smtp.gmail.com:587"))); 142 context.setProperty("server", transport.server());
136 143
137 Kube::Action("org.kde.kube.actions.sendmail", context).execute(); 144 Kube::Action("org.kde.kube.actions.sendmail", context).execute();
138 clear(); 145 clear();
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}