diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-11-03 13:42:50 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-06-23 08:19:37 +0000 |
commit | b288dd5352f6c77c875812c7f9043c266c59c505 (patch) | |
tree | ec07ada1b26f76fe4fb812139b9f5254b55f7970 /src/webengine | |
parent | 84b72e6b2387991f90293984f2666563c93cf13c (diff) |
Implement pause and resume action in Download Items
Adds the ability to pause downloads, and resume paused or interrupted
downloads.
Task-number: QTBUG-56840
Change-Id: I018bd30c3a772a36d48e4154d94f69cb8d8319e4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/webengine')
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem.cpp | 82 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p.h | 8 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p_p.h | 2 | ||||
-rw-r--r-- | src/webengine/plugin/plugin.cpp | 2 |
4 files changed, 94 insertions, 0 deletions
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp index bc40e6771..5afb19531 100644 --- a/src/webengine/api/qquickwebenginedownloaditem.cpp +++ b/src/webengine/api/qquickwebenginedownloaditem.cpp @@ -39,6 +39,8 @@ #include "qquickwebenginedownloaditem_p.h" #include "qquickwebenginedownloaditem_p_p.h" + +#include "browser_context_adapter.h" #include "qquickwebengineprofile_p.h" using QtWebEngineCore::BrowserContextAdapterClient; @@ -103,6 +105,8 @@ QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWeb , interruptReason(QQuickWebEngineDownloadItem::NoReason) , totalBytes(-1) , receivedBytes(0) + , downloadFinished(false) + , downloadPaused(false) { } @@ -145,6 +149,16 @@ void QQuickWebEngineDownloadItemPrivate::update(const BrowserContextAdapterClien totalBytes = info.totalBytes; Q_EMIT q->totalBytesChanged(); } + + if (info.done != downloadFinished) { + downloadFinished = info.done; + Q_EMIT q->isFinishedChanged(); + } + + if (info.paused != downloadPaused) { + downloadPaused = info.paused; + Q_EMIT q->isPausedChanged(); + } } void QQuickWebEngineDownloadItemPrivate::updateState(QQuickWebEngineDownloadItem::DownloadState newState) @@ -199,6 +213,46 @@ void QQuickWebEngineDownloadItem::cancel() } } + +/*! + \qmlmethod void WebEngineDownloadItem::pause() + \since QtWebEngine 1.6 + + Pauses the download. +*/ + +void QQuickWebEngineDownloadItem::pause() +{ + Q_D(QQuickWebEngineDownloadItem); + + QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (state != QQuickWebEngineDownloadItem::DownloadInProgress) + return; + + if (d->profile) + d->profile->d_ptr->browserContext()->pauseDownload(d->downloadId); +} + +/*! + \qmlmethod void WebEngineDownloadItem::resume() + \since QtWebEngine 1.6 + + Resumes the download if it was paused or interrupted. +*/ +void QQuickWebEngineDownloadItem::resume() +{ + Q_D(QQuickWebEngineDownloadItem); + + QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (d->downloadFinished || (state != QQuickWebEngineDownloadItem::DownloadInProgress && state != QQuickWebEngineDownloadItem::DownloadInterrupted)) + return; + + if (d->profile) + d->profile->d_ptr->browserContext()->resumeDownload(d->downloadId); +} + /*! \qmlproperty int WebEngineDownloadItem::id @@ -426,6 +480,34 @@ QString QQuickWebEngineDownloadItem::interruptReasonString() const static_cast<BrowserContextAdapterClient::DownloadInterruptReason>(interruptReason())); } +/*! + \qmlproperty bool WebEngineDownloadItem::isFinished + \readonly + \since QtWebEngine 1.6 + + Whether this download is finished (completed, cancelled, or non-resumable interrupted state). + */ + +bool QQuickWebEngineDownloadItem::isFinished() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadFinished; +} + +/*! + \qmlproperty bool WebEngineDownloadItem::isPaused + \readonly + \since QtWebEngine 1.6 + + Whether this download is paused. + */ + +bool QQuickWebEngineDownloadItem::isPaused() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadPaused; +} + QQuickWebEngineDownloadItem::QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate *p, QObject *parent) : QObject(parent) , d_ptr(p) diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h index 889d0bcb7..972b130aa 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p.h @@ -131,9 +131,13 @@ public: Q_PROPERTY(DownloadType type READ type NOTIFY typeChanged REVISION 3 FINAL) Q_PROPERTY(DownloadInterruptReason interruptReason READ interruptReason NOTIFY interruptReasonChanged REVISION 4 FINAL) Q_PROPERTY(QString interruptReasonString READ interruptReasonString NOTIFY interruptReasonChanged REVISION 4 FINAL) + Q_PROPERTY(bool isFinished READ isFinished NOTIFY isFinishedChanged REVISION 5 FINAL) + Q_PROPERTY(bool isPaused READ isPaused NOTIFY isPausedChanged REVISION 5 FINAL) Q_INVOKABLE void accept(); Q_INVOKABLE void cancel(); + Q_INVOKABLE void pause(); + Q_INVOKABLE void resume(); quint32 id() const; DownloadState state() const; @@ -147,6 +151,8 @@ public: DownloadType type() const; DownloadInterruptReason interruptReason() const; QString interruptReasonString() const; + bool isFinished() const; + bool isPaused() const; Q_SIGNALS: void stateChanged(); @@ -157,6 +163,8 @@ Q_SIGNALS: void pathChanged(); Q_REVISION(3) void typeChanged(); Q_REVISION(4) void interruptReasonChanged(); + Q_REVISION(5) void isFinishedChanged(); + Q_REVISION(5) void isPausedChanged(); private: QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate*, QObject *parent = 0); diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h index 4fb609492..6b4f7c8d3 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h @@ -79,6 +79,8 @@ public: qint64 receivedBytes; QString mimeType; QString downloadPath; + bool downloadFinished; + bool downloadPaused; void update(const QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info); void updateState(QQuickWebEngineDownloadItem::DownloadState newState); diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp index 668d55458..e58b2ab61 100644 --- a/src/webengine/plugin/plugin.cpp +++ b/src/webengine/plugin/plugin.cpp @@ -102,6 +102,8 @@ public: tr("Cannot create a separate instance of WebEngineDownloadItem")); qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 4>(uri, 1, 5, "WebEngineDownloadItem", tr("Cannot create a separate instance of WebEngineDownloadItem")); + qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 5>(uri, 1, 6, "WebEngineDownloadItem", + tr("Cannot create a separate instance of 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", tr("Cannot create a separate instance of WebEngineSettings")); |