diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-03 20:24:09 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-03 20:24:26 +0200 |
commit | e06e1dad4a4570e5c1181d05ab6ed7a5d74c6c91 (patch) | |
tree | ef606d36ee693eff087292a1950fe122a7376f19 /framework/actions/actionhandler.cpp | |
parent | 21f7851f044cd8b6e38c821ce12d7e1b291cae27 (diff) | |
download | kube-e06e1dad4a4570e5c1181d05ab6ed7a5d74c6c91.tar.gz kube-e06e1dad4a4570e5c1181d05ab6ed7a5d74c6c91.zip |
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.
Diffstat (limited to 'framework/actions/actionhandler.cpp')
-rw-r--r-- | framework/actions/actionhandler.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
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) | |||
45 | return false; | 45 | return false; |
46 | } | 46 | } |
47 | 47 | ||
48 | void ActionHandler::execute(Context *context) | 48 | ActionResult ActionHandler::execute(Context *context) |
49 | { | 49 | { |
50 | ActionResult result; | ||
50 | QVariant returnedValue; | 51 | QVariant returnedValue; |
51 | qWarning() << "Executing the handler"; | 52 | qWarning() << "Executing the handler"; |
52 | if (context) { | 53 | if (context) { |
54 | //The base implementation to call the handler in QML | ||
53 | QMetaObject::invokeMethod(this, "handler", | 55 | QMetaObject::invokeMethod(this, "handler", |
54 | Q_RETURN_ARG(QVariant, returnedValue), | 56 | Q_RETURN_ARG(QVariant, returnedValue), |
55 | Q_ARG(QVariant, QVariant::fromValue(context))); | 57 | Q_ARG(QVariant, QVariant::fromValue(context))); |
58 | //TODO: support async handlers in QML | ||
59 | result.setDone(); | ||
56 | } else { | 60 | } else { |
57 | qWarning() << "The handler didn't get a context"; | 61 | qWarning() << "The handler didn't get a context"; |
62 | result.setDone(); | ||
63 | result.setError(1); | ||
58 | } | 64 | } |
65 | return result; | ||
59 | } | 66 | } |
60 | 67 | ||
61 | void ActionHandler::setActionId(const QByteArray &actionId) | 68 | void ActionHandler::setActionId(const QByteArray &actionId) |
@@ -79,12 +86,36 @@ ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsRea | |||
79 | setActionId(actionId); | 86 | setActionId(actionId); |
80 | } | 87 | } |
81 | 88 | ||
89 | ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const JobHandler &handler) | ||
90 | : ActionHandler(nullptr), | ||
91 | isReadyFunction(isReady), | ||
92 | jobHandlerFunction(handler) | ||
93 | { | ||
94 | setActionId(actionId); | ||
95 | } | ||
96 | |||
82 | bool ActionHandlerHelper::isActionReady(Context *context) | 97 | bool ActionHandlerHelper::isActionReady(Context *context) |
83 | { | 98 | { |
84 | return isReadyFunction(context); | 99 | return isReadyFunction(context); |
85 | } | 100 | } |
86 | 101 | ||
87 | void ActionHandlerHelper::execute(Context *context) | 102 | ActionResult ActionHandlerHelper::execute(Context *context) |
88 | { | 103 | { |
89 | handlerFunction(context); | 104 | ActionResult result; |
105 | if (handlerFunction) { | ||
106 | handlerFunction(context); | ||
107 | result.setDone(); | ||
108 | } else { | ||
109 | jobHandlerFunction(context).then<void>([=]() { | ||
110 | auto modifyableResult = result; | ||
111 | modifyableResult.setDone(); | ||
112 | }, | ||
113 | [=](int errorCode, const QString &string) { | ||
114 | qWarning() << "Job failed: " << errorCode << string; | ||
115 | auto modifyableResult = result; | ||
116 | modifyableResult.setError(1); | ||
117 | modifyableResult.setDone(); | ||
118 | }).exec(); | ||
119 | } | ||
120 | return result; | ||
90 | } | 121 | } |