From b0d06e04e4f4a0c8645288d4a31449215ce58770 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 17 Mar 2016 20:59:19 +0100 Subject: Store accounts in sink --- accounts/maildir/maildirsettings.cpp | 75 +++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'accounts/maildir/maildirsettings.cpp') 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) { } -void MaildirSettings::setIdentifier(const QByteArray &id) -{ - mIdentifier = id; - Sink::Store::fetchOne(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList() << "path")) - .then([this](const Sink::ApplicationDomain::SinkResource &resource) { - auto path = resource.getProperty("path").toString(); - if (mPath != path) { - mPath = path; - emit pathChanged(); - } - }).exec(); -} - -QByteArray MaildirSettings::identifier() const -{ - return mIdentifier; -} void MaildirSettings::setAccountIdentifier(const QByteArray &id) { @@ -56,9 +39,22 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) } mAccountIdentifier = id; Q_ASSERT(!id.isEmpty()); - Kube::Account account(id); - auto maildirResource = account.property("maildirResource").toByteArray(); - setIdentifier(maildirResource); + Sink::Store::fetchOne(Sink::Query::IdentityFilter(id)) + .then([this](const Sink::ApplicationDomain::SinkAccount &account) { + mIcon = account.getProperty("icon").toString(); + mName = account.getProperty("name").toString(); + emit changed(); + }).exec(); + + Sink::Store::fetchOne(Sink::Query::PropertyFilter("account", QVariant::fromValue(id))) + .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + mIdentifier = resource.identifier(); + auto path = resource.getProperty("path").toString(); + if (mPath != path) { + mPath = path; + emit pathChanged(); + } + }).exec(); } QByteArray MaildirSettings::accountIdentifier() const @@ -102,6 +98,19 @@ void MaildirSettings::save() qWarning() << "The path doesn't exist: " << mPath; return; } + qDebug() << "Saving account " << mAccountIdentifier << mIdentifier; + Q_ASSERT(!mAccountIdentifier.isEmpty()); + Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier); + account.setProperty("type", "maildir"); + account.setProperty("name", mName); + account.setProperty("icon", mIcon); + Q_ASSERT(!account.identifier().isEmpty()); + Sink::Store::modify(account).then([]() {}, + [](int errorCode, const QString &errorMessage) { + qWarning() << "Error while creating account: " << errorMessage; + }) + .exec(); + if (!mIdentifier.isEmpty()) { Sink::ApplicationDomain::SinkResource resource(mIdentifier); resource.setProperty("path", mPath); @@ -117,12 +126,8 @@ void MaildirSettings::save() resource.setProperty("path", property("path")); resource.setProperty("identifier", resourceIdentifier); resource.setProperty("type", "org.kde.maildir"); - Sink::Store::create(resource).then([this, resourceIdentifier]() { - Q_ASSERT(!mAccountIdentifier.isEmpty()); - Kube::Account account(mAccountIdentifier); - account.setProperty("maildirResource", resourceIdentifier); - account.save(); - }, + resource.setProperty("account", mAccountIdentifier); + Sink::Store::create(resource).then([]() {}, [](int errorCode, const QString &errorMessage) { qWarning() << "Error while creating resource: " << errorMessage; }) @@ -136,20 +141,18 @@ void MaildirSettings::remove() qWarning() << "We're missing an identifier"; } else { Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer::create()); - Sink::Store::remove(resource).then([this]() { - Kube::Account account(mAccountIdentifier); - account.remove(); - - Kube::Settings settings("accounts"); - auto accounts = settings.property("accounts").toStringList(); - accounts.removeAll(mAccountIdentifier); - settings.setProperty("accounts", accounts); - settings.save(); - }, + Sink::Store::remove(resource).then([]() {}, [](int errorCode, const QString &errorMessage) { qWarning() << "Error while removing resource: " << errorMessage; }) .exec(); + + Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer::create()); + Sink::Store::remove(account).then([]() {}, + [](int errorCode, const QString &errorMessage) { + qWarning() << "Error while removing account: " << errorMessage; + }) + .exec(); } } -- cgit v1.2.3