diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index e953da011..a92c6583c 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -96,9 +96,21 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog, RegistryProperties): Process the form saving the settings """ log.debug('Processing settings exit') - for tabIndex in range(self.stacked_layout.count()): - self.stacked_layout.widget(tabIndex).save() - # if the display of image background are changing we need to regenerate the image cache + # We add all the forms into the stacked layout, even if the plugin is inactive, + # but we don't add the item to the list on the side if the plugin is inactive, + # so loop through the list items, and then find the tab for that item. + for item_index in range(self.setting_list_widget.count()): + # Get the list item + list_item = self.setting_list_widget.item(item_index) + if not list_item: + continue + # Now figure out if there's a tab for it, and save the tab. + plugin_name = list_item.data(QtCore.Qt.UserRole) + for tab_index in range(self.stacked_layout.count()): + tab_widget = self.stacked_layout.widget(tab_index) + if tab_widget.tab_title == plugin_name: + tab_widget.save() + # if the image background has been changed we need to regenerate the image cache if 'images_config_updated' in self.processes or 'config_screen_changed' in self.processes: self.register_post_process('images_regenerate') # Now lets process all the post save handlers diff --git a/tests/functional/openlp_core_ui/test_settingsform.py b/tests/functional/openlp_core_ui/test_settingsform.py index 5d9b413df..bc9d0621f 100644 --- a/tests/functional/openlp_core_ui/test_settingsform.py +++ b/tests/functional/openlp_core_ui/test_settingsform.py @@ -29,6 +29,7 @@ """ Package to test the openlp.core.ui.settingsform package. """ +from PyQt4 import QtGui from unittest import TestCase from openlp.core.common import Registry @@ -83,3 +84,31 @@ class TestSettingsForm(TestCase): # THEN: Stuff should happen mocked_add_widget.assert_called_with(general_tab) self.assertEqual(0, mocked_add_item.call_count, 'addItem should not have been called') + + def accept_with_inactive_plugins_test(self): + """ + Test that the accept() method works correctly when some of the plugins are inactive + """ + # GIVEN: A visible general tab and an invisible theme tab in a Settings Form + settings_form = SettingsForm(None) + general_tab = QtGui.QWidget(None) + general_tab.tab_title = 'mock-general' + general_tab.tab_title_visible = 'Mock General' + general_tab.icon_path = ':/icon/openlp-logo-16x16.png' + mocked_general_save = MagicMock() + general_tab.save = mocked_general_save + settings_form.insert_tab(general_tab, is_visible=True) + themes_tab = QtGui.QWidget(None) + themes_tab.tab_title = 'mock-themes' + themes_tab.tab_title_visible = 'Mock Themes' + themes_tab.icon_path = ':/icon/openlp-logo-16x16.png' + mocked_theme_save = MagicMock() + themes_tab.save = mocked_theme_save + settings_form.insert_tab(themes_tab, is_visible=False) + + # WHEN: The accept() method is called + settings_form.accept() + + # THEN: The general tab's save() method should have been called, but not the themes tab + mocked_general_save.assert_called_with() + self.assertEqual(0, mocked_theme_save.call_count, 'The Themes tab\'s save() should not have been called')