summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--accounts/maildir/CMakeLists.txt4
-rw-r--r--accounts/maildir/maildirsettings.cpp65
-rw-r--r--accounts/maildir/maildirsettings.h14
-rw-r--r--accounts/maildir/package/contents/ui/MaildirAccountSettings.qml37
-rw-r--r--components/package/contents/ui/Settings.qml84
-rw-r--r--framework/settings/settings.cpp7
-rw-r--r--framework/settings/settings.h1
7 files changed, 147 insertions, 65 deletions
diff --git a/accounts/maildir/CMakeLists.txt b/accounts/maildir/CMakeLists.txt
index cd25f09d..eafd430f 100644
--- a/accounts/maildir/CMakeLists.txt
+++ b/accounts/maildir/CMakeLists.txt
@@ -25,6 +25,8 @@ find_package(KF5Async CONFIG REQUIRED)
25find_package(KF5 REQUIRED COMPONENTS Package) 25find_package(KF5 REQUIRED COMPONENTS Package)
26 26
27include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/) 27include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/)
28#FIXME
29include_directories(../../framework/)
28 30
29set(SRCS 31set(SRCS
30 maildirsettings.cpp 32 maildirsettings.cpp
@@ -33,7 +35,7 @@ set(SRCS
33 35
34add_library(maildiraccountplugin SHARED ${SRCS}) 36add_library(maildiraccountplugin SHARED ${SRCS})
35qt5_use_modules(maildiraccountplugin Core Quick Qml) 37qt5_use_modules(maildiraccountplugin Core Quick Qml)
36target_link_libraries(maildiraccountplugin sink) 38target_link_libraries(maildiraccountplugin sink settingsplugin)
37 39
38kpackage_install_package(package org.kube.accounts.maildir "genericqml") 40kpackage_install_package(package org.kube.accounts.maildir "genericqml")
39 41
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp
index 4a3b1a00..a2e2e96e 100644
--- a/accounts/maildir/maildirsettings.cpp
+++ b/accounts/maildir/maildirsettings.cpp
@@ -18,8 +18,11 @@
18*/ 18*/
19#include "maildirsettings.h" 19#include "maildirsettings.h"
20 20
21#include <settings/settings.h>
22
21#include <sink/store.h> 23#include <sink/store.h>
22#include <QDebug> 24#include <QDebug>
25#include <QUuid>
23 26
24MaildirSettings::MaildirSettings(QObject *parent) 27MaildirSettings::MaildirSettings(QObject *parent)
25 : QObject(parent) 28 : QObject(parent)
@@ -31,7 +34,11 @@ void MaildirSettings::setIdentifier(const QByteArray &id)
31 mIdentifier = id; 34 mIdentifier = id;
32 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList<QByteArray>() << "path")) 35 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList<QByteArray>() << "path"))
33 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 36 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) {
34 setProperty("path", resource.getProperty("path")); 37 auto path = resource.getProperty("path").toString();
38 if (mPath != path) {
39 mPath = path;
40 emit pathChanged();
41 }
35 }).exec(); 42 }).exec();
36} 43}
37 44
@@ -40,16 +47,70 @@ QByteArray MaildirSettings::identifier() const
40 return mIdentifier; 47 return mIdentifier;
41} 48}
42 49
50void MaildirSettings::setAccountIdentifier(const QByteArray &id)
51{
52 mAccountIdentifier = id;
53 Kube::Account account(id);
54 account.property("maildirResource").toByteArray();
55 setIdentifier(account.property("maildirResource").toByteArray());
56}
57
58QByteArray MaildirSettings::accountIdentifier() const
59{
60 return mAccountIdentifier;
61}
62
63void MaildirSettings::setPath(const QString &path)
64{
65 if (mPath != path) {
66 mPath = path;
67 emit pathChanged();
68 }
69}
70
71QString MaildirSettings::path() const
72{
73 return mPath;
74}
75
43void MaildirSettings::save() 76void MaildirSettings::save()
44{ 77{
45 if (!mIdentifier.isEmpty()) { 78 if (!mIdentifier.isEmpty()) {
46 Sink::ApplicationDomain::SinkResource resource(mIdentifier); 79 Sink::ApplicationDomain::SinkResource resource(mIdentifier);
47 resource.setProperty("path", property("path")); 80 resource.setProperty("path", mPath);
48 Sink::Store::modify(resource).exec(); 81 Sink::Store::modify(resource).exec();
49 } else { 82 } else {
83 const auto resourceIdentifier = "org.kde.maildir." + QUuid::createUuid().toByteArray();
84 mIdentifier = resourceIdentifier;
85
50 Sink::ApplicationDomain::SinkResource resource; 86 Sink::ApplicationDomain::SinkResource resource;
51 resource.setProperty("path", property("path")); 87 resource.setProperty("path", property("path"));
88 resource.setProperty("identifier", resourceIdentifier);
89 resource.setProperty("type", "org.kde.maildir");
52 Sink::Store::create(resource).exec(); 90 Sink::Store::create(resource).exec();
91 Kube::Account account(mAccountIdentifier);
92 account.setProperty("maildirResource", resourceIdentifier);
93 account.save();
94 //TODO deal with errors while creating
95 }
96}
97
98void MaildirSettings::remove()
99{
100 if (!mIdentifier.isEmpty()) {
101 qWarning() << "We're missing an identifier";
102 } else {
103 Sink::ApplicationDomain::SinkResource resource(mIdentifier);
104 Sink::Store::remove(resource).exec();
105 Kube::Account account(mAccountIdentifier);
106 account.remove();
107
108 Kube::Settings settings("accounts");
109 auto accounts = settings.property("accounts").toStringList();
110 accounts.removeAll(mAccountIdentifier);
111 settings.setProperty("accounts", accounts);
112 settings.save();
113 //TODO deal with errors while removing
53 } 114 }
54} 115}
55 116
diff --git a/accounts/maildir/maildirsettings.h b/accounts/maildir/maildirsettings.h
index c0ad95c3..9a65cf39 100644
--- a/accounts/maildir/maildirsettings.h
+++ b/accounts/maildir/maildirsettings.h
@@ -24,6 +24,8 @@ class MaildirSettings : public QObject
24{ 24{
25 Q_OBJECT 25 Q_OBJECT
26 Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) 26 Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier)
27 Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier)
28 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
27 29
28public: 30public:
29 MaildirSettings(QObject *parent = 0); 31 MaildirSettings(QObject *parent = 0);
@@ -31,8 +33,20 @@ public:
31 void setIdentifier(const QByteArray &); 33 void setIdentifier(const QByteArray &);
32 QByteArray identifier() const; 34 QByteArray identifier() const;
33 35
36 void setAccountIdentifier(const QByteArray &);
37 QByteArray accountIdentifier() const;
38
39 void setPath(const QString &);
40 QString path() const;
41
34 Q_INVOKABLE void save(); 42 Q_INVOKABLE void save();
43 Q_INVOKABLE void remove();
44
45signals:
46 void pathChanged();
35 47
36private: 48private:
37 QByteArray mIdentifier; 49 QByteArray mIdentifier;
50 QByteArray mAccountIdentifier;
51 QString mPath;
38}; 52};
diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml
index 99814a06..189089fa 100644
--- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml
+++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml
@@ -21,7 +21,7 @@ import QtQuick.Layouts 1.1
21 21
22import org.kube.framework.settings 1.0 as KubeSettings 22import org.kube.framework.settings 1.0 as KubeSettings
23import org.kube.framework.theme 1.0 23import org.kube.framework.theme 1.0
24import org.kde.kube.accounts.maildir 1.0 as MaildirAccount 24import org.kube.accounts.maildir 1.0 as MaildirAccount
25 25
26 26
27Rectangle { 27Rectangle {
@@ -47,6 +47,8 @@ Rectangle {
47 id: path 47 id: path
48 placeholderText: "path" 48 placeholderText: "path"
49 Layout.fillWidth: true 49 Layout.fillWidth: true
50 text: maildirSettings.path
51 onTextChanged: { maildirSettings.path = text; }
50 } 52 }
51 53
52 Text { 54 Text {
@@ -60,6 +62,8 @@ Rectangle {
60 id: username 62 id: username
61 placeholderText: "username" 63 placeholderText: "username"
62 Layout.fillWidth: true 64 Layout.fillWidth: true
65 text: transportSettings.username
66 onTextChanged: { transportSettings.username = text; }
63 } 67 }
64 68
65 Label { text: "Password" } 69 Label { text: "Password" }
@@ -67,6 +71,8 @@ Rectangle {
67 id: password 71 id: password
68 placeholderText: "password" 72 placeholderText: "password"
69 Layout.fillWidth: true 73 Layout.fillWidth: true
74 text: transportSettings.password
75 onTextChanged: { transportSettings.password = text; }
70 } 76 }
71 77
72 Label { text: "Server" } 78 Label { text: "Server" }
@@ -74,39 +80,36 @@ Rectangle {
74 id: server 80 id: server
75 placeholderText: "server" 81 placeholderText: "server"
76 Layout.fillWidth: true 82 Layout.fillWidth: true
83 text: transportSettings.server
84 onTextChanged: { transportSettings.server = text; }
77 } 85 }
78 86
79 MaildirAccount.MaildirSettings { 87 MaildirAccount.MaildirSettings {
80 id: maildirSettings 88 id: maildirSettings
81 identifier: "org.kde.maildir.instance1" 89 accountIdentifier: accountId
82 property alias path: path.text
83 } 90 }
84 91
85 KubeSettings.Settings { 92 KubeSettings.Settings {
86 id: accountSettings
87 identifier: "account." + accountId
88 property string primaryIdentity: "current"
89 }
90 KubeSettings.Settings {
91 id: identitySettings
92 identifier: "identity.current"
93 property string transport: "current"
94 }
95 KubeSettings.Settings {
96 id: transportSettings 93 id: transportSettings
94 //TODO set a proper identifier
97 identifier: "transport.current" 95 identifier: "transport.current"
98 property alias username: username.text 96 property string server;
99 property alias password: password.text 97 property string username;
100 property alias server: server.text 98 property string password;
101 } 99 }
102 100
103 Button { 101 Button {
104 id: button
105 text: "Save" 102 text: "Save"
106 onClicked: { 103 onClicked: {
107 transportSettings.save(); 104 transportSettings.save();
108 maildirSettings.save(); 105 maildirSettings.save();
109 } 106 }
110 } 107 }
108 Button {
109 text: "Remove"
110 onClicked: {
111 maildirSettings.remove();
112 }
113 }
111 } 114 }
112} 115}
diff --git a/components/package/contents/ui/Settings.qml b/components/package/contents/ui/Settings.qml
index f6a03945..acdc42d7 100644
--- a/components/package/contents/ui/Settings.qml
+++ b/components/package/contents/ui/Settings.qml
@@ -68,57 +68,67 @@ Rectangle {
68 SplitView { 68 SplitView {
69 anchors.fill: parent 69 anchors.fill: parent
70 70
71 ScrollView { 71 ColumnLayout {
72 id: accountsList 72 ScrollView {
73 id: accountsList
73 74
74 width: Unit.size * 55 75 width: Unit.size * 55
75 Layout.maximumWidth: Unit.size * 150 76 Layout.maximumWidth: Unit.size * 150
76 Layout.minimumWidth: Unit.size * 30 77 Layout.minimumWidth: Unit.size * 30
77 78
78 ListView { 79 ListView {
79 id: listView 80 id: listView
80 81
81 model: accountsController.accounts 82 model: accountsController.accounts
82 83
83 currentIndex: -1 84 currentIndex: -1
84 85
85 delegate: PlasmaComponents.ListItem { 86 delegate: PlasmaComponents.ListItem {
86 87
87 width: listView.width 88 width: listView.width
88 height: Unit.size * 10 89 height: Unit.size * 10
89 90
90 enabled: true 91 enabled: true
91 checked: listView.currentIndex == index 92 checked: listView.currentIndex == index
92 93
93 KubeFramework.AccountFactory { 94 KubeFramework.AccountFactory {
94 id: accountFactory 95 id: accountFactory
95 accountId: modelData 96 accountId: modelData
96 }
97
98 MouseArea {
99 anchors {
100 fill: parent
101 } 97 }
102 98
103 onClicked: { 99 MouseArea {
104 accountDetails.source = accountFactory.uiPath 100 anchors {
101 fill: parent
102 }
105 103
106 listView.currentIndex = model.index 104 onClicked: {
105 console.warn("Loading module is ", accountFactory.acountId);
106 accountDetails.source = accountFactory.uiPath
107 listView.currentIndex = model.index
108 }
107 } 109 }
108 }
109 110
110 RowLayout { 111 RowLayout {
111 anchors.fill: parent 112 anchors.fill: parent
112 113
113 PlasmaCore.IconItem { 114 PlasmaCore.IconItem {
114 source: accountFactory.icon 115 source: accountFactory.icon
115 } 116 }
116 117
117 Label { 118 Label {
118 text: accountFactory.name 119 text: accountFactory.name
120 }
119 } 121 }
120 } 122 }
121 } 123 }
124
125 }
126 Button {
127 id: button
128 text: "Create New"
129 onClicked: {
130 accountsController.createAccount("maildir");
131 }
122 } 132 }
123 } 133 }
124 134
@@ -128,19 +138,5 @@ Rectangle {
128 Layout.fillWidth: true 138 Layout.fillWidth: true
129 } 139 }
130 } 140 }
131
132 /*
133 Button {
134 id: button
135 text: "Create New"
136 onClicked: {
137 accountsController.createAccount("maildir");
138 }
139 }
140
141 //TODO: Add possibility to add more accounts
142
143 */
144 } 141 }
145
146} 142}
diff --git a/framework/settings/settings.cpp b/framework/settings/settings.cpp
index 246c4a99..64bc28ba 100644
--- a/framework/settings/settings.cpp
+++ b/framework/settings/settings.cpp
@@ -22,6 +22,7 @@
22#include <QStandardPaths> 22#include <QStandardPaths>
23#include <QMetaObject> 23#include <QMetaObject>
24#include <QMetaProperty> 24#include <QMetaProperty>
25#include <QFile>
25 26
26using namespace Kube; 27using namespace Kube;
27 28
@@ -50,7 +51,6 @@ Settings::Settings(const Settings &other)
50 51
51Settings::~Settings() 52Settings::~Settings()
52{ 53{
53 // save();
54} 54}
55 55
56QSharedPointer<QSettings> Settings::getSettings() 56QSharedPointer<QSettings> Settings::getSettings()
@@ -81,6 +81,11 @@ void Settings::save()
81 settings->sync(); 81 settings->sync();
82} 82}
83 83
84void Settings::remove()
85{
86 QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QString("/kube/%1.ini").arg(QString::fromLatin1(mIdentifier)));
87}
88
84void Settings::load() 89void Settings::load()
85{ 90{
86 if (mLoaded) { 91 if (mLoaded) {
diff --git a/framework/settings/settings.h b/framework/settings/settings.h
index 685d67aa..c5cff76b 100644
--- a/framework/settings/settings.h
+++ b/framework/settings/settings.h
@@ -38,6 +38,7 @@ public:
38 QByteArray identifier() const; 38 QByteArray identifier() const;
39 39
40 Q_INVOKABLE void save(); 40 Q_INVOKABLE void save();
41 Q_INVOKABLE void remove();
41private: 42private:
42 void load(); 43 void load();
43 QSharedPointer<QSettings> getSettings(); 44 QSharedPointer<QSettings> getSettings();