summaryrefslogtreecommitdiffstats
path: root/src/core/download_manager_delegate_qt.cpp
diff options
context:
space:
mode:
authorTamas Zakor <ztamas@inf.u-szeged.hu>2019-05-28 13:54:28 +0200
committerTamas Zakor <ztamas@inf.u-szeged.hu>2019-07-05 08:57:30 +0200
commit0884fab3b161b62c1e2bb1bac6bbd74560f06232 (patch)
treeec07c0b9473c5eb05880cd1783ca11dd5bc09aa0 /src/core/download_manager_delegate_qt.cpp
parentfbc2700180d97d9c84b079b7c4da9eace19abf23 (diff)
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 <allan.jensen@qt.io>
Diffstat (limited to 'src/core/download_manager_delegate_qt.cpp')
-rw-r--r--src/core/download_manager_delegate_qt.cpp31
1 files changed, 9 insertions, 22 deletions
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<ProfileAdapterClient*> 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)) {