diff options
-rw-r--r-- | framework/src/domain/mime/attachmentmodel.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/framework/src/domain/mime/attachmentmodel.cpp b/framework/src/domain/mime/attachmentmodel.cpp index 68180afe..34843960 100644 --- a/framework/src/domain/mime/attachmentmodel.cpp +++ b/framework/src/domain/mime/attachmentmodel.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "attachmentmodel.h" | 21 | #include "attachmentmodel.h" |
22 | 22 | ||
23 | #include <mimetreeparser/objecttreeparser.h> | 23 | #include <mimetreeparser/objecttreeparser.h> |
24 | #include <fabric.h> | ||
24 | 25 | ||
25 | #include <QDebug> | 26 | #include <QDebug> |
26 | #include <KMime/Content> | 27 | #include <KMime/Content> |
@@ -153,9 +154,14 @@ static QString saveAttachmentToDisk(const QModelIndex &index, const QString &pat | |||
153 | data = KMime::CRLFtoLF(data); | 154 | data = KMime::CRLFtoLF(data); |
154 | } | 155 | } |
155 | auto fname = path + part->filename(); | 156 | auto fname = path + part->filename(); |
157 | //A file with that name already exists, we assume it's the right file | ||
158 | if (QFileInfo{fname}.exists()) { | ||
159 | return fname; | ||
160 | } | ||
156 | QFile f(fname); | 161 | QFile f(fname); |
157 | if (!f.open(QIODevice::ReadWrite)) { | 162 | if (!f.open(QIODevice::ReadWrite)) { |
158 | qWarning() << "Failed to write attachment to file:" << fname << " Error: " << f.errorString(); | 163 | qWarning() << "Failed to write attachment to file:" << fname << " Error: " << f.errorString(); |
164 | Kube::Fabric::Fabric{}.postMessage("notification", {{"message", QObject::tr("Failed to save attachment.")}}); | ||
159 | return {}; | 165 | return {}; |
160 | } | 166 | } |
161 | f.write(data); | 167 | f.write(data); |
@@ -179,7 +185,13 @@ bool AttachmentModel::saveAttachmentToDisk(const QModelIndex &index) | |||
179 | } | 185 | } |
180 | downloadDir += "/kube/"; | 186 | downloadDir += "/kube/"; |
181 | QDir{}.mkpath(downloadDir); | 187 | QDir{}.mkpath(downloadDir); |
182 | return !::saveAttachmentToDisk(index, downloadDir).isEmpty(); | 188 | |
189 | auto path = ::saveAttachmentToDisk(index, downloadDir); | ||
190 | if (path.isEmpty()) { | ||
191 | return false; | ||
192 | } | ||
193 | Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Saved the attachment to disk: ") + path}}); | ||
194 | return true; | ||
183 | } | 195 | } |
184 | 196 | ||
185 | bool AttachmentModel::openAttachment(const QModelIndex &index) | 197 | bool AttachmentModel::openAttachment(const QModelIndex &index) |
@@ -188,9 +200,13 @@ bool AttachmentModel::openAttachment(const QModelIndex &index) | |||
188 | QDir{}.mkpath(downloadDir); | 200 | QDir{}.mkpath(downloadDir); |
189 | const auto filePath = ::saveAttachmentToDisk(index, downloadDir, true); | 201 | const auto filePath = ::saveAttachmentToDisk(index, downloadDir, true); |
190 | if (!filePath.isEmpty()) { | 202 | if (!filePath.isEmpty()) { |
191 | QDesktopServices::openUrl(QUrl("file://" + filePath)); | 203 | if (!QDesktopServices::openUrl(QUrl("file://" + filePath))) { |
204 | Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Failed to open attachment.")}}); | ||
205 | return false; | ||
206 | } | ||
192 | return true; | 207 | return true; |
193 | } | 208 | } |
209 | Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Failed to save attachment for opening.")}}); | ||
194 | return false; | 210 | return false; |
195 | } | 211 | } |
196 | 212 | ||