diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-24 21:56:13 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-24 21:56:13 +0200 |
commit | 100f409967cd5c17567e401826a0773c7e848ff3 (patch) | |
tree | 64114fa1a8db36febe5448d5d199b3e9c8fc294f | |
parent | b3223155b178427354b44f05167d0afba0926cbd (diff) | |
download | kube-100f409967cd5c17567e401826a0773c7e848ff3.tar.gz kube-100f409967cd5c17567e401826a0773c7e848ff3.zip |
Dropped the now unused action framework
-rw-r--r-- | framework/src/CMakeLists.txt | 7 | ||||
-rw-r--r-- | framework/src/actions/action.cpp | 127 | ||||
-rw-r--r-- | framework/src/actions/action.h | 71 | ||||
-rw-r--r-- | framework/src/actions/actionbroker.cpp | 101 | ||||
-rw-r--r-- | framework/src/actions/actionbroker.h | 49 | ||||
-rw-r--r-- | framework/src/actions/actionhandler.cpp | 151 | ||||
-rw-r--r-- | framework/src/actions/actionhandler.h | 112 | ||||
-rw-r--r-- | framework/src/actions/actionresult.cpp | 20 | ||||
-rw-r--r-- | framework/src/actions/actionresult.h | 80 | ||||
-rw-r--r-- | framework/src/actions/context.cpp | 91 | ||||
-rw-r--r-- | framework/src/actions/context.h | 67 | ||||
-rw-r--r-- | framework/src/actions/tests/CMakeLists.txt | 6 | ||||
-rw-r--r-- | framework/src/actions/tests/actiontest.cpp | 102 | ||||
-rw-r--r-- | framework/src/domain/actions/sinkactions.cpp | 56 | ||||
-rw-r--r-- | framework/src/domain/actions/tests/CMakeLists.txt | 6 | ||||
-rw-r--r-- | framework/src/domain/actions/tests/sinkactiontest.cpp | 58 | ||||
-rw-r--r-- | framework/src/frameworkplugin.cpp | 9 | ||||
-rw-r--r-- | framework/src/sinkfabric.cpp | 2 |
18 files changed, 0 insertions, 1115 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 8dc844cc..c82626a0 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -14,16 +14,10 @@ include_directories(.) | |||
14 | 14 | ||
15 | set(SRCS | 15 | set(SRCS |
16 | frameworkplugin.cpp | 16 | frameworkplugin.cpp |
17 | actions/action.cpp | ||
18 | actions/actionhandler.cpp | ||
19 | actions/actionbroker.cpp | ||
20 | actions/actionresult.cpp | ||
21 | actions/context.cpp | ||
22 | settings/settings.cpp | 17 | settings/settings.cpp |
23 | domain/attachmentmodel.cpp | 18 | domain/attachmentmodel.cpp |
24 | domain/maillistmodel.cpp | 19 | domain/maillistmodel.cpp |
25 | domain/folderlistmodel.cpp | 20 | domain/folderlistmodel.cpp |
26 | domain/actions/sinkactions.cpp | ||
27 | domain/objecttreesource.cpp | 21 | domain/objecttreesource.cpp |
28 | domain/stringhtmlwriter.cpp | 22 | domain/stringhtmlwriter.cpp |
29 | domain/composercontroller.cpp | 23 | domain/composercontroller.cpp |
@@ -54,7 +48,6 @@ qt5_use_modules(frameworkplugin Core Quick Qml WebEngineWidgets Test) | |||
54 | target_link_libraries(frameworkplugin sink mimetreeparser KF5::MimeTreeParser KF5::Codecs KF5::Package KAsync) | 48 | target_link_libraries(frameworkplugin sink mimetreeparser KF5::MimeTreeParser KF5::Codecs KF5::Package KAsync) |
55 | install(TARGETS frameworkplugin DESTINATION ${FRAMEWORK_INSTALL_DIR}) | 49 | install(TARGETS frameworkplugin DESTINATION ${FRAMEWORK_INSTALL_DIR}) |
56 | 50 | ||
57 | add_subdirectory(domain/actions/tests) | ||
58 | add_subdirectory(domain/mimetreeparser) | 51 | add_subdirectory(domain/mimetreeparser) |
59 | 52 | ||
60 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | 53 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) |
diff --git a/framework/src/actions/action.cpp b/framework/src/actions/action.cpp deleted file mode 100644 index 1344d112..00000000 --- a/framework/src/actions/action.cpp +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
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 "action.h" | ||
20 | |||
21 | #include <QDebug> | ||
22 | #include <QEvent> | ||
23 | #include <QPointer> | ||
24 | #include <QDynamicPropertyChangeEvent> | ||
25 | #include <QMetaObject> | ||
26 | #include <QMetaProperty> | ||
27 | |||
28 | #include "actionbroker.h" | ||
29 | #include "actionhandler.h" | ||
30 | #include "context.h" | ||
31 | |||
32 | using namespace Kube; | ||
33 | |||
34 | Action::Action(QObject *parent) | ||
35 | : QObject(parent), | ||
36 | mContext(nullptr) | ||
37 | { | ||
38 | } | ||
39 | |||
40 | Action::Action(const QByteArray &actionId, Context &context, QObject *parent) | ||
41 | : QObject(parent), | ||
42 | mContext(&context), | ||
43 | mActionId(actionId) | ||
44 | { | ||
45 | setContext(&context); | ||
46 | } | ||
47 | |||
48 | Action::~Action() | ||
49 | { | ||
50 | } | ||
51 | |||
52 | void Action::setContext(Context *context) | ||
53 | { | ||
54 | //Get notified when any property changes | ||
55 | for (int i = context->metaObject()->propertyOffset(); i < context->metaObject()->propertyCount(); i++) { | ||
56 | auto property = context->metaObject()->property(i) ; | ||
57 | // qWarning() << "Property " << property.name() << property.hasNotifySignal() << property.notifySignal().name(); | ||
58 | if (QString(property.name()) != "objectName") { | ||
59 | //We do what SIGNAL does to connect to the changed signal automatically | ||
60 | QObject::connect(context, "2"+property.notifySignal().name()+"()", this, SLOT(contextChanged())); | ||
61 | } | ||
62 | } | ||
63 | mContext = context; | ||
64 | mContext->installEventFilter(this); | ||
65 | emit readyChanged(); | ||
66 | } | ||
67 | |||
68 | bool Action::eventFilter(QObject *obj, QEvent *e) | ||
69 | { | ||
70 | if (obj == mContext) { | ||
71 | if (e->type() == QEvent::DynamicPropertyChange) { | ||
72 | contextChanged(); | ||
73 | } | ||
74 | } | ||
75 | return QObject::eventFilter(obj, e); | ||
76 | } | ||
77 | |||
78 | void Action::contextChanged() | ||
79 | { | ||
80 | emit readyChanged(); | ||
81 | } | ||
82 | |||
83 | Context *Action::context() const | ||
84 | { | ||
85 | return mContext; | ||
86 | } | ||
87 | |||
88 | void Action::setActionId(const QByteArray &actionId) | ||
89 | { | ||
90 | mActionId = actionId; | ||
91 | emit readyChanged(); | ||
92 | } | ||
93 | |||
94 | QByteArray Action::actionId() const | ||
95 | { | ||
96 | return mActionId; | ||
97 | } | ||
98 | |||
99 | bool Action::ready() const | ||
100 | { | ||
101 | return ActionBroker::instance().isActionReady(mActionId, mContext, mPreHandler); | ||
102 | } | ||
103 | |||
104 | void Action::execute() | ||
105 | { | ||
106 | ActionBroker::instance().executeAction(mActionId, mContext, mPreHandler, mPostHandler); | ||
107 | } | ||
108 | |||
109 | ActionResult Action::executeWithResult() | ||
110 | { | ||
111 | return ActionBroker::instance().executeAction(mActionId, mContext, mPreHandler, mPostHandler); | ||
112 | } | ||
113 | |||
114 | void Action::addPreHandler(ActionHandler *handler) | ||
115 | { | ||
116 | //For cleanup | ||
117 | handler->setParent(this); | ||
118 | mPreHandler << handler; | ||
119 | } | ||
120 | |||
121 | void Action::addPostHandler(ActionHandler *handler) | ||
122 | { | ||
123 | //For cleanup | ||
124 | handler->setParent(this); | ||
125 | mPostHandler << handler; | ||
126 | } | ||
127 | |||
diff --git a/framework/src/actions/action.h b/framework/src/actions/action.h deleted file mode 100644 index dda8c987..00000000 --- a/framework/src/actions/action.h +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #include "context.h" | ||
23 | #include "actionresult.h" | ||
24 | |||
25 | namespace Kube { | ||
26 | |||
27 | class ActionHandler; | ||
28 | |||
29 | class Action : public QObject | ||
30 | { | ||
31 | Q_OBJECT | ||
32 | Q_PROPERTY(QByteArray actionId READ actionId WRITE setActionId) | ||
33 | //FIXME if I set the property to Context* qml fails to assign the registered type which is calle Kube::Context_QML_90 in QML... | ||
34 | Q_PROPERTY(Context* context READ context WRITE setContext) | ||
35 | Q_PROPERTY(bool ready READ ready NOTIFY readyChanged) | ||
36 | |||
37 | public: | ||
38 | Action(QObject *parent = 0); | ||
39 | Action(const QByteArray &actionId, Context &context, QObject *parent = 0); | ||
40 | ~Action(); | ||
41 | |||
42 | void setContext(Context *); | ||
43 | Context *context() const; | ||
44 | |||
45 | void setActionId(const QByteArray &); | ||
46 | QByteArray actionId() const; | ||
47 | |||
48 | bool ready() const; | ||
49 | |||
50 | Q_INVOKABLE void execute(); | ||
51 | ActionResult executeWithResult(); | ||
52 | |||
53 | void addPreHandler(ActionHandler *handler); | ||
54 | void addPostHandler(ActionHandler *handler); | ||
55 | |||
56 | bool eventFilter(QObject *obj, QEvent *e) Q_DECL_OVERRIDE; | ||
57 | |||
58 | Q_SIGNALS: | ||
59 | void readyChanged(); | ||
60 | |||
61 | private Q_SLOTS: | ||
62 | void contextChanged(); | ||
63 | |||
64 | private: | ||
65 | Context *mContext; | ||
66 | QByteArray mActionId; | ||
67 | QList<QPointer<ActionHandler>> mPreHandler; | ||
68 | QList<QPointer<ActionHandler>> mPostHandler; | ||
69 | }; | ||
70 | |||
71 | } | ||
diff --git a/framework/src/actions/actionbroker.cpp b/framework/src/actions/actionbroker.cpp deleted file mode 100644 index f6bfdd8e..00000000 --- a/framework/src/actions/actionbroker.cpp +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
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 | |||
20 | #include "actionbroker.h" | ||
21 | |||
22 | #include "context.h" | ||
23 | #include "actionhandler.h" | ||
24 | #include <sink/log.h> | ||
25 | |||
26 | #include <QDebug> | ||
27 | |||
28 | using namespace Kube; | ||
29 | |||
30 | SINK_DEBUG_AREA("actionbroker") | ||
31 | |||
32 | ActionBroker::ActionBroker(QObject *parent) | ||
33 | : QObject(parent) | ||
34 | { | ||
35 | |||
36 | } | ||
37 | |||
38 | ActionBroker &ActionBroker::instance() | ||
39 | { | ||
40 | static ActionBroker instance; | ||
41 | return instance; | ||
42 | } | ||
43 | |||
44 | bool ActionBroker::isActionReady(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler) | ||
45 | { | ||
46 | if (!context) { | ||
47 | return false; | ||
48 | } | ||
49 | for (const auto handler : preHandler) { | ||
50 | if (!handler->isActionReady(context)) { | ||
51 | return false; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | for (const auto handler : mHandler.values(actionId)) { | ||
56 | if (handler) { | ||
57 | if (handler->isActionReady(context)) { | ||
58 | return true; | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | return false; | ||
64 | } | ||
65 | |||
66 | ActionResult ActionBroker::executeAction(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler, const QList<QPointer<ActionHandler>> &postHandler) | ||
67 | { | ||
68 | ActionResult result; | ||
69 | if (context) { | ||
70 | SinkLog() << "Executing action " << actionId; | ||
71 | SinkLog() << *context; | ||
72 | for (const auto handler : preHandler) { | ||
73 | handler->execute(context); | ||
74 | } | ||
75 | //TODO the main handler should only execute once the pre handler is done | ||
76 | for (const auto handler : mHandler.values(actionId)) { | ||
77 | if (handler) { | ||
78 | result += handler->execute(context); | ||
79 | } | ||
80 | } | ||
81 | //TODO the post handler should only execute once the main handler is done | ||
82 | for (const auto handler : postHandler) { | ||
83 | handler->execute(context); | ||
84 | } | ||
85 | } else { | ||
86 | SinkWarning() << "Can't execute without context"; | ||
87 | result.setDone(); | ||
88 | result.setError(1); | ||
89 | } | ||
90 | return result; | ||
91 | } | ||
92 | |||
93 | void ActionBroker::registerHandler(const QByteArray &actionId, ActionHandler *handler) | ||
94 | { | ||
95 | mHandler.insert(actionId, handler); | ||
96 | } | ||
97 | |||
98 | void ActionBroker::unregisterHandler(const QByteArray &actionId, ActionHandler *handler) | ||
99 | { | ||
100 | mHandler.remove(actionId, handler); | ||
101 | } | ||
diff --git a/framework/src/actions/actionbroker.h b/framework/src/actions/actionbroker.h deleted file mode 100644 index d893a3e7..00000000 --- a/framework/src/actions/actionbroker.h +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #include <QMultiMap> | ||
23 | |||
24 | namespace Kube { | ||
25 | class Context; | ||
26 | class ActionHandler; | ||
27 | class ActionResult; | ||
28 | |||
29 | class ActionBroker : public QObject | ||
30 | { | ||
31 | Q_OBJECT | ||
32 | public: | ||
33 | static ActionBroker &instance(); | ||
34 | |||
35 | bool isActionReady(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler); | ||
36 | ActionResult executeAction(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler, const QList<QPointer<ActionHandler>> &postHandler); | ||
37 | |||
38 | void registerHandler(const QByteArray &actionId, ActionHandler *handler); | ||
39 | void unregisterHandler(const QByteArray &actionId, ActionHandler *handler); | ||
40 | |||
41 | Q_SIGNALS: | ||
42 | void readyChanged(); | ||
43 | |||
44 | private: | ||
45 | ActionBroker(QObject *parent = 0); | ||
46 | QMultiMap<QByteArray, QPointer<ActionHandler>> mHandler; | ||
47 | }; | ||
48 | |||
49 | } | ||
diff --git a/framework/src/actions/actionhandler.cpp b/framework/src/actions/actionhandler.cpp deleted file mode 100644 index 99fdf66a..00000000 --- a/framework/src/actions/actionhandler.cpp +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
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 | |||
20 | #include "actionhandler.h" | ||
21 | |||
22 | #include "context.h" | ||
23 | #include "actionbroker.h" | ||
24 | #include <QDebug> | ||
25 | |||
26 | using namespace Kube; | ||
27 | |||
28 | ActionHandler::ActionHandler(QObject *parent) | ||
29 | : QObject(parent) | ||
30 | { | ||
31 | |||
32 | } | ||
33 | |||
34 | ActionHandler::~ActionHandler() | ||
35 | { | ||
36 | ActionBroker::instance().unregisterHandler(mActionId, this); | ||
37 | } | ||
38 | |||
39 | bool ActionHandler::isActionReady(Context *context) | ||
40 | { | ||
41 | if (context) { | ||
42 | QVariant returnedValue; | ||
43 | QMetaObject::invokeMethod(this, "isReady", | ||
44 | Q_RETURN_ARG(QVariant, returnedValue), | ||
45 | Q_ARG(QVariant, QVariant::fromValue(context))); | ||
46 | return returnedValue.toBool(); | ||
47 | } else { | ||
48 | qWarning() << "The handler didn't get a context"; | ||
49 | } | ||
50 | return false; | ||
51 | } | ||
52 | |||
53 | ActionResult ActionHandler::execute(Context *context) | ||
54 | { | ||
55 | ActionResult result; | ||
56 | QVariant returnedValue; | ||
57 | qWarning() << "Executing the handler"; | ||
58 | if (context) { | ||
59 | //The base implementation to call the handler in QML | ||
60 | QMetaObject::invokeMethod(this, "handler", | ||
61 | Q_RETURN_ARG(QVariant, returnedValue), | ||
62 | Q_ARG(QVariant, QVariant::fromValue(context))); | ||
63 | //TODO: support async handlers in QML | ||
64 | result.setDone(); | ||
65 | } else { | ||
66 | qWarning() << "The handler didn't get a context"; | ||
67 | result.setDone(); | ||
68 | result.setError(1); | ||
69 | } | ||
70 | return result; | ||
71 | } | ||
72 | |||
73 | void ActionHandler::setActionId(const QByteArray &actionId) | ||
74 | { | ||
75 | //Reassigning the id is not supported | ||
76 | Q_ASSERT(mActionId.isEmpty()); | ||
77 | mActionId = actionId; | ||
78 | ActionBroker::instance().registerHandler(actionId, this); | ||
79 | } | ||
80 | |||
81 | QByteArray ActionHandler::actionId() const | ||
82 | { | ||
83 | return mActionId; | ||
84 | } | ||
85 | |||
86 | void ActionHandler::setRequiredProperties(const QSet<QByteArray> &requiredProperties) | ||
87 | { | ||
88 | mRequiredProperties = requiredProperties; | ||
89 | } | ||
90 | |||
91 | QSet<QByteArray> ActionHandler::requiredProperties() const | ||
92 | { | ||
93 | return mRequiredProperties; | ||
94 | } | ||
95 | |||
96 | |||
97 | ActionHandlerHelper::ActionHandlerHelper(const Handler &handler) | ||
98 | : ActionHandler(nullptr), | ||
99 | handlerFunction(handler) | ||
100 | { | ||
101 | } | ||
102 | |||
103 | ActionHandlerHelper::ActionHandlerHelper(const IsReadyFunction &isReady, const Handler &handler) | ||
104 | : ActionHandler(nullptr), | ||
105 | isReadyFunction(isReady), | ||
106 | handlerFunction(handler) | ||
107 | { | ||
108 | } | ||
109 | |||
110 | ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const Handler &handler) | ||
111 | : ActionHandler(nullptr), | ||
112 | isReadyFunction(isReady), | ||
113 | handlerFunction(handler) | ||
114 | { | ||
115 | setActionId(actionId); | ||
116 | } | ||
117 | |||
118 | ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const JobHandler &handler) | ||
119 | : ActionHandler(nullptr), | ||
120 | isReadyFunction(isReady), | ||
121 | jobHandlerFunction(handler) | ||
122 | { | ||
123 | setActionId(actionId); | ||
124 | } | ||
125 | |||
126 | bool ActionHandlerHelper::isActionReady(Context *context) | ||
127 | { | ||
128 | if (isReadyFunction) { | ||
129 | return isReadyFunction(context); | ||
130 | } | ||
131 | return true; | ||
132 | } | ||
133 | |||
134 | ActionResult ActionHandlerHelper::execute(Context *context) | ||
135 | { | ||
136 | ActionResult result; | ||
137 | if (handlerFunction) { | ||
138 | handlerFunction(context); | ||
139 | result.setDone(); | ||
140 | } else { | ||
141 | jobHandlerFunction(context).then([=](const KAsync::Error &error) { | ||
142 | auto modifyableResult = result; | ||
143 | if (error) { | ||
144 | qWarning() << "Job failed: " << error.errorCode << error.errorMessage; | ||
145 | modifyableResult.setError(1); | ||
146 | } | ||
147 | modifyableResult.setDone(); | ||
148 | }).exec(); | ||
149 | } | ||
150 | return result; | ||
151 | } | ||
diff --git a/framework/src/actions/actionhandler.h b/framework/src/actions/actionhandler.h deleted file mode 100644 index fbaedad1..00000000 --- a/framework/src/actions/actionhandler.h +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #include <QMultiMap> | ||
23 | #include <functional> | ||
24 | #include <KAsync/Async> | ||
25 | |||
26 | #include "actionresult.h" | ||
27 | #include "context.h" | ||
28 | |||
29 | namespace Kube { | ||
30 | |||
31 | class ActionHandler : public QObject | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | Q_PROPERTY(QByteArray actionId READ actionId WRITE setActionId) | ||
35 | |||
36 | public: | ||
37 | ActionHandler(QObject *parent = 0); | ||
38 | virtual ~ActionHandler(); | ||
39 | |||
40 | virtual bool isActionReady(Context *context); | ||
41 | |||
42 | virtual ActionResult execute(Context *context); | ||
43 | |||
44 | void setActionId(const QByteArray &); | ||
45 | QByteArray actionId() const; | ||
46 | |||
47 | void setRequiredProperties(const QSet<QByteArray> &requiredProperties); | ||
48 | QSet<QByteArray> requiredProperties() const; | ||
49 | |||
50 | private: | ||
51 | QByteArray mActionId; | ||
52 | QSet<QByteArray> mRequiredProperties; | ||
53 | }; | ||
54 | |||
55 | template <typename ContextType> | ||
56 | class ActionHandlerBase : public ActionHandler | ||
57 | { | ||
58 | public: | ||
59 | ActionHandlerBase(const QByteArray &actionId) | ||
60 | : ActionHandler{} | ||
61 | { | ||
62 | setActionId(actionId); | ||
63 | } | ||
64 | |||
65 | bool isActionReady(Context *c) Q_DECL_OVERRIDE | ||
66 | { | ||
67 | auto wrapper = ContextType{*c}; | ||
68 | return isActionReady(wrapper); | ||
69 | } | ||
70 | |||
71 | ActionResult execute(Context *c) Q_DECL_OVERRIDE | ||
72 | { | ||
73 | ActionResult result; | ||
74 | auto wrapper = ContextType{*c}; | ||
75 | execute(wrapper) | ||
76 | .template then([=](const KAsync::Error &error) { | ||
77 | auto modifyableResult = result; | ||
78 | if (error) { | ||
79 | qWarning() << "Job failed: " << error.errorCode << error.errorMessage; | ||
80 | modifyableResult.setError(1); | ||
81 | } | ||
82 | modifyableResult.setDone(); | ||
83 | }).exec(); | ||
84 | return result; | ||
85 | } | ||
86 | protected: | ||
87 | |||
88 | virtual bool isActionReady(ContextType &) { return true; } | ||
89 | virtual KAsync::Job<void> execute(ContextType &) = 0; | ||
90 | }; | ||
91 | |||
92 | class ActionHandlerHelper : public ActionHandler | ||
93 | { | ||
94 | public: | ||
95 | typedef std::function<bool(Context *)> IsReadyFunction; | ||
96 | typedef std::function<void(Context *)> Handler; | ||
97 | typedef std::function<KAsync::Job<void>(Context *)> JobHandler; | ||
98 | |||
99 | ActionHandlerHelper(const Handler &); | ||
100 | ActionHandlerHelper(const IsReadyFunction &, const Handler &); | ||
101 | ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const Handler &); | ||
102 | ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const JobHandler &); | ||
103 | |||
104 | bool isActionReady(Context *) Q_DECL_OVERRIDE; | ||
105 | ActionResult execute(Context *) Q_DECL_OVERRIDE; | ||
106 | private: | ||
107 | const IsReadyFunction isReadyFunction; | ||
108 | const Handler handlerFunction; | ||
109 | const JobHandler jobHandlerFunction; | ||
110 | }; | ||
111 | |||
112 | } | ||
diff --git a/framework/src/actions/actionresult.cpp b/framework/src/actions/actionresult.cpp deleted file mode 100644 index 631c61c4..00000000 --- a/framework/src/actions/actionresult.cpp +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
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 "actionresult.h" | ||
20 | |||
diff --git a/framework/src/actions/actionresult.h b/framework/src/actions/actionresult.h deleted file mode 100644 index dcf1a9ec..00000000 --- a/framework/src/actions/actionresult.h +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #include <QSharedPointer> | ||
23 | |||
24 | namespace Kube { | ||
25 | |||
26 | struct ActionResultData | ||
27 | { | ||
28 | ActionResultData() : mError(0), mDone(false) {} | ||
29 | int mError; | ||
30 | bool mDone; | ||
31 | }; | ||
32 | |||
33 | class ActionResult : public QObject | ||
34 | { | ||
35 | Q_OBJECT | ||
36 | public: | ||
37 | ActionResult() : QObject(), mData(new ActionResultData()) {} | ||
38 | ActionResult(const ActionResult &rhs) : QObject(), mData(rhs.mData) {} | ||
39 | ActionResult &operator=(const ActionResult &rhs) | ||
40 | { | ||
41 | mData = rhs.mData; | ||
42 | return *this; | ||
43 | } | ||
44 | virtual ~ActionResult() {} | ||
45 | |||
46 | ActionResult &operator+=(const ActionResult &rhs) | ||
47 | { | ||
48 | if (!error() && rhs.error()) { | ||
49 | setError(rhs.error()); | ||
50 | } | ||
51 | if (isDone() && rhs.isDone()) { | ||
52 | mData->mDone = false; | ||
53 | } | ||
54 | mData = rhs.mData; | ||
55 | return *this; | ||
56 | } | ||
57 | |||
58 | void setDone() { | ||
59 | mData->mDone = true; | ||
60 | } | ||
61 | |||
62 | bool isDone() const { | ||
63 | return mData->mDone; | ||
64 | } | ||
65 | |||
66 | void setError(int error) { | ||
67 | mData->mError = error; | ||
68 | } | ||
69 | |||
70 | int error() const { | ||
71 | return mData->mError; | ||
72 | } | ||
73 | |||
74 | private: | ||
75 | QSharedPointer<ActionResultData> mData; | ||
76 | }; | ||
77 | |||
78 | } | ||
79 | |||
80 | Q_DECLARE_METATYPE(Kube::ActionResult); | ||
diff --git a/framework/src/actions/context.cpp b/framework/src/actions/context.cpp deleted file mode 100644 index 45b660a9..00000000 --- a/framework/src/actions/context.cpp +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
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 "context.h" | ||
20 | |||
21 | #include <QDebug> | ||
22 | #include <QMetaProperty> | ||
23 | |||
24 | using namespace Kube; | ||
25 | |||
26 | Context::Context(QObject *parent) | ||
27 | : QObject(parent) | ||
28 | { | ||
29 | |||
30 | } | ||
31 | |||
32 | Context::Context(const Context &other) | ||
33 | : QObject() | ||
34 | { | ||
35 | *this = other; | ||
36 | } | ||
37 | |||
38 | Context &Context::operator=(const Context &other) | ||
39 | { | ||
40 | for (const auto &p : other.availableProperties()) { | ||
41 | setProperty(p, other.property(p)); | ||
42 | } | ||
43 | return *this; | ||
44 | } | ||
45 | |||
46 | void Context::clear() | ||
47 | { | ||
48 | auto meta = metaObject(); | ||
49 | for (auto i = meta->propertyOffset(); i < meta->propertyCount(); i++) { | ||
50 | auto property = meta->property(i); | ||
51 | setProperty(property.name(), QVariant()); | ||
52 | } | ||
53 | for (const auto &p : dynamicPropertyNames()) { | ||
54 | setProperty(p, QVariant()); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | QSet<QByteArray> Context::availableProperties() const | ||
59 | { | ||
60 | QSet<QByteArray> names; | ||
61 | auto meta = metaObject(); | ||
62 | for (auto i = meta->propertyOffset(); i < meta->propertyCount(); i++) { | ||
63 | auto property = meta->property(i); | ||
64 | names << property.name(); | ||
65 | } | ||
66 | for (const auto &p : dynamicPropertyNames()) { | ||
67 | names << p; | ||
68 | } | ||
69 | return names; | ||
70 | } | ||
71 | |||
72 | QDebug operator<<(QDebug dbg, const Kube::Context &context) | ||
73 | { | ||
74 | dbg << "Kube::Context {\n"; | ||
75 | auto metaObject = context.metaObject(); | ||
76 | for (auto i = metaObject->propertyOffset(); i < metaObject->propertyCount(); i++) { | ||
77 | auto property = metaObject->property(i); | ||
78 | dbg << property.name() << context.property(property.name()) << "\n"; | ||
79 | } | ||
80 | for (const auto &p : context.dynamicPropertyNames()) { | ||
81 | dbg << p << context.property(p) << "\n"; | ||
82 | } | ||
83 | dbg << "\n}"; | ||
84 | return dbg; | ||
85 | } | ||
86 | |||
87 | QDebug operator<<(QDebug dbg, const Kube::ContextWrapper &context) | ||
88 | { | ||
89 | dbg << context.context; | ||
90 | return dbg; | ||
91 | } | ||
diff --git a/framework/src/actions/context.h b/framework/src/actions/context.h deleted file mode 100644 index 52fbdbc1..00000000 --- a/framework/src/actions/context.h +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #define KUBE_CONTEXT_PROPERTY(TYPE, NAME, LOWERCASENAME) \ | ||
23 | public: Q_PROPERTY(TYPE LOWERCASENAME MEMBER m##NAME NOTIFY LOWERCASENAME##Changed) \ | ||
24 | Q_SIGNALS: void LOWERCASENAME##Changed(); \ | ||
25 | private: TYPE m##NAME; | ||
26 | |||
27 | #define KUBE_CONTEXTWRAPPER_PROPERTY(TYPE, NAME, LOWERCASENAME) \ | ||
28 | public: \ | ||
29 | struct NAME { \ | ||
30 | static constexpr const char *name = #LOWERCASENAME; \ | ||
31 | typedef TYPE Type; \ | ||
32 | }; \ | ||
33 | void set##NAME(const TYPE &value) { context.setProperty(NAME::name, QVariant::fromValue(value)); } \ | ||
34 | void clear##NAME() { context.setProperty(NAME::name, QVariant{}); } \ | ||
35 | TYPE get##NAME() const { return context.property(NAME::name).value<TYPE>(); } \ | ||
36 | |||
37 | |||
38 | namespace Kube { | ||
39 | |||
40 | class Context : public QObject { | ||
41 | Q_OBJECT | ||
42 | public: | ||
43 | Context(QObject *parent = 0); | ||
44 | Context(const Context &); | ||
45 | |||
46 | virtual ~Context(){}; | ||
47 | |||
48 | Context &operator=(const Context &); | ||
49 | |||
50 | virtual void clear(); | ||
51 | |||
52 | QSet<QByteArray> availableProperties() const; | ||
53 | }; | ||
54 | |||
55 | class ContextWrapper { | ||
56 | public: | ||
57 | ContextWrapper(Context &c) : context(c) {} | ||
58 | Context &context; | ||
59 | }; | ||
60 | |||
61 | } | ||
62 | |||
63 | QDebug operator<<(QDebug dbg, const Kube::Context &); | ||
64 | QDebug operator<<(QDebug dbg, const Kube::ContextWrapper &); | ||
65 | |||
66 | Q_DECLARE_METATYPE(Kube::Context*); | ||
67 | |||
diff --git a/framework/src/actions/tests/CMakeLists.txt b/framework/src/actions/tests/CMakeLists.txt deleted file mode 100644 index af872a3b..00000000 --- a/framework/src/actions/tests/CMakeLists.txt +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
2 | cmake_policy(SET CMP0063 NEW) | ||
3 | add_executable(actiontest actiontest.cpp) | ||
4 | add_test(actiontest sinkactiontest) | ||
5 | qt5_use_modules(actiontest Core Test) | ||
6 | target_link_libraries(actiontest actionplugin) | ||
diff --git a/framework/src/actions/tests/actiontest.cpp b/framework/src/actions/tests/actiontest.cpp deleted file mode 100644 index a4ec4432..00000000 --- a/framework/src/actions/tests/actiontest.cpp +++ /dev/null | |||
@@ -1,102 +0,0 @@ | |||
1 | #include <QTest> | ||
2 | #include <QDebug> | ||
3 | #include <QSignalSpy> | ||
4 | |||
5 | #include <actions/action.h> | ||
6 | #include <actions/context.h> | ||
7 | #include <actions/actionhandler.h> | ||
8 | |||
9 | #include <sink/log.h> | ||
10 | |||
11 | SINK_DEBUG_AREA("actiontest") | ||
12 | |||
13 | class HandlerContext : public Kube::Context { | ||
14 | Q_OBJECT | ||
15 | KUBE_CONTEXT_PROPERTY(QString, Property1, property1) | ||
16 | KUBE_CONTEXT_PROPERTY(QString, Property2, property2) | ||
17 | }; | ||
18 | |||
19 | class HandlerContextWrapper : public Kube::ContextWrapper { | ||
20 | using Kube::ContextWrapper::ContextWrapper; | ||
21 | KUBE_CONTEXTWRAPPER_PROPERTY(QString, Property1, property1) | ||
22 | KUBE_CONTEXTWRAPPER_PROPERTY(QString, Property2, property2) | ||
23 | }; | ||
24 | |||
25 | |||
26 | |||
27 | class Handler : public Kube::ActionHandlerBase<HandlerContextWrapper> | ||
28 | { | ||
29 | public: | ||
30 | Handler() : Kube::ActionHandlerBase<HandlerContextWrapper>{"org.kde.kube.test.action1"} | ||
31 | {} | ||
32 | |||
33 | //TODO default implementation checks that all defined properties are available in the context | ||
34 | // bool isReady() override { | ||
35 | // auto accountId = context->property("accountId").value<QByteArray>(); | ||
36 | // return !accountId.isEmpty(); | ||
37 | // } | ||
38 | |||
39 | KAsync::Job<void> execute(HandlerContextWrapper &context) | ||
40 | { | ||
41 | SinkLog() << "Executing action1"; | ||
42 | SinkLog() << context; | ||
43 | executions.append(context.context); | ||
44 | return KAsync::null<void>(); | ||
45 | } | ||
46 | mutable QList<Kube::Context> executions; | ||
47 | }; | ||
48 | |||
49 | class Context1 : public Kube::ContextWrapper { | ||
50 | using Kube::ContextWrapper::ContextWrapper; | ||
51 | KUBE_CONTEXTWRAPPER_PROPERTY(QString, Property1, property1) | ||
52 | KUBE_CONTEXTWRAPPER_PROPERTY(QByteArray, Property2, property2) | ||
53 | }; | ||
54 | |||
55 | class Context2 : public Kube::ContextWrapper { | ||
56 | using Kube::ContextWrapper::ContextWrapper; | ||
57 | KUBE_CONTEXTWRAPPER_PROPERTY(QByteArray, Property2, property2) | ||
58 | }; | ||
59 | |||
60 | |||
61 | class ActionTest : public QObject | ||
62 | { | ||
63 | Q_OBJECT | ||
64 | private slots: | ||
65 | |||
66 | void initTestCase() | ||
67 | { | ||
68 | } | ||
69 | |||
70 | void testActionExecution() | ||
71 | { | ||
72 | Handler actionHandler; | ||
73 | |||
74 | HandlerContext context; | ||
75 | //Kube::Context context; | ||
76 | HandlerContextWrapper{context}.setProperty1(QString("property1")); | ||
77 | context.setProperty("property2", QVariant::fromValue(QString("property2"))); | ||
78 | auto future = Kube::Action("org.kde.kube.test.action1", context).executeWithResult(); | ||
79 | |||
80 | QTRY_VERIFY(future.isDone()); | ||
81 | QVERIFY(!future.error()); | ||
82 | |||
83 | QCOMPARE(actionHandler.executions.size(), 1); | ||
84 | QCOMPARE(actionHandler.executions.first().availableProperties().size(), 2); | ||
85 | } | ||
86 | |||
87 | void testContextCasting() | ||
88 | { | ||
89 | Kube::Context c; | ||
90 | |||
91 | Context1 context1{c}; | ||
92 | context1.setProperty1("property1"); | ||
93 | context1.setProperty2("property2"); | ||
94 | |||
95 | auto context2 = Context2{c}; | ||
96 | QCOMPARE(context2.getProperty2(), QByteArray("property2")); | ||
97 | } | ||
98 | |||
99 | }; | ||
100 | |||
101 | QTEST_GUILESS_MAIN(ActionTest) | ||
102 | #include "actiontest.moc" | ||
diff --git a/framework/src/domain/actions/sinkactions.cpp b/framework/src/domain/actions/sinkactions.cpp deleted file mode 100644 index 460cb6a1..00000000 --- a/framework/src/domain/actions/sinkactions.cpp +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
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 | |||
20 | #include <actions/actionhandler.h> | ||
21 | |||
22 | #include <KMime/Message> | ||
23 | #include <QFile> | ||
24 | |||
25 | #include <sink/store.h> | ||
26 | #include <sink/log.h> | ||
27 | |||
28 | SINK_DEBUG_AREA("sinkactions") | ||
29 | |||
30 | using namespace Kube; | ||
31 | using namespace Sink; | ||
32 | using namespace Sink::ApplicationDomain; | ||
33 | |||
34 | class FolderContext : public Kube::ContextWrapper { | ||
35 | using Kube::ContextWrapper::ContextWrapper; | ||
36 | KUBE_CONTEXTWRAPPER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder) | ||
37 | }; | ||
38 | |||
39 | static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize", | ||
40 | [](Context *context) -> bool { | ||
41 | return true; | ||
42 | }, | ||
43 | [](Context *context_) { | ||
44 | auto context = FolderContext{*context_}; | ||
45 | if (auto folder = context.getFolder()) { | ||
46 | SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier(); | ||
47 | auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<Mail::Folder>(QVariant::fromValue(folder->identifier())); | ||
48 | scope.setType<ApplicationDomain::Mail>(); | ||
49 | Store::synchronize(scope).exec(); | ||
50 | } else { | ||
51 | SinkLog() << "Synchronizing all"; | ||
52 | Store::synchronize(SyncScope()).exec(); | ||
53 | } | ||
54 | } | ||
55 | ); | ||
56 | |||
diff --git a/framework/src/domain/actions/tests/CMakeLists.txt b/framework/src/domain/actions/tests/CMakeLists.txt deleted file mode 100644 index 2c34d628..00000000 --- a/framework/src/domain/actions/tests/CMakeLists.txt +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
2 | cmake_policy(SET CMP0063 NEW) | ||
3 | add_executable(sinkactiontest sinkactiontest.cpp) | ||
4 | add_test(sinkactiontest sinkactiontest) | ||
5 | qt5_use_modules(sinkactiontest Core Test Concurrent) | ||
6 | target_link_libraries(sinkactiontest sink frameworkplugin KF5::Mime) | ||
diff --git a/framework/src/domain/actions/tests/sinkactiontest.cpp b/framework/src/domain/actions/tests/sinkactiontest.cpp deleted file mode 100644 index 79375503..00000000 --- a/framework/src/domain/actions/tests/sinkactiontest.cpp +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | #include <QTest> | ||
2 | #include <QDebug> | ||
3 | #include <QSignalSpy> | ||
4 | #include <sink/test.h> | ||
5 | #include <sink/store.h> | ||
6 | #include <sink/log.h> | ||
7 | #include <KMime/Message> | ||
8 | |||
9 | #include <actions/action.h> | ||
10 | #include <actions/context.h> | ||
11 | |||
12 | using namespace Sink; | ||
13 | |||
14 | class SinkActionTest : public QObject | ||
15 | { | ||
16 | Q_OBJECT | ||
17 | private slots: | ||
18 | |||
19 | void initTestCase() | ||
20 | { | ||
21 | Sink::Test::initTest(); | ||
22 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | ||
23 | } | ||
24 | |||
25 | void testSaveAsDraftFail() | ||
26 | { | ||
27 | Kube::Context context; | ||
28 | auto future = Kube::Action("org.kde.kube.actions.save-as-draft", context).executeWithResult(); | ||
29 | |||
30 | QTRY_VERIFY(future.isDone()); | ||
31 | //because of empty context | ||
32 | QVERIFY(future.error()); | ||
33 | } | ||
34 | |||
35 | void testSaveAsDraftNew() | ||
36 | { | ||
37 | auto message = KMime::Message::Ptr::create(); | ||
38 | message->subject(true)->fromUnicodeString(QString::fromLatin1("Foobar"), "utf8"); | ||
39 | message->assemble(); | ||
40 | |||
41 | auto &&account = Test::TestAccount::registerAccount(); | ||
42 | |||
43 | Kube::Context context; | ||
44 | context.setProperty("message", QVariant::fromValue(message)); | ||
45 | context.setProperty("accountId", QVariant::fromValue(account.identifier)); | ||
46 | auto future = Kube::Action("org.kde.kube.actions.save-as-draft", context).executeWithResult(); | ||
47 | |||
48 | QTRY_VERIFY(future.isDone()); | ||
49 | QVERIFY(!future.error()); | ||
50 | auto mails = account.entities<Sink::ApplicationDomain::Mail>(); | ||
51 | QCOMPARE(mails.size(), 1); | ||
52 | auto mail = mails.first(); | ||
53 | QVERIFY(mail->getProperty("draft").toBool()); | ||
54 | } | ||
55 | }; | ||
56 | |||
57 | QTEST_GUILESS_MAIN(SinkActionTest) | ||
58 | #include "sinkactiontest.moc" | ||
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 294fbbc7..2064ab1a 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp | |||
@@ -32,10 +32,6 @@ | |||
32 | #include "accounts/accountsmodel.h" | 32 | #include "accounts/accountsmodel.h" |
33 | #include "accounts/accountfactory.h" | 33 | #include "accounts/accountfactory.h" |
34 | #include "settings/settings.h" | 34 | #include "settings/settings.h" |
35 | #include "actions/action.h" | ||
36 | #include "actions/context.h" | ||
37 | #include "actions/actionhandler.h" | ||
38 | #include "actions/actionresult.h" | ||
39 | #include "fabric.h" | 35 | #include "fabric.h" |
40 | 36 | ||
41 | #include <QtQml> | 37 | #include <QtQml> |
@@ -64,11 +60,6 @@ void FrameworkPlugin::registerTypes (const char *uri) | |||
64 | 60 | ||
65 | qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); | 61 | qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); |
66 | 62 | ||
67 | qmlRegisterType<Kube::Context>(uri, 1, 0, "Context"); | ||
68 | qmlRegisterType<Kube::Action>(uri, 1, 0, "Action"); | ||
69 | qmlRegisterType<Kube::ActionHandler>(uri, 1, 0, "ActionHandler"); | ||
70 | qmlRegisterType<Kube::ActionResult>(uri, 1, 0, "ActionResult"); | ||
71 | |||
72 | qmlRegisterType<Kube::Fabric::Listener>(uri, 1, 0, "Listener"); | 63 | qmlRegisterType<Kube::Fabric::Listener>(uri, 1, 0, "Listener"); |
73 | qmlRegisterSingletonType<Kube::Fabric::Fabric>(uri, 1, 0, "Fabric", example_qobject_singletontype_provider); | 64 | qmlRegisterSingletonType<Kube::Fabric::Fabric>(uri, 1, 0, "Fabric", example_qobject_singletontype_provider); |
74 | } | 65 | } |
diff --git a/framework/src/sinkfabric.cpp b/framework/src/sinkfabric.cpp index 5e209526..2615a3ca 100644 --- a/framework/src/sinkfabric.cpp +++ b/framework/src/sinkfabric.cpp | |||
@@ -17,8 +17,6 @@ | |||
17 | 02110-1301, USA. | 17 | 02110-1301, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <actions/actionhandler.h> | ||
21 | |||
22 | #include <QFile> | 20 | #include <QFile> |
23 | 21 | ||
24 | #include <sink/store.h> | 22 | #include <sink/store.h> |