From 98e17d6a8ecd46a9d6956d81f781b05e940387e4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 15 Sep 2016 11:58:26 +0200 Subject: Adapt to KAsync changes. --- framework/actions/actionhandler.cpp | 12 ++-- framework/domain/accountfactory.cpp | 2 +- framework/domain/accountscontroller.cpp | 10 +-- framework/domain/actions/sinkactions.cpp | 4 +- framework/domain/composercontroller.cpp | 2 +- framework/domain/folderlistmodel.cpp | 2 +- framework/domain/identitiesmodel.cpp | 2 +- framework/domain/settings/accountsettings.cpp | 88 +++++++++++++-------------- 8 files changed, 59 insertions(+), 63 deletions(-) (limited to 'framework') diff --git a/framework/actions/actionhandler.cpp b/framework/actions/actionhandler.cpp index 4ae8d0a9..9d58f464 100644 --- a/framework/actions/actionhandler.cpp +++ b/framework/actions/actionhandler.cpp @@ -106,14 +106,12 @@ ActionResult ActionHandlerHelper::execute(Context *context) handlerFunction(context); result.setDone(); } else { - jobHandlerFunction(context).then([=]() { + jobHandlerFunction(context).syncThen([=](const KAsync::Error &error) { auto modifyableResult = result; - modifyableResult.setDone(); - }, - [=](int errorCode, const QString &string) { - qWarning() << "Job failed: " << errorCode << string; - auto modifyableResult = result; - modifyableResult.setError(1); + if (error) { + qWarning() << "Job failed: " << error.errorCode << error.errorMessage; + modifyableResult.setError(1); + } modifyableResult.setDone(); }).exec(); } diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp index 10f01f65..6261eaf1 100644 --- a/framework/domain/accountfactory.cpp +++ b/framework/domain/accountfactory.cpp @@ -44,7 +44,7 @@ void AccountFactory::setAccountId(const QString &accountId) { mAccountId = accountId; Sink::Store::fetchOne(Sink::Query::IdentityFilter(accountId.toUtf8())) - .then([this](const Sink::ApplicationDomain::SinkAccount &account) { + .syncThen([this](const Sink::ApplicationDomain::SinkAccount &account) { mAccountType = account.getProperty("type").toByteArray(); loadPackage(); }).exec(); diff --git a/framework/domain/accountscontroller.cpp b/framework/domain/accountscontroller.cpp index 2f47fa03..5cb60d0c 100644 --- a/framework/domain/accountscontroller.cpp +++ b/framework/domain/accountscontroller.cpp @@ -34,9 +34,9 @@ void AccountsController::createAccount(const QString &accountType) { auto account = Sink::ApplicationDomain::ApplicationDomainType::createEntity(); account.setProperty("type", accountType); - Sink::Store::create(account).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while creating account: " << errorMessage; - }) - .exec(); + Sink::Store::create(account).syncThen([](const KAsync::Error &error) { + if (error) { + qWarning() << "Error while creating account: " << error.errorMessage; + } + }).exec(); } diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index 921fe748..f8a4e9ff 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -106,7 +106,7 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport); query += Sink::Query::AccountFilter(accountId); Sink::Store::fetchAll(query) - .then, QList>([=](const QList &resources) -> KAsync::Job { + .then>([=](const QList &resources) -> KAsync::Job { if (!resources.isEmpty()) { auto resourceId = resources[0]->identifier(); SinkTrace() << "Sending message via resource: " << resourceId; @@ -141,7 +141,7 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::drafts); query += Sink::Query::AccountFilter(accountId); return Sink::Store::fetchOne(query) - .then, Sink::ApplicationDomain::SinkResource>([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job { + .then([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job { Sink::ApplicationDomain::Mail mail(resource.identifier()); mail.setProperty("draft", true); mail.setBlobProperty("mimeMessage", message->encodedContent()); diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 2dcf1bb1..b2ad7ecc 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp @@ -133,7 +133,7 @@ void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) { Sink::Query query(*message.value()); query.request(); - Sink::Store::fetchOne(query).then([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { + Sink::Store::fetchOne(query).syncThen([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { m_existingMail = mail; const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); if (!mailData.isEmpty()) { diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index 14d3d5a7..000dd263 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp @@ -74,7 +74,7 @@ void FolderListModel::setAccountId(const QVariant &accountId) { const auto account = accountId.toString().toUtf8(); Sink::Store::fetchAll(Sink::Query::PropertyFilter("account", QVariant::fromValue(account))) - .then>([this, account](const QList &resources) { + .syncThen>([this, account](const QList &resources) { Sink::Query query; query.liveQuery = true; query.requestedProperties << "name" << "icon" << "parent"; diff --git a/framework/domain/identitiesmodel.cpp b/framework/domain/identitiesmodel.cpp index adb5d625..1958d2f5 100644 --- a/framework/domain/identitiesmodel.cpp +++ b/framework/domain/identitiesmodel.cpp @@ -83,7 +83,7 @@ void IdentitiesModel::runQuery(const Sink::Query &query) setSourceModel(mModel.data()); Sink::Store::fetchAll(Sink::Query()) - .then >([this](const QList &accounts) { + .syncThen >([this](const QList &accounts) { for (const auto &account : accounts) { mAccountNames.insert(account->identifier(), account->getProperty("name").toString()); mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString()); diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index cf348f39..9a3be059 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp @@ -135,18 +135,18 @@ void AccountSettings::saveAccount() 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(); + Sink::Store::modify(account) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating account: " << error.errorMessage;; + }) + .exec(); } void AccountSettings::loadAccount() { Q_ASSERT(!mAccountIdentifier.isEmpty()); Sink::Store::fetchOne(Sink::Query::IdentityFilter(mAccountIdentifier)) - .then([this](const Sink::ApplicationDomain::SinkAccount &account) { + .syncThen([this](const Sink::ApplicationDomain::SinkAccount &account) { mIcon = account.getProperty("icon").toString(); mName = account.getProperty("name").toString(); emit changed(); @@ -156,46 +156,43 @@ void AccountSettings::loadAccount() void AccountSettings::loadImapResource() { Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) - .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mImapIdentifier = resource.identifier(); mImapServer = resource.getProperty("server").toString(); mImapUsername = resource.getProperty("username").toString(); mImapPassword = resource.getProperty("password").toString(); emit imapResourceChanged(); - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the imap resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the imap resource: " << error.errorMessage; }).exec(); } void AccountSettings::loadMaildirResource() { Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) - .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mMaildirIdentifier = resource.identifier(); auto path = resource.getProperty("path").toString(); if (mPath != path) { mPath = path; emit pathChanged(); } - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the maildir resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the maildir resource: " << error.errorMessage; }).exec(); } void AccountSettings::loadMailtransportResource() { Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) - .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mMailtransportIdentifier = resource.identifier(); mSmtpServer = resource.getProperty("server").toString(); mSmtpUsername = resource.getProperty("username").toString(); mSmtpPassword = resource.getProperty("password").toString(); emit smtpResourceChanged(); - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the smtp resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the smtp resource: " << error.errorMessage; }).exec(); } @@ -203,14 +200,13 @@ void AccountSettings::loadIdentity() { //FIXME this assumes that we only ever have one identity per account Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier)) - .then([this](const Sink::ApplicationDomain::Identity &identity) { + .syncThen([this](const Sink::ApplicationDomain::Identity &identity) { mIdentityIdentifier = identity.identifier(); mUsername = identity.getProperty("username").toString(); mEmailAddress = identity.getProperty("address").toString(); emit identityChanged(); - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the identity resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the identity resource: " << error.errorMessage; }).exec(); } @@ -224,21 +220,22 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA for (const auto &pair : properties) { resource.setProperty(pair.first, pair.second); } - Sink::Store::modify(resource).then([](){}, [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while modifying resource: " << errorMessage; - }) - .exec(); + Sink::Store::modify(resource) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while modifying resource: " << error.errorMessage; + }) + .exec(); } else { auto resource = ResourceType::create(accountIdentifier); auto newIdentifier = resource.identifier(); for (const auto &pair : properties) { resource.setProperty(pair.first, pair.second); } - Sink::Store::create(resource).template then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while creating resource: " << errorMessage; - }) - .exec(); + Sink::Store::create(resource) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating resource: " << error.errorMessage; + }) + .exec(); return newIdentifier; } return identifier; @@ -275,8 +272,9 @@ void AccountSettings::saveIdentity() Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); identity.setProperty("username", mUsername); identity.setProperty("address", mEmailAddress); - Sink::Store::modify(identity).then([](){}, [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while modifying identity: " << errorMessage; + Sink::Store::modify(identity) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while modifying identity: " << error.errorMessage; }) .exec(); } else { @@ -285,9 +283,9 @@ void AccountSettings::saveIdentity() identity.setProperty("account", mAccountIdentifier); identity.setProperty("username", mUsername); identity.setProperty("address", mEmailAddress); - Sink::Store::create(identity).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while creating identity: " << errorMessage; + Sink::Store::create(identity) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating identity: " << error.errorMessage; }) .exec(); } @@ -299,9 +297,9 @@ void AccountSettings::removeResource(const QByteArray &identifier) qWarning() << "We're missing an identifier"; } else { Sink::ApplicationDomain::SinkResource resource("", identifier, 0, QSharedPointer::create()); - Sink::Store::remove(resource).template then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while removing resource: " << errorMessage; + Sink::Store::remove(resource) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while removing resource: " << error.errorMessage; }) .exec(); } @@ -313,9 +311,9 @@ void AccountSettings::removeAccount() qWarning() << "We're missing an identifier"; } else { Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer::create()); - Sink::Store::remove(account).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while removing account: " << errorMessage; + Sink::Store::remove(account) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while removing account: " << error.errorMessage; }) .exec(); } @@ -327,9 +325,9 @@ void AccountSettings::removeIdentity() qWarning() << "We're missing an identifier"; } else { Sink::ApplicationDomain::Identity identity("", mIdentityIdentifier, 0, QSharedPointer::create()); - Sink::Store::remove(identity).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while removing identity: " << errorMessage; + Sink::Store::remove(identity) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while removing identity: " << error.errorMessage; }) .exec(); } -- cgit v1.2.3