summaryrefslogtreecommitdiffstats
path: root/src/core/download_manager_delegate_qt.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-09-18 15:02:06 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-12-07 15:25:54 +0000
commitfba650c3d774c595b6726c7140ff12353f8c0a4c (patch)
treedca50fafd64d5dc9f132a80127e3264e48587a48 /src/core/download_manager_delegate_qt.cpp
parentc6c58e0e03e2ba9b9dd8e149cab30b8eb12c443f (diff)
Make the MIME-type of downloads available
An application currently have to rely on suggested filename only to guess the type of a download. This is often insufficient when the suffix is misleading or missing. This patch adds the mimetype to the reported metadata and also adds a mimetype appropriate suffix to suggested filenames. Task-number: QTBUG-48206 Change-Id: I4c70f076d6eb5ae820fd6b7f568515eeb7c18df5 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/core/download_manager_delegate_qt.cpp')
-rw-r--r--src/core/download_manager_delegate_qt.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index e9af98fd8..6d29af76a 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -46,6 +46,7 @@
#include <QFile>
#include <QFileInfo>
#include <QMap>
+#include <QMimeDatabase>
#include <QStandardPaths>
#include "browser_context_adapter.h"
@@ -102,23 +103,28 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
return true;
}
- std::string suggestedFilename = item->GetSuggestedFilename();
+ QString suggestedFilename = toQt(item->GetSuggestedFilename());
+ QString mimeTypeString = toQt(item->GetMimeType());
- if (suggestedFilename.empty())
- suggestedFilename = net::HttpContentDisposition(item->GetContentDisposition(), std::string()).filename();
+ if (suggestedFilename.isEmpty())
+ suggestedFilename = toQt(net::HttpContentDisposition(item->GetContentDisposition(), std::string()).filename());
- if (suggestedFilename.empty())
- suggestedFilename = item->GetTargetFilePath().AsUTF8Unsafe();
+ if (suggestedFilename.isEmpty())
+ suggestedFilename = toQt(item->GetTargetFilePath().AsUTF8Unsafe());
- if (suggestedFilename.empty())
- suggestedFilename = item->GetURL().ExtractFileName();
+ if (suggestedFilename.isEmpty())
+ suggestedFilename = toQt(item->GetURL().ExtractFileName());
- if (suggestedFilename.empty())
- suggestedFilename = "qwe_download";
+ if (suggestedFilename.isEmpty()) {
+ suggestedFilename = QStringLiteral("qwe_download");
+ QMimeType mimeType = QMimeDatabase().mimeTypeForName(mimeTypeString);
+ if (mimeType.isValid() && !mimeType.preferredSuffix().isEmpty())
+ suggestedFilename += QStringLiteral(".") + mimeType.preferredSuffix();
+ }
QDir defaultDownloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
- QFileInfo suggestedFile(defaultDownloadDirectory.absoluteFilePath(QString::fromStdString(suggestedFilename)));
+ QFileInfo suggestedFile(defaultDownloadDirectory.absoluteFilePath(suggestedFilename));
QString suggestedFilePath = suggestedFile.absoluteFilePath();
QString tmpFileBase = QString("%1%2%3").arg(suggestedFile.absolutePath()).arg(QDir::separator()).arg(suggestedFile.baseName());
@@ -139,6 +145,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
item->GetState(),
item->GetTotalBytes(),
item->GetReceivedBytes(),
+ mimeTypeString,
suggestedFilePath,
false /* accepted */
};
@@ -191,6 +198,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
download->GetState(),
download->GetTotalBytes(),
download->GetReceivedBytes(),
+ toQt(download->GetMimeType()),
QString(),
true /* accepted */
};