openlp/openlp/core/ui/advancedtab.py

275 lines
16 KiB
Python
Raw Normal View History

2010-07-09 21:32:32 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-12-31 15:54:46 +00:00
# Copyright (c) 2008-2023 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
2010-07-09 21:32:32 +00:00
"""
The :mod:`advancedtab` provides an advanced settings facility.
"""
2012-05-03 18:30:30 +00:00
import logging
from PyQt5 import QtWidgets
2017-10-07 07:05:07 +00:00
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.lib.settingstab import SettingsTab
2018-04-13 18:54:42 +00:00
from openlp.core.ui.icons import UiIcons
2017-10-23 22:09:57 +00:00
from openlp.core.widgets.edits import PathEdit
from openlp.core.widgets.enums import PathEditType
from openlp.core.widgets.widgets import ProxyWidget
2012-05-03 18:30:30 +00:00
2018-10-02 04:39:42 +00:00
2012-05-03 18:30:30 +00:00
log = logging.getLogger(__name__)
2010-07-09 21:32:32 +00:00
2010-07-09 21:32:32 +00:00
class AdvancedTab(SettingsTab):
"""
The :class:`AdvancedTab` manages the advanced settings tab including the UI
and the loading and saving of the displayed settings.
"""
2011-04-13 19:12:47 +00:00
def __init__(self, parent):
2010-07-09 21:32:32 +00:00
"""
Initialise the settings tab
"""
2013-02-01 20:09:47 +00:00
self.data_exists = False
2018-04-17 20:50:27 +00:00
self.icon_path = UiIcons().settings
2012-02-07 10:54:13 +00:00
advanced_translated = translate('OpenLP.AdvancedTab', 'Advanced')
2013-08-31 18:17:38 +00:00
super(AdvancedTab, self).__init__(parent, 'Advanced', advanced_translated)
2010-07-09 21:32:32 +00:00
def setup_ui(self):
2010-07-09 21:32:32 +00:00
"""
Configure the UI elements for the tab.
"""
2013-08-31 18:17:38 +00:00
self.setObjectName('AdvancedTab')
super(AdvancedTab, self).setup_ui()
2012-05-03 18:30:30 +00:00
# Data Directory
2015-11-07 00:49:40 +00:00
self.data_directory_group_box = QtWidgets.QGroupBox(self.left_column)
2013-08-31 18:17:38 +00:00
self.data_directory_group_box.setObjectName('data_directory_group_box')
2015-11-07 00:49:40 +00:00
self.data_directory_layout = QtWidgets.QFormLayout(self.data_directory_group_box)
2013-08-31 18:17:38 +00:00
self.data_directory_layout.setObjectName('data_directory_layout')
2015-11-07 00:49:40 +00:00
self.data_directory_new_label = QtWidgets.QLabel(self.data_directory_group_box)
2013-08-31 18:17:38 +00:00
self.data_directory_new_label.setObjectName('data_directory_current_label')
2017-10-23 22:09:57 +00:00
self.data_directory_path_edit = PathEdit(self.data_directory_group_box, path_type=PathEditType.Directories,
default_path=AppLocation.get_directory(AppLocation.DataDir))
self.data_directory_layout.addRow(self.data_directory_new_label, self.data_directory_path_edit)
2015-11-07 00:49:40 +00:00
self.new_data_directory_has_files_label = QtWidgets.QLabel(self.data_directory_group_box)
2013-08-31 18:17:38 +00:00
self.new_data_directory_has_files_label.setObjectName('new_data_directory_has_files_label')
2013-02-01 20:09:47 +00:00
self.new_data_directory_has_files_label.setWordWrap(True)
2015-11-07 00:49:40 +00:00
self.data_directory_cancel_button = QtWidgets.QToolButton(self.data_directory_group_box)
2013-08-31 18:17:38 +00:00
self.data_directory_cancel_button.setObjectName('data_directory_cancel_button')
2018-04-13 18:54:42 +00:00
self.data_directory_cancel_button.setIcon(UiIcons().delete)
2015-11-07 00:49:40 +00:00
self.data_directory_copy_check_layout = QtWidgets.QHBoxLayout()
2013-08-31 18:17:38 +00:00
self.data_directory_copy_check_layout.setObjectName('data_directory_copy_check_layout')
2015-11-07 00:49:40 +00:00
self.data_directory_copy_check_box = QtWidgets.QCheckBox(self.data_directory_group_box)
2013-08-31 18:17:38 +00:00
self.data_directory_copy_check_box.setObjectName('data_directory_copy_check_box')
2013-02-02 19:49:56 +00:00
self.data_directory_copy_check_layout.addWidget(self.data_directory_copy_check_box)
self.data_directory_copy_check_layout.addStretch()
self.data_directory_copy_check_layout.addWidget(self.data_directory_cancel_button)
self.data_directory_layout.addRow(self.data_directory_copy_check_layout)
2013-02-01 20:09:47 +00:00
self.data_directory_layout.addRow(self.new_data_directory_has_files_label)
2013-03-16 16:59:10 +00:00
self.left_layout.addWidget(self.data_directory_group_box)
# Display Workarounds
self.display_workaround_group_box = QtWidgets.QGroupBox(self.left_column)
2013-08-31 18:17:38 +00:00
self.display_workaround_group_box.setObjectName('display_workaround_group_box')
2015-11-07 00:49:40 +00:00
self.display_workaround_layout = QtWidgets.QVBoxLayout(self.display_workaround_group_box)
2013-08-31 18:17:38 +00:00
self.display_workaround_layout.setObjectName('display_workaround_layout')
self.ignore_aspect_ratio_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
self.ignore_aspect_ratio_check_box.setObjectName('ignore_aspect_ratio_check_box')
self.display_workaround_layout.addWidget(self.ignore_aspect_ratio_check_box)
2015-11-07 00:49:40 +00:00
self.x11_bypass_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
2013-08-31 18:17:38 +00:00
self.x11_bypass_check_box.setObjectName('x11_bypass_check_box')
2013-02-02 07:08:28 +00:00
self.display_workaround_layout.addWidget(self.x11_bypass_check_box)
2015-11-07 00:49:40 +00:00
self.alternate_rows_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
2013-08-31 18:17:38 +00:00
self.alternate_rows_check_box.setObjectName('alternate_rows_check_box')
2013-02-01 22:14:30 +00:00
self.display_workaround_layout.addWidget(self.alternate_rows_check_box)
self.allow_transparent_display_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
self.allow_transparent_display_check_box.setObjectName('allow_transparent_display_check_box')
self.display_workaround_layout.addWidget(self.allow_transparent_display_check_box)
self.left_layout.addWidget(self.display_workaround_group_box)
# Proxies
self.proxy_widget = ProxyWidget(self.right_column)
self.right_layout.addWidget(self.proxy_widget)
2017-09-28 23:28:18 +00:00
# After the last item on each side, add some spacing
self.left_layout.addStretch()
2013-03-16 16:59:10 +00:00
self.right_layout.addStretch()
2017-09-28 23:28:18 +00:00
# Set up all the connections and things
self.alternate_rows_check_box.toggled.connect(self.on_alternate_rows_check_box_toggled)
self.data_directory_path_edit.pathChanged.connect(self.on_data_directory_path_edit_path_changed)
self.data_directory_cancel_button.clicked.connect(self.on_data_directory_cancel_button_clicked)
self.data_directory_copy_check_box.toggled.connect(self.on_data_directory_copy_check_box_toggled)
2010-07-09 21:32:32 +00:00
def retranslate_ui(self):
2010-07-09 21:32:32 +00:00
"""
Setup the interface translation strings.
"""
2014-03-20 19:10:31 +00:00
self.tab_title_visible = UiStrings().Advanced
2013-02-01 20:09:47 +00:00
self.data_directory_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Data Location'))
self.data_directory_new_label.setText(translate('OpenLP.AdvancedTab', 'Path:'))
2013-02-01 20:09:47 +00:00
self.data_directory_cancel_button.setText(translate('OpenLP.AdvancedTab', 'Cancel'))
self.data_directory_cancel_button.setToolTip(
2012-12-29 09:35:24 +00:00
translate('OpenLP.AdvancedTab', 'Cancel OpenLP data directory location change.'))
2013-02-01 20:09:47 +00:00
self.data_directory_copy_check_box.setText(translate('OpenLP.AdvancedTab', 'Copy data to new location.'))
self.data_directory_copy_check_box.setToolTip(translate(
2012-12-29 09:35:24 +00:00
'OpenLP.AdvancedTab', 'Copy the OpenLP data files to the new location.'))
2013-02-01 20:09:47 +00:00
self.new_data_directory_has_files_label.setText(
2012-12-29 09:35:24 +00:00
translate('OpenLP.AdvancedTab', '<strong>WARNING:</strong> New data directory location contains '
2013-12-24 08:56:50 +00:00
'OpenLP data files. These files WILL be replaced during a copy.'))
2013-02-01 22:14:30 +00:00
self.display_workaround_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Display Workarounds'))
self.ignore_aspect_ratio_check_box.setText(translate('OpenLP.AdvancedTab', 'Ignore Aspect Ratio'))
2014-03-20 19:10:31 +00:00
self.x11_bypass_check_box.setText(translate('OpenLP.AdvancedTab', 'Bypass X11 Window Manager'))
2013-02-01 22:14:30 +00:00
self.alternate_rows_check_box.setText(translate('OpenLP.AdvancedTab', 'Use alternating row colours in lists'))
self.allow_transparent_display_check_box.setText(
translate('OpenLP.AdvancedTab', 'Disable display transparency'))
self.proxy_widget.retranslate_ui()
2010-07-09 21:32:32 +00:00
def load(self):
"""
Load settings from disk.
2010-07-09 21:32:32 +00:00
"""
2020-06-06 16:05:36 +00:00
self.ignore_aspect_ratio_check_box.setChecked(self.settings.value('advanced/ignore aspect ratio'))
self.x11_bypass_check_box.setChecked(self.settings.value('advanced/x11 bypass wm'))
2013-02-01 22:14:30 +00:00
# Prevent the dialog displayed by the alternate_rows_check_box to display.
self.alternate_rows_check_box.blockSignals(True)
2020-06-06 16:05:36 +00:00
self.alternate_rows_check_box.setChecked(self.settings.value('advanced/alternate rows'))
2013-02-01 22:14:30 +00:00
self.alternate_rows_check_box.blockSignals(False)
2020-06-06 16:05:36 +00:00
self.allow_transparent_display_check_box.setChecked(self.settings.value('advanced/disable transparent display'))
2013-02-01 20:09:47 +00:00
self.data_directory_copy_check_box.hide()
self.new_data_directory_has_files_label.hide()
self.data_directory_cancel_button.hide()
# Since data location can be changed, make sure the path is present.
self.data_directory_path_edit.path = AppLocation.get_data_path()
# Don't allow data directory move if running portable.
if self.settings.value('advanced/is portable'):
2013-02-01 20:09:47 +00:00
self.data_directory_group_box.hide()
2010-07-09 21:32:32 +00:00
def save(self):
"""
Save settings to disk.
2010-07-09 21:32:32 +00:00
"""
2020-06-06 16:05:36 +00:00
self.settings.setValue('advanced/disable transparent display',
self.allow_transparent_display_check_box.isChecked())
self.settings.setValue('advanced/ignore aspect ratio', self.ignore_aspect_ratio_check_box.isChecked())
if self.x11_bypass_check_box.isChecked() != self.settings.value('advanced/x11 bypass wm'):
self.settings.setValue('advanced/x11 bypass wm', self.x11_bypass_check_box.isChecked())
2013-08-31 18:17:38 +00:00
self.settings_form.register_post_process('config_screen_changed')
self.settings.setValue('advanced/alternate rows', self.alternate_rows_check_box.isChecked())
self.proxy_widget.save()
2010-07-09 21:32:32 +00:00
def cancel(self):
2013-02-01 19:58:18 +00:00
"""
Dialogue was cancelled, remove any pending data path change.
"""
2013-02-01 20:09:47 +00:00
self.on_data_directory_cancel_button_clicked()
2012-06-09 12:03:47 +00:00
SettingsTab.cancel(self)
2017-09-24 08:39:54 +00:00
def on_data_directory_path_edit_path_changed(self, new_path):
"""
2017-09-24 08:39:54 +00:00
Handle the `editPathChanged` signal of the data_directory_path_edit
2017-09-24 19:33:07 +00:00
:param pathlib.Path new_path: The new path
2017-09-24 08:39:54 +00:00
:rtype: None
"""
2021-04-03 15:56:47 +00:00
# Check if data already exists here.
self.check_data_overwrite(new_path)
# Make sure they want to change the data.
2021-04-03 15:56:47 +00:00
if self.data_directory_copy_check_box.isChecked():
warning_string = translate('OpenLP.AdvancedTab', 'Are you sure you want to change the '
'location of the OpenLP data directory to:\n\n{path}'
'\n\nExisting files in this directory could be '
'overwritten. The data directory will be changed when '
'OpenLP is closed.').format(path=new_path)
else:
warning_string = translate('OpenLP.AdvancedTab', 'Are you sure you want to change the '
'location of the OpenLP data directory to:\n\n{path}'
'\n\nThe data directory will be changed when OpenLP is '
'closed.').format(path=new_path)
2015-11-07 00:49:40 +00:00
answer = QtWidgets.QMessageBox.question(self, translate('OpenLP.AdvancedTab', 'Confirm Data Directory Change'),
2021-04-03 15:56:47 +00:00
warning_string, defaultButton=QtWidgets.QMessageBox.No)
2015-11-07 00:49:40 +00:00
if answer != QtWidgets.QMessageBox.Yes:
self.data_directory_path_edit.path = AppLocation.get_data_path()
2021-04-03 15:56:47 +00:00
self.new_data_directory_has_files_label.hide()
return
# Save the new location.
2017-09-24 20:26:39 +00:00
self.main_window.new_data_path = new_path
2013-02-01 20:09:47 +00:00
self.data_directory_cancel_button.show()
2013-02-01 20:09:47 +00:00
def on_data_directory_copy_check_box_toggled(self):
2013-02-01 19:58:18 +00:00
"""
Copy existing data when you change your data directory.
"""
2013-02-07 08:42:17 +00:00
self.main_window.set_copy_data(self.data_directory_copy_check_box.isChecked())
2013-02-01 20:09:47 +00:00
if self.data_exists:
if self.data_directory_copy_check_box.isChecked():
self.new_data_directory_has_files_label.show()
2012-05-03 18:30:30 +00:00
else:
2013-02-01 20:09:47 +00:00
self.new_data_directory_has_files_label.hide()
2014-03-20 19:10:31 +00:00
def check_data_overwrite(self, data_path):
2013-02-01 19:58:18 +00:00
"""
Check if there's already data in the target directory.
2017-09-24 19:33:07 +00:00
:param pathlib.Path data_path: The target directory to check
2013-02-01 19:58:18 +00:00
"""
2017-09-24 08:39:54 +00:00
if (data_path / 'songs').exists():
2013-02-01 20:09:47 +00:00
self.data_exists = True
2012-05-03 18:30:30 +00:00
# Check is they want to replace existing data.
2015-11-07 00:49:40 +00:00
answer = QtWidgets.QMessageBox.warning(self,
translate('OpenLP.AdvancedTab', 'Overwrite Existing Data'),
translate('OpenLP.AdvancedTab',
2016-05-20 16:22:06 +00:00
'WARNING: \n\nThe location you have selected \n\n{path}'
'\n\nappears to contain OpenLP data files. Do you wish to '
'replace these files with the current data '
2021-04-03 15:56:47 +00:00
'files?').format(path=data_path),
2015-11-07 00:49:40 +00:00
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes |
QtWidgets.QMessageBox.No),
QtWidgets.QMessageBox.No)
self.data_directory_copy_check_box.show()
2015-11-07 00:49:40 +00:00
if answer == QtWidgets.QMessageBox.Yes:
2013-02-01 20:09:47 +00:00
self.data_directory_copy_check_box.setChecked(True)
self.new_data_directory_has_files_label.show()
else:
2013-02-01 20:09:47 +00:00
self.data_directory_copy_check_box.setChecked(False)
self.new_data_directory_has_files_label.hide()
else:
2013-02-01 20:09:47 +00:00
self.data_exists = False
self.data_directory_copy_check_box.setChecked(True)
self.new_data_directory_has_files_label.hide()
2012-10-03 16:38:06 +00:00
2013-02-01 20:09:47 +00:00
def on_data_directory_cancel_button_clicked(self):
"""
Cancel the data directory location change
"""
self.data_directory_path_edit.path = AppLocation.get_data_path()
2013-02-01 20:09:47 +00:00
self.data_directory_copy_check_box.setChecked(False)
2017-09-24 20:26:39 +00:00
self.main_window.new_data_path = None
2013-02-07 08:42:17 +00:00
self.main_window.set_copy_data(False)
2013-02-01 20:09:47 +00:00
self.data_directory_copy_check_box.hide()
self.data_directory_cancel_button.hide()
self.new_data_directory_has_files_label.hide()
2013-02-01 22:14:30 +00:00
def on_alternate_rows_check_box_toggled(self, checked):
2012-12-10 23:35:53 +00:00
"""
Notify user about required restart.
2014-03-17 19:05:55 +00:00
:param checked: The state of the check box (boolean).
2012-12-10 23:35:53 +00:00
"""
2015-11-07 00:49:40 +00:00
QtWidgets.QMessageBox.information(self, translate('OpenLP.AdvancedTab', 'Restart Required'),
translate('OpenLP.AdvancedTab',
'This change will only take effect once OpenLP '
'has been restarted.'))