summaryrefslogtreecommitdiffstats
path: root/framework/mail/actions/sinkactions.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-21 11:46:46 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-21 11:46:46 +0100
commit42d34555397dd62399233fac1fbfa216c255ef68 (patch)
treebe2a6cd0442915bbc39243d8423d717c8727fa25 /framework/mail/actions/sinkactions.cpp
parentbf96cfa0d75d256e036c76ec64f0f456014f2739 (diff)
downloadkube-42d34555397dd62399233fac1fbfa216c255ef68.tar.gz
kube-42d34555397dd62399233fac1fbfa216c255ef68.zip
Akonadi2 -> Sink
Diffstat (limited to 'framework/mail/actions/sinkactions.cpp')
-rw-r--r--framework/mail/actions/sinkactions.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/framework/mail/actions/sinkactions.cpp b/framework/mail/actions/sinkactions.cpp
new file mode 100644
index 00000000..8918f996
--- /dev/null
+++ b/framework/mail/actions/sinkactions.cpp
@@ -0,0 +1,75 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "sinkactions.h"
20
21#include <actions/context.h>
22
23#include <sinkcommon/clientapi.h>
24
25using namespace Kube;
26
27ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const std::function<bool(Context*)> &isReady, const std::function<void(Context*)> &handler)
28 : ActionHandler(nullptr),
29 isReadyFunction(isReady),
30 handlerFunction(handler)
31{
32 setActionId(actionId);
33}
34
35bool ActionHandlerHelper::isActionReady(Context *context)
36{
37 return isReadyFunction(context);
38}
39
40void ActionHandlerHelper::execute(Context *context)
41{
42 handlerFunction(context);
43}
44
45static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read",
46 [](Context *context) -> bool {
47 return context->property("mail").isValid();
48 },
49 [](Context *context) {
50 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>();
51 if (!mail) {
52 qWarning() << "Failed to get the mail mail: " << context->property("mail");
53 return;
54 }
55 mail->setProperty("unread", false);
56 qDebug() << "Mark as read " << mail->identifier();
57 Sink::Store::modify(*mail).exec();
58 }
59);
60
61static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete",
62 [](Context *context) -> bool {
63 return context->property("mail").isValid();
64 },
65 [](Context *context) {
66 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>();
67 if (!mail) {
68 qWarning() << "Failed to get the mail mail: " << context->property("mail");
69 return;
70 }
71 mail->setProperty("unread", false);
72 qDebug() << "Remove " << mail->identifier();
73 Sink::Store::remove(*mail).exec();
74 }
75);