From ba7128b30850594c7efb258d1794e377eede364a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 1 Jan 2017 13:37:19 +0100 Subject: Instead of using the action system we use controllers only. It's simpler, and the action system was just too complex to use in a typesafe way. --- framework/domain/actions/sinkactions.cpp | 74 ++++---------------------------- 1 file changed, 9 insertions(+), 65 deletions(-) (limited to 'framework/domain/actions/sinkactions.cpp') diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index fd791a91..a2d4c02c 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -16,7 +16,7 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include + #include #include @@ -78,12 +78,18 @@ static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete", } ); +class FolderContext : public Kube::ContextWrapper { + using Kube::ContextWrapper::ContextWrapper; + KUBE_CONTEXTWRAPPER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder) +}; + static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize", [](Context *context) -> bool { return true; }, - [](Context *context) { - if (auto folder = context->property("folder").value()) { + [](Context *context_) { + auto context = FolderContext{*context_}; + if (auto folder = context.getFolder()) { SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier(); auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter(QVariant::fromValue(folder->identifier())); scope.setType(); @@ -110,65 +116,3 @@ static ActionHandlerHelper sendOutboxHandler("org.kde.kube.actions.sendOutbox", }} ); -static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", - [](Context *context) -> bool { - auto accountId = context->property("accountId").value(); - return !accountId.isEmpty(); - }, - ActionHandlerHelper::JobHandler{[](Context *context) -> KAsync::Job { - auto accountId = context->property("accountId").value(); - auto message = context->property("message").value(); - SinkLog() << "Sending a mail: " << *context; - - Query query; - query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::transport); - query.filter(accountId); - return Store::fetchAll(query) - .then>([=](const QList &resources) -> KAsync::Job { - if (!resources.isEmpty()) { - auto resourceId = resources[0]->identifier(); - SinkTrace() << "Sending message via resource: " << resourceId; - Mail mail(resourceId); - mail.setBlobProperty("mimeMessage", message->encodedContent()); - return Store::create(mail); - } - SinkWarning() << "Failed to find a mailtransport resource"; - return KAsync::error(0, "Failed to find a MailTransport resource."); - }); - }} -); - -static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", - [](Context *context) -> bool { - auto accountId = context->property("accountId").value(); - 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(); - if (!message) { - SinkWarning() << "Failed to get the mail: " << context->property("mail"); - return KAsync::error(1, "Failed to get the mail: " + context->property("mail").toString()); - } - - if (existingMail.identifier().isEmpty()) { - Query query; - query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::drafts); - query.filter(accountId); - return Store::fetchOne(query) - .then([=](const SinkResource &resource) -> KAsync::Job { - Mail mail(resource.identifier()); - mail.setDraft(true); - mail.setMimeMessage(message->encodedContent()); - return Store::create(mail); - }); - } else { - SinkWarning() << "Modifying an existing mail" << existingMail.identifier(); - existingMail.setMimeMessage(message->encodedContent()); - return Store::modify(existingMail); - } - }) -); -- cgit v1.2.3