← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~mahfiaz/openlp/bug-904438 into lp:openlp

 

mahfiaz has proposed merging lp:~mahfiaz/openlp/bug-904438 into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)
  Tim Bentley (trb143)
  Andreas Preikschat (googol)
Related bugs:
  Bug #904438 in OpenLP: "Prefilled default service name in save dialog"
  https://bugs.launchpad.net/openlp/+bug/904438

For more details, see:
https://code.launchpad.net/~mahfiaz/openlp/bug-904438/+merge/90629

Have a default name for service Save as dialog always filled in.
-- 
https://code.launchpad.net/~mahfiaz/openlp/bug-904438/+merge/90629
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/ui/advancedtab.py'
--- openlp/core/ui/advancedtab.py	2012-01-07 11:22:53 +0000
+++ openlp/core/ui/advancedtab.py	2012-01-29 23:19:27 +0000
@@ -27,6 +27,8 @@
 """
 The :mod:`advancedtab` provides an advanced settings facility.
 """
+from datetime import datetime, timedelta
+
 from PyQt4 import QtCore, QtGui
 
 from openlp.core.lib import SettingsTab, translate, build_icon,  Receiver
@@ -44,6 +46,20 @@
         """
         self.display_changed = False
         advancedTranslated = translate('OpenLP.AdvancedTab', 'Advanced')
+        # 7 stands for now, 0 to 6 is Monday to Sunday.
+        self.default_service_day = 7
+        # 11 o'clock is the most popular time for morning service.
+        self.default_service_hour = 11
+        self.default_service_minute = 0
+        self.default_service_name = unicode(translate('OpenLP.AdvancedTab',
+            'Service %Y-%m-%d %H-%M',
+            'This is the default default service name template, which can be '
+            'found under Advanced in Settings, Configure OpenLP. 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.'))
         self.default_image = u':/graphics/openlp-splash-screen.png'
         self.default_color = u'#ffffff'
         self.icon_path = u':/system/system_settings.png'
@@ -84,6 +100,58 @@
             u'enableAutoCloseCheckBox')
         self.uiLayout.addRow(self.enableAutoCloseCheckBox)
         self.leftLayout.addWidget(self.uiGroupBox)
+        self.defaultServiceGroupBox = QtGui.QGroupBox(self.leftColumn)
+        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(
+            self.defaultServiceGroupBox)
+        self.defaultServiceDay.addItems(
+            [u'', u'', u'', u'', u'', u'', u'', u''])
+        self.defaultServiceDay.setObjectName(
+            u'defaultServiceDay')
+        self.defaultServiceTime = QtGui.QTimeEdit(self.defaultServiceGroupBox)
+        self.defaultServiceTime.setObjectName(u'defaultServiceTime')
+        self.defaultServiceTimeHBox = QtGui.QHBoxLayout()
+        self.defaultServiceTimeHBox.setObjectName(u'defaultServiceTimeHBox')
+        self.defaultServiceTimeHBox.addWidget(self.defaultServiceDay)
+        self.defaultServiceTimeHBox.addWidget(self.defaultServiceTime)
+        self.defaultServiceLayout.addRow(self.defaultServiceTimeLabel,
+            self.defaultServiceTimeHBox)
+        self.defaultServiceLabel = QtGui.QLabel(self.defaultServiceGroupBox)
+        self.defaultServiceLabel.setObjectName(u'defaultServiceLabel')
+        self.defaultServiceName = QtGui.QLineEdit(self.defaultServiceGroupBox)
+        self.defaultServiceName.setObjectName(u'defaultServiceName')
+        self.defaultServiceName.setValidator(QtGui.QRegExpValidator(
+            QtCore.QRegExp(r'[^/\\?*|<>\[\]":+]+'), self))
+        self.defaultServiceRevertButton = QtGui.QToolButton(
+            self.defaultServiceGroupBox)
+        self.defaultServiceRevertButton.setObjectName(
+            u'defaultServiceRevertButton')
+        self.defaultServiceRevertButton.setIcon(
+            build_icon(u':/general/general_revert.png'))
+        self.defaultServiceHBox = QtGui.QHBoxLayout()
+        self.defaultServiceHBox.setObjectName(u'defaultServiceHBox')
+        self.defaultServiceHBox.addWidget(self.defaultServiceName)
+        self.defaultServiceHBox.addWidget(self.defaultServiceRevertButton)
+        self.defaultServiceLayout.addRow(self.defaultServiceLabel,
+            self.defaultServiceHBox)
+        self.defaultServiceExampleLabel = QtGui.QLabel(
+            self.defaultServiceGroupBox)
+        self.defaultServiceExampleLabel.setObjectName(
+            u'defaultServiceExampleLabel')
+        self.defaultServiceExample = QtGui.QLabel(self.defaultServiceGroupBox)
+        self.defaultServiceExample.setObjectName(u'defaultServiceExample')
+        self.defaultServiceLayout.addRow(self.defaultServiceExampleLabel,
+            self.defaultServiceExample)
+        self.leftLayout.addWidget(self.defaultServiceGroupBox)
         self.leftLayout.addStretch()
         self.defaultImageGroupBox = QtGui.QGroupBox(self.rightColumn)
         self.defaultImageGroupBox.setObjectName(u'defaultImageGroupBox')
@@ -133,6 +201,21 @@
         self.rightLayout.addWidget(self.x11GroupBox)
         self.rightLayout.addStretch()
 
+        self.updateDefaultServiceExample = False
+        QtCore.QObject.connect(self.defaultServiceCheckBox,
+            QtCore.SIGNAL(u'toggled(bool)'), self.defaultServiceCheckBoxToggled)
+        QtCore.QObject.connect(self.defaultServiceDay,
+            QtCore.SIGNAL(u'currentIndexChanged(int)'),
+            self.onDefaultServiceDayChanged)
+        QtCore.QObject.connect(self.defaultServiceTime,
+            QtCore.SIGNAL(u'timeChanged(QTime)'),
+            self.updateServiceNameExample)
+        QtCore.QObject.connect(self.defaultServiceName,
+            QtCore.SIGNAL(u'textChanged(QString)'),
+            self.updateServiceNameExample)
+        QtCore.QObject.connect(self.defaultServiceRevertButton,
+            QtCore.SIGNAL(u'pressed()'),
+            self.onDefaultServiceRevertButtonPressed)
         QtCore.QObject.connect(self.defaultColorButton,
             QtCore.SIGNAL(u'pressed()'), self.onDefaultColorButtonPressed)
         QtCore.QObject.connect(self.defaultBrowseButton,
@@ -162,6 +245,40 @@
             'Expand new service items on creation'))
         self.enableAutoCloseCheckBox.setText(translate('OpenLP.AdvancedTab',
             'Enable application exit confirmation'))
+        self.defaultServiceGroupBox.setTitle(
+            translate('OpenLP.AdvancedTab', 'Default Service Name'))
+        self.defaultServiceCheckBox.setText(
+            translate('OpenLP.AdvancedTab', 'Enable default service name'))
+        self.defaultServiceTimeLabel.setText(
+            translate('OpenLP.AdvancedTab', 'Date and Time:'))
+        self.defaultServiceDay.setItemText(0,
+            translate('OpenLP.AdvancedTab', 'Monday'))
+        self.defaultServiceDay.setItemText(1,
+            translate('OpenLP.AdvancedTab', 'Tuesday'))
+        self.defaultServiceDay.setItemText(2,
+            translate('OpenLP.AdvancedTab', 'Wednesday'))
+        self.defaultServiceDay.setItemText(3,
+            translate('OpenLP.AdvancedTab', 'Thurdsday'))
+        self.defaultServiceDay.setItemText(4,
+            translate('OpenLP.AdvancedTab', 'Friday'))
+        self.defaultServiceDay.setItemText(5,
+            translate('OpenLP.AdvancedTab', 'Saturday'))
+        self.defaultServiceDay.setItemText(6,
+            translate('OpenLP.AdvancedTab', 'Sunday'))
+        self.defaultServiceDay.setItemText(7,
+            translate('OpenLP.AdvancedTab', 'Now'))
+        self.defaultServiceTime.setToolTip(translate('OpenLP.AdvancedTab',
+            'Time when usual service starts.'))
+        self.defaultServiceLabel.setText(
+            translate('OpenLP.AdvancedTab', 'Name:'))
+        self.defaultServiceName.setToolTip(translate('OpenLP.AdvancedTab',
+            'Consult the OpenLP manual for usage.'))
+        self.defaultServiceRevertButton.setToolTip(unicode(
+            translate('OpenLP.AdvancedTab',
+            'Revert to the default service name "%s".')) %
+            self.default_service_name)
+        self.defaultServiceExampleLabel.setText(translate('OpenLP.AdvancedTab',
+            'Example:'))
         self.hideMouseGroupBox.setTitle(translate('OpenLP.AdvancedTab',
             'Mouse Cursor'))
         self.hideMouseCheckBox.setText(translate('OpenLP.AdvancedTab',
@@ -213,6 +330,21 @@
             QtCore.QVariant(True)).toBool())
         self.hideMouseCheckBox.setChecked(
             settings.value(u'hide mouse', QtCore.QVariant(False)).toBool())
+        self.defaultServiceDay.setCurrentIndex(
+            settings.value(u'default service day',
+            QtCore.QVariant(self.default_service_day)).toInt()[0])
+        self.defaultServiceTime.setTime(QtCore.QTime(
+            settings.value(u'default service hour',
+            self.default_service_hour).toInt()[0],
+            settings.value(u'default service minute',
+            self.default_service_minute).toInt()[0]))
+        self.updateDefaultServiceExample = True
+        self.defaultServiceName.setText(settings.value(u'default service name',
+            self.default_service_name).toString())
+        default_service_enabled = settings.value(u'default service enabled',
+            QtCore.QVariant(True)).toBool()
+        self.defaultServiceCheckBox.setChecked(default_service_enabled)
+        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',
@@ -228,8 +360,25 @@
         """
         Save settings to disk.
         """
+        preset_is_valid = self.generate_service_name_example()[0]
+        service_name = unicode(self.defaultServiceName.text())
+        if not preset_is_valid:
+            service_name = self.default_service_name
+            self.defaultServiceName.setText(service_name)
         settings = QtCore.QSettings()
         settings.beginGroup(self.settingsSection)
+        settings.setValue(u'default service enabled',
+            self.defaultServiceCheckBox.isChecked())
+        if service_name == self.default_service_name:
+            settings.remove(u'default service name')
+        else:
+            settings.setValue(u'default service name', service_name)
+        settings.setValue(u'default service day',
+            self.defaultServiceDay.currentIndex())
+        settings.setValue(u'default service hour',
+            self.defaultServiceTime.time().hour())
+        settings.setValue(u'default service minute',
+            self.defaultServiceTime.time().minute())
         settings.setValue(u'recent file count',
             QtCore.QVariant(self.recentSpinBox.value()))
         settings.setValue(u'save current plugin',
@@ -253,6 +402,49 @@
             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.defaultServiceDay.currentIndex() 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.defaultServiceDay.currentIndex() == 7:
+            time = datetime.now()
+        else:
+            now = datetime.now()
+            day_delta = self.defaultServiceDay.currentIndex() - now.weekday()
+            if day_delta < 0:
+                day_delta += 7
+            time = now + timedelta(days=day_delta)
+            time = time.replace(hour = self.defaultServiceTime.time().hour(),
+                minute = self.defaultServiceTime.time().minute())
+        try:
+            service_name_example = time.strftime(unicode(
+                self.defaultServiceName.text()))
+        except ValueError:
+            preset_is_valid = False
+            service_name_example = translate('OpenLP.AdvancedTab',
+                'Syntax error.')
+        return preset_is_valid, service_name_example
+
+    def updateServiceNameExample(self, returned_value):
+        if not self.updateDefaultServiceExample:
+            return
+        name_example = self.generate_service_name_example()[1]
+        self.defaultServiceExample.setText(name_example)
+
+    def onDefaultServiceDayChanged(self, service_day):
+        self.defaultServiceTime.setEnabled(service_day is not 7)
+        self.updateServiceNameExample(None)
+
+    def onDefaultServiceRevertButtonPressed(self):
+        self.defaultServiceName.setText(self.default_service_name)
+        self.defaultServiceName.setFocus()
+
     def onDefaultColorButtonPressed(self):
         new_color = QtGui.QColorDialog.getColor(
             QtGui.QColor(self.default_color), self)

=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2012-01-01 13:43:43 +0000
+++ openlp/core/ui/servicemanager.py	2012-01-29 23:19:27 +0000
@@ -31,6 +31,7 @@
 import shutil
 import zipfile
 from tempfile import mkstemp
+from datetime import datetime, timedelta
 
 log = logging.getLogger(__name__)
 
@@ -612,10 +613,44 @@
         Get a file name and then call :func:`ServiceManager.saveFile` to
         save the file.
         """
+        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 under Advanced in Settings, Configure OpenLP. '
+                '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:
+            default_filename = u''
+        directory = unicode(SettingsManager.get_last_dir(
+            self.mainwindow.servicemanagerSettingsSection))
+        path = os.path.join(directory, default_filename)
         fileName = unicode(QtGui.QFileDialog.getSaveFileName(self.mainwindow,
-            UiStrings().SaveService,
-            SettingsManager.get_last_dir(
-            self.mainwindow.servicemanagerSettingsSection),
+            UiStrings().SaveService, path,
             translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz)')))
         if not fileName:
             return False


Follow ups