← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/bugs into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/bugs into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  #693150 Custom Slide Display footer option
  https://bugs.launchpad.net/bugs/693150
  #693202 delete theme
  https://bugs.launchpad.net/bugs/693202

For more details, see:
https://code.launchpad.net/~trb143/openlp/bugs/+merge/44502

Fix up theme delete / rename validation for now.
-- 
https://code.launchpad.net/~trb143/openlp/bugs/+merge/44502
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/bugs into lp:openlp.
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py	2010-12-16 16:08:10 +0000
+++ openlp/core/ui/thememanager.py	2010-12-22 18:56:30 +0000
@@ -223,15 +223,17 @@
         """
         Renames an existing theme to a new name
         """
-        item = self.themeListWidget.currentItem()
-        oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
-        self.fileRenameForm.fileNameEdit.setText(oldThemeName)
-        self.saveThemeName = u''
-        if self.fileRenameForm.exec_():
-            newThemeName =  unicode(self.fileRenameForm.fileNameEdit.text())
-            oldThemeData = self.getThemeData(oldThemeName)
-            self.deleteTheme(oldThemeName)
-            self.cloneThemeData(oldThemeData, newThemeName)
+        action = unicode(translate('OpenLP.ThemeManager', 'Rename'))
+        if self._validate_theme_action(action):
+            item = self.themeListWidget.currentItem()
+            oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
+            self.fileRenameForm.fileNameEdit.setText(oldThemeName)
+            self.saveThemeName = u''
+            if self.fileRenameForm.exec_():
+                newThemeName =  unicode(self.fileRenameForm.fileNameEdit.text())
+                oldThemeData = self.getThemeData(oldThemeName)
+                self.deleteTheme(oldThemeName)
+                self.cloneThemeData(oldThemeData, newThemeName)
 
     def onCopyTheme(self):
         """
@@ -286,47 +288,13 @@
         """
         Delete a theme
         """
-        self.global_theme = unicode(QtCore.QSettings().value(
-            self.settingsSection + u'/global theme',
-            QtCore.QVariant(u'')).toString())
-        if check_item_selected(self.themeListWidget,
-            translate('OpenLP.ThemeManager',
-            'You must select a theme to delete.')):
+        action = unicode(translate('OpenLP.ThemeManager', 'Delete'))
+        if self._validate_theme_action(action):
             item = self.themeListWidget.currentItem()
             theme = unicode(item.text())
-            # confirm deletion
-            answer = QtGui.QMessageBox.question(self,
-                translate('OpenLP.ThemeManager', 'Delete Confirmation'),
-                unicode(translate('OpenLP.ThemeManager', 'Delete %s theme?'))
-                % theme,
-                QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
-                QtGui.QMessageBox.No), QtGui.QMessageBox.No)
-            if answer == QtGui.QMessageBox.No:
-                return
-            # should be the same unless default
-            if theme != unicode(item.data(QtCore.Qt.UserRole).toString()):
-                QtGui.QMessageBox.critical(self,
-                    translate('OpenLP.ThemeManager', 'Error'),
-                    translate('OpenLP.ThemeManager',
-                        'You are unable to delete the default theme.'))
-            else:
-                for plugin in self.parent.pluginManager.plugins:
-                    if plugin.usesTheme(theme):
-                        QtGui.QMessageBox.critical(self,
-                            translate('OpenLP.ThemeManager', 'Error'),
-                            unicode(translate('OpenLP.ThemeManager',
-                                'Theme %s is used in the %s plugin.')) % \
-                                (theme, plugin.name))
-                        return
-                if unicode(self.serviceComboBox.currentText()) == theme:
-                    QtGui.QMessageBox.critical(self,
-                        translate('OpenLP.ThemeManager', 'Error'),
-                        unicode(translate('OpenLP.ThemeManager',
-                        'Theme %s is used by the service manager.')) % theme)
-                    return
-                row = self.themeListWidget.row(item)
-                self.themeListWidget.takeItem(row)
-                self.deleteTheme(theme)
+            row = self.themeListWidget.row(item)
+            self.themeListWidget.takeItem(row)
+            self.deleteTheme(theme)
 
     def deleteTheme(self, theme):
         """
@@ -782,3 +750,49 @@
         theme.parse(themeXml)
         theme.extend_image_filename(path)
         return theme
+
+    def _validate_theme_action(self, action):
+        """
+        Check to see if theme has been selected and the destructive action
+        is allowed.
+        """
+        self.global_theme = unicode(QtCore.QSettings().value(
+            self.settingsSection + u'/global theme',
+            QtCore.QVariant(u'')).toString())
+        if check_item_selected(self.themeListWidget,
+            unicode(translate('OpenLP.ThemeManager',
+            'You must select a theme to %s.')) % action):
+            item = self.themeListWidget.currentItem()
+            theme = unicode(item.text())
+            # confirm deletion
+            answer = QtGui.QMessageBox.question(self,
+                unicode(translate('OpenLP.ThemeManager', '%s Confirmation'))
+                % action,
+                unicode(translate('OpenLP.ThemeManager', '%s %s theme?'))
+                % (action, theme),
+                QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
+                QtGui.QMessageBox.No), QtGui.QMessageBox.No)
+            if answer == QtGui.QMessageBox.No:
+                return False
+            # should be the same unless default
+            if theme != unicode(item.data(QtCore.Qt.UserRole).toString()):
+                QtGui.QMessageBox.critical(self,
+                    translate('OpenLP.ThemeManager', 'Error'),
+                    translate('OpenLP.ThemeManager',
+                        'You are unable to delete the default theme.'))
+            else:
+                for plugin in self.parent.pluginManager.plugins:
+                    if plugin.usesTheme(theme):
+                        QtGui.QMessageBox.critical(self,
+                            translate('OpenLP.ThemeManager', 'Error'),
+                            unicode(translate('OpenLP.ThemeManager',
+                                'Theme %s is used in the %s plugin.')) % \
+                                (theme, plugin.name))
+                        return False
+                if unicode(self.serviceComboBox.currentText()) == theme:
+                    QtGui.QMessageBox.critical(self,
+                        translate('OpenLP.ThemeManager', 'Error'),
+                        unicode(translate('OpenLP.ThemeManager',
+                        'Theme %s is used by the service manager.')) % theme)
+                    return False
+        return True


Follow ups