summaryrefslogtreecommitdiffstats
path: root/framework/domain/actions/sinkactions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/actions/sinkactions.cpp')
-rw-r--r--framework/domain/actions/sinkactions.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp
index 921fe748..cc8d324e 100644
--- a/framework/domain/actions/sinkactions.cpp
+++ b/framework/domain/actions/sinkactions.cpp
@@ -28,20 +28,22 @@
28SINK_DEBUG_AREA("sinkactions") 28SINK_DEBUG_AREA("sinkactions")
29 29
30using namespace Kube; 30using namespace Kube;
31using namespace Sink;
32using namespace Sink::ApplicationDomain;
31 33
32static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read", 34static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read",
33 [](Context *context) -> bool { 35 [](Context *context) -> bool {
34 return context->property("mail").isValid(); 36 return context->property("mail").isValid();
35 }, 37 },
36 [](Context *context) { 38 [](Context *context) {
37 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); 39 auto mail = context->property("mail").value<Mail::Ptr>();
38 if (!mail) { 40 if (!mail) {
39 SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); 41 SinkWarning() << "Failed to get the mail mail: " << context->property("mail");
40 return; 42 return;
41 } 43 }
42 mail->setProperty("unread", false); 44 mail->setProperty("unread", false);
43 SinkLog() << "Mark as read " << mail->identifier(); 45 SinkLog() << "Mark as read " << mail->identifier();
44 Sink::Store::modify(*mail).exec(); 46 Store::modify(*mail).exec();
45 } 47 }
46); 48);
47 49
@@ -50,14 +52,14 @@ static ActionHandlerHelper moveToTrashHandler("org.kde.kube.actions.move-to-tras
50 return context->property("mail").isValid(); 52 return context->property("mail").isValid();
51 }, 53 },
52 [](Context *context) { 54 [](Context *context) {
53 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); 55 auto mail = context->property("mail").value<Mail::Ptr>();
54 if (!mail) { 56 if (!mail) {
55 SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); 57 SinkWarning() << "Failed to get the mail mail: " << context->property("mail");
56 return; 58 return;
57 } 59 }
58 mail->setTrash(true); 60 mail->setTrash(true);
59 SinkLog() << "Move to trash " << mail->identifier(); 61 SinkLog() << "Move to trash " << mail->identifier();
60 Sink::Store::modify(*mail).exec(); 62 Store::modify(*mail).exec();
61 } 63 }
62); 64);
63 65
@@ -66,13 +68,13 @@ static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete",
66 return context->property("mail").isValid(); 68 return context->property("mail").isValid();
67 }, 69 },
68 [](Context *context) { 70 [](Context *context) {
69 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); 71 auto mail = context->property("mail").value<Mail::Ptr>();
70 if (!mail) { 72 if (!mail) {
71 SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); 73 SinkWarning() << "Failed to get the mail mail: " << context->property("mail");
72 return; 74 return;
73 } 75 }
74 SinkLog() << "Remove " << mail->identifier(); 76 SinkLog() << "Remove " << mail->identifier();
75 Sink::Store::remove(*mail).exec(); 77 Store::remove(*mail).exec();
76 } 78 }
77); 79);
78 80
@@ -81,12 +83,12 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize"
81 return true; 83 return true;
82 }, 84 },
83 [](Context *context) { 85 [](Context *context) {
84 if (auto folder = context->property("folder").value<Sink::ApplicationDomain::Folder::Ptr>()) { 86 if (auto folder = context->property("folder").value<Folder::Ptr>()) {
85 SinkLog() << "Synchronizing resource " << folder->resourceInstanceIdentifier(); 87 SinkLog() << "Synchronizing resource " << folder->resourceInstanceIdentifier();
86 Sink::Store::synchronize(Sink::Query::ResourceFilter(folder->resourceInstanceIdentifier())).exec(); 88 Store::synchronize(Query().resourceFilter(folder->resourceInstanceIdentifier())).exec();
87 } else { 89 } else {
88 SinkLog() << "Synchronizing all"; 90 SinkLog() << "Synchronizing all";
89 Sink::Store::synchronize(Sink::Query()).exec(); 91 Store::synchronize(Query()).exec();
90 } 92 }
91 } 93 }
92); 94);
@@ -102,17 +104,17 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail",
102 auto message = context->property("message").value<KMime::Message::Ptr>(); 104 auto message = context->property("message").value<KMime::Message::Ptr>();
103 SinkLog() << "Sending a mail: "; 105 SinkLog() << "Sending a mail: ";
104 106
105 Sink::Query query; 107 Query query;
106 query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport); 108 query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport);
107 query += Sink::Query::AccountFilter(accountId); 109 query.filter<SinkResource::Account>(accountId);
108 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(query) 110 Store::fetchAll<ApplicationDomain::SinkResource>(query)
109 .then<void, KAsync::Job<void>, QList<Sink::ApplicationDomain::SinkResource::Ptr>>([=](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> { 111 .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> {
110 if (!resources.isEmpty()) { 112 if (!resources.isEmpty()) {
111 auto resourceId = resources[0]->identifier(); 113 auto resourceId = resources[0]->identifier();
112 SinkTrace() << "Sending message via resource: " << resourceId; 114 SinkTrace() << "Sending message via resource: " << resourceId;
113 Sink::ApplicationDomain::Mail mail(resourceId); 115 Mail mail(resourceId);
114 mail.setBlobProperty("mimeMessage", message->encodedContent()); 116 mail.setBlobProperty("mimeMessage", message->encodedContent());
115 return Sink::Store::create(mail); 117 return Store::create(mail);
116 } 118 }
117 SinkWarning() << "Failed to find a mailtransport resource"; 119 SinkWarning() << "Failed to find a mailtransport resource";
118 return KAsync::error<void>(0, "Failed to find a MailTransport resource."); 120 return KAsync::error<void>(0, "Failed to find a MailTransport resource.");
@@ -127,30 +129,30 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft",
127 return !accountId.isEmpty() && message; 129 return !accountId.isEmpty() && message;
128 }, 130 },
129 ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> { 131 ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> {
130 SinkWarning() << "executing save as draft"; 132 SinkLog() << "Executing the save-as-draft action";
131 const auto accountId = context->property("accountId").value<QByteArray>(); 133 const auto accountId = context->property("accountId").value<QByteArray>();
132 const auto message = context->property("message").value<KMime::Message::Ptr>(); 134 const auto message = context->property("message").value<KMime::Message::Ptr>();
133 auto existingMail = context->property("existingMail").value<Sink::ApplicationDomain::Mail>(); 135 auto existingMail = context->property("existingMail").value<Mail>();
134 if (!message) { 136 if (!message) {
135 SinkWarning() << "Failed to get the mail: " << context->property("mail"); 137 SinkWarning() << "Failed to get the mail: " << context->property("mail");
136 return KAsync::error<void>(1, "Failed to get the mail: " + context->property("mail").toString()); 138 return KAsync::error<void>(1, "Failed to get the mail: " + context->property("mail").toString());
137 } 139 }
138 140
139 if (existingMail.identifier().isEmpty()) { 141 if (existingMail.identifier().isEmpty()) {
140 Sink::Query query; 142 Query query;
141 query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::drafts); 143 query.containsFilter<SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::drafts);
142 query += Sink::Query::AccountFilter(accountId); 144 query.filter<SinkResource::Account>(accountId);
143 return Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(query) 145 return Store::fetchOne<SinkResource>(query)
144 .then<void, KAsync::Job<void>, Sink::ApplicationDomain::SinkResource>([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job<void> { 146 .then<void, SinkResource>([=](const SinkResource &resource) -> KAsync::Job<void> {
145 Sink::ApplicationDomain::Mail mail(resource.identifier()); 147 Mail mail(resource.identifier());
146 mail.setProperty("draft", true); 148 mail.setDraft(true);
147 mail.setBlobProperty("mimeMessage", message->encodedContent()); 149 mail.setMimeMessage(message->encodedContent());
148 return Sink::Store::create(mail); 150 return Store::create(mail);
149 }); 151 });
150 } else { 152 } else {
151 SinkWarning() << "Modifying an existing mail" << existingMail.identifier(); 153 SinkWarning() << "Modifying an existing mail" << existingMail.identifier();
152 existingMail.setBlobProperty("mimeMessage", message->encodedContent()); 154 existingMail.setMimeMessage(message->encodedContent());
153 return Sink::Store::modify(existingMail); 155 return Store::modify(existingMail);
154 } 156 }
155 }) 157 })
156); 158);