diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-10 15:53:06 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-10 15:53:06 +0200 |
commit | df10583b42f49a58d27dd6dd322f22fd88ce1418 (patch) | |
tree | 34c2dc39c47b60ebc28130985ac976172da478ad | |
parent | 6e76e328b2adbc20bd2da6628a7f57aaa7afe5b1 (diff) | |
download | kube-df10583b42f49a58d27dd6dd322f22fd88ce1418.tar.gz kube-df10583b42f49a58d27dd6dd322f22fd88ce1418.zip |
Support for loading drafts
-rw-r--r-- | components/mail/contents/ui/main.qml | 29 | ||||
-rw-r--r-- | components/package/contents/ui/Composer.qml | 15 | ||||
-rw-r--r-- | components/package/contents/ui/FocusComposer.qml | 2 | ||||
-rw-r--r-- | components/package/contents/ui/MailListView.qml | 7 | ||||
-rw-r--r-- | framework/domain/composercontroller.cpp | 33 | ||||
-rw-r--r-- | framework/domain/composercontroller.h | 7 | ||||
-rw-r--r-- | framework/domain/maillistmodel.cpp | 5 | ||||
-rw-r--r-- | framework/domain/maillistmodel.h | 1 |
8 files changed, 83 insertions, 16 deletions
diff --git a/components/mail/contents/ui/main.qml b/components/mail/contents/ui/main.qml index 15a2b0b8..c2569cdc 100644 --- a/components/mail/contents/ui/main.qml +++ b/components/mail/contents/ui/main.qml | |||
@@ -38,7 +38,9 @@ ApplicationWindow { | |||
38 | KubeAction.Context { | 38 | KubeAction.Context { |
39 | id: maillistcontext | 39 | id: maillistcontext |
40 | property variant mail | 40 | property variant mail |
41 | property bool isDraft | ||
41 | mail: mailListView.currentMail | 42 | mail: mailListView.currentMail |
43 | isDraft: mailListView.isDraft | ||
42 | } | 44 | } |
43 | 45 | ||
44 | KubeAction.Context { | 46 | KubeAction.Context { |
@@ -54,6 +56,12 @@ ApplicationWindow { | |||
54 | } | 56 | } |
55 | 57 | ||
56 | KubeAction.Action { | 58 | KubeAction.Action { |
59 | id: editAction | ||
60 | actionId: "org.kde.kube.actions.edit" | ||
61 | context: maillistcontext | ||
62 | } | ||
63 | |||
64 | KubeAction.Action { | ||
57 | id: markAsReadAction | 65 | id: markAsReadAction |
58 | actionId: "org.kde.kube.actions.mark-as-read" | 66 | actionId: "org.kde.kube.actions.mark-as-read" |
59 | context: maillistcontext | 67 | context: maillistcontext |
@@ -180,6 +188,17 @@ ApplicationWindow { | |||
180 | } | 188 | } |
181 | } | 189 | } |
182 | 190 | ||
191 | KubeAction.ActionHandler { | ||
192 | actionId: "org.kde.kube.actions.edit" | ||
193 | function isReady(context) { | ||
194 | return context.mail && context.isDraft; | ||
195 | } | ||
196 | |||
197 | function handler(context) { | ||
198 | composerComponent.createObject(app, {"draftMessage": context.mail}) | ||
199 | } | ||
200 | } | ||
201 | |||
183 | ToolButton { | 202 | ToolButton { |
184 | id: newMailButton | 203 | id: newMailButton |
185 | 204 | ||
@@ -202,6 +221,16 @@ ApplicationWindow { | |||
202 | } | 221 | } |
203 | } | 222 | } |
204 | 223 | ||
224 | ToolButton { | ||
225 | Layout.fillHeight: true | ||
226 | iconName: "mail-message-edit" | ||
227 | text: "Edit" | ||
228 | enabled: editAction.ready | ||
229 | onClicked: { | ||
230 | editAction.execute() | ||
231 | } | ||
232 | } | ||
233 | |||
205 | Item { | 234 | Item { |
206 | Layout.fillWidth: true | 235 | Layout.fillWidth: true |
207 | } | 236 | } |
diff --git a/components/package/contents/ui/Composer.qml b/components/package/contents/ui/Composer.qml index 8c6f9c77..ed8fb2f2 100644 --- a/components/package/contents/ui/Composer.qml +++ b/components/package/contents/ui/Composer.qml | |||
@@ -26,6 +26,7 @@ import org.kube.framework.domain 1.0 as KubeFramework | |||
26 | Item { | 26 | Item { |
27 | id: root | 27 | id: root |
28 | property variant originalMessage | 28 | property variant originalMessage |
29 | property variant draftMessage | ||
29 | 30 | ||
30 | function send() { | 31 | function send() { |
31 | composer.send() | 32 | composer.send() |
@@ -40,17 +41,25 @@ Item { | |||
40 | } | 41 | } |
41 | 42 | ||
42 | KubeFramework.Retriever { | 43 | KubeFramework.Retriever { |
43 | id: retriever | 44 | id: originalMessageRetriever |
44 | propertyName: "mimeMessage" | 45 | propertyName: "mimeMessage" |
45 | model: KubeFramework.MailListModel { | 46 | model: KubeFramework.MailListModel { |
46 | id: mailListModel | ||
47 | mail: root.originalMessage | 47 | mail: root.originalMessage |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | KubeFramework.Retriever { | ||
52 | id: draftMessageRetriever | ||
53 | propertyName: "mimeMessage" | ||
54 | model: KubeFramework.MailListModel { | ||
55 | mail: root.draftMessage | ||
56 | } | ||
57 | } | ||
58 | |||
51 | KubeFramework.ComposerController { | 59 | KubeFramework.ComposerController { |
52 | id: composer | 60 | id: composer |
53 | originalMessage: retriever.value | 61 | originalMessage: originalMessageRetriever.value |
62 | draftMessage: draftMessageRetriever.value | ||
54 | } | 63 | } |
55 | 64 | ||
56 | ColumnLayout { | 65 | ColumnLayout { |
diff --git a/components/package/contents/ui/FocusComposer.qml b/components/package/contents/ui/FocusComposer.qml index 1cd3cb32..4e61b6c1 100644 --- a/components/package/contents/ui/FocusComposer.qml +++ b/components/package/contents/ui/FocusComposer.qml | |||
@@ -24,6 +24,7 @@ import org.kube.framework.theme 1.0 | |||
24 | Rectangle { | 24 | Rectangle { |
25 | id: root | 25 | id: root |
26 | property variant originalMessage | 26 | property variant originalMessage |
27 | property variant draftMessage | ||
27 | 28 | ||
28 | color: ColorPalette.border | 29 | color: ColorPalette.border |
29 | 30 | ||
@@ -62,6 +63,7 @@ Rectangle { | |||
62 | Layout.fillWidth: true | 63 | Layout.fillWidth: true |
63 | Layout.fillHeight: true | 64 | Layout.fillHeight: true |
64 | originalMessage: root.originalMessage | 65 | originalMessage: root.originalMessage |
66 | draftMessage: root.draftMessage | ||
65 | } | 67 | } |
66 | 68 | ||
67 | RowLayout { | 69 | RowLayout { |
diff --git a/components/package/contents/ui/MailListView.qml b/components/package/contents/ui/MailListView.qml index 12d6c705..9caaa9ce 100644 --- a/components/package/contents/ui/MailListView.qml +++ b/components/package/contents/ui/MailListView.qml | |||
@@ -29,6 +29,7 @@ Controls.ScrollView { | |||
29 | id: root | 29 | id: root |
30 | property variant parentFolder | 30 | property variant parentFolder |
31 | property variant currentMail | 31 | property variant currentMail |
32 | property bool isDraft : false | ||
32 | 33 | ||
33 | ListView { | 34 | ListView { |
34 | id: listView | 35 | id: listView |
@@ -69,6 +70,12 @@ Controls.ScrollView { | |||
69 | when: listView.currentIndex == index | 70 | when: listView.currentIndex == index |
70 | value: model.domainObject | 71 | value: model.domainObject |
71 | } | 72 | } |
73 | QtQml.Binding { | ||
74 | target: root | ||
75 | property: "isDraft" | ||
76 | when: listView.currentIndex == index | ||
77 | value: model.draft | ||
78 | } | ||
72 | 79 | ||
73 | RowLayout { | 80 | RowLayout { |
74 | 81 | ||
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 0cf61442..94914f17 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -113,17 +113,21 @@ QStringList ComposerController::attachemts() const | |||
113 | return m_attachments; | 113 | return m_attachments; |
114 | } | 114 | } |
115 | 115 | ||
116 | QVariant ComposerController::originalMessage() const | ||
117 | { | ||
118 | return m_originalMessage; | ||
119 | } | ||
120 | |||
121 | void ComposerController::addAttachment(const QUrl &fileUrl) | 116 | void ComposerController::addAttachment(const QUrl &fileUrl) |
122 | { | 117 | { |
123 | m_attachments.append(fileUrl.toString()); | 118 | m_attachments.append(fileUrl.toString()); |
124 | emit attachmentsChanged(); | 119 | emit attachmentsChanged(); |
125 | } | 120 | } |
126 | 121 | ||
122 | void ComposerController::setMessage(const KMime::Message::Ptr &msg) | ||
123 | { | ||
124 | setTo(msg->to(true)->asUnicodeString()); | ||
125 | setCc(msg->cc(true)->asUnicodeString()); | ||
126 | setSubject(msg->subject(true)->asUnicodeString()); | ||
127 | setBody(msg->body()); | ||
128 | m_msg = QVariant::fromValue(msg); | ||
129 | } | ||
130 | |||
127 | void ComposerController::setOriginalMessage(const QVariant &originalMessage) | 131 | void ComposerController::setOriginalMessage(const QVariant &originalMessage) |
128 | { | 132 | { |
129 | const auto mailData = KMime::CRLFtoLF(originalMessage.toByteArray()); | 133 | const auto mailData = KMime::CRLFtoLF(originalMessage.toByteArray()); |
@@ -133,11 +137,20 @@ void ComposerController::setOriginalMessage(const QVariant &originalMessage) | |||
133 | mail->parse(); | 137 | mail->parse(); |
134 | auto reply = MailTemplates::reply(mail); | 138 | auto reply = MailTemplates::reply(mail); |
135 | //We assume reply | 139 | //We assume reply |
136 | setTo(reply->to(true)->asUnicodeString()); | 140 | setMessage(reply); |
137 | setCc(reply->cc(true)->asUnicodeString()); | 141 | } else { |
138 | setSubject(reply->subject(true)->asUnicodeString()); | 142 | m_msg = QVariant(); |
139 | setBody(reply->body()); | 143 | } |
140 | m_msg = QVariant::fromValue(reply); | 144 | } |
145 | |||
146 | void ComposerController::setDraftMessage(const QVariant &originalMessage) | ||
147 | { | ||
148 | const auto mailData = KMime::CRLFtoLF(originalMessage.toByteArray()); | ||
149 | if (!mailData.isEmpty()) { | ||
150 | KMime::Message::Ptr mail(new KMime::Message); | ||
151 | mail->setContent(mailData); | ||
152 | mail->parse(); | ||
153 | setMessage(mail); | ||
141 | } else { | 154 | } else { |
142 | m_msg = QVariant(); | 155 | m_msg = QVariant(); |
143 | } | 156 | } |
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index 4ad505d8..b24c16a9 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -32,7 +32,8 @@ class Message; | |||
32 | class ComposerController : public QObject | 32 | class ComposerController : public QObject |
33 | { | 33 | { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | Q_PROPERTY (QVariant originalMessage READ originalMessage WRITE setOriginalMessage) | 35 | Q_PROPERTY (QVariant originalMessage WRITE setOriginalMessage) |
36 | Q_PROPERTY (QVariant draftMessage WRITE setDraftMessage) | ||
36 | Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) | 37 | Q_PROPERTY (QString to READ to WRITE setTo NOTIFY toChanged) |
37 | Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) | 38 | Q_PROPERTY (QString cc READ cc WRITE setCc NOTIFY ccChanged) |
38 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) | 39 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) |
@@ -64,8 +65,8 @@ public: | |||
64 | 65 | ||
65 | QStringList attachemts() const; | 66 | QStringList attachemts() const; |
66 | 67 | ||
67 | QVariant originalMessage() const; | ||
68 | void setOriginalMessage(const QVariant &originalMessage); | 68 | void setOriginalMessage(const QVariant &originalMessage); |
69 | void setDraftMessage(const QVariant &draft); | ||
69 | 70 | ||
70 | signals: | 71 | signals: |
71 | void subjectChanged(); | 72 | void subjectChanged(); |
@@ -83,6 +84,7 @@ public slots: | |||
83 | void addAttachment(const QUrl &fileUrl); | 84 | void addAttachment(const QUrl &fileUrl); |
84 | 85 | ||
85 | private: | 86 | private: |
87 | void setMessage(const QSharedPointer<KMime::Message> &msg); | ||
86 | QSharedPointer<KMime::Message> assembleMessage(); | 88 | QSharedPointer<KMime::Message> assembleMessage(); |
87 | QString m_to; | 89 | QString m_to; |
88 | QString m_cc; | 90 | QString m_cc; |
@@ -90,7 +92,6 @@ private: | |||
90 | QString m_subject; | 92 | QString m_subject; |
91 | QString m_body; | 93 | QString m_body; |
92 | QStringList m_attachments; | 94 | QStringList m_attachments; |
93 | QVariant m_originalMessage; | ||
94 | QVariant m_msg; | 95 | QVariant m_msg; |
95 | int m_currentAccountIndex; | 96 | int m_currentAccountIndex; |
96 | }; | 97 | }; |
diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index cbf39a86..4ea7075c 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp | |||
@@ -46,6 +46,7 @@ QHash< int, QByteArray > MailListModel::roleNames() const | |||
46 | roles[Date] = "date"; | 46 | roles[Date] = "date"; |
47 | roles[Unread] = "unread"; | 47 | roles[Unread] = "unread"; |
48 | roles[Important] = "important"; | 48 | roles[Important] = "important"; |
49 | roles[Draft] = "draft"; | ||
49 | roles[Id] = "id"; | 50 | roles[Id] = "id"; |
50 | roles[MimeMessage] = "mimeMessage"; | 51 | roles[MimeMessage] = "mimeMessage"; |
51 | roles[DomainObject] = "domainObject"; | 52 | roles[DomainObject] = "domainObject"; |
@@ -70,6 +71,8 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const | |||
70 | return mail->getUnread(); | 71 | return mail->getUnread(); |
71 | case Important: | 72 | case Important: |
72 | return mail->getImportant(); | 73 | return mail->getImportant(); |
74 | case Draft: | ||
75 | return mail->getDraft(); | ||
73 | case Id: | 76 | case Id: |
74 | return mail->identifier(); | 77 | return mail->identifier(); |
75 | case DomainObject: | 78 | case DomainObject: |
@@ -113,6 +116,7 @@ void MailListModel::setParentFolder(const QVariant &parentFolder) | |||
113 | query.request<Mail::Date>(); | 116 | query.request<Mail::Date>(); |
114 | query.request<Mail::Unread>(); | 117 | query.request<Mail::Unread>(); |
115 | query.request<Mail::Important>(); | 118 | query.request<Mail::Important>(); |
119 | query.request<Mail::Draft>(); | ||
116 | query.request<Mail::Folder>(); | 120 | query.request<Mail::Folder>(); |
117 | query.filter<Mail::Folder>(*folder); | 121 | query.filter<Mail::Folder>(*folder); |
118 | qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier(); | 122 | qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier(); |
@@ -140,6 +144,7 @@ void MailListModel::setMail(const QVariant &variant) | |||
140 | query.request<Mail::Date>(); | 144 | query.request<Mail::Date>(); |
141 | query.request<Mail::Unread>(); | 145 | query.request<Mail::Unread>(); |
142 | query.request<Mail::Important>(); | 146 | query.request<Mail::Important>(); |
147 | query.request<Mail::Draft>(); | ||
143 | query.request<Mail::MimeMessage>(); | 148 | query.request<Mail::MimeMessage>(); |
144 | qWarning() << "Running mail query: " << mail->resourceInstanceIdentifier() << mail->identifier(); | 149 | qWarning() << "Running mail query: " << mail->resourceInstanceIdentifier() << mail->identifier(); |
145 | runQuery(query); | 150 | runQuery(query); |
diff --git a/framework/domain/maillistmodel.h b/framework/domain/maillistmodel.h index 47a2a091..13662a17 100644 --- a/framework/domain/maillistmodel.h +++ b/framework/domain/maillistmodel.h | |||
@@ -47,6 +47,7 @@ public: | |||
47 | Date, | 47 | Date, |
48 | Unread, | 48 | Unread, |
49 | Important, | 49 | Important, |
50 | Draft, | ||
50 | Id, | 51 | Id, |
51 | MimeMessage, | 52 | MimeMessage, |
52 | DomainObject | 53 | DomainObject |