From e06e1dad4a4570e5c1181d05ab6ed7a5d74c6c91 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 3 May 2016 20:24:09 +0200 Subject: A save-as-draft action & action results This patch introduces tracking of actions, so they can be tested. It also provides a save-as-draft action, that looks for the draft folder, and stores the mail accordingly. --- framework/actions/actionhandler.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'framework/actions/actionhandler.cpp') diff --git a/framework/actions/actionhandler.cpp b/framework/actions/actionhandler.cpp index d4b01734..4ae8d0a9 100644 --- a/framework/actions/actionhandler.cpp +++ b/framework/actions/actionhandler.cpp @@ -45,17 +45,24 @@ bool ActionHandler::isActionReady(Context *context) return false; } -void ActionHandler::execute(Context *context) +ActionResult ActionHandler::execute(Context *context) { + ActionResult result; QVariant returnedValue; qWarning() << "Executing the handler"; if (context) { + //The base implementation to call the handler in QML QMetaObject::invokeMethod(this, "handler", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, QVariant::fromValue(context))); + //TODO: support async handlers in QML + result.setDone(); } else { qWarning() << "The handler didn't get a context"; + result.setDone(); + result.setError(1); } + return result; } void ActionHandler::setActionId(const QByteArray &actionId) @@ -79,12 +86,36 @@ ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsRea setActionId(actionId); } +ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const JobHandler &handler) + : ActionHandler(nullptr), + isReadyFunction(isReady), + jobHandlerFunction(handler) +{ + setActionId(actionId); +} + bool ActionHandlerHelper::isActionReady(Context *context) { return isReadyFunction(context); } -void ActionHandlerHelper::execute(Context *context) +ActionResult ActionHandlerHelper::execute(Context *context) { - handlerFunction(context); + ActionResult result; + if (handlerFunction) { + handlerFunction(context); + result.setDone(); + } else { + jobHandlerFunction(context).then([=]() { + auto modifyableResult = result; + modifyableResult.setDone(); + }, + [=](int errorCode, const QString &string) { + qWarning() << "Job failed: " << errorCode << string; + auto modifyableResult = result; + modifyableResult.setError(1); + modifyableResult.setDone(); + }).exec(); + } + return result; } -- cgit v1.2.3