From 8a3aca63b063bbefc2fc46abecdec31222cf8bd4 Mon Sep 17 00:00:00 2001 From: Peter Vilim Date: Thu, 1 Jan 2015 22:32:39 -0600 Subject: [PATCH 1/6] Confirm quit if downloads running --- qutebrowser/config/configtypes.py | 55 +++++++++++++++++++++++++++- qutebrowser/mainwindow/mainwindow.py | 44 +++++++++++++++------- 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 0cc7592b4..4b445cd00 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -25,6 +25,7 @@ import base64 import codecs import os.path import sre_constants +import itertools from PyQt5.QtCore import QUrl from PyQt5.QtGui import QColor, QFont @@ -1223,14 +1224,66 @@ class AcceptCookies(BaseType): ('never', "Don't accept cookies at all.")) -class ConfirmQuit(BaseType): +class ConfirmQuit(List): """Whether to display a confirmation when the window is closed.""" + typestr = 'string-list' + valid_values = ValidValues(('always', "Always show a confirmation."), ('multiple-tabs', "Show a confirmation if " "multiple tabs are opened."), + ('downloads', "show a confirmation if downloads" + "are running"), ('never', "Never show a confirmation.")) + # Values that can be combined with commas + combinable_values = ('multiple-tabs', 'downloads') + + def transform(self, value): + # Backward compatible + if value == 'never': + return value + # Split configuration string into list + else: + return super().transform(value) + + def validate(self, value): + values = self.transform(value) + # Backward compatibility + if values == 'never': + return + # Never can't be set with other options + elif 'never' in values and isinstance(values, list): + raise configexc.ValidationError(value, "List cannot contain never!") + # Always can't be set with other options + elif 'always' in values and isinstance(values, list): + raise configexc.ValidationError(value, + "List cannot contain always!") + # Values have to be valid + elif not set(values).issubset(set(self.valid_values.values)): + raise configexc.ValidationError(value, "List contains invalid" + " values!") + # List can't have duplicates + elif len(set(values)) != len(values): + raise configexc.ValidationError(value, "List contains duplicate" + " values!") + + def complete(self): + combinations = [] + # Generate combinations of the options that can be combined + for size in range(2, len(self.combinable_values) + 1): + combinations = combinations + list( + itertools.combinations(self.combinable_values, size)) + out = [] + # Add valid single values + for val in self.valid_values: + out.append((val, self.valid_values.descriptions[val])) + # Add combinations to list of options + for val in combinations: + desc = '' + val = ','.join(val) + out.append((val, desc)) + return out class ForwardUnboundKeys(BaseType): diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 2b2311dd2..801ded657 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -327,21 +327,37 @@ class MainWindow(QWidget): def closeEvent(self, e): """Override closeEvent to display a confirmation if needed.""" confirm_quit = config.get('ui', 'confirm-quit') - count = self._tabbed_browser.count() - if confirm_quit == 'never': + tab_count = self._tabbed_browser.count() + download_manager = objreg.get('download-manager', scope='window', + window=self.win_id) + download_count = download_manager.rowCount() + quit_text = [] + # Close if set to never ask for confirmation (backward compatible) + if confirm_quit == 'never' or 'never' in confirm_quit: pass - elif confirm_quit == 'multiple-tabs' and count <= 1: - pass - else: - text = "Close {} {}?".format( - count, "tab" if count == 1 else "tabs") - confirmed = message.ask(self.win_id, text, - usertypes.PromptMode.yesno, default=True) - if not confirmed: - log.destroy.debug("Cancelling losing of window {}".format( - self.win_id)) - e.ignore() - return + # Ask if set to always ask before closing + if 'always' in confirm_quit: + quit_text.append("Close?") + # Ask if multiple-tabs are open + if 'multiple-tabs' in confirm_quit and tab_count > 1: + quit_text.append("Close {} {}?".format( + tab_count, "tab" if tab_count == 1 else "tabs")) + # Ask if multiple downloads running + if 'downloads' in confirm_quit and download_count > 0: + quit_text.append("Close {} {}?".format( + tab_count, "download" if tab_count == 1 else "downloads")) + # Process all quit messages that user must confirm + if len(quit_text) > 0: + for text in quit_text: + confirmed = message.ask(self.win_id, text, + usertypes.PromptMode.yesno, + default=True) + # Stop asking if the user cancels + if not confirmed: + log.destroy.debug("Cancelling losing of window {}".format( + self.win_id)) + e.ignore() + return e.accept() objreg.get('app').geometry = bytes(self.saveGeometry()) log.destroy.debug("Closing window {}".format(self.win_id)) From 0305dedbfbe8d76e1ffef560a9189ee63c774d4e Mon Sep 17 00:00:00 2001 From: Peter Vilim Date: Mon, 5 Jan 2015 01:01:22 -0600 Subject: [PATCH 2/6] Use multiple lines for quit messages --- qutebrowser/config/configtypes.py | 14 ++++++----- qutebrowser/mainwindow/mainwindow.py | 36 +++++++++++++--------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 4b445cd00..65d8f6e95 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1253,10 +1253,12 @@ class ConfirmQuit(List): if values == 'never': return # Never can't be set with other options - elif 'never' in values and isinstance(values, list): + elif 'never' in values and isinstance(values, + list) and len(values) > 1: raise configexc.ValidationError(value, "List cannot contain never!") # Always can't be set with other options - elif 'always' in values and isinstance(values, list): + elif 'always' in values and isinstance(values, + list) and len(values) > 1: raise configexc.ValidationError(value, "List cannot contain always!") # Values have to be valid @@ -1269,17 +1271,17 @@ class ConfirmQuit(List): " values!") def complete(self): - combinations = [] + permutations = [] # Generate combinations of the options that can be combined for size in range(2, len(self.combinable_values) + 1): - combinations = combinations + list( - itertools.combinations(self.combinable_values, size)) + permutations = permutations + list( + itertools.permutations(self.combinable_values, size)) out = [] # Add valid single values for val in self.valid_values: out.append((val, self.valid_values.descriptions[val])) # Add combinations to list of options - for val in combinations: + for val in permutations: desc = '' val = ','.join(val) out.append((val, desc)) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 801ded657..6c482e34b 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -331,33 +331,31 @@ class MainWindow(QWidget): download_manager = objreg.get('download-manager', scope='window', window=self.win_id) download_count = download_manager.rowCount() - quit_text = [] + quit_texts = [] # Close if set to never ask for confirmation (backward compatible) if confirm_quit == 'never' or 'never' in confirm_quit: pass - # Ask if set to always ask before closing - if 'always' in confirm_quit: - quit_text.append("Close?") # Ask if multiple-tabs are open if 'multiple-tabs' in confirm_quit and tab_count > 1: - quit_text.append("Close {} {}?".format( - tab_count, "tab" if tab_count == 1 else "tabs")) + quit_texts.append("{} {} open.".format( + tab_count, "tab is" if tab_count == 1 else "tabs are")) # Ask if multiple downloads running if 'downloads' in confirm_quit and download_count > 0: - quit_text.append("Close {} {}?".format( - tab_count, "download" if tab_count == 1 else "downloads")) + quit_texts.append("{} {} running.".format( + tab_count, + "download is" if tab_count == 1 else "downloads are")) # Process all quit messages that user must confirm - if len(quit_text) > 0: - for text in quit_text: - confirmed = message.ask(self.win_id, text, - usertypes.PromptMode.yesno, - default=True) - # Stop asking if the user cancels - if not confirmed: - log.destroy.debug("Cancelling losing of window {}".format( - self.win_id)) - e.ignore() - return + if quit_texts or 'always' in confirm_quit: + text = '\n'.join(['Really quit?'] + quit_texts) + confirmed = message.ask(self.win_id, text, + usertypes.PromptMode.yesno, + default=True) + # Stop asking if the user cancels + if not confirmed: + log.destroy.debug("Cancelling losing of window {}".format( + self.win_id)) + e.ignore() + return e.accept() objreg.get('app').geometry = bytes(self.saveGeometry()) log.destroy.debug("Closing window {}".format(self.win_id)) From dfa276a20c588753d81fdf645d48ec6ebbcf7c83 Mon Sep 17 00:00:00 2001 From: Peter Vilim Date: Mon, 5 Jan 2015 22:41:42 -0600 Subject: [PATCH 3/6] backward compatibility, space, combinations --- qutebrowser/config/configtypes.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 65d8f6e95..3c85d7859 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1233,32 +1233,19 @@ class ConfirmQuit(List): valid_values = ValidValues(('always', "Always show a confirmation."), ('multiple-tabs', "Show a confirmation if " "multiple tabs are opened."), - ('downloads', "show a confirmation if downloads" + ('downloads', "show a confirmation if downloads " "are running"), ('never', "Never show a confirmation.")) # Values that can be combined with commas combinable_values = ('multiple-tabs', 'downloads') - def transform(self, value): - # Backward compatible - if value == 'never': - return value - # Split configuration string into list - else: - return super().transform(value) - def validate(self, value): values = self.transform(value) - # Backward compatibility - if values == 'never': - return # Never can't be set with other options - elif 'never' in values and isinstance(values, - list) and len(values) > 1: + if 'never' in values and len(values) > 1: raise configexc.ValidationError(value, "List cannot contain never!") # Always can't be set with other options - elif 'always' in values and isinstance(values, - list) and len(values) > 1: + elif 'always' in values and len(values) > 1: raise configexc.ValidationError(value, "List cannot contain always!") # Values have to be valid @@ -1271,17 +1258,17 @@ class ConfirmQuit(List): " values!") def complete(self): - permutations = [] + combinations = [] # Generate combinations of the options that can be combined for size in range(2, len(self.combinable_values) + 1): - permutations = permutations + list( - itertools.permutations(self.combinable_values, size)) + combinations = combinations + list( + itertools.combinations(self.combinable_values, size)) out = [] # Add valid single values for val in self.valid_values: out.append((val, self.valid_values.descriptions[val])) # Add combinations to list of options - for val in permutations: + for val in combinations: desc = '' val = ','.join(val) out.append((val, desc)) From f828e554f70f02e2b4e2ffc504239d75db810658 Mon Sep 17 00:00:00 2001 From: Peter Vilim Date: Tue, 6 Jan 2015 04:03:21 -0600 Subject: [PATCH 4/6] misc fixes --- qutebrowser/config/configtypes.py | 17 ++++++++--------- qutebrowser/mainwindow/mainwindow.py | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 3c85d7859..1e27b1082 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1246,22 +1246,22 @@ class ConfirmQuit(List): raise configexc.ValidationError(value, "List cannot contain never!") # Always can't be set with other options elif 'always' in values and len(values) > 1: - raise configexc.ValidationError(value, - "List cannot contain always!") + raise configexc.ValidationError( + value, "List cannot contain always!") # Values have to be valid elif not set(values).issubset(set(self.valid_values.values)): - raise configexc.ValidationError(value, "List contains invalid" - " values!") + raise configexc.ValidationError( + value, "List contains invalid values!") # List can't have duplicates elif len(set(values)) != len(values): - raise configexc.ValidationError(value, "List contains duplicate" - " values!") + raise configexc.ValidationError( + value, "List contains duplicate values!") def complete(self): combinations = [] # Generate combinations of the options that can be combined for size in range(2, len(self.combinable_values) + 1): - combinations = combinations + list( + combinations += list( itertools.combinations(self.combinable_values, size)) out = [] # Add valid single values @@ -1270,8 +1270,7 @@ class ConfirmQuit(List): # Add combinations to list of options for val in combinations: desc = '' - val = ','.join(val) - out.append((val, desc)) + out.append((','.join(val), desc)) return out diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 6c482e34b..c5a0b00a9 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -332,8 +332,8 @@ class MainWindow(QWidget): window=self.win_id) download_count = download_manager.rowCount() quit_texts = [] - # Close if set to never ask for confirmation (backward compatible) - if confirm_quit == 'never' or 'never' in confirm_quit: + # Close if set to never ask for confirmation + if 'never' in confirm_quit: pass # Ask if multiple-tabs are open if 'multiple-tabs' in confirm_quit and tab_count > 1: @@ -352,7 +352,7 @@ class MainWindow(QWidget): default=True) # Stop asking if the user cancels if not confirmed: - log.destroy.debug("Cancelling losing of window {}".format( + log.destroy.debug("Cancelling closing of window {}".format( self.win_id)) e.ignore() return From 5c37d4a19de9f4bd9e2db77c8b9fcdd4c4e9c5fd Mon Sep 17 00:00:00 2001 From: Peter Vilim Date: Tue, 6 Jan 2015 04:14:41 -0600 Subject: [PATCH 5/6] fix line lengths --- qutebrowser/config/configtypes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 1e27b1082..d74aa6a0a 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1233,8 +1233,8 @@ class ConfirmQuit(List): valid_values = ValidValues(('always', "Always show a confirmation."), ('multiple-tabs', "Show a confirmation if " "multiple tabs are opened."), - ('downloads', "show a confirmation if downloads " - "are running"), + ('downloads', "Show a confirmation if " + "downloads are running"), ('never', "Never show a confirmation.")) # Values that can be combined with commas combinable_values = ('multiple-tabs', 'downloads') @@ -1243,7 +1243,8 @@ class ConfirmQuit(List): values = self.transform(value) # Never can't be set with other options if 'never' in values and len(values) > 1: - raise configexc.ValidationError(value, "List cannot contain never!") + raise configexc.ValidationError( + value, "List cannot contain never!") # Always can't be set with other options elif 'always' in values and len(values) > 1: raise configexc.ValidationError( From c4bb9344a94a07e970ecd4cf77761698ce0f21dd Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 Jan 2015 11:29:13 +0100 Subject: [PATCH 6/6] Regenerate docs. --- README.asciidoc | 2 +- doc/help/settings.asciidoc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.asciidoc b/README.asciidoc index 005ca59e6..dcab97005 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -127,6 +127,7 @@ Contributors, sorted by the number of commits in descending order: * Florian Bruhin * Claude * John ShaggyTwoDope Jenkins +* Peter Vilim * rikn00 * Martin Zimmermann * Joel Torstensson @@ -136,7 +137,6 @@ Contributors, sorted by the number of commits in descending order: * Mathias Fussenegger * Larry Hynes * Thiago Barroso Perrotta -* Peter Vilim * Matthias Lisin * Helen Sherwood-Taylor * HalosGhost diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 8422d9b61..aea88a6e1 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -390,6 +390,7 @@ Valid values: * +always+: Always show a confirmation. * +multiple-tabs+: Show a confirmation if multiple tabs are opened. + * +downloads+: Show a confirmation if downloads are running * +never+: Never show a confirmation. Default: +pass:[never]+