diff options
author | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2019-05-09 14:49:56 +0200 |
---|---|---|
committer | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2019-05-16 11:57:07 +0000 |
commit | a4eeb9dbd995d598bd3a639dd450def7c242b383 (patch) | |
tree | 99d1b0fe8fa64be15948b601960c54e5b632783b /src | |
parent | 0c2beb49b858f49489fa4f1ecee6bfdd6ce57e68 (diff) |
Add API to get the suggested download file name
[ChangeLog][DownloadItem] Add functions and property
to get the suggested download file name.
Task-number: QTBUG-56978
Change-Id: I902870c6358271322da613a15ccc11639384e404
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/download_manager_delegate_qt.cpp | 10 | ||||
-rw-r--r-- | src/core/profile_adapter_client.h | 1 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem.cpp | 12 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p.h | 2 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p_p.h | 1 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.cpp | 11 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 1 |
10 files changed, 38 insertions, 3 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 2af958068..ba506601f 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -208,7 +208,8 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem* false /* done */, downloadType, item->GetLastReason(), - adapterClient + adapterClient, + suggestedFilename }; for (ProfileAdapterClient *client : qAsConst(clients)) { @@ -309,7 +310,9 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content false, /* done */ ProfileAdapterClient::SavePage, ProfileAdapterClient::NoReason, - adapterClient + adapterClient, + QFileInfo(suggestedFilePath).fileName() + }; for (ProfileAdapterClient *client : qAsConst(clients)) { @@ -375,7 +378,8 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(download::DownloadItem *downlo download->IsDone(), 0 /* downloadType (unused) */, download->GetLastReason(), - adapterClient + adapterClient, + toQt(download->GetSuggestedFilename()) }; for (ProfileAdapterClient *client : qAsConst(clients)) { diff --git a/src/core/profile_adapter_client.h b/src/core/profile_adapter_client.h index b463043da..3589f6cd7 100644 --- a/src/core/profile_adapter_client.h +++ b/src/core/profile_adapter_client.h @@ -138,6 +138,7 @@ public: int downloadType; int downloadInterruptReason; WebContentsAdapterClient *page; + QString suggestedFileName; }; virtual ~ProfileAdapterClient() { } diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp index cbd0e994a..d5f6a3ef1 100644 --- a/src/webengine/api/qquickwebenginedownloaditem.cpp +++ b/src/webengine/api/qquickwebenginedownloaditem.cpp @@ -446,6 +446,18 @@ void QQuickWebEngineDownloadItem::setPath(QString path) Q_EMIT pathChanged(); } } +/*! + \qmlproperty string WebEngineDownloadItem::suggestedFileName + \since QtWebEngine 1.10 + + Returns the suggested file name. +*/ + +QString QQuickWebEngineDownloadItem::suggestedFileName() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->suggestedFileName; +} /*! \qmlproperty enumeration WebEngineDownloadItem::savePageFormat diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h index 1b17f71aa..613b0173d 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p.h @@ -138,6 +138,7 @@ public: Q_PROPERTY(bool isSavePageDownload READ isSavePageDownload CONSTANT REVISION 6 FINAL) Q_PROPERTY(QQuickWebEngineView *view READ view CONSTANT REVISION 7 FINAL) Q_PROPERTY(QUrl url READ url CONSTANT REVISION 8 FINAL) + Q_PROPERTY(QString suggestedFileName READ suggestedFileName CONSTANT REVISION 8 FINAL) Q_INVOKABLE void accept(); Q_INVOKABLE void cancel(); @@ -161,6 +162,7 @@ public: bool isSavePageDownload() const; QQuickWebEngineView *view() const; QUrl url() const; + QString suggestedFileName() const; Q_SIGNALS: void stateChanged(); diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h index 955a6fd6a..e4d90d8ef 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h @@ -83,6 +83,7 @@ public: bool downloadPaused; QQuickWebEngineView *view; QUrl downloadUrl; + QString suggestedFileName; void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info); void updateState(QQuickWebEngineDownloadItem::DownloadState newState); diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 911e4cbce..2dbd0e94b 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -243,6 +243,7 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) itemPrivate->totalBytes = info.totalBytes; itemPrivate->mimeType = info.mimeType; itemPrivate->downloadPath = info.path; + itemPrivate->suggestedFileName = info.suggestedFileName; itemPrivate->savePageFormat = static_cast<QQuickWebEngineDownloadItem::SavePageFormat>( info.savePageFormat); itemPrivate->type = static_cast<QQuickWebEngineDownloadItem::DownloadType>(info.downloadType); diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index 4575f2929..ec088762e 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -536,6 +536,17 @@ void QWebEngineDownloadItem::setPath(QString path) d->downloadPath = path; } +/*! + \since 5.14 + + Returns the suggested file name. +*/ + +QString QWebEngineDownloadItem::suggestedFileName() const +{ + Q_D(const QWebEngineDownloadItem); + return d->suggestedFileName; +} /*! Returns whether this download is finished (completed, cancelled, or non-resumable interrupted state). diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.h b/src/webenginewidgets/api/qwebenginedownloaditem.h index 981a3c374..0ae6b2575 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem.h @@ -128,6 +128,7 @@ public: DownloadInterruptReason interruptReason() const; QString interruptReasonString() const; bool isSavePageDownload() const; + QString suggestedFileName() const; QWebEnginePage *page() const; diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h index b3bc8a3fe..ac5db7dcd 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h @@ -78,6 +78,7 @@ public: const QUrl downloadUrl; QString mimeType; bool downloadPaused; + QString suggestedFileName; qint64 totalBytes; qint64 receivedBytes; diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index 237d68473..6e7191355 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -227,6 +227,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) itemPrivate->downloadState = info.accepted ? QWebEngineDownloadItem::DownloadInProgress : QWebEngineDownloadItem::DownloadRequested; itemPrivate->downloadPath = info.path; + itemPrivate->suggestedFileName = info.suggestedFileName; itemPrivate->mimeType = info.mimeType; itemPrivate->savePageFormat = static_cast<QWebEngineDownloadItem::SavePageFormat>(info.savePageFormat); itemPrivate->type = static_cast<QWebEngineDownloadItem::DownloadType>(info.downloadType); |