diff options
author | Anu Aliyas <anu.aliyas@qt.io> | 2023-04-17 13:34:23 +0200 |
---|---|---|
committer | Anu Aliyas <anu.aliyas@qt.io> | 2023-04-20 16:32:38 +0200 |
commit | 97c3782e2f5ecd3115aab1d0216b989b55f54f21 (patch) | |
tree | 0a8832e5d214707e224585165ae8dd5bc428d84c /src | |
parent | 421d3c4e0b57170343df57de0b222d0f57a7bcb7 (diff) | |
download | qtwebengine-97c3782e2f5ecd3115aab1d0216b989b55f54f21.tar.gz |
Add WebEngineView::save() convenience API
Add the convenience method QQuickWebEngineView::save for saving pages without
the need to explicitly handle download requests.
Task-number: QTBUG-56093
Change-Id: I67909fdca6472d1ea9b32e0f89c1ab90219bca3b
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/webenginequick/api/qquickwebengineprofile.cpp | 3 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineview.cpp | 7 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineview_p.h | 5 | ||||
-rw-r--r-- | src/webenginequick/doc/src/webengineview_lgpl.qdoc | 19 |
4 files changed, 33 insertions, 1 deletions
diff --git a/src/webenginequick/api/qquickwebengineprofile.cpp b/src/webenginequick/api/qquickwebengineprofile.cpp index a830e969e..92ab9dc25 100644 --- a/src/webenginequick/api/qquickwebengineprofile.cpp +++ b/src/webenginequick/api/qquickwebengineprofile.cpp @@ -212,7 +212,8 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) QWebEngineDownloadRequestPrivate *itemPrivate = new QWebEngineDownloadRequestPrivate(m_profileAdapter); itemPrivate->downloadId = info.id; - itemPrivate->downloadState = QWebEngineDownloadRequest::DownloadRequested; + itemPrivate->downloadState = info.accepted ? QWebEngineDownloadRequest::DownloadInProgress + : QWebEngineDownloadRequest::DownloadRequested; itemPrivate->startTime = info.startTime; itemPrivate->downloadUrl = info.url; itemPrivate->totalBytes = info.totalBytes; diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp index 2d49c9419..f11274741 100644 --- a/src/webenginequick/api/qquickwebengineview.cpp +++ b/src/webenginequick/api/qquickwebengineview.cpp @@ -2411,6 +2411,13 @@ QQmlComponent *QQuickWebEngineView::touchHandleDelegate() const return d_ptr->m_touchHandleDelegate; } +void QQuickWebEngineView::save(const QString &filePath, + QWebEngineDownloadRequest::SavePageFormat format) const +{ + Q_D(const QQuickWebEngineView); + d->adapter->save(filePath, format); +} + QT_END_NAMESPACE #include "moc_qquickwebengineview_p.cpp" diff --git a/src/webenginequick/api/qquickwebengineview_p.h b/src/webenginequick/api/qquickwebengineview_p.h index 946bf1e0a..f057ba9be 100644 --- a/src/webenginequick/api/qquickwebengineview_p.h +++ b/src/webenginequick/api/qquickwebengineview_p.h @@ -17,6 +17,7 @@ #include <QtWebEngineCore/qtwebenginecoreglobal.h> #include <QtWebEngineCore/qwebenginequotarequest.h> +#include <QtWebEngineCore/qwebenginedownloadrequest.h> #include <QtWebEngineQuick/private/qtwebenginequickglobal_p.h> #include <QtGui/qcolor.h> #include <QtQml/qqmlregistration.h> @@ -465,6 +466,10 @@ QT_WARNING_POP QQmlComponent *touchHandleDelegate() const; void setTouchHandleDelegate(QQmlComponent *delegagte); + Q_REVISION(6, 6) + Q_INVOKABLE void save(const QString &filePath, + QWebEngineDownloadRequest::SavePageFormat format = + QWebEngineDownloadRequest::MimeHtmlSaveFormat) const; public Q_SLOTS: void runJavaScript(const QString&, const QJSValue & = QJSValue()); diff --git a/src/webenginequick/doc/src/webengineview_lgpl.qdoc b/src/webenginequick/doc/src/webengineview_lgpl.qdoc index be626c053..4dc99f00b 100644 --- a/src/webenginequick/doc/src/webengineview_lgpl.qdoc +++ b/src/webenginequick/doc/src/webengineview_lgpl.qdoc @@ -1528,5 +1528,24 @@ */ +/*! + \qmlmethod void WebEngineView::save(const QString &filePath, QWebEngineDownloadRequest::SavePageFormat format) + \since QtWebEngine 6.6 + + Save the current web page to disk. + + The web page is saved to \a filePath in the specified \a{format}. + + This is a shortcut for the following actions: + \list + \li Trigger the Save web action. + \li Accept the next download item and set the specified file path and save format. + \endlist + + This function issues an asynchronous download request for the web page and returns immediately. + + \sa QWebEngineDownloadRequest::SavePageFormat +*/ + \sa {WebEngine Qt Quick Custom Touch Handle Example} */ |