diff options
-rw-r--r-- | accounts/maildir/maildirsettings.cpp | 21 | ||||
-rw-r--r-- | accounts/maildir/maildirsettings.h | 3 | ||||
-rw-r--r-- | accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | 6 |
3 files changed, 30 insertions, 0 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index 58ff77fd..18abaebb 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <sink/store.h> | 23 | #include <sink/store.h> |
24 | #include <QDebug> | 24 | #include <QDebug> |
25 | #include <QUuid> | 25 | #include <QUuid> |
26 | #include <QDir> | ||
26 | 27 | ||
27 | MaildirSettings::MaildirSettings(QObject *parent) | 28 | MaildirSettings::MaildirSettings(QObject *parent) |
28 | : QObject(parent) | 29 | : QObject(parent) |
@@ -77,8 +78,28 @@ QString MaildirSettings::path() const | |||
77 | return mPath; | 78 | return mPath; |
78 | } | 79 | } |
79 | 80 | ||
81 | QValidator *MaildirSettings::pathValidator() const | ||
82 | { | ||
83 | class PathValidator : public QValidator { | ||
84 | State validate(QString &input, int &pos) const { | ||
85 | Q_UNUSED(pos); | ||
86 | if (QDir(input).exists()) { | ||
87 | return Acceptable; | ||
88 | } else { | ||
89 | return Intermediate; | ||
90 | } | ||
91 | } | ||
92 | }; | ||
93 | static PathValidator *pathValidator = new PathValidator; | ||
94 | return pathValidator; | ||
95 | } | ||
96 | |||
80 | void MaildirSettings::save() | 97 | void MaildirSettings::save() |
81 | { | 98 | { |
99 | if (!QDir(mPath).exists()) { | ||
100 | qWarning() << "The path doesn't exist: " << mPath; | ||
101 | return; | ||
102 | } | ||
82 | if (!mIdentifier.isEmpty()) { | 103 | if (!mIdentifier.isEmpty()) { |
83 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); | 104 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); |
84 | resource.setProperty("path", mPath); | 105 | resource.setProperty("path", mPath); |
diff --git a/accounts/maildir/maildirsettings.h b/accounts/maildir/maildirsettings.h index 9a65cf39..063fb9da 100644 --- a/accounts/maildir/maildirsettings.h +++ b/accounts/maildir/maildirsettings.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #pragma once | 19 | #pragma once |
20 | 20 | ||
21 | #include <QObject> | 21 | #include <QObject> |
22 | #include <QValidator> | ||
22 | 23 | ||
23 | class MaildirSettings : public QObject | 24 | class MaildirSettings : public QObject |
24 | { | 25 | { |
@@ -26,6 +27,7 @@ class MaildirSettings : public QObject | |||
26 | Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) | 27 | Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) |
27 | Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) | 28 | Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) |
28 | Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) | 29 | Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) |
30 | Q_PROPERTY(QValidator* pathValidator READ pathValidator) | ||
29 | 31 | ||
30 | public: | 32 | public: |
31 | MaildirSettings(QObject *parent = 0); | 33 | MaildirSettings(QObject *parent = 0); |
@@ -38,6 +40,7 @@ public: | |||
38 | 40 | ||
39 | void setPath(const QString &); | 41 | void setPath(const QString &); |
40 | QString path() const; | 42 | QString path() const; |
43 | QValidator *pathValidator() const; | ||
41 | 44 | ||
42 | Q_INVOKABLE void save(); | 45 | Q_INVOKABLE void save(); |
43 | Q_INVOKABLE void remove(); | 46 | Q_INVOKABLE void remove(); |
diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml index 2f5049e0..61828f34 100644 --- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml +++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | |||
@@ -51,6 +51,12 @@ Rectangle { | |||
51 | Layout.fillWidth: true | 51 | Layout.fillWidth: true |
52 | text: maildirSettings.path | 52 | text: maildirSettings.path |
53 | onTextChanged: { maildirSettings.path = text; } | 53 | onTextChanged: { maildirSettings.path = text; } |
54 | validator: maildirSettings.pathValidator | ||
55 | Rectangle { | ||
56 | anchors.fill: parent | ||
57 | opacity: 0.2 | ||
58 | color: path.acceptableInput ? "green" : "yellow" | ||
59 | } | ||
54 | } | 60 | } |
55 | 61 | ||
56 | Button { | 62 | Button { |