summaryrefslogtreecommitdiffstats
path: root/framework/domain/actions/sinkactions.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-01 13:37:19 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-02 00:31:41 +0100
commitba7128b30850594c7efb258d1794e377eede364a (patch)
treef805d511f6d12b0799c05b414054db8b8635bfc9 /framework/domain/actions/sinkactions.cpp
parent431c257dd29e2e3d8878db200f0de4d452bffe92 (diff)
downloadkube-ba7128b30850594c7efb258d1794e377eede364a.tar.gz
kube-ba7128b30850594c7efb258d1794e377eede364a.zip
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.
Diffstat (limited to 'framework/domain/actions/sinkactions.cpp')
-rw-r--r--framework/domain/actions/sinkactions.cpp74
1 files changed, 9 insertions, 65 deletions
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 @@
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA. 17 02110-1301, USA.
18*/ 18*/
19#include <actions/context.h> 19
20#include <actions/actionhandler.h> 20#include <actions/actionhandler.h>
21 21
22#include <KMime/Message> 22#include <KMime/Message>
@@ -78,12 +78,18 @@ static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete",
78 } 78 }
79); 79);
80 80
81class FolderContext : public Kube::ContextWrapper {
82 using Kube::ContextWrapper::ContextWrapper;
83 KUBE_CONTEXTWRAPPER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder)
84};
85
81static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize", 86static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize",
82 [](Context *context) -> bool { 87 [](Context *context) -> bool {
83 return true; 88 return true;
84 }, 89 },
85 [](Context *context) { 90 [](Context *context_) {
86 if (auto folder = context->property("folder").value<Folder::Ptr>()) { 91 auto context = FolderContext{*context_};
92 if (auto folder = context.getFolder()) {
87 SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier(); 93 SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier();
88 auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<Mail::Folder>(QVariant::fromValue(folder->identifier())); 94 auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<Mail::Folder>(QVariant::fromValue(folder->identifier()));
89 scope.setType<ApplicationDomain::Mail>(); 95 scope.setType<ApplicationDomain::Mail>();
@@ -110,65 +116,3 @@ static ActionHandlerHelper sendOutboxHandler("org.kde.kube.actions.sendOutbox",
110 }} 116 }}
111); 117);
112 118
113static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail",
114 [](Context *context) -> bool {
115 auto accountId = context->property("accountId").value<QByteArray>();
116 return !accountId.isEmpty();
117 },
118 ActionHandlerHelper::JobHandler{[](Context *context) -> KAsync::Job<void> {
119 auto accountId = context->property("accountId").value<QByteArray>();
120 auto message = context->property("message").value<KMime::Message::Ptr>();
121 SinkLog() << "Sending a mail: " << *context;
122
123 Query query;
124 query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport);
125 query.filter<SinkResource::Account>(accountId);
126 return Store::fetchAll<ApplicationDomain::SinkResource>(query)
127 .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> {
128 if (!resources.isEmpty()) {
129 auto resourceId = resources[0]->identifier();
130 SinkTrace() << "Sending message via resource: " << resourceId;
131 Mail mail(resourceId);
132 mail.setBlobProperty("mimeMessage", message->encodedContent());
133 return Store::create(mail);
134 }
135 SinkWarning() << "Failed to find a mailtransport resource";
136 return KAsync::error<void>(0, "Failed to find a MailTransport resource.");
137 });
138 }}
139);
140
141static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft",
142 [](Context *context) -> bool {
143 auto accountId = context->property("accountId").value<QByteArray>();
144 return !accountId.isEmpty();
145 },
146 ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> {
147 SinkLog() << "Executing the save-as-draft action";
148 SinkLog() << *context;
149 const auto accountId = context->property("accountId").value<QByteArray>();
150 const auto message = context->property("message").value<KMime::Message::Ptr>();
151 auto existingMail = context->property("existingMail").value<Mail>();
152 if (!message) {
153 SinkWarning() << "Failed to get the mail: " << context->property("mail");
154 return KAsync::error<void>(1, "Failed to get the mail: " + context->property("mail").toString());
155 }
156
157 if (existingMail.identifier().isEmpty()) {
158 Query query;
159 query.containsFilter<SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::drafts);
160 query.filter<SinkResource::Account>(accountId);
161 return Store::fetchOne<SinkResource>(query)
162 .then<void, SinkResource>([=](const SinkResource &resource) -> KAsync::Job<void> {
163 Mail mail(resource.identifier());
164 mail.setDraft(true);
165 mail.setMimeMessage(message->encodedContent());
166 return Store::create(mail);
167 });
168 } else {
169 SinkWarning() << "Modifying an existing mail" << existingMail.identifier();
170 existingMail.setMimeMessage(message->encodedContent());
171 return Store::modify(existingMail);
172 }
173 })
174);