diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-24 12:59:23 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-24 12:59:23 +0200 |
commit | acf2a53fea8fdbe366627e45fffe87434e3c2e7e (patch) | |
tree | f241beb77b302df6967b34d7297f55f23eaf6dea | |
parent | 9ed658053d5d41f4bf8c83072e6fa62990bd7ad8 (diff) | |
download | kube-acf2a53fea8fdbe366627e45fffe87434e3c2e7e.tar.gz kube-acf2a53fea8fdbe366627e45fffe87434e3c2e7e.zip |
Attachment open and download buttons
We'll need proper icons though.
-rw-r--r-- | framework/qml/AttachmentDelegate.qml | 33 | ||||
-rw-r--r-- | framework/qml/MailViewer.qml | 10 | ||||
-rw-r--r-- | framework/src/domain/mime/attachmentmodel.cpp | 40 | ||||
-rw-r--r-- | framework/src/domain/mime/messageparser.h | 1 |
4 files changed, 56 insertions, 28 deletions
diff --git a/framework/qml/AttachmentDelegate.qml b/framework/qml/AttachmentDelegate.qml index 994afd8c..081baf5d 100644 --- a/framework/qml/AttachmentDelegate.qml +++ b/framework/qml/AttachmentDelegate.qml | |||
@@ -17,8 +17,6 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | import QtQuick 2.7 | 19 | import QtQuick 2.7 |
20 | import QtQuick.Layouts 1.1 | ||
21 | import org.kde.kirigami 1.0 as Kirigami | ||
22 | import org.kube.framework 1.0 as Kube | 20 | import org.kube.framework 1.0 as Kube |
23 | 21 | ||
24 | Item { | 22 | Item { |
@@ -26,9 +24,11 @@ Item { | |||
26 | 24 | ||
27 | property string name | 25 | property string name |
28 | property string icon | 26 | property string icon |
27 | signal open; | ||
28 | signal download; | ||
29 | 29 | ||
30 | width: content.width + Kirigami.Units.gridUnit / 2 | 30 | width: content.width + Kube.Units.gridUnit / 2 |
31 | height: content.height + Kirigami.Units.gridUnit / 2 | 31 | height: content.height + Kube.Units.gridUnit / 2 |
32 | 32 | ||
33 | Rectangle { | 33 | Rectangle { |
34 | anchors.fill: parent | 34 | anchors.fill: parent |
@@ -37,26 +37,25 @@ Item { | |||
37 | color: Kube.Colors.disabledTextColor | 37 | color: Kube.Colors.disabledTextColor |
38 | } | 38 | } |
39 | 39 | ||
40 | RowLayout { | 40 | Row { |
41 | id: content | 41 | id: content |
42 | 42 | ||
43 | anchors.centerIn: parent | 43 | anchors.centerIn: parent |
44 | 44 | ||
45 | spacing: Kirigami.Units.smallSpacing | 45 | spacing: Kube.Units.smallSpacing |
46 | 46 | ||
47 | Rectangle { | 47 | Rectangle { |
48 | id: mimetype | 48 | id: mimetype |
49 | 49 | ||
50 | height: Kirigami.Units.gridUnit | 50 | height: Kube.Units.gridUnit |
51 | width: Kirigami.Units.gridUnit | 51 | width: Kube.Units.gridUnit |
52 | 52 | ||
53 | color: Kube.Colors.backgroundColor | 53 | color: Kube.Colors.backgroundColor |
54 | 54 | ||
55 | Kirigami.Icon { | 55 | Kube.Icon { |
56 | height: parent.height | 56 | height: parent.height |
57 | width: height | 57 | width: height |
58 | 58 | iconName: root.icon | |
59 | source: root.icon | ||
60 | } | 59 | } |
61 | } | 60 | } |
62 | 61 | ||
@@ -64,5 +63,17 @@ Item { | |||
64 | text: root.name | 63 | text: root.name |
65 | color: Kube.Colors.backgroundColor | 64 | color: Kube.Colors.backgroundColor |
66 | } | 65 | } |
66 | Kube.IconButton { | ||
67 | height: parent.height | ||
68 | width: height | ||
69 | iconName: Kube.Icons.goDown | ||
70 | onClicked: root.download() | ||
71 | } | ||
72 | Kube.IconButton { | ||
73 | height: parent.height | ||
74 | width: height | ||
75 | iconName: Kube.Icons.edit | ||
76 | onClicked: root.open() | ||
77 | } | ||
67 | } | 78 | } |
68 | } | 79 | } |
diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml index d2c0a3be..14c4bc8a 100644 --- a/framework/qml/MailViewer.qml +++ b/framework/qml/MailViewer.qml | |||
@@ -286,11 +286,11 @@ Rectangle { | |||
286 | icon: model.iconName | 286 | icon: model.iconName |
287 | 287 | ||
288 | clip: true | 288 | clip: true |
289 | 289 | onDownload: { | |
290 | //TODO size encrypted signed type | 290 | messageParser.attachments.saveAttachmentToDisk(messageParser.attachments.index(index, 0)) |
291 | MouseArea { | 291 | } |
292 | anchors.fill: parent | 292 | onOpen: { |
293 | onClicked: messageParser.attachments.saveAttachmentToDisk(messageParser.attachments.index(index, 0)) | 293 | messageParser.attachments.openAttachment(messageParser.attachments.index(index, 0)) |
294 | } | 294 | } |
295 | } | 295 | } |
296 | } | 296 | } |
diff --git a/framework/src/domain/mime/attachmentmodel.cpp b/framework/src/domain/mime/attachmentmodel.cpp index 714177e1..99745796 100644 --- a/framework/src/domain/mime/attachmentmodel.cpp +++ b/framework/src/domain/mime/attachmentmodel.cpp | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <KMime/Content> | 24 | #include <KMime/Content> |
25 | #include <QFile> | 25 | #include <QFile> |
26 | #include <QStandardPaths> | 26 | #include <QStandardPaths> |
27 | #include <QDesktopServices> | ||
27 | #include <QDir> | 28 | #include <QDir> |
28 | 29 | ||
29 | QString sizeHuman(const Content::Ptr &content) | 30 | QString sizeHuman(const Content::Ptr &content) |
@@ -129,34 +130,49 @@ QVariant AttachmentModel::data(const QModelIndex &index, int role) const | |||
129 | return QVariant(); | 130 | return QVariant(); |
130 | } | 131 | } |
131 | 132 | ||
132 | bool AttachmentModel::saveAttachmentToDisk(const QModelIndex &index) | 133 | static QString saveAttachmentToDisk(const QModelIndex &index, const QString &path) |
133 | { | 134 | { |
134 | if (index.internalPointer()) { | 135 | if (index.internalPointer()) { |
135 | const auto entry = static_cast<Part *>(index.internalPointer()); | 136 | const auto entry = static_cast<Part *>(index.internalPointer()); |
136 | const auto content = entry->content().at(0); | 137 | const auto content = entry->content().at(0); |
137 | auto filename = entry->mailMime()->filename(); | 138 | auto filename = entry->mailMime()->filename(); |
138 | auto data = content->mailMime()->decodedContent(); | 139 | auto data = content->mailMime()->decodedContent(); |
139 | |||
140 | auto downloadDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); | ||
141 | if (downloadDir.isEmpty()) { | ||
142 | downloadDir = "~"; | ||
143 | } | ||
144 | downloadDir += "/kube/"; | ||
145 | QDir{}.mkpath(downloadDir); | ||
146 | |||
147 | auto fname = downloadDir + filename; | ||
148 | |||
149 | if (content->mailMime()->isText() && !data.isEmpty()) { | 140 | if (content->mailMime()->isText() && !data.isEmpty()) { |
150 | // convert CRLF to LF before writing text attachments to disk | 141 | // convert CRLF to LF before writing text attachments to disk |
151 | data = KMime::CRLFtoLF(data); | 142 | data = KMime::CRLFtoLF(data); |
152 | } | 143 | } |
144 | auto fname = path + filename; | ||
153 | QFile f(fname); | 145 | QFile f(fname); |
154 | if (!f.open(QIODevice::ReadWrite)) { | 146 | if (!f.open(QIODevice::ReadWrite)) { |
155 | qWarning() << "Failed to write attachment to file:" << fname << " Error: " << f.errorString(); | 147 | qWarning() << "Failed to write attachment to file:" << fname << " Error: " << f.errorString(); |
156 | return false; | 148 | return {}; |
157 | } | 149 | } |
158 | f.write(data); | 150 | f.write(data); |
159 | qInfo() << "Wrote attachment to file: " << fname; | 151 | qInfo() << "Wrote attachment to file: " << fname; |
152 | return fname; | ||
153 | } | ||
154 | return {}; | ||
155 | |||
156 | } | ||
157 | |||
158 | bool AttachmentModel::saveAttachmentToDisk(const QModelIndex &index) | ||
159 | { | ||
160 | auto downloadDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); | ||
161 | if (downloadDir.isEmpty()) { | ||
162 | downloadDir = "~"; | ||
163 | } | ||
164 | downloadDir += "/kube/"; | ||
165 | QDir{}.mkpath(downloadDir); | ||
166 | return !::saveAttachmentToDisk(index, downloadDir).isEmpty(); | ||
167 | } | ||
168 | |||
169 | bool AttachmentModel::openAttachment(const QModelIndex &index) | ||
170 | { | ||
171 | auto downloadDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation)+ "/kube/"; | ||
172 | QDir{}.mkpath(downloadDir); | ||
173 | const auto filePath = ::saveAttachmentToDisk(index, downloadDir); | ||
174 | if (!filePath.isEmpty()) { | ||
175 | QDesktopServices::openUrl(QUrl("file://" + filePath)); | ||
160 | return true; | 176 | return true; |
161 | } | 177 | } |
162 | return false; | 178 | return false; |
diff --git a/framework/src/domain/mime/messageparser.h b/framework/src/domain/mime/messageparser.h index 1f44b296..de72a025 100644 --- a/framework/src/domain/mime/messageparser.h +++ b/framework/src/domain/mime/messageparser.h | |||
@@ -112,6 +112,7 @@ public: | |||
112 | int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; | 112 | int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; |
113 | 113 | ||
114 | Q_INVOKABLE bool saveAttachmentToDisk(const QModelIndex &parent); | 114 | Q_INVOKABLE bool saveAttachmentToDisk(const QModelIndex &parent); |
115 | Q_INVOKABLE bool openAttachment(const QModelIndex &index); | ||
115 | 116 | ||
116 | private: | 117 | private: |
117 | std::unique_ptr<AttachmentModelPrivate> d; | 118 | std::unique_ptr<AttachmentModelPrivate> d; |