summaryrefslogtreecommitdiffstats
path: root/src/core/download_manager_delegate_qt.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-12 11:32:02 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-12 11:35:45 +0100
commita077399f4c17f57e911334867c918cc6ddeb15fc (patch)
treec8e4d326d7a074e9d16b68399ecc5f728f8533fe /src/core/download_manager_delegate_qt.cpp
parent3d698f5de377bde2293e222536bc50171cfdf1b8 (diff)
parent12dd6ff845656eb625e2ee3d0e73392bc2c61983 (diff)
Merge branch '5.6' into dev
Diffstat (limited to 'src/core/download_manager_delegate_qt.cpp')
-rw-r--r--src/core/download_manager_delegate_qt.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index b6de27ca8..454e1ff49 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"
@@ -108,23 +109,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());
@@ -145,6 +151,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
item->GetState(),
item->GetTotalBytes(),
item->GetReceivedBytes(),
+ mimeTypeString,
suggestedFilePath,
BrowserContextAdapterClient::UnknownSavePageFormat,
false /* accepted */
@@ -214,6 +221,7 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
content::DownloadItem::IN_PROGRESS,
0, /* totalBytes */
0, /* receivedBytes */
+ QStringLiteral("application/x-mimearchive"),
suggestedFilePath,
BrowserContextAdapterClient::MimeHtmlSaveFormat,
false /* accepted */
@@ -249,6 +257,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
download->GetState(),
download->GetTotalBytes(),
download->GetReceivedBytes(),
+ toQt(download->GetMimeType()),
QString(),
BrowserContextAdapterClient::UnknownSavePageFormat,
true /* accepted */