diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-11 11:12:12 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-11 11:12:12 +0200 |
commit | aaf114296e50bfa93b831491738cd0a780085c3d (patch) | |
tree | 2ee864ac6bf39e2b856ffaf0137dd78fda40c7d8 | |
parent | df10583b42f49a58d27dd6dd322f22fd88ce1418 (diff) | |
download | kube-aaf114296e50bfa93b831491738cd0a780085c3d.tar.gz kube-aaf114296e50bfa93b831491738cd0a780085c3d.zip |
Let the controller retrieve what it requires, remember the id of the
draft to modfiy.
-rw-r--r-- | components/mail/contents/ui/main.qml | 6 | ||||
-rw-r--r-- | components/package/contents/ui/Composer.qml | 24 | ||||
-rw-r--r-- | components/package/contents/ui/FocusComposer.qml | 8 | ||||
-rw-r--r-- | framework/domain/actions/sinkactions.cpp | 2 | ||||
-rw-r--r-- | framework/domain/composercontroller.cpp | 50 | ||||
-rw-r--r-- | framework/domain/composercontroller.h | 8 |
6 files changed, 40 insertions, 58 deletions
diff --git a/components/mail/contents/ui/main.qml b/components/mail/contents/ui/main.qml index c2569cdc..8d7047ab 100644 --- a/components/mail/contents/ui/main.qml +++ b/components/mail/contents/ui/main.qml | |||
@@ -184,7 +184,8 @@ ApplicationWindow { | |||
184 | } | 184 | } |
185 | 185 | ||
186 | function handler(context) { | 186 | function handler(context) { |
187 | composerComponent.createObject(app, {"originalMessage": context.mail}) | 187 | var component = composerComponent.createObject(app) |
188 | component.loadMessage(context.mail, false) | ||
188 | } | 189 | } |
189 | } | 190 | } |
190 | 191 | ||
@@ -195,7 +196,8 @@ ApplicationWindow { | |||
195 | } | 196 | } |
196 | 197 | ||
197 | function handler(context) { | 198 | function handler(context) { |
198 | composerComponent.createObject(app, {"draftMessage": context.mail}) | 199 | var component= composerComponent.createObject(app, {"draftMessage": context.mail}) |
200 | component.loadMessage(context.mail, true) | ||
199 | } | 201 | } |
200 | } | 202 | } |
201 | 203 | ||
diff --git a/components/package/contents/ui/Composer.qml b/components/package/contents/ui/Composer.qml index ed8fb2f2..aef6913b 100644 --- a/components/package/contents/ui/Composer.qml +++ b/components/package/contents/ui/Composer.qml | |||
@@ -25,8 +25,10 @@ import org.kube.framework.domain 1.0 as KubeFramework | |||
25 | 25 | ||
26 | Item { | 26 | Item { |
27 | id: root | 27 | id: root |
28 | property variant originalMessage | 28 | |
29 | property variant draftMessage | 29 | function loadMessage(message, loadAsDraft) { |
30 | composer.loadMessage(message, loadAsDraft) | ||
31 | } | ||
30 | 32 | ||
31 | function send() { | 33 | function send() { |
32 | composer.send() | 34 | composer.send() |
@@ -40,26 +42,8 @@ Item { | |||
40 | composer.clear(); | 42 | composer.clear(); |
41 | } | 43 | } |
42 | 44 | ||
43 | KubeFramework.Retriever { | ||
44 | id: originalMessageRetriever | ||
45 | propertyName: "mimeMessage" | ||
46 | model: KubeFramework.MailListModel { | ||
47 | mail: root.originalMessage | ||
48 | } | ||
49 | } | ||
50 | |||
51 | KubeFramework.Retriever { | ||
52 | id: draftMessageRetriever | ||
53 | propertyName: "mimeMessage" | ||
54 | model: KubeFramework.MailListModel { | ||
55 | mail: root.draftMessage | ||
56 | } | ||
57 | } | ||
58 | |||
59 | KubeFramework.ComposerController { | 45 | KubeFramework.ComposerController { |
60 | id: composer | 46 | id: composer |
61 | originalMessage: originalMessageRetriever.value | ||
62 | draftMessage: draftMessageRetriever.value | ||
63 | } | 47 | } |
64 | 48 | ||
65 | ColumnLayout { | 49 | ColumnLayout { |
diff --git a/components/package/contents/ui/FocusComposer.qml b/components/package/contents/ui/FocusComposer.qml index 4e61b6c1..ea410338 100644 --- a/components/package/contents/ui/FocusComposer.qml +++ b/components/package/contents/ui/FocusComposer.qml | |||
@@ -23,8 +23,10 @@ import org.kube.framework.theme 1.0 | |||
23 | 23 | ||
24 | Rectangle { | 24 | Rectangle { |
25 | id: root | 25 | id: root |
26 | property variant originalMessage | 26 | |
27 | property variant draftMessage | 27 | function loadMessage(message, loadAsDraft) { |
28 | composer.loadMessage(message, loadAsDraft); | ||
29 | } | ||
28 | 30 | ||
29 | color: ColorPalette.border | 31 | color: ColorPalette.border |
30 | 32 | ||
@@ -62,8 +64,6 @@ Rectangle { | |||
62 | 64 | ||
63 | Layout.fillWidth: true | 65 | Layout.fillWidth: true |
64 | Layout.fillHeight: true | 66 | Layout.fillHeight: true |
65 | originalMessage: root.originalMessage | ||
66 | draftMessage: root.draftMessage | ||
67 | } | 67 | } |
68 | 68 | ||
69 | RowLayout { | 69 | RowLayout { |
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index 354a5aca..129b538a 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp | |||
@@ -130,7 +130,7 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", | |||
130 | return Sink::Store::create(mail); | 130 | return Sink::Store::create(mail); |
131 | }); | 131 | }); |
132 | } else { | 132 | } else { |
133 | qWarning() << "Modifying an existing mail"; | 133 | qWarning() << "Modifying an existing mail" << existingMail.identifier(); |
134 | existingMail.setBlobProperty("mimeMessage", message->encodedContent()); | 134 | existingMail.setBlobProperty("mimeMessage", message->encodedContent()); |
135 | return Sink::Store::modify(existingMail); | 135 | return Sink::Store::modify(existingMail); |
136 | } | 136 | } |
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 94914f17..2dcf1bb1 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <QVariant> | 27 | #include <QVariant> |
28 | #include <QDebug> | 28 | #include <QDebug> |
29 | #include <QQmlEngine> | 29 | #include <QQmlEngine> |
30 | #include <sink/store.h> | ||
30 | 31 | ||
31 | #include "accountsmodel.h" | 32 | #include "accountsmodel.h" |
32 | #include "identitiesmodel.h" | 33 | #include "identitiesmodel.h" |
@@ -128,32 +129,28 @@ void ComposerController::setMessage(const KMime::Message::Ptr &msg) | |||
128 | m_msg = QVariant::fromValue(msg); | 129 | m_msg = QVariant::fromValue(msg); |
129 | } | 130 | } |
130 | 131 | ||
131 | void ComposerController::setOriginalMessage(const QVariant &originalMessage) | 132 | void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) |
132 | { | 133 | { |
133 | const auto mailData = KMime::CRLFtoLF(originalMessage.toByteArray()); | 134 | Sink::Query query(*message.value<Sink::ApplicationDomain::Mail::Ptr>()); |
134 | if (!mailData.isEmpty()) { | 135 | query.request<Sink::ApplicationDomain::Mail::MimeMessage>(); |
135 | KMime::Message::Ptr mail(new KMime::Message); | 136 | Sink::Store::fetchOne<Sink::ApplicationDomain::Mail>(query).then<void, Sink::ApplicationDomain::Mail>([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { |
136 | mail->setContent(mailData); | 137 | m_existingMail = mail; |
137 | mail->parse(); | 138 | const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); |
138 | auto reply = MailTemplates::reply(mail); | 139 | if (!mailData.isEmpty()) { |
139 | //We assume reply | 140 | KMime::Message::Ptr mail(new KMime::Message); |
140 | setMessage(reply); | 141 | mail->setContent(mailData); |
141 | } else { | 142 | mail->parse(); |
142 | m_msg = QVariant(); | 143 | if (loadAsDraft) { |
143 | } | 144 | auto reply = MailTemplates::reply(mail); |
144 | } | 145 | //We assume reply |
145 | 146 | setMessage(reply); | |
146 | void ComposerController::setDraftMessage(const QVariant &originalMessage) | 147 | } else { |
147 | { | 148 | setMessage(mail); |
148 | const auto mailData = KMime::CRLFtoLF(originalMessage.toByteArray()); | 149 | } |
149 | if (!mailData.isEmpty()) { | 150 | } else { |
150 | KMime::Message::Ptr mail(new KMime::Message); | 151 | qWarning() << "Retrieved empty message"; |
151 | mail->setContent(mailData); | 152 | } |
152 | mail->parse(); | 153 | }).exec(); |
153 | setMessage(mail); | ||
154 | } else { | ||
155 | m_msg = QVariant(); | ||
156 | } | ||
157 | } | 154 | } |
158 | 155 | ||
159 | KMime::Message::Ptr ComposerController::assembleMessage() | 156 | KMime::Message::Ptr ComposerController::assembleMessage() |
@@ -203,6 +200,7 @@ void ComposerController::saveAsDraft() | |||
203 | Kube::Context context; | 200 | Kube::Context context; |
204 | context.setProperty("message", QVariant::fromValue(mail)); | 201 | context.setProperty("message", QVariant::fromValue(mail)); |
205 | context.setProperty("accountId", QVariant::fromValue(currentAccountId)); | 202 | context.setProperty("accountId", QVariant::fromValue(currentAccountId)); |
203 | context.setProperty("existingMail", QVariant::fromValue(m_existingMail)); | ||
206 | Kube::Action("org.kde.kube.actions.save-as-draft", context).execute(); | 204 | Kube::Action("org.kde.kube.actions.save-as-draft", context).execute(); |
207 | clear(); | 205 | clear(); |
208 | } | 206 | } |
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index b24c16a9..8390c639 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <QStringList> | 24 | #include <QStringList> |
25 | #include <QVariant> | 25 | #include <QVariant> |
26 | #include <QAbstractItemModel> | 26 | #include <QAbstractItemModel> |
27 | #include <sink/applicationdomaintype.h> | ||
27 | 28 | ||
28 | namespace KMime { | 29 | namespace KMime { |
29 | class Message; | 30 | class Message; |
@@ -32,8 +33,6 @@ class Message; | |||
32 | class ComposerController : public QObject | 33 | class ComposerController : public QObject |
33 | { | 34 | { |
34 | Q_OBJECT | 35 | Q_OBJECT |
35 | Q_PROPERTY (QVariant originalMessage WRITE setOriginalMessage) | ||
36 | Q_PROPERTY (QVariant draftMessage WRITE setDraftMessage) | ||
37 | Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) | 36 | Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) |
38 | Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) | 37 | Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) |
39 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) | 38 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) |
@@ -64,9 +63,7 @@ public: | |||
64 | QAbstractItemModel *identityModel() const; | 63 | QAbstractItemModel *identityModel() const; |
65 | 64 | ||
66 | QStringList attachemts() const; | 65 | QStringList attachemts() const; |
67 | 66 | Q_INVOKABLE void loadMessage(const QVariant &draft, bool loadAsDraft); | |
68 | void setOriginalMessage(const QVariant &originalMessage); | ||
69 | void setDraftMessage(const QVariant &draft); | ||
70 | 67 | ||
71 | signals: | 68 | signals: |
72 | void subjectChanged(); | 69 | void subjectChanged(); |
@@ -92,6 +89,7 @@ private: | |||
92 | QString m_subject; | 89 | QString m_subject; |
93 | QString m_body; | 90 | QString m_body; |
94 | QStringList m_attachments; | 91 | QStringList m_attachments; |
92 | Sink::ApplicationDomain::Mail m_existingMail; | ||
95 | QVariant m_msg; | 93 | QVariant m_msg; |
96 | int m_currentAccountIndex; | 94 | int m_currentAccountIndex; |
97 | }; | 95 | }; |