summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2019-02-11 19:13:01 +0100
committerKirill Burtsev <kirill.burtsev@qt.io>2019-02-19 15:30:38 +0000
commit755f7e414583c5458c2d421d047a1c7890c8d8d2 (patch)
tree8fa1a5c5bbec9329566c8b51f64b4d012a57fc44
parent9c59897f9d24041e3e1bb9553d5b4bc1f1ec538a (diff)
Set download state to finished when cancelling or destroying the download item
Task-number: QTBUG-73839 Change-Id: Ieebaa802bdfe0c410618e4213a9bedbbae9d0f61 Reviewed-by: Michael Brüning <michael.bruning@qt.io> Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem.cpp20
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p_p.h1
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem.cpp19
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem_p.h4
4 files changed, 34 insertions, 10 deletions
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp
index b69e6b7d..7d138287 100644
--- a/src/webengine/api/qquickwebenginedownloaditem.cpp
+++ b/src/webengine/api/qquickwebenginedownloaditem.cpp
@@ -185,10 +185,8 @@ void QQuickWebEngineDownloadItemPrivate::update(const ProfileAdapterClient::Down
Q_EMIT q->totalBytesChanged();
}
- if (info.done != downloadFinished) {
- downloadFinished = info.done;
- Q_EMIT q->isFinishedChanged();
- }
+ if (info.done)
+ setFinished();
if (info.paused != downloadPaused) {
downloadPaused = info.paused;
@@ -206,6 +204,17 @@ void QQuickWebEngineDownloadItemPrivate::updateState(QQuickWebEngineDownloadItem
}
}
+void QQuickWebEngineDownloadItemPrivate::setFinished()
+{
+ Q_Q(QQuickWebEngineDownloadItem);
+
+ if (downloadFinished)
+ return;
+
+ downloadFinished = true;
+ Q_EMIT q->isFinishedChanged();
+}
+
/*!
\qmlmethod void WebEngineDownloadItem::accept()
@@ -255,6 +264,7 @@ void QQuickWebEngineDownloadItem::cancel()
return;
d->updateState(QQuickWebEngineDownloadItem::DownloadCancelled);
+ d->setFinished();
// We directly cancel the download if the user cancels before
// it even started, so no need to notify the profile here.
@@ -617,6 +627,8 @@ QQuickWebEngineDownloadItem::QQuickWebEngineDownloadItem(QQuickWebEngineDownload
QQuickWebEngineDownloadItem::~QQuickWebEngineDownloadItem()
{
+ if (!isFinished())
+ cancel();
if (d_ptr->profile)
d_ptr->profile->d_ptr->profileAdapter()->removeDownload(d_ptr->downloadId);
}
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
index 4b89335b..f444c04a 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
@@ -85,6 +85,7 @@ public:
void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info);
void updateState(QQuickWebEngineDownloadItem::DownloadState newState);
+ void setFinished();
};
QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
index 55d4fcca..f0f0958a 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp
+++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
@@ -197,11 +197,8 @@ void QWebEngineDownloadItemPrivate::update(const ProfileAdapterClient::DownloadI
Q_EMIT q->downloadProgress(receivedBytes, totalBytes);
}
- if (info.done != downloadFinished) {
- downloadFinished = info.done;
- if (downloadFinished)
- Q_EMIT q->finished();
- }
+ if (info.done)
+ setFinished();
if (downloadPaused != info.paused) {
downloadPaused = info.paused;
@@ -209,6 +206,15 @@ void QWebEngineDownloadItemPrivate::update(const ProfileAdapterClient::DownloadI
}
}
+void QWebEngineDownloadItemPrivate::setFinished()
+{
+ if (downloadFinished)
+ return;
+
+ downloadFinished = true;
+ Q_EMIT q_ptr->finished();
+}
+
/*!
Accepts the current download request, which will start the download.
@@ -262,6 +268,7 @@ void QWebEngineDownloadItem::cancel()
} else {
d->downloadState = QWebEngineDownloadItem::DownloadCancelled;
Q_EMIT stateChanged(d->downloadState);
+ d->setFinished();
}
}
@@ -653,6 +660,8 @@ QWebEngineDownloadItem::QWebEngineDownloadItem(QWebEngineDownloadItemPrivate *p,
*/
QWebEngineDownloadItem::~QWebEngineDownloadItem()
{
+ if (!isFinished())
+ cancel();
if (auto profileAdapter = d_ptr->profile->profileAdapter())
profileAdapter->removeDownload(d_ptr->downloadId);
}
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h
index bdcda5be..b3bc8a3f 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h
+++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h
@@ -53,7 +53,7 @@
#include "qtwebenginewidgetsglobal.h"
-#include "qwebenginedownloaditem_p.h"
+#include "qwebenginedownloaditem.h"
#include "qwebengineprofile_p.h"
#include <QString>
@@ -84,6 +84,8 @@ public:
QWebEnginePage *page;
void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info);
+
+ void setFinished();
};
QT_END_NAMESPACE