summaryrefslogtreecommitdiffstats
path: root/framework/domain/actions/sinkactions.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-13 16:24:31 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-16 14:54:14 +0100
commit630f45719a527f8ee739b03bc62f886badea6df3 (patch)
treeb9d859cbfedb30ad8a9570e3b87a419bf24ba6c7 /framework/domain/actions/sinkactions.cpp
parentb1a2e2de201985a00980bead5272977cda4ef637 (diff)
downloadkube-630f45719a527f8ee739b03bc62f886badea6df3.tar.gz
kube-630f45719a527f8ee739b03bc62f886badea6df3.zip
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.
Diffstat (limited to 'framework/domain/actions/sinkactions.cpp')
-rw-r--r--framework/domain/actions/sinkactions.cpp15
1 files changed, 7 insertions, 8 deletions
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"
98static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", 98static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail",
99 [](Context *context) -> bool { 99 [](Context *context) -> bool {
100 auto accountId = context->property("accountId").value<QByteArray>(); 100 auto accountId = context->property("accountId").value<QByteArray>();
101 auto message = context->property("message").value<KMime::Message::Ptr>(); 101 return !accountId.isEmpty();
102 return !accountId.isEmpty() && message;
103 }, 102 },
104 [](Context *context) { 103 ActionHandlerHelper::JobHandler{[](Context *context) -> KAsync::Job<void> {
105 auto accountId = context->property("accountId").value<QByteArray>(); 104 auto accountId = context->property("accountId").value<QByteArray>();
106 auto message = context->property("message").value<KMime::Message::Ptr>(); 105 auto message = context->property("message").value<KMime::Message::Ptr>();
107 SinkLog() << "Sending a mail: "; 106 SinkLog() << "Sending a mail: ";
@@ -109,7 +108,7 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail",
109 Query query; 108 Query query;
110 query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); 109 query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport);
111 query.filter<SinkResource::Account>(accountId); 110 query.filter<SinkResource::Account>(accountId);
112 Store::fetchAll<ApplicationDomain::SinkResource>(query) 111 return Store::fetchAll<ApplicationDomain::SinkResource>(query)
113 .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> { 112 .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> {
114 if (!resources.isEmpty()) { 113 if (!resources.isEmpty()) {
115 auto resourceId = resources[0]->identifier(); 114 auto resourceId = resources[0]->identifier();
@@ -120,18 +119,18 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail",
120 } 119 }
121 SinkWarning() << "Failed to find a mailtransport resource"; 120 SinkWarning() << "Failed to find a mailtransport resource";
122 return KAsync::error<void>(0, "Failed to find a MailTransport resource."); 121 return KAsync::error<void>(0, "Failed to find a MailTransport resource.");
123 }).exec(); 122 });
124 } 123 }}
125); 124);
126 125
127static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", 126static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft",
128 [](Context *context) -> bool { 127 [](Context *context) -> bool {
129 auto accountId = context->property("accountId").value<QByteArray>(); 128 auto accountId = context->property("accountId").value<QByteArray>();
130 auto message = context->property("message").value<KMime::Message::Ptr>(); 129 return !accountId.isEmpty();
131 return !accountId.isEmpty() && message;
132 }, 130 },
133 ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> { 131 ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> {
134 SinkLog() << "Executing the save-as-draft action"; 132 SinkLog() << "Executing the save-as-draft action";
133 SinkLog() << *context;
135 const auto accountId = context->property("accountId").value<QByteArray>(); 134 const auto accountId = context->property("accountId").value<QByteArray>();
136 const auto message = context->property("message").value<KMime::Message::Ptr>(); 135 const auto message = context->property("message").value<KMime::Message::Ptr>();
137 auto existingMail = context->property("existingMail").value<Mail>(); 136 auto existingMail = context->property("existingMail").value<Mail>();