diff options
author | Michael Bohlender <michael.bohlender@kdemail.net> | 2016-11-22 18:03:24 +0100 |
---|---|---|
committer | Michael Bohlender <michael.bohlender@kdemail.net> | 2016-11-22 18:03:24 +0100 |
commit | d6ded01b2e07981b8c1f6139b25935c8c26db0eb (patch) | |
tree | 5332ed06da83fe7af36456d0f2acb4438fd5ba4a | |
parent | 929324eefea8c33d586174d2f6d6c34fb06e42dd (diff) | |
download | kube-d6ded01b2e07981b8c1f6139b25935c8c26db0eb.tar.gz kube-d6ded01b2e07981b8c1f6139b25935c8c26db0eb.zip |
connect maildir controller and maildir account wizzard page
-rw-r--r-- | accounts/maildir/CMakeLists.txt | 1 | ||||
-rw-r--r-- | accounts/maildir/maildiraccountplugin.cpp | 2 | ||||
-rw-r--r-- | accounts/maildir/maildircontroller.cpp | 107 | ||||
-rw-r--r-- | accounts/maildir/maildircontroller.h | 64 | ||||
-rw-r--r-- | components/accounts/CreateMaildir.qml | 18 |
5 files changed, 188 insertions, 4 deletions
diff --git a/accounts/maildir/CMakeLists.txt b/accounts/maildir/CMakeLists.txt index e50d4179..c8bf37c9 100644 --- a/accounts/maildir/CMakeLists.txt +++ b/accounts/maildir/CMakeLists.txt | |||
@@ -31,6 +31,7 @@ include_directories(../../framework/) | |||
31 | set(SRCS | 31 | set(SRCS |
32 | maildirsettings.cpp | 32 | maildirsettings.cpp |
33 | maildiraccountplugin.cpp | 33 | maildiraccountplugin.cpp |
34 | maildircontroller.cpp | ||
34 | ) | 35 | ) |
35 | 36 | ||
36 | add_library(maildiraccountplugin SHARED ${SRCS}) | 37 | add_library(maildiraccountplugin SHARED ${SRCS}) |
diff --git a/accounts/maildir/maildiraccountplugin.cpp b/accounts/maildir/maildiraccountplugin.cpp index 2c3c8c4d..5ae49d8e 100644 --- a/accounts/maildir/maildiraccountplugin.cpp +++ b/accounts/maildir/maildiraccountplugin.cpp | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "maildiraccountplugin.h" | 1 | #include "maildiraccountplugin.h" |
2 | 2 | ||
3 | #include "maildirsettings.h" | 3 | #include "maildirsettings.h" |
4 | #include "maildircontroller.h" | ||
4 | 5 | ||
5 | #include <QtQml> | 6 | #include <QtQml> |
6 | 7 | ||
@@ -8,4 +9,5 @@ void MaildirAccountPlugin::registerTypes (const char *uri) | |||
8 | { | 9 | { |
9 | Q_ASSERT(uri == QLatin1String("org.kube.accounts.maildir")); | 10 | Q_ASSERT(uri == QLatin1String("org.kube.accounts.maildir")); |
10 | qmlRegisterType<MaildirSettings>(uri, 1, 0, "MaildirSettings"); | 11 | qmlRegisterType<MaildirSettings>(uri, 1, 0, "MaildirSettings"); |
12 | qmlRegisterType<MaildirController>(uri, 1, 0, "MaildirController"); | ||
11 | } | 13 | } |
diff --git a/accounts/maildir/maildircontroller.cpp b/accounts/maildir/maildircontroller.cpp new file mode 100644 index 00000000..dc34d59a --- /dev/null +++ b/accounts/maildir/maildircontroller.cpp | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net> | ||
3 | * Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU Library General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or (at your | ||
8 | * option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
13 | * License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Library General Public License | ||
16 | * along with this library; see the file COPYING.LIB. If not, write to the | ||
17 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | * 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | #include "maildircontroller.h" | ||
22 | |||
23 | #include <sink/store.h> | ||
24 | |||
25 | using namespace Sink; | ||
26 | using namespace Sink::ApplicationDomain; | ||
27 | |||
28 | MaildirController::MaildirController(QObject *parent) | ||
29 | : QObject(parent) | ||
30 | { | ||
31 | } | ||
32 | |||
33 | QByteArray MaildirController::accountIdentifier() const | ||
34 | { | ||
35 | return mAccountIdentifier; | ||
36 | } | ||
37 | |||
38 | void MaildirController::setAccountIdentifier(const QByteArray &id) | ||
39 | { | ||
40 | if (id.isEmpty()) { | ||
41 | return; | ||
42 | } | ||
43 | mAccountIdentifier = id; | ||
44 | |||
45 | //clear | ||
46 | mIcon = QString(); | ||
47 | mName = QString(); | ||
48 | mPath = QUrl(); | ||
49 | |||
50 | //load | ||
51 | } | ||
52 | |||
53 | QUrl MaildirController::path() const | ||
54 | { | ||
55 | return QUrl(mPath); | ||
56 | } | ||
57 | |||
58 | void MaildirController::setPath(const QUrl &path) | ||
59 | { | ||
60 | auto normalizedPath = path.path(); | ||
61 | if (mPath != normalizedPath) { | ||
62 | mPath = normalizedPath; | ||
63 | emit pathChanged(); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | void MaildirController::createAccount() | ||
68 | { | ||
69 | auto account = ApplicationDomainType::createEntity<SinkAccount>(); | ||
70 | account.setProperty("type", "maildir"); | ||
71 | account.setProperty("name", mName); | ||
72 | account.setProperty("icon", mIcon); | ||
73 | Store::create(account).exec().waitForFinished(); | ||
74 | |||
75 | auto resource = ApplicationDomainType::createEntity<SinkResource>(); | ||
76 | resource.setResourceType("sink.maildir"); | ||
77 | resource.setAccount(account); | ||
78 | resource.setProperty("path", mPath); | ||
79 | //TODO not yet implemented in resource? // resource.setProperty("readonly", readonly); | ||
80 | Store::create(resource).exec().waitForFinished(); | ||
81 | } | ||
82 | |||
83 | //TODO | ||
84 | void MaildirController::loadAccount(const QByteArray &id) | ||
85 | { | ||
86 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | ||
87 | Store::fetchOne<SinkAccount>(Query().filter(mAccountIdentifier)) | ||
88 | .syncThen<void, SinkAccount>([this](const SinkAccount &account) { | ||
89 | mIcon = account.getIcon(); | ||
90 | mName = account.getName(); | ||
91 | emit nameChanged(); | ||
92 | emit iconChanged(); | ||
93 | }).exec(); | ||
94 | } | ||
95 | |||
96 | //TODO | ||
97 | void MaildirController::modifyAccount() | ||
98 | { | ||
99 | } | ||
100 | |||
101 | void MaildirController::deleteAccount() | ||
102 | { | ||
103 | if (!mAccountIdentifier.isEmpty()) { | ||
104 | SinkAccount account(mAccountIdentifier); | ||
105 | Store::remove(account).exec(); | ||
106 | } | ||
107 | } | ||
diff --git a/accounts/maildir/maildircontroller.h b/accounts/maildir/maildircontroller.h new file mode 100644 index 00000000..80ffb8ca --- /dev/null +++ b/accounts/maildir/maildircontroller.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Michael Bohlender, <michael.bohlender@kdemail.net> | ||
3 | * Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along | ||
16 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include <QObject> | ||
23 | #include <QString> | ||
24 | #include <QByteArray> | ||
25 | #include <QUrl> | ||
26 | |||
27 | class MaildirController : public QObject | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | |||
31 | Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier NOTIFY accountIdentifierChanged) | ||
32 | |||
33 | Q_PROPERTY(QString name MEMBER mName NOTIFY nameChanged) | ||
34 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY iconChanged) | ||
35 | Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged) | ||
36 | |||
37 | public: | ||
38 | explicit MaildirController(QObject *parent = Q_NULLPTR); | ||
39 | |||
40 | QByteArray accountIdentifier() const; | ||
41 | void setAccountIdentifier(const QByteArray &id); | ||
42 | |||
43 | QUrl path() const; | ||
44 | void setPath(const QUrl &path); | ||
45 | |||
46 | signals: | ||
47 | void accountIdentifierChanged(); | ||
48 | void nameChanged(); | ||
49 | void iconChanged(); | ||
50 | void pathChanged(); | ||
51 | |||
52 | public slots: | ||
53 | void createAccount(); | ||
54 | void loadAccount(const QByteArray &id); | ||
55 | void modifyAccount(); | ||
56 | void deleteAccount(); | ||
57 | |||
58 | private: | ||
59 | QByteArray mAccountIdentifier; | ||
60 | QString mIcon; | ||
61 | QString mName; | ||
62 | QUrl mPath; | ||
63 | }; | ||
64 | |||
diff --git a/components/accounts/CreateMaildir.qml b/components/accounts/CreateMaildir.qml index 2b22d8b0..01f1a83d 100644 --- a/components/accounts/CreateMaildir.qml +++ b/components/accounts/CreateMaildir.qml | |||
@@ -23,13 +23,13 @@ import QtQuick.Controls 2.0 as Controls2 | |||
23 | import org.kde.kirigami 1.0 as Kirigami | 23 | import org.kde.kirigami 1.0 as Kirigami |
24 | import QtQuick.Dialogs 1.0 as Dialogs | 24 | import QtQuick.Dialogs 1.0 as Dialogs |
25 | 25 | ||
26 | import org.kube.framework.domain 1.0 as KubeFramework | 26 | import org.kube.accounts.maildir 1.0 as MaildirAccount |
27 | 27 | ||
28 | Item { | 28 | Item { |
29 | id: root | 29 | id: root |
30 | 30 | ||
31 | //Controller | 31 | //Controller |
32 | KubeFramework.AccountsController { | 32 | MaildirAccount.MaildirController { |
33 | id: accountsController | 33 | id: accountsController |
34 | } | 34 | } |
35 | 35 | ||
@@ -98,6 +98,12 @@ Item { | |||
98 | Controls.TextField { | 98 | Controls.TextField { |
99 | id: title | 99 | id: title |
100 | Layout.fillWidth: true | 100 | Layout.fillWidth: true |
101 | |||
102 | text: accountsController.name | ||
103 | |||
104 | onTextChanged: { | ||
105 | accountsController.name = text | ||
106 | } | ||
101 | } | 107 | } |
102 | 108 | ||
103 | Kirigami.Label { | 109 | Kirigami.Label { |
@@ -112,6 +118,8 @@ Item { | |||
112 | Layout.fillWidth: true | 118 | Layout.fillWidth: true |
113 | 119 | ||
114 | enabled: false | 120 | enabled: false |
121 | |||
122 | text: accountsController.path | ||
115 | } | 123 | } |
116 | 124 | ||
117 | Controls.Button { | 125 | Controls.Button { |
@@ -132,13 +140,14 @@ Item { | |||
132 | selectFolder: true | 140 | selectFolder: true |
133 | 141 | ||
134 | onAccepted: { | 142 | onAccepted: { |
135 | //root.path = fileDialog.fileUrl | 143 | accountsController.path = fileDialog.fileUrl |
136 | } | 144 | } |
137 | } | 145 | } |
138 | } | 146 | } |
139 | } | 147 | } |
140 | } | 148 | } |
141 | 149 | ||
150 | /* | ||
142 | Kirigami.Label { | 151 | Kirigami.Label { |
143 | text: "" | 152 | text: "" |
144 | } | 153 | } |
@@ -146,6 +155,7 @@ Item { | |||
146 | id: readOnly | 155 | id: readOnly |
147 | text: "Read only" | 156 | text: "Read only" |
148 | } | 157 | } |
158 | */ | ||
149 | 159 | ||
150 | Kirigami.Label { | 160 | Kirigami.Label { |
151 | text: "" | 161 | text: "" |
@@ -177,7 +187,7 @@ Item { | |||
177 | text: "Save" | 187 | text: "Save" |
178 | 188 | ||
179 | onClicked: { | 189 | onClicked: { |
180 | //accountsController.createMaildirAccount(root.name, root.path, root.readOnly) | 190 | accountsController.createAccount() |
181 | popup.close() | 191 | popup.close() |
182 | } | 192 | } |
183 | } | 193 | } |