From 17ea5b6534d6221e50cdd37dc773e03b5d34665e Mon Sep 17 00:00:00 2001 From: Tamas Zakor Date: Fri, 29 Nov 2019 14:43:24 +0100 Subject: Fix Q(Quick)WebEngineDownloadItem::setDownloadDirectory() Keep the custom file name if the calling order of setDownloadDirectory() and setDownloadFileName() changes. Also do not emit patchChanged signal twice if setDownloadDirectory() changes the uniquifier of the file name. Add TempDir for qml auto tests what uses QTemporaryDir() to create temporary directory for downloads. See https://cgit.kde.org/messagelib.git/commit/?id=2c113dcb155b11bf2c0af3c85544962485784b26 for details. Fixes: QTBUG-80566 Change-Id: Ia76f263558eaf55cb297700407948523788c6229 Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginedownloaditem.cpp | 14 +++++++++----- src/webenginewidgets/api/qwebenginedownloaditem_p.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index fd7d90704..7366dbf59 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -170,6 +170,7 @@ QWebEngineDownloadItemPrivate::QWebEngineDownloadItemPrivate(QWebEngineProfilePr , interruptReason(QWebEngineDownloadItem::NoReason) , downloadUrl(url) , downloadPaused(false) + , isCustomFileName(false) , totalBytes(-1) , receivedBytes(0) , page(0) @@ -594,14 +595,15 @@ void QWebEngineDownloadItem::setDownloadDirectory(const QString &directory) if (d->downloadState != QWebEngineDownloadItem::DownloadRequested) { qWarning("Setting the download directory is not allowed after the download has been accepted."); return; - } + } if (!directory.isEmpty() && d->downloadDirectory != directory) d->downloadDirectory = directory; - d->downloadFileName = QFileInfo(d->profile->profileAdapter()->determineDownloadPath(d->downloadDirectory, - d->suggestedFileName, - d->startTime)).fileName(); + if (!d->isCustomFileName) + d->downloadFileName = QFileInfo(d->profile->profileAdapter()->determineDownloadPath(d->downloadDirectory, + d->suggestedFileName, + d->startTime)).fileName(); } /*! @@ -634,8 +636,10 @@ void QWebEngineDownloadItem::setDownloadFileName(const QString &fileName) return; } - if (!fileName.isEmpty()) + if (!fileName.isEmpty()) { d->downloadFileName = fileName; + d->isCustomFileName = true; + } } /*! diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h index 034684a00..04c6fadcc 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h @@ -82,6 +82,7 @@ public: QString suggestedFileName; QString downloadDirectory; QString downloadFileName; + bool isCustomFileName; qint64 totalBytes; qint64 receivedBytes; -- cgit v1.2.3