From 0884fab3b161b62c1e2bb1bac6bbd74560f06232 Mon Sep 17 00:00:00 2001 From: Tamas Zakor Date: Tue, 28 May 2019 13:54:28 +0200 Subject: Add API to change download directory path and file name Add functions and property to change the download directory and file name in QWebEngineDownloadItem and QQuickWebEngineDownloadItem and deprecate the path() and setPath(). Regenerating the uniquifying download filename after change the download directory. [ChangeLog][DownloadItem] Add functions and property to change the download directory and file name in QWebEngineDownloadItem and QQuickWebEngineDownloadItem and deprecate the path() and setPath(). Task-number: QTBUG-56978 Change-Id: I6e63da82a187add8bc3206cc80c8bf6865fbdd35 Reviewed-by: Allan Sandfeld Jensen --- src/core/download_manager_delegate_qt.cpp | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'src/core/download_manager_delegate_qt.cpp') diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index ba506601f..34e290317 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -168,22 +168,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem* QDir defaultDownloadDirectory(m_profileAdapter->downloadPath()); - QFileInfo suggestedFile(defaultDownloadDirectory.absoluteFilePath(suggestedFilename)); - QString suggestedFilePath = suggestedFile.absoluteFilePath(); - base::FilePath tmpFilePath(toFilePath(suggestedFilePath).NormalizePathSeparatorsTo('/')); - - int uniquifier = base::GetUniquePathNumber(tmpFilePath, base::FilePath::StringType()); - if (uniquifier > 0) - suggestedFilePath = toQt(tmpFilePath.InsertBeforeExtensionASCII(base::StringPrintf(" (%d)", uniquifier)).AsUTF8Unsafe()); - else if (uniquifier == -1) { - base::Time::Exploded exploded; - item->GetStartTime().LocalExplode(&exploded); - std::string suffix = base::StringPrintf( - " - %04d-%02d-%02dT%02d%02d%02d.%03d", exploded.year, exploded.month, - exploded.day_of_month, exploded.hour, exploded.minute, - exploded.second, exploded.millisecond); - suggestedFilePath = toQt(tmpFilePath.InsertBeforeExtensionASCII(suffix).AsUTF8Unsafe()); - } + QString suggestedFilePath = m_profileAdapter->determineDownloadPath(defaultDownloadDirectory.absolutePath(), suggestedFilename, item->GetStartTime().ToTimeT()); item->AddObserver(this); QList clients = m_profileAdapter->clients(); @@ -209,7 +194,8 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem* downloadType, item->GetLastReason(), adapterClient, - suggestedFilename + suggestedFilename, + item->GetStartTime().ToTimeT() }; for (ProfileAdapterClient *client : qAsConst(clients)) { @@ -218,7 +204,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem* break; } - suggestedFile.setFile(info.path); + QFileInfo suggestedFile(info.path); if (info.accepted && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) { qWarning("Creating download path failed, download cancelled: %s", suggestedFile.absolutePath().toUtf8().data()); @@ -279,7 +265,7 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content acceptedByDefault = true; } if (QFileInfo(suggestedFilePath).isRelative()) { - const QDir downloadDir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); + const QDir downloadDir(m_profileAdapter->downloadPath()); suggestedFilePath = downloadDir.absoluteFilePath(suggestedFilePath); } @@ -311,8 +297,8 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content ProfileAdapterClient::SavePage, ProfileAdapterClient::NoReason, adapterClient, - QFileInfo(suggestedFilePath).fileName() - + QFileInfo(suggestedFilePath).fileName(), + time_t(QDateTime::currentMSecsSinceEpoch()) }; for (ProfileAdapterClient *client : qAsConst(clients)) { @@ -379,7 +365,8 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(download::DownloadItem *downlo 0 /* downloadType (unused) */, download->GetLastReason(), adapterClient, - toQt(download->GetSuggestedFilename()) + toQt(download->GetSuggestedFilename()), + download->GetStartTime().ToTimeT() }; for (ProfileAdapterClient *client : qAsConst(clients)) { -- cgit v1.2.3