summaryrefslogtreecommitdiffstats
path: root/accounts
diff options
context:
space:
mode:
Diffstat (limited to 'accounts')
-rw-r--r--accounts/maildir/maildirsettings.cpp85
-rw-r--r--accounts/maildir/maildirsettings.h11
-rw-r--r--accounts/maildir/package/contents/ui/MaildirAccountSettings.qml40
-rw-r--r--accounts/maildir/tests/settingstest.cpp13
4 files changed, 122 insertions, 27 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp
index 847ce92e..fa30851c 100644
--- a/accounts/maildir/maildirsettings.cpp
+++ b/accounts/maildir/maildirsettings.cpp
@@ -38,6 +38,18 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id)
38 return; 38 return;
39 } 39 }
40 mAccountIdentifier = id; 40 mAccountIdentifier = id;
41
42 //Clear
43 mIcon = QString();
44 mName = QString();
45 mPath = QString();
46 mSmtpServer = QString();
47 mSmtpUsername = QString();
48 mSmtpPassword = QString();
49 emit changed();
50 emit pathChanged();
51 emit smtpResourceChanged();
52
41 Q_ASSERT(!id.isEmpty()); 53 Q_ASSERT(!id.isEmpty());
42 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(id)) 54 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(id))
43 .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { 55 .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) {
@@ -46,7 +58,7 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id)
46 emit changed(); 58 emit changed();
47 }).exec(); 59 }).exec();
48 60
49 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::PropertyFilter("account", QVariant::fromValue(id))) 61 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::PropertyFilter("account", QVariant::fromValue(id)) + Sink::Query::PropertyFilter("type", QString("org.kde.maildir")))
50 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 62 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) {
51 mIdentifier = resource.identifier(); 63 mIdentifier = resource.identifier();
52 auto path = resource.getProperty("path").toString(); 64 auto path = resource.getProperty("path").toString();
@@ -54,6 +66,21 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id)
54 mPath = path; 66 mPath = path;
55 emit pathChanged(); 67 emit pathChanged();
56 } 68 }
69 },
70 [](int errorCode, const QString &errorMessage) {
71 qWarning() << "Failed to find the maildir resource: " << errorMessage;
72 }).exec();
73
74 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::PropertyFilter("account", QVariant::fromValue(id)) + Sink::Query::PropertyFilter("type", QString("org.kde.mailtransport")))
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 maildir resource: " << errorMessage;
57 }).exec(); 84 }).exec();
58} 85}
59 86
@@ -92,13 +119,32 @@ QValidator *MaildirSettings::pathValidator() const
92 return pathValidator; 119 return pathValidator;
93} 120}
94 121
122QValidator *MaildirSettings::smtpServerValidator() const
123{
124 class SmtpServerValidator : public QValidator {
125 State validate(QString &input, int &pos) const {
126 Q_UNUSED(pos);
127 // smtps://mainserver.example.net:475
128 const QUrl url(input);
129 static QSet<QString> validProtocols = QSet<QString>() << "smtp" << "smtps";
130 if (url.isValid() && validProtocols.contains(url.scheme().toLower())) {
131 return Acceptable;
132 } else {
133 return Intermediate;
134 }
135 }
136 };
137 static SmtpServerValidator *validator = new SmtpServerValidator;
138 return validator;
139}
140
95void MaildirSettings::save() 141void MaildirSettings::save()
96{ 142{
97 if (!QDir(mPath).exists()) { 143 if (!QDir(mPath).exists()) {
98 qWarning() << "The path doesn't exist: " << mPath; 144 qWarning() << "The path doesn't exist: " << mPath;
99 return; 145 return;
100 } 146 }
101 qDebug() << "Saving account " << mAccountIdentifier << mIdentifier; 147 qDebug() << "Saving account " << mAccountIdentifier << mIdentifier << mMailtransportIdentifier;
102 Q_ASSERT(!mAccountIdentifier.isEmpty()); 148 Q_ASSERT(!mAccountIdentifier.isEmpty());
103 Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier); 149 Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier);
104 account.setProperty("type", "maildir"); 150 account.setProperty("type", "maildir");
@@ -133,6 +179,34 @@ void MaildirSettings::save()
133 }) 179 })
134 .exec(); 180 .exec();
135 } 181 }
182
183 if (!mMailtransportIdentifier.isEmpty()) {
184 Sink::ApplicationDomain::SinkResource resource(mMailtransportIdentifier);
185 resource.setProperty("server", mSmtpServer);
186 resource.setProperty("username", mSmtpUsername);
187 resource.setProperty("password", mSmtpPassword);
188 Sink::Store::modify(resource).then<void>([](){}, [](int errorCode, const QString &errorMessage) {
189 qWarning() << "Error while modifying resource: " << errorMessage;
190 })
191 .exec();
192 } else {
193 //FIXME we shouldn't have to do this magic
194 const auto resourceIdentifier = "org.kde.mailtransport." + QUuid::createUuid().toByteArray();
195 mMailtransportIdentifier = resourceIdentifier;
196
197 Sink::ApplicationDomain::SinkResource resource;
198 resource.setProperty("identifier", resourceIdentifier);
199 resource.setProperty("type", "org.kde.mailtransport");
200 resource.setProperty("account", mAccountIdentifier);
201 resource.setProperty("server", mSmtpServer);
202 resource.setProperty("username", mSmtpUsername);
203 resource.setProperty("password", mSmtpPassword);
204 Sink::Store::create(resource).then<void>([]() {},
205 [](int errorCode, const QString &errorMessage) {
206 qWarning() << "Error while creating resource: " << errorMessage;
207 })
208 .exec();
209 }
136} 210}
137 211
138void MaildirSettings::remove() 212void MaildirSettings::remove()
@@ -140,6 +214,13 @@ void MaildirSettings::remove()
140 if (mIdentifier.isEmpty()) { 214 if (mIdentifier.isEmpty()) {
141 qWarning() << "We're missing an identifier"; 215 qWarning() << "We're missing an identifier";
142 } else { 216 } else {
217 Sink::ApplicationDomain::SinkResource mailTransportResource("", mMailtransportIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
218 Sink::Store::remove(mailTransportResource).then<void>([]() {},
219 [](int errorCode, const QString &errorMessage) {
220 qWarning() << "Error while removing resource: " << errorMessage;
221 })
222 .exec();
223
143 Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 224 Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
144 Sink::Store::remove(resource).then<void>([]() {}, 225 Sink::Store::remove(resource).then<void>([]() {},
145 [](int errorCode, const QString &errorMessage) { 226 [](int errorCode, const QString &errorMessage) {
diff --git a/accounts/maildir/maildirsettings.h b/accounts/maildir/maildirsettings.h
index f79208db..be69ffb8 100644
--- a/accounts/maildir/maildirsettings.h
+++ b/accounts/maildir/maildirsettings.h
@@ -29,6 +29,10 @@ class MaildirSettings : public QObject
29 Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT) 29 Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT)
30 Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed) 30 Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed)
31 Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed) 31 Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed)
32 Q_PROPERTY(QString smtpServer MEMBER mSmtpServer NOTIFY smtpResourceChanged)
33 Q_PROPERTY(QValidator* smtpServerValidator READ smtpServerValidator CONSTANT)
34 Q_PROPERTY(QString smtpUsername MEMBER mSmtpUsername NOTIFY smtpResourceChanged)
35 Q_PROPERTY(QString smtpPassword MEMBER mSmtpPassword NOTIFY smtpResourceChanged)
32 36
33public: 37public:
34 MaildirSettings(QObject *parent = 0); 38 MaildirSettings(QObject *parent = 0);
@@ -40,17 +44,24 @@ public:
40 QUrl path() const; 44 QUrl path() const;
41 QValidator *pathValidator() const; 45 QValidator *pathValidator() const;
42 46
47 QValidator *smtpServerValidator() const;
48
43 Q_INVOKABLE void save(); 49 Q_INVOKABLE void save();
44 Q_INVOKABLE void remove(); 50 Q_INVOKABLE void remove();
45 51
46signals: 52signals:
47 void pathChanged(); 53 void pathChanged();
54 void smtpResourceChanged();
48 void changed(); 55 void changed();
49 56
50private: 57private:
51 QByteArray mIdentifier; 58 QByteArray mIdentifier;
52 QByteArray mAccountIdentifier; 59 QByteArray mAccountIdentifier;
60 QByteArray mMailtransportIdentifier;
53 QString mPath; 61 QString mPath;
54 QString mIcon; 62 QString mIcon;
55 QString mName; 63 QString mName;
64 QString mSmtpServer;
65 QString mSmtpUsername;
66 QString mSmtpPassword;
56}; 67};
diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml
index d6292072..e508a475 100644
--- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml
+++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml
@@ -78,7 +78,7 @@ Rectangle {
78 Button { 78 Button {
79 iconName: "folder" 79 iconName: "folder"
80 onClicked: { 80 onClicked: {
81 fileDialogObject = fileDialogComponent.createObject(parent); 81 fileDialogComponent.createObject(parent);
82 } 82 }
83 83
84 Component { 84 Component {
@@ -92,10 +92,8 @@ Rectangle {
92 92
93 onAccepted: { 93 onAccepted: {
94 maildirSettings.path = fileDialog.fileUrl 94 maildirSettings.path = fileDialog.fileUrl
95 fileDialogObject.destroy()
96 } 95 }
97 onRejected: { 96 onRejected: {
98 fileDialogObject.destroy()
99 } 97 }
100 } 98 }
101 } 99 }
@@ -110,29 +108,33 @@ Rectangle {
110 108
111 Label { text: "Username" } 109 Label { text: "Username" }
112 TextField { 110 TextField {
113 id: username 111 placeholderText: "Username"
114 placeholderText: "username"
115 Layout.fillWidth: true 112 Layout.fillWidth: true
116 text: transportSettings.username 113 text: maildirSettings.smtpUsername
117 onTextChanged: { transportSettings.username = text; } 114 onTextChanged: { maildirSettings.smtpUsername = text; }
118 } 115 }
119 116
120 Label { text: "Password" } 117 Label { text: "Password" }
121 TextField { 118 TextField {
122 id: password 119 placeholderText: "Password"
123 placeholderText: "password"
124 Layout.fillWidth: true 120 Layout.fillWidth: true
125 text: transportSettings.password 121 text: maildirSettings.smtpPassword
126 onTextChanged: { transportSettings.password = text; } 122 onTextChanged: { maildirSettings.smtpPassword = text; }
127 } 123 }
128 124
129 Label { text: "Server" } 125 Label { text: "Server" }
130 TextField { 126 TextField {
131 id: server 127 id: server
132 placeholderText: "server" 128 placeholderText: "smtps://mainserver.example.net:465"
133 Layout.fillWidth: true 129 Layout.fillWidth: true
134 text: transportSettings.server 130 text: maildirSettings.smtpServer
135 onTextChanged: { transportSettings.server = text; } 131 onTextChanged: { maildirSettings.smtpServer = text; }
132 validator: maildirSettings.smtpServerValidator
133 Rectangle {
134 anchors.fill: parent
135 opacity: 0.2
136 color: server.acceptableInput ? "green" : "yellow"
137 }
136 } 138 }
137 139
138 MaildirAccount.MaildirSettings { 140 MaildirAccount.MaildirSettings {
@@ -140,19 +142,9 @@ Rectangle {
140 accountIdentifier: accountId 142 accountIdentifier: accountId
141 } 143 }
142 144
143 KubeSettings.Settings {
144 id: transportSettings
145 //TODO set a proper identifier
146 identifier: "transport.current"
147 property string server;
148 property string username;
149 property string password;
150 }
151
152 Button { 145 Button {
153 text: "Save" 146 text: "Save"
154 onClicked: { 147 onClicked: {
155 transportSettings.save();
156 maildirSettings.save(); 148 maildirSettings.save();
157 } 149 }
158 } 150 }
diff --git a/accounts/maildir/tests/settingstest.cpp b/accounts/maildir/tests/settingstest.cpp
index 8f8471f0..07665c24 100644
--- a/accounts/maildir/tests/settingstest.cpp
+++ b/accounts/maildir/tests/settingstest.cpp
@@ -23,14 +23,20 @@ private slots:
23 { 23 {
24 auto accountId = "accountid"; 24 auto accountId = "accountid";
25 auto maildirPath = QDir::tempPath(); 25 auto maildirPath = QDir::tempPath();
26 auto smtpServer = QString("smtpserver");
27 auto smtpUsername = QString("username");
28 auto smtpPassword = QString("password");
26 29
27 MaildirSettings settings; 30 MaildirSettings settings;
28 settings.setAccountIdentifier(accountId); 31 settings.setAccountIdentifier(accountId);
29 settings.setPath(maildirPath); 32 settings.setPath(maildirPath);
33 settings.setProperty("smtpServer", smtpServer);
34 settings.setProperty("smtpUsername", smtpUsername);
35 settings.setProperty("smtpPassword", smtpPassword);
30 settings.save(); 36 settings.save();
31 37
32 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) { 38 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) {
33 QCOMPARE(resources.size(), 1); 39 QCOMPARE(resources.size(), 2);
34 }) 40 })
35 .exec().waitForFinished(); 41 .exec().waitForFinished();
36 42
@@ -38,10 +44,15 @@ private slots:
38 { 44 {
39 MaildirSettings readSettings; 45 MaildirSettings readSettings;
40 QSignalSpy spy(&readSettings, &MaildirSettings::pathChanged); 46 QSignalSpy spy(&readSettings, &MaildirSettings::pathChanged);
47 QSignalSpy spy1(&readSettings, &MaildirSettings::smtpResourceChanged);
41 readSettings.setAccountIdentifier(accountId); 48 readSettings.setAccountIdentifier(accountId);
42 QTRY_VERIFY(spy.count()); 49 QTRY_VERIFY(spy.count());
50 QTRY_VERIFY(spy1.count());
43 QVERIFY(!readSettings.accountIdentifier().isEmpty()); 51 QVERIFY(!readSettings.accountIdentifier().isEmpty());
44 QCOMPARE(readSettings.path().toString(), maildirPath); 52 QCOMPARE(readSettings.path().toString(), maildirPath);
53 QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer);
54 QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername);
55 QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword);
45 } 56 }
46 57
47 { 58 {