From cdc1234ebb3dce76c4a7963c8db511f20dae72b3 Mon Sep 17 00:00:00 2001 From: robbiejackson Date: Wed, 18 Aug 2021 18:59:29 +0100 Subject: [PATCH] code and settings test done --- openlp/core/common/settings.py | 1 + openlp/core/ui/generaltab.py | 9 ++++++++- openlp/core/ui/servicemanager.py | 12 ++++++++++++ tests/openlp_core/ui/test_generaltab.py | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/openlp/core/common/settings.py b/openlp/core/common/settings.py index f8d8c2188..31193c851 100644 --- a/openlp/core/common/settings.py +++ b/openlp/core/common/settings.py @@ -156,6 +156,7 @@ class Settings(QtCore.QSettings): 'advanced/ignore aspect ratio': False, 'advanced/is portable': False, 'advanced/max recent files': 20, + 'advanced/new service message': True, 'advanced/print file meta data': False, 'advanced/print notes': False, 'advanced/print slide text': False, diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index 39b9bb5bf..49bb989c7 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -33,7 +33,6 @@ from openlp.core.ui.style import HAS_DARK_STYLE from openlp.core.widgets.buttons import ColorButton from openlp.core.widgets.edits import PathEdit - log = logging.getLogger(__name__) @@ -41,6 +40,7 @@ class GeneralTab(SettingsTab): """ GeneralTab is the general settings tab in the settings dialog. """ + def __init__(self, parent): """ Initialise the general settings tab @@ -166,6 +166,9 @@ class GeneralTab(SettingsTab): self.enable_auto_close_check_box = QtWidgets.QCheckBox(self.ui_group_box) self.enable_auto_close_check_box.setObjectName('enable_auto_close_check_box') self.ui_layout.addRow(self.enable_auto_close_check_box) + self.new_service_message_check_box = QtWidgets.QCheckBox(self.ui_group_box) + self.new_service_message_check_box.setObjectName('new_service_message_check_box') + self.ui_layout.addRow(self.new_service_message_check_box) if not is_win() and HAS_DARK_STYLE: self.use_dark_style_checkbox = QtWidgets.QCheckBox(self.ui_group_box) self.use_dark_style_checkbox.setObjectName('use_dark_style_checkbox') @@ -245,6 +248,8 @@ class GeneralTab(SettingsTab): self.enable_auto_close_check_box.setText(translate('OpenLP.AdvancedTab', 'Enable application exit confirmation')) self.slide_no_in_footer_checkbox.setText(translate('SongsPlugin.GeneralTab', 'Include slide number in footer')) + self.new_service_message_check_box.setText(translate('OpenLP.AdvancedTab', + 'Alert if New clicked on blank service')) self.search_as_type_check_box.setText(translate('SongsPlugin.GeneralTab', 'Enable search as you type')) if not is_win() and HAS_DARK_STYLE: self.use_dark_style_checkbox.setText(translate('OpenLP.AdvancedTab', 'Use dark style (needs restart)')) @@ -285,6 +290,7 @@ class GeneralTab(SettingsTab): self.autoscroll_combo_box.setCurrentIndex(i) self.enable_auto_close_check_box.setChecked(self.settings.value('advanced/enable exit confirmation')) self.slide_no_in_footer_checkbox.setChecked(self.settings.value('advanced/slide numbers in footer')) + self.new_service_message_check_box.setChecked(self.settings.value('advanced/new service message')) if not is_win() and HAS_DARK_STYLE: self.use_dark_style_checkbox.setChecked(self.settings.value('advanced/use_dark_style')) self.hide_mouse_check_box.setChecked(self.settings.value('advanced/hide mouse')) @@ -317,6 +323,7 @@ class GeneralTab(SettingsTab): self.settings.setValue('advanced/autoscrolling', self.autoscroll_map[self.autoscroll_combo_box.currentIndex()]) self.settings.setValue('advanced/slide numbers in footer', self.slide_no_in_footer_checkbox.isChecked()) self.settings.setValue('advanced/enable exit confirmation', self.enable_auto_close_check_box.isChecked()) + self.settings.setValue('advanced/new service message', self.new_service_message_check_box.isChecked()) self.settings.setValue('advanced/hide mouse', self.hide_mouse_check_box.isChecked()) self.settings.setValue('advanced/search as type', self.is_search_as_you_type_enabled) if not is_win() and HAS_DARK_STYLE: diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 70181116b..c68ef63c4 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -442,6 +442,18 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi elif result == QtWidgets.QMessageBox.Save: if not self.decide_save_method(): return False + if not self.service_items and self.settings.value('advanced/new service message'): + do_not_show_again = QtWidgets.QCheckBox(translate('OpenLP.Ui', 'Do not show this message again'), None) + message_box = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Information, + translate('OpenLP.Ui', 'Create a new service.'), + translate('OpenLP.Ui', 'You already have a blank new service.\n' + 'Add some items to it then press Save'), + QtWidgets.QMessageBox.Ok, + self) + message_box.setCheckBox(do_not_show_again) + message_box.exec() + if message_box.checkBox().isChecked(): + self.settings.setValue('advanced/new service message', False) self.new_file() def on_load_service_clicked(self, checked): diff --git a/tests/openlp_core/ui/test_generaltab.py b/tests/openlp_core/ui/test_generaltab.py index deb3ce1c1..edff9ff7d 100644 --- a/tests/openlp_core/ui/test_generaltab.py +++ b/tests/openlp_core/ui/test_generaltab.py @@ -74,3 +74,21 @@ def test_slide_numbers_in_footer(settings): # THEN: the settings should be updated assert settings.value('advanced/slide numbers in footer') is True + + +def test_new_service_message(settings): + """ + Test that when the new service message option is changed then the settings are updated + """ + # GIVEN: Settings, a settings form and a general tab + settings.setValue('advanced/new service message', True) + settings_form = SettingsForm(None) + general_tab = GeneralTab(settings_form) + settings_form.insert_tab(general_tab, is_visible=True) + + # WHEN: I click the checkbox and then save + QtTest.QTest.mouseClick(general_tab.new_service_message_check_box, QtCore.Qt.LeftButton) + settings_form.accept() + + # THEN: the settings should be updated + assert settings.value('advanced/new service message') is False