diff options
Diffstat (limited to 'accounts/maildir/maildirsettings.cpp')
-rw-r--r-- | accounts/maildir/maildirsettings.cpp | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index 1d48fc24..847ce92e 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp | |||
@@ -31,23 +31,6 @@ MaildirSettings::MaildirSettings(QObject *parent) | |||
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | void MaildirSettings::setIdentifier(const QByteArray &id) | ||
35 | { | ||
36 | mIdentifier = id; | ||
37 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList<QByteArray>() << "path")) | ||
38 | .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { | ||
39 | auto path = resource.getProperty("path").toString(); | ||
40 | if (mPath != path) { | ||
41 | mPath = path; | ||
42 | emit pathChanged(); | ||
43 | } | ||
44 | }).exec(); | ||
45 | } | ||
46 | |||
47 | QByteArray MaildirSettings::identifier() const | ||
48 | { | ||
49 | return mIdentifier; | ||
50 | } | ||
51 | 34 | ||
52 | void MaildirSettings::setAccountIdentifier(const QByteArray &id) | 35 | void MaildirSettings::setAccountIdentifier(const QByteArray &id) |
53 | { | 36 | { |
@@ -56,9 +39,22 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) | |||
56 | } | 39 | } |
57 | mAccountIdentifier = id; | 40 | mAccountIdentifier = id; |
58 | Q_ASSERT(!id.isEmpty()); | 41 | Q_ASSERT(!id.isEmpty()); |
59 | Kube::Account account(id); | 42 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(id)) |
60 | auto maildirResource = account.property("maildirResource").toByteArray(); | 43 | .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { |
61 | setIdentifier(maildirResource); | 44 | mIcon = account.getProperty("icon").toString(); |
45 | mName = account.getProperty("name").toString(); | ||
46 | emit changed(); | ||
47 | }).exec(); | ||
48 | |||
49 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::PropertyFilter("account", QVariant::fromValue(id))) | ||
50 | .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { | ||
51 | mIdentifier = resource.identifier(); | ||
52 | auto path = resource.getProperty("path").toString(); | ||
53 | if (mPath != path) { | ||
54 | mPath = path; | ||
55 | emit pathChanged(); | ||
56 | } | ||
57 | }).exec(); | ||
62 | } | 58 | } |
63 | 59 | ||
64 | QByteArray MaildirSettings::accountIdentifier() const | 60 | QByteArray MaildirSettings::accountIdentifier() const |
@@ -102,6 +98,19 @@ void MaildirSettings::save() | |||
102 | qWarning() << "The path doesn't exist: " << mPath; | 98 | qWarning() << "The path doesn't exist: " << mPath; |
103 | return; | 99 | return; |
104 | } | 100 | } |
101 | qDebug() << "Saving account " << mAccountIdentifier << mIdentifier; | ||
102 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | ||
103 | Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier); | ||
104 | account.setProperty("type", "maildir"); | ||
105 | account.setProperty("name", mName); | ||
106 | account.setProperty("icon", mIcon); | ||
107 | Q_ASSERT(!account.identifier().isEmpty()); | ||
108 | Sink::Store::modify(account).then<void>([]() {}, | ||
109 | [](int errorCode, const QString &errorMessage) { | ||
110 | qWarning() << "Error while creating account: " << errorMessage; | ||
111 | }) | ||
112 | .exec(); | ||
113 | |||
105 | if (!mIdentifier.isEmpty()) { | 114 | if (!mIdentifier.isEmpty()) { |
106 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); | 115 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); |
107 | resource.setProperty("path", mPath); | 116 | resource.setProperty("path", mPath); |
@@ -117,12 +126,8 @@ void MaildirSettings::save() | |||
117 | resource.setProperty("path", property("path")); | 126 | resource.setProperty("path", property("path")); |
118 | resource.setProperty("identifier", resourceIdentifier); | 127 | resource.setProperty("identifier", resourceIdentifier); |
119 | resource.setProperty("type", "org.kde.maildir"); | 128 | resource.setProperty("type", "org.kde.maildir"); |
120 | Sink::Store::create(resource).then<void>([this, resourceIdentifier]() { | 129 | resource.setProperty("account", mAccountIdentifier); |
121 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | 130 | Sink::Store::create(resource).then<void>([]() {}, |
122 | Kube::Account account(mAccountIdentifier); | ||
123 | account.setProperty("maildirResource", resourceIdentifier); | ||
124 | account.save(); | ||
125 | }, | ||
126 | [](int errorCode, const QString &errorMessage) { | 131 | [](int errorCode, const QString &errorMessage) { |
127 | qWarning() << "Error while creating resource: " << errorMessage; | 132 | qWarning() << "Error while creating resource: " << errorMessage; |
128 | }) | 133 | }) |
@@ -136,20 +141,18 @@ void MaildirSettings::remove() | |||
136 | qWarning() << "We're missing an identifier"; | 141 | qWarning() << "We're missing an identifier"; |
137 | } else { | 142 | } else { |
138 | Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 143 | Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
139 | Sink::Store::remove(resource).then<void>([this]() { | 144 | Sink::Store::remove(resource).then<void>([]() {}, |
140 | Kube::Account account(mAccountIdentifier); | ||
141 | account.remove(); | ||
142 | |||
143 | Kube::Settings settings("accounts"); | ||
144 | auto accounts = settings.property("accounts").toStringList(); | ||
145 | accounts.removeAll(mAccountIdentifier); | ||
146 | settings.setProperty("accounts", accounts); | ||
147 | settings.save(); | ||
148 | }, | ||
149 | [](int errorCode, const QString &errorMessage) { | 145 | [](int errorCode, const QString &errorMessage) { |
150 | qWarning() << "Error while removing resource: " << errorMessage; | 146 | qWarning() << "Error while removing resource: " << errorMessage; |
151 | }) | 147 | }) |
152 | .exec(); | 148 | .exec(); |
149 | |||
150 | Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
151 | Sink::Store::remove(account).then<void>([]() {}, | ||
152 | [](int errorCode, const QString &errorMessage) { | ||
153 | qWarning() << "Error while removing account: " << errorMessage; | ||
154 | }) | ||
155 | .exec(); | ||
153 | } | 156 | } |
154 | } | 157 | } |
155 | 158 | ||