Merge branch 'master' of https://github.com/skinnay/qutebrowser into skinnay-master

This commit is contained in:
Florian Bruhin 2015-11-02 17:55:40 +01:00
commit 0fb2778e4b
3 changed files with 20 additions and 13 deletions

View File

@ -771,7 +771,7 @@ class DownloadManager(QAbstractListModel):
fileobj: The file object to write the answer to.
filename: A path to write the data to.
auto_remove: Whether to remove the download even if
ui -> remove-finished-downloads is set to false.
ui -> remove-finished-downloads is set to -1.
Return:
The created DownloadItem.
@ -790,9 +790,10 @@ class DownloadManager(QAbstractListModel):
download = DownloadItem(reply, self._win_id, self)
download.cancelled.connect(
functools.partial(self.remove_item, download))
if config.get('ui', 'remove-finished-downloads') or auto_remove:
delay = config.get('ui', 'remove-finished-downloads')
if delay > -1 or auto_remove:
download.finished.connect(
functools.partial(self.remove_item, download))
functools.partial(self.remove_item_delayed, download, delay))
download.data_changed.connect(
functools.partial(self.on_data_changed, download))
download.error.connect(self.on_error)
@ -1011,6 +1012,10 @@ class DownloadManager(QAbstractListModel):
if not self.downloads:
self._update_timer.stop()
def remove_item_delayed(self, download, delay):
"""Remove a given download after a short delay."""
QTimer.singleShot(delay, functools.partial(self.remove_item, download))
def remove_items(self, downloads):
"""Remove an iterable of downloads."""
# On the first pass, we only generate the indices so we get the

View File

@ -255,21 +255,20 @@ def init(parent=None):
_init_misc()
def _get_value_transformer(old, new):
def _get_value_transformer(mapping):
"""Get a function which transforms a value for CHANGED_OPTIONS.
Args:
old: The old value - if the supplied value doesn't match this, it's
returned untransformed.
new: The new value.
mapping: A dictionary mapping old values to new values. Value is not
transformed if the supplied value doesn't match the old value.
Return:
A function which takes a value and transforms it.
"""
def transformer(val):
if val == old:
return new
else:
try:
return mapping[val]
except KeyError:
return val
return transformer
@ -352,9 +351,11 @@ class ConfigManager(QObject):
]
CHANGED_OPTIONS = {
('content', 'cookies-accept'):
_get_value_transformer('default', 'no-3rdparty'),
_get_value_transformer({'default': 'no-3rdparty'}),
('tabs', 'position'): _transform_position,
('ui', 'downloads-position'): _transform_position,
('ui', 'remove-finished-downloads'):
_get_value_transformer({'false': '-1', 'true': '2000'})
}
changed = pyqtSignal(str, str)

View File

@ -291,8 +291,9 @@ def data(readonly=False):
"Whether to enable smooth scrolling for webpages."),
('remove-finished-downloads',
SettingValue(typ.Bool(), 'false'),
"Whether to remove finished downloads automatically."),
SettingValue(typ.Int(minval=-1), '-1'),
"Number of milliseconds to wait before removing finished "
"downloads. Will not be removed if value is -1."),
('hide-statusbar',
SettingValue(typ.Bool(), 'false'),