diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-13 16:24:31 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-16 14:54:14 +0100 |
commit | 630f45719a527f8ee739b03bc62f886badea6df3 (patch) | |
tree | b9d859cbfedb30ad8a9570e3b87a419bf24ba6c7 | |
parent | b1a2e2de201985a00980bead5272977cda4ef637 (diff) | |
download | kube-630f45719a527f8ee739b03bc62f886badea6df3.tar.gz kube-630f45719a527f8ee739b03bc62f886badea6df3.zip |
Revamp of composercontroller to use actions more.
Instead of setting all properties individually we directly assign all
properties to a context that we assign to the actions.
This way actions can automatically update themselves as new data becomes
available, and we avoid the setter/getter boilerplate, at the cost of a
less explicit interface (But that could be improved by allowing to
define the required properties of a context in c++).
By relying on prehandler/posthandler to execute certain actions we
simplify the control flow and enable the future extension with handlers
that i.e. do encryption etc.
-rw-r--r-- | components/package/contents/ui/FocusComposer.qml | 55 | ||||
-rw-r--r-- | framework/actions/action.cpp | 20 | ||||
-rw-r--r-- | framework/actions/action.h | 3 | ||||
-rw-r--r-- | framework/actions/actionbroker.cpp | 16 | ||||
-rw-r--r-- | framework/actions/actionbroker.h | 2 | ||||
-rw-r--r-- | framework/actions/actionhandler.cpp | 17 | ||||
-rw-r--r-- | framework/actions/actionhandler.h | 2 | ||||
-rw-r--r-- | framework/actions/context.cpp | 16 | ||||
-rw-r--r-- | framework/actions/context.h | 2 | ||||
-rw-r--r-- | framework/domain/actions/sinkactions.cpp | 15 | ||||
-rw-r--r-- | framework/domain/composercontroller.cpp | 229 | ||||
-rw-r--r-- | framework/domain/composercontroller.h | 64 | ||||
-rw-r--r-- | framework/domain/identitiesmodel.cpp | 25 | ||||
-rw-r--r-- | framework/domain/settings/accountsettings.cpp | 29 |
14 files changed, 249 insertions, 246 deletions
diff --git a/components/package/contents/ui/FocusComposer.qml b/components/package/contents/ui/FocusComposer.qml index 8b7c2db9..aee20cd5 100644 --- a/components/package/contents/ui/FocusComposer.qml +++ b/components/package/contents/ui/FocusComposer.qml | |||
@@ -23,24 +23,39 @@ import QtQuick.Controls 2.0 as Controls2 | |||
23 | import org.kde.kirigami 1.0 as Kirigami | 23 | import org.kde.kirigami 1.0 as Kirigami |
24 | 24 | ||
25 | import org.kube.framework.domain 1.0 as KubeFramework | 25 | import org.kube.framework.domain 1.0 as KubeFramework |
26 | import org.kube.framework.actions 1.0 as KubeAction | ||
26 | 27 | ||
27 | Controls2.Popup { | 28 | Controls2.Popup { |
28 | id: root | 29 | id: root |
29 | 30 | ||
30 | //Controler | 31 | //Controller |
31 | KubeFramework.ComposerController { | 32 | KubeFramework.ComposerController { |
32 | id: composer | 33 | id: composer |
34 | |||
35 | mailContext: KubeAction.Context { | ||
36 | id: mailcontext | ||
37 | property variant to | ||
38 | property variant cc | ||
39 | property variant bcc | ||
40 | property variant from | ||
41 | property variant subject | ||
42 | property variant body | ||
43 | } | ||
44 | |||
45 | /* onDone: { */ | ||
46 | /* root.close() */ | ||
47 | /* } */ | ||
33 | } | 48 | } |
34 | 49 | ||
50 | //actions | ||
51 | property variant sendAction: composer.sendAction | ||
52 | property variant saveAsDraftAction: composer.saveAsDraftAction | ||
53 | |||
35 | //BEGIN functions | 54 | //BEGIN functions |
36 | function loadMessage(message, loadAsDraft) { | 55 | function loadMessage(message, loadAsDraft) { |
37 | composer.loadMessage(message, loadAsDraft) | 56 | composer.loadMessage(message, loadAsDraft) |
38 | } | 57 | } |
39 | 58 | ||
40 | function send() { | ||
41 | composer.send() | ||
42 | } | ||
43 | |||
44 | function saveAsDraft() { | 59 | function saveAsDraft() { |
45 | composer.saveAsDraft() | 60 | composer.saveAsDraft() |
46 | } | 61 | } |
@@ -84,9 +99,9 @@ Controls2.Popup { | |||
84 | 99 | ||
85 | Layout.fillWidth: true | 100 | Layout.fillWidth: true |
86 | 101 | ||
87 | text: composer.to | 102 | text: mailcontext.to |
88 | onTextChanged: { | 103 | onTextChanged: { |
89 | composer.to = text; | 104 | mailcontext.to = text; |
90 | } | 105 | } |
91 | 106 | ||
92 | model: composer.recepientAutocompletionModel | 107 | model: composer.recepientAutocompletionModel |
@@ -109,10 +124,10 @@ Controls2.Popup { | |||
109 | 124 | ||
110 | visible: false | 125 | visible: false |
111 | 126 | ||
112 | text: composer.cc | 127 | text: mailcontext.cc |
113 | 128 | ||
114 | onTextChanged: { | 129 | onTextChanged: { |
115 | composer.cc = text; | 130 | mailcontext.cc = text; |
116 | } | 131 | } |
117 | 132 | ||
118 | model: composer.recepientAutocompletionModel | 133 | model: composer.recepientAutocompletionModel |
@@ -134,10 +149,10 @@ Controls2.Popup { | |||
134 | 149 | ||
135 | visible : false | 150 | visible : false |
136 | 151 | ||
137 | text: composer.bcc | 152 | text: mailcontext.bcc |
138 | 153 | ||
139 | onTextChanged: { | 154 | onTextChanged: { |
140 | composer.bcc = text; | 155 | mailcontext.bcc = text; |
141 | } | 156 | } |
142 | 157 | ||
143 | model: composer.recepientAutocompletionModel | 158 | model: composer.recepientAutocompletionModel |
@@ -194,20 +209,20 @@ Controls2.Popup { | |||
194 | 209 | ||
195 | placeholderText: "Enter Subject..." | 210 | placeholderText: "Enter Subject..." |
196 | 211 | ||
197 | text: composer.subject | 212 | text: mailcontext.subject |
198 | 213 | ||
199 | onTextChanged: { | 214 | onTextChanged: { |
200 | composer.subject = text; | 215 | mailcontext.subject = text; |
201 | } | 216 | } |
202 | } | 217 | } |
203 | 218 | ||
204 | Controls2.TextArea { | 219 | Controls2.TextArea { |
205 | id: content | 220 | id: content |
206 | 221 | ||
207 | text: composer.body | 222 | text: mailcontext.body |
208 | 223 | ||
209 | onTextChanged: { | 224 | onTextChanged: { |
210 | composer.body = text; | 225 | mailcontext.body = text; |
211 | } | 226 | } |
212 | 227 | ||
213 | Layout.fillWidth: true | 228 | Layout.fillWidth: true |
@@ -220,7 +235,6 @@ Controls2.Popup { | |||
220 | width: parent.width | 235 | width: parent.width |
221 | 236 | ||
222 | Controls2.Button { | 237 | Controls2.Button { |
223 | |||
224 | text: "Discard" | 238 | text: "Discard" |
225 | 239 | ||
226 | onClicked: { | 240 | onClicked: { |
@@ -234,21 +248,20 @@ Controls2.Popup { | |||
234 | 248 | ||
235 | 249 | ||
236 | Controls2.Button { | 250 | Controls2.Button { |
237 | |||
238 | text: "Save as Draft" | 251 | text: "Save as Draft" |
239 | 252 | ||
253 | enabled: saveAsDraftAction.ready | ||
240 | onClicked: { | 254 | onClicked: { |
241 | saveAsDraft() | 255 | saveAsDraftAction.execute() |
242 | root.close() | ||
243 | } | 256 | } |
244 | } | 257 | } |
245 | 258 | ||
246 | Controls2.Button { | 259 | Controls2.Button { |
247 | text: "Send" | 260 | text: "Send" |
248 | 261 | ||
262 | enabled: sendAction.ready | ||
249 | onClicked: { | 263 | onClicked: { |
250 | send() | 264 | sendAction.execute() |
251 | root.close() | ||
252 | } | 265 | } |
253 | } | 266 | } |
254 | } | 267 | } |
diff --git a/framework/actions/action.cpp b/framework/actions/action.cpp index f41feb66..1344d112 100644 --- a/framework/actions/action.cpp +++ b/framework/actions/action.cpp | |||
@@ -42,7 +42,11 @@ Action::Action(const QByteArray &actionId, Context &context, QObject *parent) | |||
42 | mContext(&context), | 42 | mContext(&context), |
43 | mActionId(actionId) | 43 | mActionId(actionId) |
44 | { | 44 | { |
45 | setContext(&context); | ||
46 | } | ||
45 | 47 | ||
48 | Action::~Action() | ||
49 | { | ||
46 | } | 50 | } |
47 | 51 | ||
48 | void Action::setContext(Context *context) | 52 | void Action::setContext(Context *context) |
@@ -61,6 +65,16 @@ void Action::setContext(Context *context) | |||
61 | emit readyChanged(); | 65 | emit readyChanged(); |
62 | } | 66 | } |
63 | 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 | |||
64 | void Action::contextChanged() | 78 | void Action::contextChanged() |
65 | { | 79 | { |
66 | emit readyChanged(); | 80 | emit readyChanged(); |
@@ -84,7 +98,7 @@ QByteArray Action::actionId() const | |||
84 | 98 | ||
85 | bool Action::ready() const | 99 | bool Action::ready() const |
86 | { | 100 | { |
87 | return ActionBroker::instance().isActionReady(mActionId, mContext); | 101 | return ActionBroker::instance().isActionReady(mActionId, mContext, mPreHandler); |
88 | } | 102 | } |
89 | 103 | ||
90 | void Action::execute() | 104 | void Action::execute() |
@@ -99,11 +113,15 @@ ActionResult Action::executeWithResult() | |||
99 | 113 | ||
100 | void Action::addPreHandler(ActionHandler *handler) | 114 | void Action::addPreHandler(ActionHandler *handler) |
101 | { | 115 | { |
116 | //For cleanup | ||
117 | handler->setParent(this); | ||
102 | mPreHandler << handler; | 118 | mPreHandler << handler; |
103 | } | 119 | } |
104 | 120 | ||
105 | void Action::addPostHandler(ActionHandler *handler) | 121 | void Action::addPostHandler(ActionHandler *handler) |
106 | { | 122 | { |
123 | //For cleanup | ||
124 | handler->setParent(this); | ||
107 | mPostHandler << handler; | 125 | mPostHandler << handler; |
108 | } | 126 | } |
109 | 127 | ||
diff --git a/framework/actions/action.h b/framework/actions/action.h index 47e41138..dda8c987 100644 --- a/framework/actions/action.h +++ b/framework/actions/action.h | |||
@@ -37,6 +37,7 @@ class Action : public QObject | |||
37 | public: | 37 | public: |
38 | Action(QObject *parent = 0); | 38 | Action(QObject *parent = 0); |
39 | Action(const QByteArray &actionId, Context &context, QObject *parent = 0); | 39 | Action(const QByteArray &actionId, Context &context, QObject *parent = 0); |
40 | ~Action(); | ||
40 | 41 | ||
41 | void setContext(Context *); | 42 | void setContext(Context *); |
42 | Context *context() const; | 43 | Context *context() const; |
@@ -52,6 +53,8 @@ public: | |||
52 | void addPreHandler(ActionHandler *handler); | 53 | void addPreHandler(ActionHandler *handler); |
53 | void addPostHandler(ActionHandler *handler); | 54 | void addPostHandler(ActionHandler *handler); |
54 | 55 | ||
56 | bool eventFilter(QObject *obj, QEvent *e) Q_DECL_OVERRIDE; | ||
57 | |||
55 | Q_SIGNALS: | 58 | Q_SIGNALS: |
56 | void readyChanged(); | 59 | void readyChanged(); |
57 | 60 | ||
diff --git a/framework/actions/actionbroker.cpp b/framework/actions/actionbroker.cpp index 24ef0b2c..17145440 100644 --- a/framework/actions/actionbroker.cpp +++ b/framework/actions/actionbroker.cpp | |||
@@ -21,11 +21,14 @@ | |||
21 | 21 | ||
22 | #include "context.h" | 22 | #include "context.h" |
23 | #include "actionhandler.h" | 23 | #include "actionhandler.h" |
24 | #include <sink/log.h> | ||
24 | 25 | ||
25 | #include <QDebug> | 26 | #include <QDebug> |
26 | 27 | ||
27 | using namespace Kube; | 28 | using namespace Kube; |
28 | 29 | ||
30 | SINK_DEBUG_AREA("actionbroker") | ||
31 | |||
29 | ActionBroker::ActionBroker(QObject *parent) | 32 | ActionBroker::ActionBroker(QObject *parent) |
30 | : QObject(parent) | 33 | : QObject(parent) |
31 | { | 34 | { |
@@ -38,15 +41,20 @@ ActionBroker &ActionBroker::instance() | |||
38 | return instance; | 41 | return instance; |
39 | } | 42 | } |
40 | 43 | ||
41 | bool ActionBroker::isActionReady(const QByteArray &actionId, Context *context) | 44 | bool ActionBroker::isActionReady(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler) |
42 | { | 45 | { |
43 | if (!context) { | 46 | if (!context) { |
44 | return false; | 47 | return false; |
45 | } | 48 | } |
49 | for (const auto handler : preHandler) { | ||
50 | if (!handler->isActionReady(context)) { | ||
51 | return false; | ||
52 | } | ||
53 | } | ||
46 | 54 | ||
47 | for (const auto handler : mHandler.values(actionId)) { | 55 | for (const auto handler : mHandler.values(actionId)) { |
48 | if (handler) { | 56 | if (handler) { |
49 | if (handler-> isActionReady(context)) { | 57 | if (handler->isActionReady(context)) { |
50 | return true; | 58 | return true; |
51 | } | 59 | } |
52 | } | 60 | } |
@@ -59,6 +67,8 @@ ActionResult ActionBroker::executeAction(const QByteArray &actionId, Context *co | |||
59 | { | 67 | { |
60 | ActionResult result; | 68 | ActionResult result; |
61 | if (context) { | 69 | if (context) { |
70 | SinkLog() << "Executing action " << actionId; | ||
71 | SinkLog() << *context; | ||
62 | for (const auto handler : preHandler) { | 72 | for (const auto handler : preHandler) { |
63 | handler->execute(context); | 73 | handler->execute(context); |
64 | } | 74 | } |
@@ -73,7 +83,7 @@ ActionResult ActionBroker::executeAction(const QByteArray &actionId, Context *co | |||
73 | handler->execute(context); | 83 | handler->execute(context); |
74 | } | 84 | } |
75 | } else { | 85 | } else { |
76 | qWarning() << "Can't execute without context"; | 86 | SinkWarning() << "Can't execute without context"; |
77 | result.setDone(); | 87 | result.setDone(); |
78 | result.setError(1); | 88 | result.setError(1); |
79 | } | 89 | } |
diff --git a/framework/actions/actionbroker.h b/framework/actions/actionbroker.h index d2787c79..84678c16 100644 --- a/framework/actions/actionbroker.h +++ b/framework/actions/actionbroker.h | |||
@@ -32,7 +32,7 @@ class ActionBroker : public QObject | |||
32 | public: | 32 | public: |
33 | static ActionBroker &instance(); | 33 | static ActionBroker &instance(); |
34 | 34 | ||
35 | bool isActionReady(const QByteArray &actionId, Context *context); | 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); | 36 | ActionResult executeAction(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler, const QList<QPointer<ActionHandler>> &postHandler); |
37 | 37 | ||
38 | void registerHandler(const QByteArray &actionId, ActionHandler *handler); | 38 | void registerHandler(const QByteArray &actionId, ActionHandler *handler); |
diff --git a/framework/actions/actionhandler.cpp b/framework/actions/actionhandler.cpp index 9d58f464..dc9edeca 100644 --- a/framework/actions/actionhandler.cpp +++ b/framework/actions/actionhandler.cpp | |||
@@ -77,6 +77,18 @@ QByteArray ActionHandler::actionId() const | |||
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | ActionHandlerHelper::ActionHandlerHelper(const Handler &handler) | ||
81 | : ActionHandler(nullptr), | ||
82 | handlerFunction(handler) | ||
83 | { | ||
84 | } | ||
85 | |||
86 | ActionHandlerHelper::ActionHandlerHelper(const IsReadyFunction &isReady, const Handler &handler) | ||
87 | : ActionHandler(nullptr), | ||
88 | isReadyFunction(isReady), | ||
89 | handlerFunction(handler) | ||
90 | { | ||
91 | } | ||
80 | 92 | ||
81 | ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const Handler &handler) | 93 | ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const Handler &handler) |
82 | : ActionHandler(nullptr), | 94 | : ActionHandler(nullptr), |
@@ -96,7 +108,10 @@ ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsRea | |||
96 | 108 | ||
97 | bool ActionHandlerHelper::isActionReady(Context *context) | 109 | bool ActionHandlerHelper::isActionReady(Context *context) |
98 | { | 110 | { |
99 | return isReadyFunction(context); | 111 | if (isReadyFunction) { |
112 | return isReadyFunction(context); | ||
113 | } | ||
114 | return true; | ||
100 | } | 115 | } |
101 | 116 | ||
102 | ActionResult ActionHandlerHelper::execute(Context *context) | 117 | ActionResult ActionHandlerHelper::execute(Context *context) |
diff --git a/framework/actions/actionhandler.h b/framework/actions/actionhandler.h index 762b8d45..09ed13c6 100644 --- a/framework/actions/actionhandler.h +++ b/framework/actions/actionhandler.h | |||
@@ -55,6 +55,8 @@ public: | |||
55 | typedef std::function<void(Context*)> Handler; | 55 | typedef std::function<void(Context*)> Handler; |
56 | typedef std::function<KAsync::Job<void>(Context*)> JobHandler; | 56 | typedef std::function<KAsync::Job<void>(Context*)> JobHandler; |
57 | 57 | ||
58 | ActionHandlerHelper(const Handler &); | ||
59 | ActionHandlerHelper(const IsReadyFunction &, const Handler &); | ||
58 | ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const Handler &); | 60 | ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const Handler &); |
59 | ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const JobHandler &); | 61 | ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const JobHandler &); |
60 | 62 | ||
diff --git a/framework/actions/context.cpp b/framework/actions/context.cpp index a7f87d16..205b1606 100644 --- a/framework/actions/context.cpp +++ b/framework/actions/context.cpp | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "context.h" | 19 | #include "context.h" |
20 | 20 | ||
21 | #include <QDebug> | 21 | #include <QDebug> |
22 | #include <QMetaProperty> | ||
22 | 23 | ||
23 | using namespace Kube; | 24 | using namespace Kube; |
24 | 25 | ||
@@ -27,3 +28,18 @@ Context::Context(QObject *parent) | |||
27 | { | 28 | { |
28 | 29 | ||
29 | } | 30 | } |
31 | |||
32 | QDebug operator<<(QDebug dbg, const Kube::Context &context) | ||
33 | { | ||
34 | dbg << "Kube::Context {\n"; | ||
35 | auto metaObject = context.QObject::metaObject(); | ||
36 | for (auto i = metaObject->propertyOffset(); i < metaObject->propertyCount(); i++) { | ||
37 | auto property = metaObject->property(i); | ||
38 | dbg << property.name() << context.property(property.name()) << "\n"; | ||
39 | } | ||
40 | for (const auto &p : context.dynamicPropertyNames()) { | ||
41 | dbg << p << context.property(p) << "\n"; | ||
42 | } | ||
43 | dbg << "\n}"; | ||
44 | return dbg; | ||
45 | } | ||
diff --git a/framework/actions/context.h b/framework/actions/context.h index 7289f850..562e110e 100644 --- a/framework/actions/context.h +++ b/framework/actions/context.h | |||
@@ -31,5 +31,7 @@ public: | |||
31 | 31 | ||
32 | } | 32 | } |
33 | 33 | ||
34 | QDebug operator<<(QDebug dbg, const Kube::Context &); | ||
35 | |||
34 | Q_DECLARE_METATYPE(Kube::Context*); | 36 | Q_DECLARE_METATYPE(Kube::Context*); |
35 | 37 | ||
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index f996b91d..39b39a0a 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp | |||
@@ -98,10 +98,9 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" | |||
98 | static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", | 98 | static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", |
99 | [](Context *context) -> bool { | 99 | [](Context *context) -> bool { |
100 | auto accountId = context->property("accountId").value<QByteArray>(); | 100 | auto accountId = context->property("accountId").value<QByteArray>(); |
101 | auto message = context->property("message").value<KMime::Message::Ptr>(); | 101 | return !accountId.isEmpty(); |
102 | return !accountId.isEmpty() && message; | ||
103 | }, | 102 | }, |
104 | [](Context *context) { | 103 | ActionHandlerHelper::JobHandler{[](Context *context) -> KAsync::Job<void> { |
105 | auto accountId = context->property("accountId").value<QByteArray>(); | 104 | auto accountId = context->property("accountId").value<QByteArray>(); |
106 | auto message = context->property("message").value<KMime::Message::Ptr>(); | 105 | auto message = context->property("message").value<KMime::Message::Ptr>(); |
107 | SinkLog() << "Sending a mail: "; | 106 | SinkLog() << "Sending a mail: "; |
@@ -109,7 +108,7 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", | |||
109 | Query query; | 108 | Query query; |
110 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); | 109 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); |
111 | query.filter<SinkResource::Account>(accountId); | 110 | query.filter<SinkResource::Account>(accountId); |
112 | Store::fetchAll<ApplicationDomain::SinkResource>(query) | 111 | return Store::fetchAll<ApplicationDomain::SinkResource>(query) |
113 | .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> { | 112 | .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> { |
114 | if (!resources.isEmpty()) { | 113 | if (!resources.isEmpty()) { |
115 | auto resourceId = resources[0]->identifier(); | 114 | auto resourceId = resources[0]->identifier(); |
@@ -120,18 +119,18 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", | |||
120 | } | 119 | } |
121 | SinkWarning() << "Failed to find a mailtransport resource"; | 120 | SinkWarning() << "Failed to find a mailtransport resource"; |
122 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); | 121 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); |
123 | }).exec(); | 122 | }); |
124 | } | 123 | }} |
125 | ); | 124 | ); |
126 | 125 | ||
127 | static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", | 126 | static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", |
128 | [](Context *context) -> bool { | 127 | [](Context *context) -> bool { |
129 | auto accountId = context->property("accountId").value<QByteArray>(); | 128 | auto accountId = context->property("accountId").value<QByteArray>(); |
130 | auto message = context->property("message").value<KMime::Message::Ptr>(); | 129 | return !accountId.isEmpty(); |
131 | return !accountId.isEmpty() && message; | ||
132 | }, | 130 | }, |
133 | ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> { | 131 | ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> { |
134 | SinkLog() << "Executing the save-as-draft action"; | 132 | SinkLog() << "Executing the save-as-draft action"; |
133 | SinkLog() << *context; | ||
135 | const auto accountId = context->property("accountId").value<QByteArray>(); | 134 | const auto accountId = context->property("accountId").value<QByteArray>(); |
136 | const auto message = context->property("message").value<KMime::Message::Ptr>(); | 135 | const auto message = context->property("message").value<KMime::Message::Ptr>(); |
137 | auto existingMail = context->property("existingMail").value<Mail>(); | 136 | auto existingMail = context->property("existingMail").value<Mail>(); |
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 7fd2593d..18ebc4c4 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "composercontroller.h" | 21 | #include "composercontroller.h" |
22 | #include <actions/context.h> | 22 | #include <actions/context.h> |
23 | #include <actions/action.h> | 23 | #include <actions/action.h> |
24 | #include <actions/actionhandler.h> | ||
24 | #include <settings/settings.h> | 25 | #include <settings/settings.h> |
25 | #include <KMime/Message> | 26 | #include <KMime/Message> |
26 | #include <KCodecs/KEmailAddress> | 27 | #include <KCodecs/KEmailAddress> |
@@ -39,78 +40,25 @@ | |||
39 | 40 | ||
40 | SINK_DEBUG_AREA("composercontroller"); | 41 | SINK_DEBUG_AREA("composercontroller"); |
41 | 42 | ||
42 | ComposerController::ComposerController(QObject *parent) : QObject(parent) | 43 | Q_DECLARE_METATYPE(KMime::Types::Mailbox) |
43 | { | ||
44 | } | ||
45 | |||
46 | QString ComposerController::to() const | ||
47 | { | ||
48 | return m_to; | ||
49 | } | ||
50 | |||
51 | void ComposerController::setTo(const QString &to) | ||
52 | { | ||
53 | if(m_to != to) { | ||
54 | m_to = to; | ||
55 | emit toChanged(); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | QString ComposerController::cc() const | ||
60 | { | ||
61 | return m_cc; | ||
62 | } | ||
63 | |||
64 | void ComposerController::setCc(const QString &cc) | ||
65 | { | ||
66 | if(m_cc != cc) { | ||
67 | m_cc = cc; | ||
68 | emit ccChanged(); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | QString ComposerController::bcc() const | ||
73 | { | ||
74 | return m_bcc; | ||
75 | } | ||
76 | |||
77 | void ComposerController::setBcc(const QString &bcc) | ||
78 | { | ||
79 | if(m_bcc != bcc) { | ||
80 | m_bcc = bcc; | ||
81 | emit bccChanged(); | ||
82 | } | ||
83 | } | ||
84 | 44 | ||
85 | QString ComposerController::subject() const | 45 | ComposerController::ComposerController(QObject *parent) : QObject(parent) |
86 | { | ||
87 | return m_subject; | ||
88 | } | ||
89 | |||
90 | void ComposerController::setSubject(const QString &subject) | ||
91 | { | 46 | { |
92 | if(m_subject != subject) { | ||
93 | m_subject = subject; | ||
94 | emit subjectChanged(); | ||
95 | } | ||
96 | } | 47 | } |
97 | 48 | ||
98 | QString ComposerController::body() const | 49 | QString ComposerController::recepientSearchString() const |
99 | { | 50 | { |
100 | return m_body; | 51 | return QString(); |
101 | } | 52 | } |
102 | 53 | ||
103 | void ComposerController::setBody(const QString &body) | 54 | Kube::Context* ComposerController::mailContext() const |
104 | { | 55 | { |
105 | if(m_body != body) { | 56 | return mContext; |
106 | m_body = body; | ||
107 | emit bodyChanged(); | ||
108 | } | ||
109 | } | 57 | } |
110 | 58 | ||
111 | QString ComposerController::recepientSearchString() const | 59 | void ComposerController::setMailContext(Kube::Context *context) |
112 | { | 60 | { |
113 | return QString(); | 61 | mContext = context; |
114 | } | 62 | } |
115 | 63 | ||
116 | void ComposerController::setRecepientSearchString(const QString &s) | 64 | void ComposerController::setRecepientSearchString(const QString &s) |
@@ -134,24 +82,13 @@ QAbstractItemModel *ComposerController::recepientAutocompletionModel() const | |||
134 | return model; | 82 | return model; |
135 | } | 83 | } |
136 | 84 | ||
137 | QStringList ComposerController::attachemts() const | ||
138 | { | ||
139 | return m_attachments; | ||
140 | } | ||
141 | |||
142 | void ComposerController::addAttachment(const QUrl &fileUrl) | ||
143 | { | ||
144 | m_attachments.append(fileUrl.toString()); | ||
145 | emit attachmentsChanged(); | ||
146 | } | ||
147 | |||
148 | void ComposerController::setMessage(const KMime::Message::Ptr &msg) | 85 | void ComposerController::setMessage(const KMime::Message::Ptr &msg) |
149 | { | 86 | { |
150 | setTo(msg->to(true)->asUnicodeString()); | 87 | mContext->setProperty("to", msg->to(true)->asUnicodeString()); |
151 | setCc(msg->cc(true)->asUnicodeString()); | 88 | mContext->setProperty("cc", msg->cc(true)->asUnicodeString()); |
152 | setSubject(msg->subject(true)->asUnicodeString()); | 89 | mContext->setProperty("subject", msg->subject(true)->asUnicodeString()); |
153 | setBody(msg->body()); | 90 | mContext->setProperty("body", msg->body()); |
154 | m_msg = QVariant::fromValue(msg); | 91 | mContext->setProperty("existingMessage", QVariant::fromValue(msg)); |
155 | } | 92 | } |
156 | 93 | ||
157 | void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) | 94 | void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) |
@@ -159,7 +96,7 @@ void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) | |||
159 | Sink::Query query(*message.value<Sink::ApplicationDomain::Mail::Ptr>()); | 96 | Sink::Query query(*message.value<Sink::ApplicationDomain::Mail::Ptr>()); |
160 | query.request<Sink::ApplicationDomain::Mail::MimeMessage>(); | 97 | query.request<Sink::ApplicationDomain::Mail::MimeMessage>(); |
161 | Sink::Store::fetchOne<Sink::ApplicationDomain::Mail>(query).syncThen<void, Sink::ApplicationDomain::Mail>([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { | 98 | Sink::Store::fetchOne<Sink::ApplicationDomain::Mail>(query).syncThen<void, Sink::ApplicationDomain::Mail>([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { |
162 | m_existingMail = mail; | 99 | mContext->setProperty("existingMail", QVariant::fromValue(mail)); |
163 | const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); | 100 | const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); |
164 | if (!mailData.isEmpty()) { | 101 | if (!mailData.isEmpty()) { |
165 | KMime::Message::Ptr mail(new KMime::Message); | 102 | KMime::Message::Ptr mail(new KMime::Message); |
@@ -196,84 +133,88 @@ void applyAddresses(const QString &list, std::function<void(const QByteArray &, | |||
196 | } | 133 | } |
197 | } | 134 | } |
198 | 135 | ||
199 | bool ComposerController::identityIsSet() const | 136 | void ComposerController::clear() |
200 | { | 137 | { |
201 | return (identityModel()->rowCount() > 0) && (m_currentAccountIndex >= 0); | 138 | mContext->setProperty("subject", QVariant()); |
139 | mContext->setProperty("body", QVariant()); | ||
140 | mContext->setProperty("to", QVariant()); | ||
141 | mContext->setProperty("cc", QVariant()); | ||
142 | mContext->setProperty("bcc", QVariant()); | ||
202 | } | 143 | } |
203 | 144 | ||
204 | KMime::Message::Ptr ComposerController::assembleMessage() | 145 | |
146 | Kube::ActionHandler *ComposerController::messageHandler() | ||
205 | { | 147 | { |
206 | auto mail = m_msg.value<KMime::Message::Ptr>(); | 148 | return new Kube::ActionHandlerHelper( |
207 | if (!mail) { | 149 | [](Kube::Context *context) { |
208 | mail = KMime::Message::Ptr::create(); | 150 | auto identity = context->property("identity"); |
209 | } | 151 | return identity.isValid(); |
210 | applyAddresses(m_to, [&](const QByteArray &addrSpec, const QByteArray &displayName) { | 152 | }, |
211 | mail->to(true)->addAddress(addrSpec, displayName); | 153 | [this](Kube::Context *context) { |
212 | recordForAutocompletion(addrSpec, displayName); | 154 | auto mail = context->property("existingMessage").value<KMime::Message::Ptr>(); |
213 | }); | 155 | if (!mail) { |
214 | applyAddresses(m_cc, [&](const QByteArray &addrSpec, const QByteArray &displayName) { | 156 | mail = KMime::Message::Ptr::create(); |
215 | mail->cc(true)->addAddress(addrSpec, displayName); | 157 | } |
216 | recordForAutocompletion(addrSpec, displayName); | 158 | applyAddresses(context->property("to").toString(), [&](const QByteArray &addrSpec, const QByteArray &displayName) { |
217 | }); | 159 | mail->to(true)->addAddress(addrSpec, displayName); |
218 | applyAddresses(m_bcc, [&](const QByteArray &addrSpec, const QByteArray &displayName) { | 160 | recordForAutocompletion(addrSpec, displayName); |
219 | mail->bcc(true)->addAddress(addrSpec, displayName); | 161 | }); |
220 | recordForAutocompletion(addrSpec, displayName); | 162 | applyAddresses(context->property("cc").toString(), [&](const QByteArray &addrSpec, const QByteArray &displayName) { |
221 | }); | 163 | mail->cc(true)->addAddress(addrSpec, displayName); |
222 | if (!identityIsSet()) { | 164 | recordForAutocompletion(addrSpec, displayName); |
223 | SinkWarning() << "We don't have an identity to send the mail with."; | 165 | }); |
224 | } else { | 166 | applyAddresses(context->property("bcc").toString(), [&](const QByteArray &addrSpec, const QByteArray &displayName) { |
225 | auto currentIndex = identityModel()->index(m_currentAccountIndex, 0); | 167 | mail->bcc(true)->addAddress(addrSpec, displayName); |
226 | KMime::Types::Mailbox mb; | 168 | recordForAutocompletion(addrSpec, displayName); |
227 | mb.setName(currentIndex.data(IdentitiesModel::Username).toString()); | 169 | }); |
228 | mb.setAddress(currentIndex.data(IdentitiesModel::Address).toString().toUtf8()); | 170 | |
229 | mail->from(true)->addAddress(mb); | 171 | mail->from(true)->addAddress(context->property("identity").value<KMime::Types::Mailbox>()); |
230 | mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); | 172 | |
231 | mail->setBody(m_body.toUtf8()); | 173 | mail->subject(true)->fromUnicodeString(context->property("subject").toString(), "utf-8"); |
232 | mail->assemble(); | 174 | mail->setBody(context->property("body").toString().toUtf8()); |
233 | return mail; | 175 | mail->assemble(); |
234 | } | 176 | |
235 | return KMime::Message::Ptr(); | 177 | context->setProperty("message", QVariant::fromValue(mail)); |
178 | } | ||
179 | ); | ||
236 | } | 180 | } |
237 | 181 | ||
238 | void ComposerController::send() | 182 | Kube::Action* ComposerController::saveAsDraftAction() |
239 | { | 183 | { |
240 | auto mail = assembleMessage(); | 184 | auto action = new Kube::Action("org.kde.kube.actions.save-as-draft", *mContext); |
241 | 185 | action->addPreHandler(messageHandler()); | |
242 | //TODO deactivate action if we don't have the identiy set | 186 | return action; |
243 | if (!identityIsSet()) { | ||
244 | SinkWarning() << "We don't have an identity to send the mail with."; | ||
245 | } else { | ||
246 | auto currentAccountId = identityModel()->index(m_currentAccountIndex, 0).data(IdentitiesModel::AccountId).toByteArray(); | ||
247 | |||
248 | Kube::Context context; | ||
249 | context.setProperty("message", QVariant::fromValue(mail)); | ||
250 | context.setProperty("accountId", QVariant::fromValue(currentAccountId)); | ||
251 | |||
252 | qDebug() << "Current account " << currentAccountId; | ||
253 | |||
254 | Kube::Action("org.kde.kube.actions.sendmail", context).execute(); | ||
255 | clear(); | ||
256 | } | ||
257 | } | 187 | } |
258 | 188 | ||
259 | void ComposerController::saveAsDraft() | 189 | Kube::Action* ComposerController::sendAction() |
260 | { | 190 | { |
261 | auto mail = assembleMessage(); | 191 | qWarning() << "send action"; |
262 | auto currentAccountId = identityModel()->index(m_currentAccountIndex, 0).data(IdentitiesModel::AccountId).toByteArray(); | 192 | auto action = new Kube::Action("org.kde.kube.actions.sendmail", *mContext); |
193 | // action->addPreHandler(identityHandler()); | ||
194 | action->addPreHandler(messageHandler()); | ||
195 | // action->addPreHandler(encryptionHandler()); | ||
196 | return action; | ||
197 | } | ||
263 | 198 | ||
264 | Kube::Context context; | 199 | void ComposerController::setCurrentIdentityIndex(int index) |
265 | context.setProperty("message", QVariant::fromValue(mail)); | 200 | { |
266 | context.setProperty("accountId", QVariant::fromValue(currentAccountId)); | 201 | m_currentAccountIndex = index; |
267 | context.setProperty("existingMail", QVariant::fromValue(m_existingMail)); | 202 | auto currentIndex = identityModel()->index(m_currentAccountIndex, 0); |
268 | Kube::Action("org.kde.kube.actions.save-as-draft", context).execute(); | 203 | if (currentIndex.isValid()) { |
269 | clear(); | 204 | auto currentAccountId = currentIndex.data(IdentitiesModel::AccountId).toByteArray(); |
205 | SinkWarning() << "valid identity for index: " << index << " out of available in model: " << identityModel()->rowCount(); | ||
206 | KMime::Types::Mailbox mb; | ||
207 | mb.setName(currentIndex.data(IdentitiesModel::Username).toString()); | ||
208 | mb.setAddress(currentIndex.data(IdentitiesModel::Address).toString().toUtf8()); | ||
209 | SinkLog() << "Setting current identity: " << mb.prettyAddress() << "Account: " << currentAccountId; | ||
210 | mContext->setProperty("identity", QVariant::fromValue(mb)); | ||
211 | mContext->setProperty("accountId", QVariant::fromValue(currentAccountId)); | ||
212 | } else { | ||
213 | SinkWarning() << "No valid identity for index: " << index << " out of available in model: " << identityModel()->rowCount(); | ||
214 | } | ||
270 | } | 215 | } |
271 | 216 | ||
272 | void ComposerController::clear() | 217 | int ComposerController::currentIdentityIndex() const |
273 | { | 218 | { |
274 | setSubject(""); | 219 | return m_currentAccountIndex; |
275 | setBody(""); | ||
276 | setTo(""); | ||
277 | setCc(""); | ||
278 | setBcc(""); | ||
279 | } | 220 | } |
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index aa2ae0d7..6fad0685 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -26,6 +26,9 @@ | |||
26 | #include <QAbstractItemModel> | 26 | #include <QAbstractItemModel> |
27 | #include <sink/applicationdomaintype.h> | 27 | #include <sink/applicationdomaintype.h> |
28 | 28 | ||
29 | #include <actions/context.h> | ||
30 | #include <actions/action.h> | ||
31 | |||
29 | namespace KMime { | 32 | namespace KMime { |
30 | class Message; | 33 | class Message; |
31 | } | 34 | } |
@@ -33,34 +36,21 @@ class Message; | |||
33 | class ComposerController : public QObject | 36 | class ComposerController : public QObject |
34 | { | 37 | { |
35 | Q_OBJECT | 38 | Q_OBJECT |
36 | Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) | 39 | Q_PROPERTY (Kube::Context* mailContext READ mailContext WRITE setMailContext) |
37 | Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) | 40 | Q_PROPERTY (int currentIdentityIndex READ currentIdentityIndex WRITE setCurrentIdentityIndex) |
38 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) | 41 | |
39 | Q_PROPERTY (QString subject READ subject WRITE setSubject NOTIFY subjectChanged) | ||
40 | Q_PROPERTY (QString body READ body WRITE setBody NOTIFY bodyChanged) | ||
41 | Q_PROPERTY (QString recepientSearchString READ recepientSearchString WRITE setRecepientSearchString) | 42 | Q_PROPERTY (QString recepientSearchString READ recepientSearchString WRITE setRecepientSearchString) |
42 | Q_PROPERTY (QAbstractItemModel* recepientAutocompletionModel READ recepientAutocompletionModel CONSTANT) | 43 | Q_PROPERTY (QAbstractItemModel* recepientAutocompletionModel READ recepientAutocompletionModel CONSTANT) |
43 | Q_PROPERTY (QAbstractItemModel* identityModel READ identityModel CONSTANT) | 44 | Q_PROPERTY (QAbstractItemModel* identityModel READ identityModel CONSTANT) |
44 | Q_PROPERTY (int currentIdentityIndex MEMBER m_currentAccountIndex) | 45 | |
45 | Q_PROPERTY (QStringList attachments READ attachemts NOTIFY attachmentsChanged) | 46 | Q_PROPERTY (Kube::Action* sendAction READ sendAction) |
47 | Q_PROPERTY (Kube::Action* saveAsDraftAction READ saveAsDraftAction) | ||
46 | 48 | ||
47 | public: | 49 | public: |
48 | explicit ComposerController(QObject *parent = Q_NULLPTR); | 50 | explicit ComposerController(QObject *parent = Q_NULLPTR); |
49 | 51 | ||
50 | QString to() const; | 52 | Kube::Context* mailContext() const; |
51 | void setTo(const QString &to); | 53 | void setMailContext(Kube::Context *context); |
52 | |||
53 | QString cc() const; | ||
54 | void setCc(const QString &cc); | ||
55 | |||
56 | QString bcc() const; | ||
57 | void setBcc(const QString &bcc); | ||
58 | |||
59 | QString subject() const; | ||
60 | void setSubject(const QString &subject); | ||
61 | |||
62 | QString body() const; | ||
63 | void setBody(const QString &body); | ||
64 | 54 | ||
65 | QString recepientSearchString() const; | 55 | QString recepientSearchString() const; |
66 | void setRecepientSearchString(const QString &body); | 56 | void setRecepientSearchString(const QString &body); |
@@ -68,36 +58,22 @@ public: | |||
68 | QAbstractItemModel *identityModel() const; | 58 | QAbstractItemModel *identityModel() const; |
69 | QAbstractItemModel *recepientAutocompletionModel() const; | 59 | QAbstractItemModel *recepientAutocompletionModel() const; |
70 | 60 | ||
71 | QStringList attachemts() const; | ||
72 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); | 61 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); |
73 | 62 | ||
74 | signals: | 63 | Kube::Action* sendAction(); |
75 | void subjectChanged(); | 64 | Kube::Action* saveAsDraftAction(); |
76 | void bodyChanged(); | 65 | |
77 | void toChanged(); | 66 | void setCurrentIdentityIndex(int index); |
78 | void ccChanged(); | 67 | int currentIdentityIndex() const; |
79 | void bccChanged(); | ||
80 | void fromIndexChanged(); | ||
81 | void attachmentsChanged(); | ||
82 | 68 | ||
83 | public slots: | 69 | public slots: |
84 | void send(); | ||
85 | void saveAsDraft(); | ||
86 | void clear(); | 70 | void clear(); |
87 | void addAttachment(const QUrl &fileUrl); | ||
88 | 71 | ||
89 | private: | 72 | private: |
90 | bool identityIsSet() const; | 73 | Kube::ActionHandler *messageHandler(); |
91 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); | 74 | void recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName); |
92 | void setMessage(const QSharedPointer<KMime::Message> &msg); | 75 | void setMessage(const QSharedPointer<KMime::Message> &msg); |
93 | QSharedPointer<KMime::Message> assembleMessage(); | 76 | |
94 | QString m_to; | 77 | int m_currentAccountIndex = -1; |
95 | QString m_cc; | 78 | Kube::Context *mContext; |
96 | QString m_bcc; | ||
97 | QString m_subject; | ||
98 | QString m_body; | ||
99 | QStringList m_attachments; | ||
100 | Sink::ApplicationDomain::Mail m_existingMail; | ||
101 | QVariant m_msg; | ||
102 | int m_currentAccountIndex; | ||
103 | }; | 79 | }; |
diff --git a/framework/domain/identitiesmodel.cpp b/framework/domain/identitiesmodel.cpp index 8f5c4963..33cc191c 100644 --- a/framework/domain/identitiesmodel.cpp +++ b/framework/domain/identitiesmodel.cpp | |||
@@ -18,12 +18,17 @@ | |||
18 | */ | 18 | */ |
19 | #include "identitiesmodel.h" | 19 | #include "identitiesmodel.h" |
20 | #include <sink/store.h> | 20 | #include <sink/store.h> |
21 | #include <sink/log.h> | ||
22 | |||
23 | using namespace Sink; | ||
21 | 24 | ||
22 | IdentitiesModel::IdentitiesModel(QObject *parent) : QIdentityProxyModel() | 25 | IdentitiesModel::IdentitiesModel(QObject *parent) : QIdentityProxyModel() |
23 | { | 26 | { |
24 | Sink::Query query; | 27 | Sink::Query query; |
25 | query.setFlags(Sink::Query::LiveQuery); | 28 | query.setFlags(Sink::Query::LiveQuery); |
26 | query.requestedProperties << "name" << "username" << "address" << "account"; | 29 | query.request<Sink::ApplicationDomain::Identity::Name>() |
30 | .request<Sink::ApplicationDomain::Identity::Address>() | ||
31 | .request<Sink::ApplicationDomain::Identity::Account>(); | ||
27 | runQuery(query); | 32 | runQuery(query); |
28 | } | 33 | } |
29 | 34 | ||
@@ -53,21 +58,21 @@ QVariant IdentitiesModel::data(const QModelIndex &idx, int role) const | |||
53 | auto srcIdx = mapToSource(idx); | 58 | auto srcIdx = mapToSource(idx); |
54 | switch (role) { | 59 | switch (role) { |
55 | case Name: | 60 | case Name: |
56 | return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); | 61 | return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getName(); |
57 | case Username: | 62 | case Username: |
58 | return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString(); | 63 | return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getName(); |
59 | case Address: | 64 | case Address: |
60 | return srcIdx.sibling(srcIdx.row(), 2).data(Qt::DisplayRole).toString(); | 65 | return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAddress(); |
61 | case IdentityId: | 66 | case IdentityId: |
62 | return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier(); | 67 | return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->identifier(); |
63 | case AccountId: | 68 | case AccountId: |
64 | return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->getProperty("account").toByteArray(); | 69 | return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAccount(); |
65 | case AccountName: { | 70 | case AccountName: { |
66 | const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); | 71 | const auto accountId = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAccount(); |
67 | return mAccountNames.value(accountId); | 72 | return mAccountNames.value(accountId); |
68 | } | 73 | } |
69 | case AccountIcon: { | 74 | case AccountIcon: { |
70 | const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); | 75 | const auto accountId = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAccount(); |
71 | return mAccountIcons.value(accountId); | 76 | return mAccountIcons.value(accountId); |
72 | } | 77 | } |
73 | case DisplayName: { | 78 | case DisplayName: { |
@@ -85,8 +90,8 @@ void IdentitiesModel::runQuery(const Sink::Query &query) | |||
85 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkAccount>(Sink::Query()) | 90 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkAccount>(Sink::Query()) |
86 | .syncThen<void, QList<Sink::ApplicationDomain::SinkAccount::Ptr> >([this](const QList<Sink::ApplicationDomain::SinkAccount::Ptr> &accounts) { | 91 | .syncThen<void, QList<Sink::ApplicationDomain::SinkAccount::Ptr> >([this](const QList<Sink::ApplicationDomain::SinkAccount::Ptr> &accounts) { |
87 | for (const auto &account : accounts) { | 92 | for (const auto &account : accounts) { |
88 | mAccountNames.insert(account->identifier(), account->getProperty("name").toString()); | 93 | mAccountNames.insert(account->identifier(), account->getName()); |
89 | mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString()); | 94 | mAccountIcons.insert(account->identifier(), account->getIcon()); |
90 | } | 95 | } |
91 | emit layoutChanged(); | 96 | emit layoutChanged(); |
92 | }).exec(); | 97 | }).exec(); |
diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index f2c5a66f..067d1d79 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "accountsettings.h" | 19 | #include "accountsettings.h" |
20 | 20 | ||
21 | #include <sink/store.h> | 21 | #include <sink/store.h> |
22 | #include <sink/log.h> | ||
22 | #include <QDebug> | 23 | #include <QDebug> |
23 | #include <QDir> | 24 | #include <QDir> |
24 | #include <QUrl> | 25 | #include <QUrl> |
@@ -26,6 +27,8 @@ | |||
26 | using namespace Sink; | 27 | using namespace Sink; |
27 | using namespace Sink::ApplicationDomain; | 28 | using namespace Sink::ApplicationDomain; |
28 | 29 | ||
30 | SINK_DEBUG_AREA("accountsettings") | ||
31 | |||
29 | AccountSettings::AccountSettings(QObject *parent) | 32 | AccountSettings::AccountSettings(QObject *parent) |
30 | : QObject(parent) | 33 | : QObject(parent) |
31 | { | 34 | { |
@@ -181,7 +184,7 @@ void AccountSettings::loadMaildirResource() | |||
181 | emit pathChanged(); | 184 | emit pathChanged(); |
182 | } | 185 | } |
183 | }).onError([](const KAsync::Error &error) { | 186 | }).onError([](const KAsync::Error &error) { |
184 | qWarning() << "Failed to find the maildir resource: " << error.errorMessage; | 187 | SinkWarning() << "Failed to find the maildir resource: " << error.errorMessage; |
185 | }).exec(); | 188 | }).exec(); |
186 | } | 189 | } |
187 | 190 | ||
@@ -195,7 +198,7 @@ void AccountSettings::loadMailtransportResource() | |||
195 | mSmtpPassword = resource.getProperty("password").toString(); | 198 | mSmtpPassword = resource.getProperty("password").toString(); |
196 | emit smtpResourceChanged(); | 199 | emit smtpResourceChanged(); |
197 | }).onError([](const KAsync::Error &error) { | 200 | }).onError([](const KAsync::Error &error) { |
198 | qWarning() << "Failed to find the smtp resource: " << error.errorMessage; | 201 | SinkWarning() << "Failed to find the smtp resource: " << error.errorMessage; |
199 | }).exec(); | 202 | }).exec(); |
200 | } | 203 | } |
201 | 204 | ||
@@ -209,7 +212,7 @@ void AccountSettings::loadIdentity() | |||
209 | mEmailAddress = identity.getAddress(); | 212 | mEmailAddress = identity.getAddress(); |
210 | emit identityChanged(); | 213 | emit identityChanged(); |
211 | }).onError([](const KAsync::Error &error) { | 214 | }).onError([](const KAsync::Error &error) { |
212 | qWarning() << "Failed to find the identity resource: " << error.errorMessage; | 215 | SinkWarning() << "Failed to find the identity resource: " << error.errorMessage; |
213 | }).exec(); | 216 | }).exec(); |
214 | } | 217 | } |
215 | 218 | ||
@@ -225,7 +228,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA | |||
225 | } | 228 | } |
226 | Store::modify(resource) | 229 | Store::modify(resource) |
227 | .onError([](const KAsync::Error &error) { | 230 | .onError([](const KAsync::Error &error) { |
228 | qWarning() << "Error while modifying resource: " << error.errorMessage; | 231 | SinkWarning() << "Error while modifying resource: " << error.errorMessage; |
229 | }) | 232 | }) |
230 | .exec(); | 233 | .exec(); |
231 | } else { | 234 | } else { |
@@ -236,7 +239,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA | |||
236 | } | 239 | } |
237 | Store::create(resource) | 240 | Store::create(resource) |
238 | .onError([](const KAsync::Error &error) { | 241 | .onError([](const KAsync::Error &error) { |
239 | qWarning() << "Error while creating resource: " << error.errorMessage; | 242 | SinkWarning() << "Error while creating resource: " << error.errorMessage; |
240 | }) | 243 | }) |
241 | .exec(); | 244 | .exec(); |
242 | return newIdentifier; | 245 | return newIdentifier; |
@@ -277,7 +280,7 @@ void AccountSettings::saveIdentity() | |||
277 | identity.setAddress(mEmailAddress); | 280 | identity.setAddress(mEmailAddress); |
278 | Store::modify(identity) | 281 | Store::modify(identity) |
279 | .onError([](const KAsync::Error &error) { | 282 | .onError([](const KAsync::Error &error) { |
280 | qWarning() << "Error while modifying identity: " << error.errorMessage; | 283 | SinkWarning() << "Error while modifying identity: " << error.errorMessage; |
281 | }) | 284 | }) |
282 | .exec(); | 285 | .exec(); |
283 | } else { | 286 | } else { |
@@ -288,7 +291,7 @@ void AccountSettings::saveIdentity() | |||
288 | identity.setAddress(mEmailAddress); | 291 | identity.setAddress(mEmailAddress); |
289 | Store::create(identity) | 292 | Store::create(identity) |
290 | .onError([](const KAsync::Error &error) { | 293 | .onError([](const KAsync::Error &error) { |
291 | qWarning() << "Error while creating identity: " << error.errorMessage; | 294 | SinkWarning() << "Error while creating identity: " << error.errorMessage; |
292 | }) | 295 | }) |
293 | .exec(); | 296 | .exec(); |
294 | } | 297 | } |
@@ -297,12 +300,12 @@ void AccountSettings::saveIdentity() | |||
297 | void AccountSettings::removeResource(const QByteArray &identifier) | 300 | void AccountSettings::removeResource(const QByteArray &identifier) |
298 | { | 301 | { |
299 | if (identifier.isEmpty()) { | 302 | if (identifier.isEmpty()) { |
300 | qWarning() << "We're missing an identifier"; | 303 | SinkWarning() << "We're missing an identifier"; |
301 | } else { | 304 | } else { |
302 | SinkResource resource(identifier); | 305 | SinkResource resource(identifier); |
303 | Store::remove(resource) | 306 | Store::remove(resource) |
304 | .onError([](const KAsync::Error &error) { | 307 | .onError([](const KAsync::Error &error) { |
305 | qWarning() << "Error while removing resource: " << error.errorMessage; | 308 | SinkWarning() << "Error while removing resource: " << error.errorMessage; |
306 | }) | 309 | }) |
307 | .exec(); | 310 | .exec(); |
308 | } | 311 | } |
@@ -311,12 +314,12 @@ void AccountSettings::removeResource(const QByteArray &identifier) | |||
311 | void AccountSettings::removeAccount() | 314 | void AccountSettings::removeAccount() |
312 | { | 315 | { |
313 | if (mAccountIdentifier.isEmpty()) { | 316 | if (mAccountIdentifier.isEmpty()) { |
314 | qWarning() << "We're missing an identifier"; | 317 | SinkWarning() << "We're missing an identifier"; |
315 | } else { | 318 | } else { |
316 | SinkAccount account(mAccountIdentifier); | 319 | SinkAccount account(mAccountIdentifier); |
317 | Store::remove(account) | 320 | Store::remove(account) |
318 | .onError([](const KAsync::Error &error) { | 321 | .onError([](const KAsync::Error &error) { |
319 | qWarning() << "Error while removing account: " << error.errorMessage; | 322 | SinkWarning() << "Error while removing account: " << error.errorMessage; |
320 | }) | 323 | }) |
321 | .exec(); | 324 | .exec(); |
322 | } | 325 | } |
@@ -325,12 +328,12 @@ void AccountSettings::removeAccount() | |||
325 | void AccountSettings::removeIdentity() | 328 | void AccountSettings::removeIdentity() |
326 | { | 329 | { |
327 | if (mIdentityIdentifier.isEmpty()) { | 330 | if (mIdentityIdentifier.isEmpty()) { |
328 | qWarning() << "We're missing an identifier"; | 331 | SinkWarning() << "We're missing an identifier"; |
329 | } else { | 332 | } else { |
330 | Identity identity(mIdentityIdentifier); | 333 | Identity identity(mIdentityIdentifier); |
331 | Store::remove(identity) | 334 | Store::remove(identity) |
332 | .onError([](const KAsync::Error &error) { | 335 | .onError([](const KAsync::Error &error) { |
333 | qWarning() << "Error while removing identity: " << error.errorMessage; | 336 | SinkWarning() << "Error while removing identity: " << error.errorMessage; |
334 | }) | 337 | }) |
335 | .exec(); | 338 | .exec(); |
336 | } | 339 | } |