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