diff options
Diffstat (limited to 'accounts/maildir/maildirsettings.cpp')
-rw-r--r-- | accounts/maildir/maildirsettings.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index fa30851c..e47b834f 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp | |||
@@ -82,6 +82,18 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) | |||
82 | [](int errorCode, const QString &errorMessage) { | 82 | [](int errorCode, const QString &errorMessage) { |
83 | qWarning() << "Failed to find the maildir resource: " << errorMessage; | 83 | qWarning() << "Failed to find the maildir resource: " << errorMessage; |
84 | }).exec(); | 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::PropertyFilter("account", QVariant::fromValue(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(); | ||
85 | } | 97 | } |
86 | 98 | ||
87 | QByteArray MaildirSettings::accountIdentifier() const | 99 | QByteArray MaildirSettings::accountIdentifier() const |
@@ -207,6 +219,27 @@ void MaildirSettings::save() | |||
207 | }) | 219 | }) |
208 | .exec(); | 220 | .exec(); |
209 | } | 221 | } |
222 | |||
223 | if (!mIdentityIdentifier.isEmpty()) { | ||
224 | Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); | ||
225 | identity.setProperty("username", mUsername); | ||
226 | identity.setProperty("address", mEmailAddress); | ||
227 | Sink::Store::modify(identity).then<void>([](){}, [](int errorCode, const QString &errorMessage) { | ||
228 | qWarning() << "Error while modifying identity: " << errorMessage; | ||
229 | }) | ||
230 | .exec(); | ||
231 | } else { | ||
232 | auto identity = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Identity>(); | ||
233 | mIdentityIdentifier = identity.identifier(); | ||
234 | identity.setProperty("account", mAccountIdentifier); | ||
235 | identity.setProperty("username", mUsername); | ||
236 | identity.setProperty("address", mEmailAddress); | ||
237 | Sink::Store::create(identity).then<void>([]() {}, | ||
238 | [](int errorCode, const QString &errorMessage) { | ||
239 | qWarning() << "Error while creating identity: " << errorMessage; | ||
240 | }) | ||
241 | .exec(); | ||
242 | } | ||
210 | } | 243 | } |
211 | 244 | ||
212 | void MaildirSettings::remove() | 245 | void MaildirSettings::remove() |