diff options
Diffstat (limited to 'accounts/maildir/maildircontroller.cpp')
-rw-r--r-- | accounts/maildir/maildircontroller.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
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 | } | ||