Fix 1416703

This commit is contained in:
Phill Ridout 2015-02-12 20:44:34 +00:00
parent cfa8e4f2df
commit f6de8a4f7a
2 changed files with 20 additions and 2 deletions

View File

@ -45,6 +45,13 @@ if is_linux():
X11_BYPASS_DEFAULT = False
def recent_files_conv(value):
if isinstance(value, list):
return value
elif isinstance(value, str):
return [value]
class Settings(QtCore.QSettings):
"""
Class to wrap QSettings.
@ -328,7 +335,7 @@ class Settings(QtCore.QSettings):
('general/language', 'core/language', []),
('general/last version test', 'core/last version test', []),
('general/loop delay', 'core/loop delay', []),
('general/recent files', 'core/recent files', []),
('general/recent files', 'core/recent files', [(recent_files_conv, None)]),
('general/save prompt', 'core/save prompt', []),
('general/screen blank', 'core/screen blank', []),
('general/show splash', 'core/show splash', []),
@ -410,7 +417,9 @@ class Settings(QtCore.QSettings):
for new, old in rules:
# If the value matches with the condition (rule), then use the provided value. This is used to
# convert values. E. g. an old value 1 results in True, and 0 in False.
if old == old_value:
if callable(new):
old_value = new(old_value)
elif old == old_value:
old_value = new
break
self.setValue(new_key, old_value)

View File

@ -25,6 +25,7 @@ Package to test the openlp.core.lib.settings package.
from unittest import TestCase
from openlp.core.common import Settings
from tests.functional import patch
from tests.helpers.testmixin import TestMixin
@ -120,3 +121,11 @@ class TestSettings(TestCase, TestMixin):
# THEN: An exception with the non-existing key should be thrown
self.assertEqual(str(cm.exception), "'core/does not exists'", 'We should get an exception')
def extend_default_settings_test(self):
with patch.dict(Settings() .__default_settings__, {1: 2, 3: 4}, clear=True):
Settings().extend_default_settings({'a': 'b', 'c': 'd'})
ds = Settings().__default_settings__
self.assertDictEqual(ds, {1: 2, 3: 4, 'a': 'b', 'c': 'd'})