Commit eda8fbdf authored by Andras Becsi's avatar Andras Becsi Committed by Andras Becsi
Browse files

Reverse the logic for download cancellation


Since we require downloads to be explicitly accepted
we should have 'accepted' as a member in the download
info instead of 'cancelled'.

Change-Id: Ia8ff4a4b29f3c8631f4cb1c410ece5f11d9cdc93
Reviewed-by: default avatarAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Showing with 10 additions and 11 deletions
...@@ -64,7 +64,7 @@ public: ...@@ -64,7 +64,7 @@ public:
const qint64 receivedBytes; const qint64 receivedBytes;
QString path; QString path;
bool cancelled; bool accepted;
}; };
virtual ~BrowserContextAdapterClient() { } virtual ~BrowserContextAdapterClient() { }
......
...@@ -126,7 +126,6 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i ...@@ -126,7 +126,6 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
item->AddObserver(this); item->AddObserver(this);
if (m_contextAdapter->client()) { if (m_contextAdapter->client()) {
bool cancelled = false;
BrowserContextAdapterClient::DownloadItemInfo info = { BrowserContextAdapterClient::DownloadItemInfo info = {
item->GetId(), item->GetId(),
toQt(item->GetURL()), toQt(item->GetURL()),
...@@ -134,18 +133,18 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i ...@@ -134,18 +133,18 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
item->GetTotalBytes(), item->GetTotalBytes(),
item->GetReceivedBytes(), item->GetReceivedBytes(),
suggestedFilePath, suggestedFilePath,
cancelled false /* accepted */
}; };
m_contextAdapter->client()->downloadRequested(info); m_contextAdapter->client()->downloadRequested(info);
suggestedFile.setFile(info.path); suggestedFile.setFile(info.path);
if (!info.cancelled && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) { if (info.accepted && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) {
qWarning("Creating download path failed, download cancelled: %s", suggestedFile.absolutePath().toUtf8().data()); qWarning("Creating download path failed, download cancelled: %s", suggestedFile.absolutePath().toUtf8().data());
cancelled = true; info.accepted = false;
} }
if (info.cancelled) { if (!info.accepted) {
cancelDownload(callback); cancelDownload(callback);
return true; return true;
} }
...@@ -180,7 +179,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa ...@@ -180,7 +179,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
download->GetTotalBytes(), download->GetTotalBytes(),
download->GetReceivedBytes(), download->GetReceivedBytes(),
QString(), QString(),
false true /* accepted */
}; };
m_contextAdapter->client()->downloadUpdated(info); m_contextAdapter->client()->downloadUpdated(info);
} }
......
...@@ -100,8 +100,8 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) ...@@ -100,8 +100,8 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
QQuickWebEngineDownloadItem::DownloadState state = download->state(); QQuickWebEngineDownloadItem::DownloadState state = download->state();
info.path = download->path(); info.path = download->path();
info.cancelled = state == QQuickWebEngineDownloadItem::DownloadCancelled info.accepted = state != QQuickWebEngineDownloadItem::DownloadCancelled
|| state == QQuickWebEngineDownloadItem::DownloadRequested; && state != QQuickWebEngineDownloadItem::DownloadRequested;
} }
void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info) void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info)
......
...@@ -152,11 +152,11 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) ...@@ -152,11 +152,11 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
QWebEngineDownloadItem::DownloadState state = download->state(); QWebEngineDownloadItem::DownloadState state = download->state();
info.path = download->path(); info.path = download->path();
info.cancelled = state == QWebEngineDownloadItem::DownloadCancelled; info.accepted = state != QWebEngineDownloadItem::DownloadCancelled;
if (state == QWebEngineDownloadItem::DownloadRequested) { if (state == QWebEngineDownloadItem::DownloadRequested) {
// Delete unaccepted downloads. // Delete unaccepted downloads.
info.cancelled = true; info.accepted = false;
m_ongoingDownloads.remove(info.id); m_ongoingDownloads.remove(info.id);
delete download; delete download;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment