From 630f45719a527f8ee739b03bc62f886badea6df3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 13 Dec 2016 16:24:31 +0100 Subject: Revamp of composercontroller to use actions more. Instead of setting all properties individually we directly assign all properties to a context that we assign to the actions. This way actions can automatically update themselves as new data becomes available, and we avoid the setter/getter boilerplate, at the cost of a less explicit interface (But that could be improved by allowing to define the required properties of a context in c++). By relying on prehandler/posthandler to execute certain actions we simplify the control flow and enable the future extension with handlers that i.e. do encryption etc. --- framework/domain/actions/sinkactions.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'framework/domain/actions/sinkactions.cpp') diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index f996b91d..39b39a0a 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -98,10 +98,9 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", [](Context *context) -> bool { auto accountId = context->property("accountId").value(); - auto message = context->property("message").value(); - return !accountId.isEmpty() && message; + return !accountId.isEmpty(); }, - [](Context *context) { + ActionHandlerHelper::JobHandler{[](Context *context) -> KAsync::Job { auto accountId = context->property("accountId").value(); auto message = context->property("message").value(); SinkLog() << "Sending a mail: "; @@ -109,7 +108,7 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", Query query; query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::transport); query.filter(accountId); - Store::fetchAll(query) + return Store::fetchAll(query) .then>([=](const QList &resources) -> KAsync::Job { if (!resources.isEmpty()) { auto resourceId = resources[0]->identifier(); @@ -120,18 +119,18 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", } SinkWarning() << "Failed to find a mailtransport resource"; return KAsync::error(0, "Failed to find a MailTransport resource."); - }).exec(); - } + }); + }} ); static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", [](Context *context) -> bool { auto accountId = context->property("accountId").value(); - auto message = context->property("message").value(); - return !accountId.isEmpty() && message; + return !accountId.isEmpty(); }, ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job { SinkLog() << "Executing the save-as-draft action"; + SinkLog() << *context; const auto accountId = context->property("accountId").value(); const auto message = context->property("message").value(); auto existingMail = context->property("existingMail").value(); -- cgit v1.2.3