From 19e1588c025f518b20d3169c65ea71b739aea2e8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 10 May 2016 15:01:07 +0200 Subject: Use the capability filter to avoid hardcoding resources --- accounts/maildir/maildirsettings.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'accounts') diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index 96b75a1e..c66f9729 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp @@ -57,7 +57,7 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) emit changed(); }).exec(); - Sink::Store::fetchOne(Sink::Query::PropertyFilter("account", QVariant::fromValue(id)) + Sink::Query::PropertyFilter("type", QString("org.kde.maildir"))) + Sink::Store::fetchOne(Sink::Query::AccountFilter(id) + Sink::Query::CapabilityFilter("storage")) .then([this](const Sink::ApplicationDomain::SinkResource &resource) { mIdentifier = resource.identifier(); auto path = resource.getProperty("path").toString(); @@ -70,7 +70,7 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) qWarning() << "Failed to find the maildir resource: " << errorMessage; }).exec(); - Sink::Store::fetchOne(Sink::Query::PropertyFilter("account", QVariant::fromValue(id)) + Sink::Query::PropertyFilter("type", QString("org.kde.mailtransport"))) + Sink::Store::fetchOne(Sink::Query::AccountFilter(id) + Sink::Query::CapabilityFilter("transport")) .then([this](const Sink::ApplicationDomain::SinkResource &resource) { mMailtransportIdentifier = resource.identifier(); mSmtpServer = resource.getProperty("server").toString(); @@ -83,7 +83,7 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) }).exec(); //FIXME this assumes that we only ever have one identity per account - Sink::Store::fetchOne(Sink::Query::PropertyFilter("account", QVariant::fromValue(id))) + Sink::Store::fetchOne(Sink::Query::AccountFilter(id)) .then([this](const Sink::ApplicationDomain::Identity &identity) { mIdentityIdentifier = identity.identifier(); mUsername = identity.getProperty("username").toString(); @@ -176,11 +176,9 @@ void MaildirSettings::save() }) .exec(); } else { - auto resource = Sink::ApplicationDomain::ApplicationDomainType::createEntity(); - mIdentifier = resource.identifier(); + auto resource = Sink::ApplicationDomain::MaildirResource::create(mAccountIdentifier); resource.setProperty("path", property("path")); - resource.setProperty("type", "org.kde.maildir"); - resource.setProperty("account", mAccountIdentifier); + mIdentifier = resource.identifier(); Sink::Store::create(resource).then([]() {}, [](int errorCode, const QString &errorMessage) { qWarning() << "Error while creating resource: " << errorMessage; @@ -198,10 +196,8 @@ void MaildirSettings::save() }) .exec(); } else { - auto resource = Sink::ApplicationDomain::ApplicationDomainType::createEntity(); + auto resource = Sink::ApplicationDomain::MailtransportResource::create(mAccountIdentifier); mMailtransportIdentifier = resource.identifier(); - resource.setProperty("type", "org.kde.mailtransport"); - resource.setProperty("account", mAccountIdentifier); resource.setProperty("server", mSmtpServer); resource.setProperty("username", mSmtpUsername); resource.setProperty("password", mSmtpPassword); -- cgit v1.2.3