summaryrefslogtreecommitdiffstats
path: root/src/webengine/api/qquickwebenginedownloaditem.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2016-11-03 13:42:50 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-06-23 08:19:37 +0000
commitb288dd5352f6c77c875812c7f9043c266c59c505 (patch)
treeec07ada1b26f76fe4fb812139b9f5254b55f7970 /src/webengine/api/qquickwebenginedownloaditem.cpp
parent84b72e6b2387991f90293984f2666563c93cf13c (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/api/qquickwebenginedownloaditem.cpp')
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem.cpp82
1 files changed, 82 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)