From 643d2cc6dd5c1b527c261227d272b1c67b834109 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 8 May 2016 03:17:30 +0200 Subject: [PATCH 1/5] fix confirm-quit=downloads with finished downloads Issue #846 .rowCount() returns all downloads, even the finished ones that have not yet been removed from the list. For confirming the quit event, we should only consider downloads that are still running. --- qutebrowser/browser/downloads.py | 8 ++++++++ qutebrowser/mainwindow/mainwindow.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 6cbeff434..6ac4cabb2 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -1238,3 +1238,11 @@ class DownloadManager(QAbstractListModel): # We don't have children return 0 return len(self.downloads) + + def running_downloads(self): + """Return the amount of still running downloads. + + Return: + The number of unfinished downloads. + """ + return len([1 for download in self.downloads if not download.done]) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index d93e672b4..533280b40 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -413,7 +413,7 @@ class MainWindow(QWidget): tab_count = self.tabbed_browser.count() download_manager = objreg.get('download-manager', scope='window', window=self.win_id) - download_count = download_manager.rowCount() + download_count = download_manager.running_downloads() quit_texts = [] # Ask if multiple-tabs are open if 'multiple-tabs' in confirm_quit and tab_count > 1: From 99182e3e79fe06abdd12086189f8434515411309 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 8 May 2016 23:24:50 +0200 Subject: [PATCH 2/5] downloads: change len() to sum() --- qutebrowser/browser/downloads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 6ac4cabb2..96c960f52 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -1245,4 +1245,4 @@ class DownloadManager(QAbstractListModel): Return: The number of unfinished downloads. """ - return len([1 for download in self.downloads if not download.done]) + return sum(1 for download in self.downloads if not download.done) From 1fa50021c1bdb3b0380fe5319124a2f176c57cab Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 8 May 2016 23:28:01 +0200 Subject: [PATCH 3/5] downloads: use right index for beginInsertRows len(self.downloads) is already the index of the item in the download list, this should be used for beginInsertRows(). The +1 is only for the human readable part. --- qutebrowser/browser/downloads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 96c960f52..66d72cf14 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -897,8 +897,8 @@ class DownloadManager(QAbstractListModel): download.redirected.connect( functools.partial(self.on_redirect, download)) download.basename = suggested_filename - idx = len(self.downloads) + 1 - download.index = idx + idx = len(self.downloads) + download.index = idx + 1 # "Human readable" index self.beginInsertRows(QModelIndex(), idx, idx) self.downloads.append(download) self.endInsertRows() From f7dc9b54bde4732861a60bb4d7219a8fd9c7d6e6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 9 May 2016 07:06:58 +0200 Subject: [PATCH 4/5] Add a test for #846 --- tests/integration/features/downloads.feature | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/integration/features/downloads.feature b/tests/integration/features/downloads.feature index 8509a435c..152336c49 100644 --- a/tests/integration/features/downloads.feature +++ b/tests/integration/features/downloads.feature @@ -200,3 +200,14 @@ Feature: Downloading things from a website. And I run :close And I wait 0.5s Then no crash should happen + + ## https://github.com/The-Compiler/qutebrowser/issues/846 + + Scenario: Quitting with finished downloads and confirm-quit=downloads + Given I have a fresh instance + When I set storage -> prompt-download-directory to false + And I set ui -> confirm-quit to downloads + And I open data/downloads/download.bin + And I wait until the download is finished + And I run :close + Then qutebrowser should quit From 7f99c36ec5817860ff226ce2c7de330d0573b65e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 9 May 2016 07:07:46 +0200 Subject: [PATCH 5/5] Update changelog --- CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 561f5d6d6..10b7f7ad2 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -53,6 +53,7 @@ Fixed - Close file handles correctly when a download failed - Fixed crash when using `;Y` (`:hint links yank-primary`) on a system without primary selection +- Don't display quit confirmation with finished downloads v0.6.2 ------