diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index b2d8f6ea7..c136f00aa 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -30,6 +30,7 @@ Provide HTML Tag management and Formatting Tag access class """ import cPickle +import json from openlp.core.lib import Settings, translate @@ -66,7 +67,8 @@ class FormattingTags(object): if isinstance(tag[element], unicode): tag[element] = tag[element].encode('utf8') # Formatting Tags were also known as display tags. - Settings().setValue(u'displayTags/html_tags', cPickle.dumps(tags) if tags else u'') + Settings().setValue(u'displayTags/html_tags', json.dumps(tags) if tags else u'') + Settings().setValue(u'displayTags/html_tags_json', True) @staticmethod def load_tags(): @@ -159,10 +161,14 @@ class FormattingTags(object): # Formatting Tags were also known as display tags. user_expands = Settings().value(u'displayTags/html_tags') + user_format_json = Settings().value(u'displayTags/html_tags_json') # cPickle only accepts str not unicode strings user_expands_string = str(user_expands) if user_expands_string: - user_tags = cPickle.loads(user_expands_string) + if user_format_json: + user_tags = json.loads(user_expands_string) + else: + user_tags = cPickle.loads(user_expands_string) for tag in user_tags: for element in tag: if isinstance(tag[element], str): diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index 5e73ffc1d..427c24c58 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -116,6 +116,7 @@ class Settings(QtCore.QSettings): u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT, u'crashreport/last directory': u'', u'displayTags/html_tags': u'', + u'displayTags/html_tags_json': False, u'core/audio repeat list': False, u'core/auto open': False, u'core/auto preview': False, diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index 26d87f466..326dde5c8 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -33,11 +33,11 @@ class TestFormattingTags(TestCase): """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ - patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + patch(u'openlp.core.lib.formattingtags.json') as mocked_json: # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate mocked_settings.value.return_value = u'' - mocked_cPickle.load.return_value = [] + mocked_json.load.return_value = [] # WHEN: Get the display tags. FormattingTags.load_tags() @@ -54,11 +54,11 @@ class TestFormattingTags(TestCase): """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ - patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + patch(u'openlp.core.lib.formattingtags.json') as mocked_json: # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate mocked_settings.value.return_value = u'' - mocked_cPickle.loads.side_effect = [[], [TAG]] + mocked_json.loads.side_effect = [[], [TAG]] # WHEN: Get the display tags. FormattingTags.load_tags()