diff options
author | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2019-04-15 10:16:02 +0200 |
---|---|---|
committer | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2019-04-29 06:18:26 +0000 |
commit | 5d6086d1b97461b35c143839a8a6ba1b990bb87c (patch) | |
tree | 3f0811a9ce1b99fd20253e1d11d9bea1499db029 | |
parent | 15ebee1c10a954ea2408e35e53fa8307defc3970 (diff) |
Extend the QQuickWebEngineDownloadItem Qml type with url property
Task-number: QTBUG-72996
Change-Id: I8af67d69a9a88ccbc95e37a252615dd3fd3ca0ca
Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem.cpp | 17 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p.h | 3 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p_p.h | 3 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 2 | ||||
-rw-r--r-- | src/webengine/plugin/plugin.cpp | 2 | ||||
-rw-r--r-- | src/webengine/plugin/plugin.pro | 2 | ||||
-rw-r--r-- | tests/auto/quick/publicapi/tst_publicapi.cpp | 1 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_download.qml | 8 |
8 files changed, 33 insertions, 5 deletions
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp index 981d11633..8aff4e625 100644 --- a/src/webengine/api/qquickwebenginedownloaditem.cpp +++ b/src/webengine/api/qquickwebenginedownloaditem.cpp @@ -96,7 +96,7 @@ static inline QQuickWebEngineDownloadItem::DownloadInterruptReason toDownloadInt return static_cast<QQuickWebEngineDownloadItem::DownloadInterruptReason>(reason); } -QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfile *p) +QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfile *p, const QUrl &url) : profile(p) , downloadId(-1) , downloadState(QQuickWebEngineDownloadItem::DownloadCancelled) @@ -108,6 +108,7 @@ QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWeb , downloadFinished(false) , downloadPaused(false) , view(nullptr) + , downloadUrl(url) { } @@ -386,6 +387,20 @@ qint64 QQuickWebEngineDownloadItem::receivedBytes() const } /*! + \qmlproperty url WebEngineDownloadItem::url + \readonly + \since QtWebEngine 1.10 + + Returns the download's origin URL. +*/ + +QUrl QQuickWebEngineDownloadItem::url() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadUrl; +} + +/*! \qmlproperty string WebEngineDownloadItem::mimeType \since QtWebEngine 1.2 diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h index d19ca4828..1b17f71aa 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p.h @@ -55,6 +55,7 @@ #include <QObject> #include <QScopedPointer> #include <QString> +#include <QUrl> QT_BEGIN_NAMESPACE @@ -136,6 +137,7 @@ public: Q_PROPERTY(bool isPaused READ isPaused NOTIFY isPausedChanged REVISION 5 FINAL) 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_INVOKABLE void accept(); Q_INVOKABLE void cancel(); @@ -158,6 +160,7 @@ public: bool isPaused() const; bool isSavePageDownload() const; QQuickWebEngineView *view() const; + QUrl url() const; Q_SIGNALS: void stateChanged(); diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h index f444c04a5..955a6fd6a 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h @@ -67,7 +67,7 @@ class QQuickWebEngineDownloadItemPrivate { friend class QQuickWebEngineProfilePrivate; public: Q_DECLARE_PUBLIC(QQuickWebEngineDownloadItem) - QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfile *p); + QQuickWebEngineDownloadItemPrivate(QQuickWebEngineProfile *p, const QUrl &url); ~QQuickWebEngineDownloadItemPrivate(); quint32 downloadId; @@ -82,6 +82,7 @@ public: bool downloadFinished; bool downloadPaused; QQuickWebEngineView *view; + QUrl downloadUrl; 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 4832ba303..911e4cbce 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -237,7 +237,7 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) Q_Q(QQuickWebEngineProfile); Q_ASSERT(!m_ongoingDownloads.contains(info.id)); - QQuickWebEngineDownloadItemPrivate *itemPrivate = new QQuickWebEngineDownloadItemPrivate(q); + QQuickWebEngineDownloadItemPrivate *itemPrivate = new QQuickWebEngineDownloadItemPrivate(q, info.url); itemPrivate->downloadId = info.id; itemPrivate->downloadState = QQuickWebEngineDownloadItem::DownloadRequested; itemPrivate->totalBytes = info.totalBytes; diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp index cd2f5e001..bd367dea2 100644 --- a/src/webengine/plugin/plugin.cpp +++ b/src/webengine/plugin/plugin.cpp @@ -120,6 +120,8 @@ public: msgUncreatableType("WebEngineDownloadItem")); qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 7>(uri, 1, 8, "WebEngineDownloadItem", msgUncreatableType("WebEngineDownloadItem")); + qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 8>(uri, 1, 10, "WebEngineDownloadItem", + msgUncreatableType("WebEngineDownloadItem")); qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest>(uri, 1, 1, "WebEngineNewViewRequest", msgUncreatableType("WebEngineNewViewRequest")); qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest, 1>(uri, 1, 5, "WebEngineNewViewRequest", tr("Cannot create separate instance of WebEngineNewViewRequest")); qmlRegisterUncreatableType<QQuickWebEngineSettings>(uri, 1, 1, "WebEngineSettings", msgUncreatableType("WebEngineSettings")); diff --git a/src/webengine/plugin/plugin.pro b/src/webengine/plugin/plugin.pro index 0c1310de3..3b30bece2 100644 --- a/src/webengine/plugin/plugin.pro +++ b/src/webengine/plugin/plugin.pro @@ -1,7 +1,7 @@ CXX_MODULE = qml TARGET = qtwebengineplugin TARGETPATH = QtWebEngine -IMPORT_VERSION = 1.9 +IMPORT_VERSION = 1.10 QT += qml quick QT_PRIVATE += core-private webenginecore-private webengine-private diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index ed4a030df..787510422 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -260,6 +260,7 @@ static const QStringList expectedAPI = QStringList() << "QQuickWebEngineDownloadItem.type --> DownloadType" << "QQuickWebEngineDownloadItem.typeChanged() --> void" << "QQuickWebEngineDownloadItem.view --> QQuickWebEngineView*" + << "QQuickWebEngineDownloadItem.url --> QUrl" << "QQuickWebEngineFileDialogRequest.FileModeOpen --> FileMode" << "QQuickWebEngineFileDialogRequest.FileModeOpenMultiple --> FileMode" << "QQuickWebEngineFileDialogRequest.FileModeSave --> FileMode" diff --git a/tests/auto/quick/qmltests/data/tst_download.qml b/tests/auto/quick/qmltests/data/tst_download.qml index 5eb704cce..04838f57d 100644 --- a/tests/auto/quick/qmltests/data/tst_download.qml +++ b/tests/auto/quick/qmltests/data/tst_download.qml @@ -28,7 +28,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtWebEngine 1.9 +import QtWebEngine 1.10 import Qt.labs.platform 1.0 TestWebEngineView { @@ -42,6 +42,7 @@ TestWebEngineView { property bool cancelDownload: false property var downloadState: [] property var downloadInterruptReason: null + property url downloadUrl: "" function urlToPath(url) { var path = url.toString() @@ -81,6 +82,7 @@ TestWebEngineView { download.path = "testfile.zip" download.accept() } + downloadUrl = download.url } onDownloadFinished: { receivedBytes = download.receivedBytes; @@ -106,6 +108,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) + compare(downloadUrl, webEngineView.url) compare(downloadState[0], WebEngineDownloadItem.DownloadRequested) verify(!downloadInterruptReason) } @@ -115,6 +118,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) + compare(downloadUrl, webEngineView.url) compare(totalBytes, 325) verify(!downloadInterruptReason) } @@ -124,6 +128,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) + compare(downloadUrl, webEngineView.url) compare(downloadState[0], WebEngineDownloadItem.DownloadRequested) tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadInProgress) downloadFinishedSpy.wait() @@ -138,6 +143,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("download.zip") downLoadRequestedSpy.wait() compare(downLoadRequestedSpy.count, 1) + compare(downloadUrl, webEngineView.url) compare(downloadFinishedSpy.count, 1) tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadCancelled) tryCompare(webEngineView, "downloadInterruptReason", WebEngineDownloadItem.UserCanceled) |