Add a YamlConfig._migrate_bool helper

This commit is contained in:
Florian Bruhin 2018-06-09 19:57:11 +02:00
parent 7949335a2b
commit b0325e17b7

View File

@ -233,6 +233,14 @@ class YamlConfig(QObject):
if errors:
raise configexc.ConfigFileErrors('autoconfig.yml', errors)
def _migrate_bool(self, settings, name, true_value, false_value):
"""Migrate a boolean in the settings."""
if name in settings:
for scope, val in settings[name].items():
if isinstance(val, bool):
settings[name][scope] = true_value if val else false_value
self._mark_changed()
def _handle_migrations(self, settings):
"""Migrate older configs to the newest format."""
# Simple renamed/deleted options
@ -268,23 +276,9 @@ class YamlConfig(QObject):
del settings['bindings.default']
self._mark_changed()
# Option to show favicons only for pinned tabs changed the type of
# tabs.favicons.show from Bool to String
name = 'tabs.favicons.show'
if name in settings:
for scope, val in settings[name].items():
if isinstance(val, bool):
settings[name][scope] = 'always' if val else 'never'
self._mark_changed()
# qt.force_software_rendering isn't a boolean anymore
name = 'qt.force_software_rendering'
if name in settings:
for scope, val in settings[name].items():
if isinstance(val, bool):
settings[name][scope] = ('software-opengl' if val
else 'none')
self._mark_changed()
self._migrate_bool(settings, 'tabs.favicons.show', 'always', 'never')
self._migrate_bool(settings, 'qt.force_software_rendering',
'software-opengl', 'none')
return settings