From 114e04f60f8dd01eb9bb5b68fa72961c16c65401 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 22 Jun 2017 17:57:18 +0200 Subject: Post notifications when saving an attachment --- framework/src/domain/mime/attachmentmodel.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'framework') 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 @@ #include "attachmentmodel.h" #include +#include #include #include @@ -153,9 +154,14 @@ static QString saveAttachmentToDisk(const QModelIndex &index, const QString &pat data = KMime::CRLFtoLF(data); } auto fname = path + part->filename(); + //A file with that name already exists, we assume it's the right file + if (QFileInfo{fname}.exists()) { + return fname; + } QFile f(fname); if (!f.open(QIODevice::ReadWrite)) { qWarning() << "Failed to write attachment to file:" << fname << " Error: " << f.errorString(); + Kube::Fabric::Fabric{}.postMessage("notification", {{"message", QObject::tr("Failed to save attachment.")}}); return {}; } f.write(data); @@ -179,7 +185,13 @@ bool AttachmentModel::saveAttachmentToDisk(const QModelIndex &index) } downloadDir += "/kube/"; QDir{}.mkpath(downloadDir); - return !::saveAttachmentToDisk(index, downloadDir).isEmpty(); + + auto path = ::saveAttachmentToDisk(index, downloadDir); + if (path.isEmpty()) { + return false; + } + Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Saved the attachment to disk: ") + path}}); + return true; } bool AttachmentModel::openAttachment(const QModelIndex &index) @@ -188,9 +200,13 @@ bool AttachmentModel::openAttachment(const QModelIndex &index) QDir{}.mkpath(downloadDir); const auto filePath = ::saveAttachmentToDisk(index, downloadDir, true); if (!filePath.isEmpty()) { - QDesktopServices::openUrl(QUrl("file://" + filePath)); + if (!QDesktopServices::openUrl(QUrl("file://" + filePath))) { + Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Failed to open attachment.")}}); + return false; + } return true; } + Kube::Fabric::Fabric{}.postMessage("notification", {{"message", tr("Failed to save attachment for opening.")}}); return false; } -- cgit v1.2.3