summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--accounts/CMakeLists.txt1
-rw-r--r--accounts/imap/CMakeLists.txt48
-rw-r--r--accounts/imap/imapaccountplugin.cpp29
-rw-r--r--accounts/imap/imapaccountplugin.h31
-rw-r--r--accounts/imap/imapsettings.cpp250
-rw-r--r--accounts/imap/imapsettings.h74
-rw-r--r--accounts/imap/package/contents/ui/ImapAccountSettings.qml164
-rw-r--r--accounts/imap/package/metadata.desktop8
-rw-r--r--accounts/imap/qmldir3
-rw-r--r--accounts/imap/tests/CMakeLists.txt6
-rw-r--r--accounts/imap/tests/settingstest.cpp87
11 files changed, 701 insertions, 0 deletions
diff --git a/accounts/CMakeLists.txt b/accounts/CMakeLists.txt
index 25fa7f67..212a62ff 100644
--- a/accounts/CMakeLists.txt
+++ b/accounts/CMakeLists.txt
@@ -1 +1,2 @@
1add_subdirectory(maildir) 1add_subdirectory(maildir)
2add_subdirectory(imap)
diff --git a/accounts/imap/CMakeLists.txt b/accounts/imap/CMakeLists.txt
new file mode 100644
index 00000000..afff7102
--- /dev/null
+++ b/accounts/imap/CMakeLists.txt
@@ -0,0 +1,48 @@
1project(kube-accounts-imap)
2
3cmake_minimum_required(VERSION 2.8.12)
4
5include(CPack)
6include(FeatureSummary)
7find_package(PkgConfig)
8
9################# set KDE specific information #################
10
11find_package(ECM 0.0.8 REQUIRED NO_MODULE)
12
13# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
14set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
15
16include(KDEInstallDirs)
17include(KDECMakeSettings)
18include(KDECompilerSettings)
19
20find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui)
21
22set (QT_MIN_VERSION "5.4.0")
23find_package(Sink CONFIG REQUIRED)
24find_package(KF5Async CONFIG REQUIRED)
25find_package(KF5 REQUIRED COMPONENTS Package)
26
27include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/)
28#FIXME
29include_directories(../../framework/)
30
31set(SRCS
32 imapsettings.cpp
33 imapaccountplugin.cpp
34)
35
36add_library(imapaccountplugin SHARED ${SRCS})
37qt5_use_modules(imapaccountplugin Core Quick Qml)
38target_link_libraries(imapaccountplugin sink settingsplugin)
39
40add_library(imapaccount_static STATIC ${SRCS})
41qt5_use_modules(imapaccount_static Core Quick Qml)
42target_link_libraries(imapaccount_static sink settingsplugin)
43add_subdirectory(tests)
44
45kpackage_install_package(package org.kube.accounts.imap "genericqml")
46
47install(TARGETS imapaccountplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/accounts/imap)
48install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/accounts/imap)
diff --git a/accounts/imap/imapaccountplugin.cpp b/accounts/imap/imapaccountplugin.cpp
new file mode 100644
index 00000000..781c9a5e
--- /dev/null
+++ b/accounts/imap/imapaccountplugin.cpp
@@ -0,0 +1,29 @@
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 "imapaccountplugin.h"
20
21#include "imapsettings.h"
22
23#include <QtQml>
24
25void ImapAccountPlugin::registerTypes (const char *uri)
26{
27 Q_ASSERT(uri == QLatin1String("org.kube.accounts.imap"));
28 qmlRegisterType<ImapSettings>(uri, 1, 0, "ImapSettings");
29}
diff --git a/accounts/imap/imapaccountplugin.h b/accounts/imap/imapaccountplugin.h
new file mode 100644
index 00000000..7977efeb
--- /dev/null
+++ b/accounts/imap/imapaccountplugin.h
@@ -0,0 +1,31 @@
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 <QQmlEngine>
22#include <QQmlExtensionPlugin>
23
24class ImapAccountPlugin : public QQmlExtensionPlugin
25{
26 Q_OBJECT
27 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
28
29public:
30 virtual void registerTypes(const char *uri);
31};
diff --git a/accounts/imap/imapsettings.cpp b/accounts/imap/imapsettings.cpp
new file mode 100644
index 00000000..7d93606d
--- /dev/null
+++ b/accounts/imap/imapsettings.cpp
@@ -0,0 +1,250 @@
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 "imapsettings.h"
20
21#include <settings/settings.h>
22
23#include <sink/store.h>
24#include <QDebug>
25#include <QDir>
26#include <QUrl>
27
28ImapSettings::ImapSettings(QObject *parent)
29 : QObject(parent)
30{
31}
32
33
34void ImapSettings::setAccountIdentifier(const QByteArray &id)
35{
36 if (id.isEmpty()) {
37 return;
38 }
39 mAccountIdentifier = id;
40
41 //Clear
42 mIcon = QString();
43 mName = QString();
44 mImapServer = QString();
45 mImapUsername = QString();
46 mImapPassword = QString();
47 mSmtpServer = QString();
48 mSmtpUsername = QString();
49 mSmtpPassword = QString();
50 emit changed();
51 emit imapResourceChanged();
52 emit smtpResourceChanged();
53
54 Q_ASSERT(!id.isEmpty());
55 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(id))
56 .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) {
57 mIcon = account.getProperty("icon").toString();
58 mName = account.getProperty("name").toString();
59 emit changed();
60 }).exec();
61
62 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(id) + Sink::Query::CapabilityFilter("storage"))
63 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) {
64 mIdentifier = resource.identifier();
65 mImapServer = resource.getProperty("server").toString();
66 mImapUsername = resource.getProperty("username").toString();
67 mImapPassword = resource.getProperty("password").toString();
68 emit imapResourceChanged();
69 },
70 [](int errorCode, const QString &errorMessage) {
71 qWarning() << "Failed to find the imap resource: " << errorMessage;
72 }).exec();
73
74 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(id) + Sink::Query::CapabilityFilter("transport"))
75 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) {
76 mMailtransportIdentifier = resource.identifier();
77 mSmtpServer = resource.getProperty("server").toString();
78 mSmtpUsername = resource.getProperty("username").toString();
79 mSmtpPassword = resource.getProperty("password").toString();
80 emit smtpResourceChanged();
81 },
82 [](int errorCode, const QString &errorMessage) {
83 qWarning() << "Failed to find the smtp resource: " << errorMessage;
84 }).exec();
85
86 //FIXME this assumes that we only ever have one identity per account
87 Sink::Store::fetchOne<Sink::ApplicationDomain::Identity>(Sink::Query::AccountFilter(id))
88 .then<void, Sink::ApplicationDomain::Identity>([this](const Sink::ApplicationDomain::Identity &identity) {
89 mIdentityIdentifier = identity.identifier();
90 mUsername = identity.getProperty("username").toString();
91 mEmailAddress = identity.getProperty("address").toString();
92 emit identityChanged();
93 },
94 [](int errorCode, const QString &errorMessage) {
95 qWarning() << "Failed to find the identity resource: " << errorMessage;
96 }).exec();
97}
98
99QByteArray ImapSettings::accountIdentifier() const
100{
101 return mAccountIdentifier;
102}
103
104QValidator *ImapSettings::imapServerValidator() const
105{
106 class ImapServerValidator : public QValidator {
107 State validate(QString &input, int &pos) const {
108 Q_UNUSED(pos);
109 // imaps://mainserver.example.net:475
110 const QUrl url(input);
111 static QSet<QString> validProtocols = QSet<QString>() << "imap" << "imaps";
112 if (url.isValid() && validProtocols.contains(url.scheme().toLower())) {
113 return Acceptable;
114 } else {
115 return Intermediate;
116 }
117 }
118 };
119 static ImapServerValidator *validator = new ImapServerValidator;
120 return validator;
121}
122
123QValidator *ImapSettings::smtpServerValidator() const
124{
125 class SmtpServerValidator : public QValidator {
126 State validate(QString &input, int &pos) const {
127 Q_UNUSED(pos);
128 // smtps://mainserver.example.net:475
129 const QUrl url(input);
130 static QSet<QString> validProtocols = QSet<QString>() << "smtp" << "smtps";
131 if (url.isValid() && validProtocols.contains(url.scheme().toLower())) {
132 return Acceptable;
133 } else {
134 return Intermediate;
135 }
136 }
137 };
138 static SmtpServerValidator *validator = new SmtpServerValidator;
139 return validator;
140}
141
142void ImapSettings::save()
143{
144 qDebug() << "Saving account " << mAccountIdentifier << mIdentifier << mMailtransportIdentifier;
145 Q_ASSERT(!mAccountIdentifier.isEmpty());
146 Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier);
147 account.setProperty("type", "imap");
148 account.setProperty("name", mName);
149 account.setProperty("icon", mIcon);
150 Q_ASSERT(!account.identifier().isEmpty());
151 Sink::Store::modify(account).then<void>([]() {},
152 [](int errorCode, const QString &errorMessage) {
153 qWarning() << "Error while creating account: " << errorMessage;
154 })
155 .exec();
156
157 if (!mIdentifier.isEmpty()) {
158 Sink::ApplicationDomain::SinkResource resource(mIdentifier);
159 resource.setProperty("server", mImapServer);
160 resource.setProperty("username", mImapUsername);
161 resource.setProperty("password", mImapPassword);
162 Sink::Store::modify(resource).then<void>([](){}, [](int errorCode, const QString &errorMessage) {
163 qWarning() << "Error while modifying resource: " << errorMessage;
164 })
165 .exec();
166 } else {
167 auto resource = Sink::ApplicationDomain::ImapResource::create(mAccountIdentifier);
168 mIdentifier = resource.identifier();
169 resource.setProperty("server", mImapServer);
170 resource.setProperty("username", mImapUsername);
171 resource.setProperty("password", mImapPassword);
172 Sink::Store::create(resource).then<void>([]() {},
173 [](int errorCode, const QString &errorMessage) {
174 qWarning() << "Error while creating resource: " << errorMessage;
175 })
176 .exec();
177 }
178
179 if (!mMailtransportIdentifier.isEmpty()) {
180 Sink::ApplicationDomain::SinkResource resource(mMailtransportIdentifier);
181 resource.setProperty("server", mSmtpServer);
182 resource.setProperty("username", mSmtpUsername);
183 resource.setProperty("password", mSmtpPassword);
184 Sink::Store::modify(resource).then<void>([](){}, [](int errorCode, const QString &errorMessage) {
185 qWarning() << "Error while modifying resource: " << errorMessage;
186 })
187 .exec();
188 } else {
189 auto resource = Sink::ApplicationDomain::MailtransportResource::create(mAccountIdentifier);
190 mMailtransportIdentifier = resource.identifier();
191 resource.setProperty("server", mSmtpServer);
192 resource.setProperty("username", mSmtpUsername);
193 resource.setProperty("password", mSmtpPassword);
194 Sink::Store::create(resource).then<void>([]() {},
195 [](int errorCode, const QString &errorMessage) {
196 qWarning() << "Error while creating resource: " << errorMessage;
197 })
198 .exec();
199 }
200
201 if (!mIdentityIdentifier.isEmpty()) {
202 Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier);
203 identity.setProperty("username", mUsername);
204 identity.setProperty("address", mEmailAddress);
205 Sink::Store::modify(identity).then<void>([](){}, [](int errorCode, const QString &errorMessage) {
206 qWarning() << "Error while modifying identity: " << errorMessage;
207 })
208 .exec();
209 } else {
210 auto identity = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Identity>();
211 mIdentityIdentifier = identity.identifier();
212 identity.setProperty("account", mAccountIdentifier);
213 identity.setProperty("username", mUsername);
214 identity.setProperty("address", mEmailAddress);
215 Sink::Store::create(identity).then<void>([]() {},
216 [](int errorCode, const QString &errorMessage) {
217 qWarning() << "Error while creating identity: " << errorMessage;
218 })
219 .exec();
220 }
221}
222
223void ImapSettings::remove()
224{
225 if (mIdentifier.isEmpty()) {
226 qWarning() << "We're missing an identifier";
227 } else {
228 Sink::ApplicationDomain::SinkResource mailTransportResource("", mMailtransportIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
229 Sink::Store::remove(mailTransportResource).then<void>([]() {},
230 [](int errorCode, const QString &errorMessage) {
231 qWarning() << "Error while removing resource: " << errorMessage;
232 })
233 .exec();
234
235 Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
236 Sink::Store::remove(resource).then<void>([]() {},
237 [](int errorCode, const QString &errorMessage) {
238 qWarning() << "Error while removing resource: " << errorMessage;
239 })
240 .exec();
241
242 Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
243 Sink::Store::remove(account).then<void>([]() {},
244 [](int errorCode, const QString &errorMessage) {
245 qWarning() << "Error while removing account: " << errorMessage;
246 })
247 .exec();
248 }
249}
250
diff --git a/accounts/imap/imapsettings.h b/accounts/imap/imapsettings.h
new file mode 100644
index 00000000..30bd67d1
--- /dev/null
+++ b/accounts/imap/imapsettings.h
@@ -0,0 +1,74 @@
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 <QValidator>
23
24class ImapSettings : public QObject
25{
26 Q_OBJECT
27 Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier)
28 Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed)
29 Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed)
30 Q_PROPERTY(QString userName MEMBER mUsername NOTIFY identityChanged)
31 Q_PROPERTY(QString emailAddress MEMBER mEmailAddress NOTIFY identityChanged)
32 Q_PROPERTY(QString imapServer MEMBER mImapServer NOTIFY imapResourceChanged)
33 Q_PROPERTY(QValidator* imapServerValidator READ imapServerValidator CONSTANT)
34 Q_PROPERTY(QString imapUsername MEMBER mImapUsername NOTIFY imapResourceChanged)
35 Q_PROPERTY(QString imapPassword MEMBER mImapPassword NOTIFY imapResourceChanged)
36 Q_PROPERTY(QString smtpServer MEMBER mSmtpServer NOTIFY smtpResourceChanged)
37 Q_PROPERTY(QValidator* smtpServerValidator READ smtpServerValidator CONSTANT)
38 Q_PROPERTY(QString smtpUsername MEMBER mSmtpUsername NOTIFY smtpResourceChanged)
39 Q_PROPERTY(QString smtpPassword MEMBER mSmtpPassword NOTIFY smtpResourceChanged)
40
41public:
42 ImapSettings(QObject *parent = 0);
43
44 void setAccountIdentifier(const QByteArray &);
45 QByteArray accountIdentifier() const;
46
47 QValidator *imapServerValidator() const;
48 QValidator *smtpServerValidator() const;
49
50 Q_INVOKABLE void save();
51 Q_INVOKABLE void remove();
52
53signals:
54 void imapResourceChanged();
55 void smtpResourceChanged();
56 void identityChanged();
57 void changed();
58
59private:
60 QByteArray mIdentifier;
61 QByteArray mAccountIdentifier;
62 QByteArray mMailtransportIdentifier;
63 QByteArray mIdentityIdentifier;
64 QString mIcon;
65 QString mName;
66 QString mUsername;
67 QString mEmailAddress;
68 QString mImapServer;
69 QString mImapUsername;
70 QString mImapPassword;
71 QString mSmtpServer;
72 QString mSmtpUsername;
73 QString mSmtpPassword;
74};
diff --git a/accounts/imap/package/contents/ui/ImapAccountSettings.qml b/accounts/imap/package/contents/ui/ImapAccountSettings.qml
new file mode 100644
index 00000000..4dfa3ba4
--- /dev/null
+++ b/accounts/imap/package/contents/ui/ImapAccountSettings.qml
@@ -0,0 +1,164 @@
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
21import QtQuick.Dialogs 1.0
22
23import org.kube.framework.settings 1.0 as KubeSettings
24import org.kube.framework.theme 1.0
25import org.kube.accounts.imap 1.0 as ImapAccount
26
27
28Rectangle {
29 id: root
30 property string accountId
31 property string accountName
32 property string icon
33
34 color: ColorPalette.background
35
36 GridLayout {
37 id: gridLayout
38 columns: 2
39 Layout.fillWidth: true
40
41 Text {
42 Layout.columnSpan: 2
43 Layout.fillWidth: true
44 text: "General:"
45 }
46
47 Label { text: "Account Name" }
48 TextField {
49 id: name
50 placeholderText: accountName
51 Layout.fillWidth: true
52 text: imapSettings.accountName
53 onTextChanged: { imapSettings.accountName = text; root.accountName = text; }
54 }
55
56 Label { text: "User Name" }
57 TextField {
58 placeholderText: "Your Name"
59 Layout.fillWidth: true
60 text: imapSettings.userName
61 onTextChanged: { imapSettings.userName = text; }
62 }
63
64 Label { text: "Email Address" }
65 TextField {
66 placeholderText: "Your EMail Address"
67 Layout.fillWidth: true
68 text: imapSettings.emailAddress
69 onTextChanged: { imapSettings.emailAddress = text; }
70 }
71
72 Text {
73 Layout.columnSpan: 2
74 Layout.fillWidth: true
75 text: "Imap:"
76 }
77
78 Label { text: "Username" }
79 TextField {
80 placeholderText: "Username"
81 Layout.fillWidth: true
82 text: imapSettings.imapUsername
83 onTextChanged: { imapSettings.imapUsername = text; }
84 }
85
86 Label { text: "Password" }
87 TextField {
88 placeholderText: "Password"
89 Layout.fillWidth: true
90 text: imapSettings.imapPassword
91 onTextChanged: { imapSettings.imapPassword = text; }
92 }
93
94 Label { text: "Server" }
95 TextField {
96 id: server
97 placeholderText: "imaps://mainserver.example.net:993"
98 Layout.fillWidth: true
99 text: imapSettings.imapServer
100 onTextChanged: { imapSettings.imapServer = text; }
101 validator: imapSettings.imapServerValidator
102 Rectangle {
103 anchors.fill: parent
104 opacity: 0.2
105 color: server.acceptableInput ? "green" : "yellow"
106 }
107 }
108
109 Text {
110 Layout.columnSpan: 2
111 Layout.fillWidth: true
112 text: "Smtp:"
113 }
114
115 Label { text: "Username" }
116 TextField {
117 placeholderText: "Username"
118 Layout.fillWidth: true
119 text: imapSettings.smtpUsername
120 onTextChanged: { imapSettings.smtpUsername = text; }
121 }
122
123 Label { text: "Password" }
124 TextField {
125 placeholderText: "Password"
126 Layout.fillWidth: true
127 text: imapSettings.smtpPassword
128 onTextChanged: { imapSettings.smtpPassword = text; }
129 }
130
131 Label { text: "Server" }
132 TextField {
133 id: server
134 placeholderText: "smtps://mainserver.example.net:465"
135 Layout.fillWidth: true
136 text: imapSettings.smtpServer
137 onTextChanged: { imapSettings.smtpServer = text; }
138 validator: imapSettings.smtpServerValidator
139 Rectangle {
140 anchors.fill: parent
141 opacity: 0.2
142 color: server.acceptableInput ? "green" : "yellow"
143 }
144 }
145
146 ImapAccount.ImapSettings {
147 id: imapSettings
148 accountIdentifier: accountId
149 }
150
151 Button {
152 text: "Save"
153 onClicked: {
154 imapSettings.save();
155 }
156 }
157 Button {
158 text: "Remove"
159 onClicked: {
160 imapSettings.remove();
161 }
162 }
163 }
164}
diff --git a/accounts/imap/package/metadata.desktop b/accounts/imap/package/metadata.desktop
new file mode 100644
index 00000000..7c4320c3
--- /dev/null
+++ b/accounts/imap/package/metadata.desktop
@@ -0,0 +1,8 @@
1[Desktop Entry]
2Name=Kube Imap Accounts Plugin
3X-KDE-PluginInfo-Name=org.kube.accounts.imap
4Exec=kpackagelauncherqml -a org.kube.accounts.imap
5X-Plasma-MainScript=ui/ImapAccountSettings.qml
6X-KDE-ServiceTypes=KPackage/GenericQML
7Icon=folder
8Type=Service
diff --git a/accounts/imap/qmldir b/accounts/imap/qmldir
new file mode 100644
index 00000000..5e4861c0
--- /dev/null
+++ b/accounts/imap/qmldir
@@ -0,0 +1,3 @@
1module org.kube.accounts.maildir
2
3plugin maildiraccountplugin
diff --git a/accounts/imap/tests/CMakeLists.txt b/accounts/imap/tests/CMakeLists.txt
new file mode 100644
index 00000000..9c914370
--- /dev/null
+++ b/accounts/imap/tests/CMakeLists.txt
@@ -0,0 +1,6 @@
1include_directories(../)
2cmake_policy(SET CMP0063 NEW)
3add_executable(imapsettingstest settingstest.cpp)
4add_test(imapsettingstest settingstest)
5qt5_use_modules(imapsettingstest Core Test Concurrent)
6target_link_libraries(imapsettingstest sink imapaccount_static)
diff --git a/accounts/imap/tests/settingstest.cpp b/accounts/imap/tests/settingstest.cpp
new file mode 100644
index 00000000..923f7e14
--- /dev/null
+++ b/accounts/imap/tests/settingstest.cpp
@@ -0,0 +1,87 @@
1#include <QTest>
2#include <QDebug>
3#include <QSignalSpy>
4#include <functional>
5#include <QStandardPaths>
6#include <QDir>
7#include <sink/test.h>
8#include <sink/store.h>
9
10#include "imapsettings.h"
11
12class SettingsTest : public QObject
13{
14 Q_OBJECT
15private slots:
16
17 void initTestCase()
18 {
19 Sink::Test::initTest();
20 }
21
22 void testLoad()
23 {
24 auto accountId = "accountid";
25 auto imapServer = QString("imapserver");
26 auto imapUsername = QString("username");
27 auto imapPassword = QString("password");
28 auto smtpServer = QString("smtpserver");
29 auto smtpUsername = QString("username");
30 auto smtpPassword = QString("password");
31 auto username = QString("username");
32 auto emailAddress = QString("emailAddress");
33
34 ImapSettings settings;
35 settings.setAccountIdentifier(accountId);
36 settings.setProperty("imapServer", imapServer);
37 settings.setProperty("imapUsername", imapUsername);
38 settings.setProperty("imapPassword", imapPassword);
39 settings.setProperty("smtpServer", smtpServer);
40 settings.setProperty("smtpUsername", smtpUsername);
41 settings.setProperty("smtpPassword", smtpPassword);
42 settings.setProperty("userName", username);
43 settings.setProperty("emailAddress", emailAddress);
44 settings.save();
45
46 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) {
47 QCOMPARE(resources.size(), 2);
48 })
49 .exec().waitForFinished();
50
51 //Ensure we can read back all the information using the accountid
52 {
53 ImapSettings readSettings;
54 QSignalSpy spy(&readSettings, &ImapSettings::imapResourceChanged);
55 QSignalSpy spy1(&readSettings, &ImapSettings::smtpResourceChanged);
56 readSettings.setAccountIdentifier(accountId);
57 //Once for clear and once for the new setting
58 QTRY_COMPARE(spy.count(), 2);
59 QTRY_COMPARE(spy1.count(), 2);
60 QVERIFY(!readSettings.accountIdentifier().isEmpty());
61 QCOMPARE(readSettings.property("imapServer").toString(), imapServer);
62 QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername);
63 QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword);
64 QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer);
65 QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername);
66 QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword);
67 QCOMPARE(readSettings.property("userName").toString(), smtpUsername);
68 QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress);
69 }
70
71 {
72 ImapSettings settings;
73 QSignalSpy spy(&settings, &ImapSettings::imapResourceChanged);
74 settings.setAccountIdentifier(accountId);
75 QTRY_COMPARE(spy.count(), 2);
76 settings.remove();
77 }
78
79 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) {
80 QCOMPARE(resources.size(), 0);
81 })
82 .exec().waitForFinished();
83 }
84};
85
86QTEST_GUILESS_MAIN(SettingsTest)
87#include "settingstest.moc"