diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-11 20:57:54 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-11 20:57:54 +0100 |
commit | 68a41da9b16091a577a94cec7eccd4c892905391 (patch) | |
tree | 34d213b2077a6ffa635db86d70ee6d8f4ace7bbc /accounts/maildir/maildirsettings.cpp | |
parent | 9cc5f00f34dc9d478178bde569b6783270981adb (diff) | |
download | kube-68a41da9b16091a577a94cec7eccd4c892905391.tar.gz kube-68a41da9b16091a577a94cec7eccd4c892905391.zip |
Extended maildir settings to create and register the sink resource
Diffstat (limited to 'accounts/maildir/maildirsettings.cpp')
-rw-r--r-- | accounts/maildir/maildirsettings.cpp | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index 4a3b1a00..a2e2e96e 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp | |||
@@ -18,8 +18,11 @@ | |||
18 | */ | 18 | */ |
19 | #include "maildirsettings.h" | 19 | #include "maildirsettings.h" |
20 | 20 | ||
21 | #include <settings/settings.h> | ||
22 | |||
21 | #include <sink/store.h> | 23 | #include <sink/store.h> |
22 | #include <QDebug> | 24 | #include <QDebug> |
25 | #include <QUuid> | ||
23 | 26 | ||
24 | MaildirSettings::MaildirSettings(QObject *parent) | 27 | MaildirSettings::MaildirSettings(QObject *parent) |
25 | : QObject(parent) | 28 | : QObject(parent) |
@@ -31,7 +34,11 @@ void MaildirSettings::setIdentifier(const QByteArray &id) | |||
31 | mIdentifier = id; | 34 | mIdentifier = id; |
32 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList<QByteArray>() << "path")) | 35 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList<QByteArray>() << "path")) |
33 | .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { | 36 | .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { |
34 | setProperty("path", resource.getProperty("path")); | 37 | auto path = resource.getProperty("path").toString(); |
38 | if (mPath != path) { | ||
39 | mPath = path; | ||
40 | emit pathChanged(); | ||
41 | } | ||
35 | }).exec(); | 42 | }).exec(); |
36 | } | 43 | } |
37 | 44 | ||
@@ -40,16 +47,70 @@ QByteArray MaildirSettings::identifier() const | |||
40 | return mIdentifier; | 47 | return mIdentifier; |
41 | } | 48 | } |
42 | 49 | ||
50 | void MaildirSettings::setAccountIdentifier(const QByteArray &id) | ||
51 | { | ||
52 | mAccountIdentifier = id; | ||
53 | Kube::Account account(id); | ||
54 | account.property("maildirResource").toByteArray(); | ||
55 | setIdentifier(account.property("maildirResource").toByteArray()); | ||
56 | } | ||
57 | |||
58 | QByteArray MaildirSettings::accountIdentifier() const | ||
59 | { | ||
60 | return mAccountIdentifier; | ||
61 | } | ||
62 | |||
63 | void MaildirSettings::setPath(const QString &path) | ||
64 | { | ||
65 | if (mPath != path) { | ||
66 | mPath = path; | ||
67 | emit pathChanged(); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | QString MaildirSettings::path() const | ||
72 | { | ||
73 | return mPath; | ||
74 | } | ||
75 | |||
43 | void MaildirSettings::save() | 76 | void MaildirSettings::save() |
44 | { | 77 | { |
45 | if (!mIdentifier.isEmpty()) { | 78 | if (!mIdentifier.isEmpty()) { |
46 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); | 79 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); |
47 | resource.setProperty("path", property("path")); | 80 | resource.setProperty("path", mPath); |
48 | Sink::Store::modify(resource).exec(); | 81 | Sink::Store::modify(resource).exec(); |
49 | } else { | 82 | } else { |
83 | const auto resourceIdentifier = "org.kde.maildir." + QUuid::createUuid().toByteArray(); | ||
84 | mIdentifier = resourceIdentifier; | ||
85 | |||
50 | Sink::ApplicationDomain::SinkResource resource; | 86 | Sink::ApplicationDomain::SinkResource resource; |
51 | resource.setProperty("path", property("path")); | 87 | resource.setProperty("path", property("path")); |
88 | resource.setProperty("identifier", resourceIdentifier); | ||
89 | resource.setProperty("type", "org.kde.maildir"); | ||
52 | Sink::Store::create(resource).exec(); | 90 | Sink::Store::create(resource).exec(); |
91 | Kube::Account account(mAccountIdentifier); | ||
92 | account.setProperty("maildirResource", resourceIdentifier); | ||
93 | account.save(); | ||
94 | //TODO deal with errors while creating | ||
95 | } | ||
96 | } | ||
97 | |||
98 | void MaildirSettings::remove() | ||
99 | { | ||
100 | if (!mIdentifier.isEmpty()) { | ||
101 | qWarning() << "We're missing an identifier"; | ||
102 | } else { | ||
103 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); | ||
104 | Sink::Store::remove(resource).exec(); | ||
105 | Kube::Account account(mAccountIdentifier); | ||
106 | account.remove(); | ||
107 | |||
108 | Kube::Settings settings("accounts"); | ||
109 | auto accounts = settings.property("accounts").toStringList(); | ||
110 | accounts.removeAll(mAccountIdentifier); | ||
111 | settings.setProperty("accounts", accounts); | ||
112 | settings.save(); | ||
113 | //TODO deal with errors while removing | ||
53 | } | 114 | } |
54 | } | 115 | } |
55 | 116 | ||