diff options
Diffstat (limited to 'accounts')
-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 |
4 files changed, 174 insertions, 0 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 | |||