Added checkbox for to disable default service name, just as suggested.

This commit is contained in:
Mattias Põldaru 2012-01-25 11:32:20 +02:00
parent 62a5578528
commit 8c483a58b3
2 changed files with 56 additions and 30 deletions

View File

@ -103,7 +103,11 @@ class AdvancedTab(SettingsTab):
self.defaultServiceGroupBox.setObjectName(u'defaultServiceGroupBox')
self.defaultServiceLayout = QtGui.QFormLayout(
self.defaultServiceGroupBox)
self.defaultServiceCheckBox = QtGui.QCheckBox(
self.defaultServiceGroupBox)
self.defaultServiceCheckBox.setObjectName(u'defaultServiceCheckBox')
self.defaultServiceLayout.setObjectName(u'defaultServiceLayout')
self.defaultServiceLayout.addRow(self.defaultServiceCheckBox)
self.defaultServiceTimeLabel = QtGui.QLabel(self.defaultServiceGroupBox)
self.defaultServiceTimeLabel.setObjectName(u'defaultServiceTimeLabel')
self.defaultServiceDay = QtGui.QComboBox(
@ -200,6 +204,8 @@ class AdvancedTab(SettingsTab):
self.rightLayout.addWidget(self.x11GroupBox)
self.rightLayout.addStretch()
QtCore.QObject.connect(self.defaultServiceCheckBox,
QtCore.SIGNAL(u'toggled(bool)'), self.defaultServiceCheckBoxToggled)
QtCore.QObject.connect(self.defaultServiceDay,
QtCore.SIGNAL(u'currentIndexChanged(int)'),
self.onDefaultServiceDayChanged)
@ -243,6 +249,9 @@ class AdvancedTab(SettingsTab):
'Enable application exit confirmation'))
self.defaultServiceGroupBox.setTitle(
translate('OpenLP.AdvancedTab', 'Default Service Name'))
self.defaultServiceCheckBox.setText(
translate('OpenLP.AdvancedTab',
'Save As dialog has prefilled service name'))
self.defaultServiceTimeLabel.setText(
translate('OpenLP.AdvancedTab', 'Date and Time:'))
self.defaultServiceDay.setItemText(0,
@ -272,9 +281,8 @@ class AdvancedTab(SettingsTab):
self.defaultServiceExampleLabel.setText(translate('OpenLP.AdvancedTab',
'Example:'))
self.defaultServiceNote.setText(
translate('OpenLP.AdvancedTab', 'Note: Leave Name field blank to '
'have no prefilled name in Save As dialog. '
'Consult manual for special symbols usage.'))
translate('OpenLP.AdvancedTab', 'Note: '
'Consult OpenLP manual for special symbols usage.'))
self.hideMouseGroupBox.setTitle(translate('OpenLP.AdvancedTab',
'Mouse Cursor'))
self.hideMouseCheckBox.setText(translate('OpenLP.AdvancedTab',
@ -326,6 +334,9 @@ class AdvancedTab(SettingsTab):
QtCore.QVariant(True)).toBool())
self.hideMouseCheckBox.setChecked(
settings.value(u'hide mouse', QtCore.QVariant(False)).toBool())
default_service_enabled = settings.value(u'default service enabled',
QtCore.QVariant(True)).toBool()
self.defaultServiceCheckBox.setChecked(default_service_enabled)
self.service_day, ok = settings.value(u'default service day',
QtCore.QVariant(self.default_service_day)).toInt()
self.service_hour, ok = settings.value(u'default service hour',
@ -338,6 +349,7 @@ class AdvancedTab(SettingsTab):
self.defaultServiceTime.setTime(
QtCore.QTime(self.service_hour, self.service_minute))
self.defaultServiceName.setText(self.service_name)
self.defaultServiceCheckBoxToggled(default_service_enabled)
self.x11BypassCheckBox.setChecked(
settings.value(u'x11 bypass wm', QtCore.QVariant(True)).toBool())
self.default_color = settings.value(u'default color',
@ -359,6 +371,8 @@ class AdvancedTab(SettingsTab):
self.defaultServiceName.setText(self.service_name)
settings = QtCore.QSettings()
settings.beginGroup(self.settingsSection)
settings.setValue(u'default service enabled',
self.defaultServiceCheckBox.isChecked())
if self.service_name == self.default_service_name:
settings.remove(u'default service name')
else:
@ -392,6 +406,13 @@ class AdvancedTab(SettingsTab):
Receiver.send_message(u'config_screen_changed')
self.display_changed = False
def defaultServiceCheckBoxToggled(self, default_service_enabled):
self.defaultServiceDay.setEnabled(default_service_enabled)
time_enabled = default_service_enabled and self.service_day is not 7
self.defaultServiceTime.setEnabled(time_enabled)
self.defaultServiceName.setEnabled(default_service_enabled)
self.defaultServiceRevertButton.setEnabled(default_service_enabled)
def generate_service_name_example(self):
preset_is_valid = True
if self.service_day == 7:
@ -418,7 +439,7 @@ class AdvancedTab(SettingsTab):
def onDefaultServiceDayChanged(self, index):
self.service_day = index
self.defaultServiceTime.setReadOnly(self.service_day == 7)
self.defaultServiceTime.setEnabled(self.service_day is not 7)
self.updateServiceNameExample()
def onDefaultServiceTimeChanged(self, time):

View File

@ -613,33 +613,38 @@ class ServiceManager(QtGui.QWidget):
Get a file name and then call :func:`ServiceManager.saveFile` to
save the file.
"""
service_day, ok = QtCore.QSettings().value(
u'advanced/default service day', 7).toInt()
if service_day == 7:
time = datetime.now()
default_service_enabled = QtCore.QSettings().value(
u'advanced/default service enabled', QtCore.QVariant(True)).toBool()
if default_service_enabled:
service_day, ok = QtCore.QSettings().value(
u'advanced/default service day', 7).toInt()
if service_day == 7:
time = datetime.now()
else:
service_hour, ok = QtCore.QSettings().value(
u'advanced/default service hour', 11).toInt()
service_minute, ok = QtCore.QSettings().value(
u'advanced/default service minute', 0).toInt()
now = datetime.now()
day_delta = service_day - now.weekday()
if day_delta < 0:
day_delta += 7
time = now + timedelta(days=day_delta)
time = time.replace(hour=service_hour, minute=service_minute)
default_pattern = unicode(QtCore.QSettings().value(
u'advanced/default service name',
translate('OpenLP.AdvancedTab',
'Service %Y-%m-%d %H-%M',
'This is the default default service name template, which can '
'be found in Advanced tab under Tools, Settings. Please do not '
'include any of the following characters: /\\?*|<>\[\]":+\n'
'You can use any of the directives as shown on page '
'http://docs.python.org/library/datetime.html'
'#strftime-strptime-behavior , but if possible, please keep '
'the resulting string sortable by name.')).toString())
default_filename = time.strftime(default_pattern)
else:
service_hour, ok = QtCore.QSettings().value(
u'advanced/default service hour', 11).toInt()
service_minute, ok = QtCore.QSettings().value(
u'advanced/default service minute', 0).toInt()
now = datetime.now()
day_delta = service_day - now.weekday()
if day_delta < 0:
day_delta += 7
time = now + timedelta(days=day_delta)
time = time.replace(hour = service_hour, minute = service_minute)
default_pattern = unicode(QtCore.QSettings().value(
u'advanced/default service name',
translate('OpenLP.AdvancedTab',
'Service %Y-%m-%d %H-%M',
'This is the default default service name template, which can be '
'found in Advanced tab under Tools, Settings. Please do not '
'include any of the following characters: /\\?*|<>\[\]":+\n'
'You can use any of the directives as shown on page '
'http://docs.python.org/library/datetime.html'
'#strftime-strptime-behavior , but if possible, please keep '
'the resulting string sortable by name.')).toString())
default_filename = time.strftime(default_pattern)
default_filename = u''
directory = unicode(SettingsManager.get_last_dir(
self.mainwindow.servicemanagerSettingsSection))
path = os.path.join(directory, default_filename)