More Theme Management cleanups

This commit is contained in:
Tim Bentley 2010-12-27 10:18:09 +00:00
parent a464ab791b
commit 399970e7c7
4 changed files with 108 additions and 118 deletions

View File

@ -108,11 +108,11 @@ class ServiceManager(QtGui.QWidget):
self.suffixes = [] self.suffixes = []
self.droppos = 0 self.droppos = 0
self.expandTabs = False self.expandTabs = False
#is a new service and has not been saved # is a new service and has not been saved
self.isNew = True self.isNew = True
self.serviceNoteForm = ServiceNoteForm(self.parent) self.serviceNoteForm = ServiceNoteForm(self.parent)
self.serviceItemEditForm = ServiceItemEditForm(self.parent) self.serviceItemEditForm = ServiceItemEditForm(self.parent)
#start with the layout # start with the layout
self.layout = QtGui.QVBoxLayout(self) self.layout = QtGui.QVBoxLayout(self)
self.layout.setSpacing(0) self.layout.setSpacing(0)
self.layout.setMargin(0) self.layout.setMargin(0)
@ -245,7 +245,7 @@ class ServiceManager(QtGui.QWidget):
self.parent.serviceSettingsSection + u'/service theme', self.parent.serviceSettingsSection + u'/service theme',
QtCore.QVariant(u'')).toString()) QtCore.QVariant(u'')).toString())
self.servicePath = AppLocation.get_section_data_path(u'servicemanager') self.servicePath = AppLocation.get_section_data_path(u'servicemanager')
#build the drag and drop context menu # build the drag and drop context menu
self.dndMenu = QtGui.QMenu() self.dndMenu = QtGui.QMenu()
self.newAction = self.dndMenu.addAction( self.newAction = self.dndMenu.addAction(
translate('OpenLP.ServiceManager', '&Add New Item')) translate('OpenLP.ServiceManager', '&Add New Item'))

View File

@ -114,22 +114,30 @@ class ThemeManager(QtGui.QWidget):
self.exportAction = self.menu.addAction( self.exportAction = self.menu.addAction(
translate('OpenLP.ThemeManager', '&Export Theme')) translate('OpenLP.ThemeManager', '&Export Theme'))
self.exportAction.setIcon(build_icon(u':/general/general_export.png')) self.exportAction.setIcon(build_icon(u':/general/general_export.png'))
#Signals # Signals
QtCore.QObject.connect(self.themeListWidget, QtCore.QObject.connect(self.themeListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.changeGlobalFromScreen) self.changeGlobalFromScreen)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'theme_update_global'), self.changeGlobalFromTab) QtCore.SIGNAL(u'theme_update_global'), self.changeGlobalFromTab)
#Variables QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'config_updated'), self.configUpdated)
# Variables
self.themelist = [] self.themelist = []
self.path = AppLocation.get_section_data_path(self.settingsSection) self.path = AppLocation.get_section_data_path(self.settingsSection)
self.checkThemesExists(self.path) self.checkDirectoryExists(self.path)
self.thumbPath = os.path.join(self.path, u'thumbnails') self.thumbPath = os.path.join(self.path, u'thumbnails')
self.checkThemesExists(self.thumbPath) self.checkDirectoryExists(self.thumbPath)
self.themeForm.path = self.path self.themeForm.path = self.path
self.oldBackgroundImage = None self.oldBackgroundImage = None
self.editingDefault = False self.editingDefault = False
# Last little bits of setting up # Last little bits of setting up
self.configUpdated()
def configUpdated(self, firstTime=False):
"""
Triggered when Config dialog is updated.
"""
self.global_theme = unicode(QtCore.QSettings().value( self.global_theme = unicode(QtCore.QSettings().value(
self.settingsSection + u'/global theme', self.settingsSection + u'/global theme',
QtCore.QVariant(u'')).toString()) QtCore.QVariant(u'')).toString())
@ -215,7 +223,6 @@ class ThemeManager(QtGui.QWidget):
editing form for the user to make their customisations. editing form for the user to make their customisations.
""" """
theme = ThemeXML() theme = ThemeXML()
self.saveThemeName = u''
self.themeForm.theme = theme self.themeForm.theme = theme
self.themeForm.exec_() self.themeForm.exec_()
@ -228,9 +235,9 @@ class ThemeManager(QtGui.QWidget):
item = self.themeListWidget.currentItem() item = self.themeListWidget.currentItem()
oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
self.fileRenameForm.fileNameEdit.setText(oldThemeName) self.fileRenameForm.fileNameEdit.setText(oldThemeName)
self.saveThemeName = oldThemeName
if self.fileRenameForm.exec_(): if self.fileRenameForm.exec_():
newThemeName = unicode(self.fileRenameForm.fileNameEdit.text()) newThemeName = unicode(self.fileRenameForm.fileNameEdit.text())
if self.checkIfThemeExists(newThemeName):
oldThemeData = self.getThemeData(oldThemeName) oldThemeData = self.getThemeData(oldThemeName)
self.deleteTheme(oldThemeName) self.deleteTheme(oldThemeName)
self.cloneThemeData(oldThemeData, newThemeName) self.cloneThemeData(oldThemeData, newThemeName)
@ -245,9 +252,9 @@ class ThemeManager(QtGui.QWidget):
item = self.themeListWidget.currentItem() item = self.themeListWidget.currentItem()
oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString()) oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
self.fileRenameForm.fileNameEdit.setText(oldThemeName) self.fileRenameForm.fileNameEdit.setText(oldThemeName)
self.saveThemeName = u''
if self.fileRenameForm.exec_(True): if self.fileRenameForm.exec_(True):
newThemeName = unicode(self.fileRenameForm.fileNameEdit.text()) newThemeName = unicode(self.fileRenameForm.fileNameEdit.text())
if self.checkIfThemeExists(newThemeName):
themeData = self.getThemeData(oldThemeName) themeData = self.getThemeData(oldThemeName)
self.cloneThemeData(themeData, newThemeName) self.cloneThemeData(themeData, newThemeName)
self.loadThemes() self.loadThemes()
@ -282,8 +289,6 @@ class ThemeManager(QtGui.QWidget):
unicode(item.data(QtCore.Qt.UserRole).toString())) unicode(item.data(QtCore.Qt.UserRole).toString()))
if theme.background_type == u'image': if theme.background_type == u'image':
self.oldBackgroundImage = theme.background_filename self.oldBackgroundImage = theme.background_filename
self.saveThemeName = unicode(
item.data(QtCore.Qt.UserRole).toString())
self.themeForm.theme = theme self.themeForm.theme = theme
self.themeForm.exec_(True) self.themeForm.exec_(True)
@ -446,7 +451,7 @@ class ThemeManager(QtGui.QWidget):
else: else:
return self.createThemeFromXml(xml, self.path) return self.createThemeFromXml(xml, self.path)
def checkThemesExists(self, dir): def checkDirectoryExists(self, dir):
""" """
Check a theme directory exists and if not create it Check a theme directory exists and if not create it
@ -609,6 +614,20 @@ class ThemeManager(QtGui.QWidget):
newtheme.display_vertical_align = vAlignCorrection newtheme.display_vertical_align = vAlignCorrection
return newtheme.extract_xml() return newtheme.extract_xml()
def checkIfThemeExists(self, themeName):
"""
Check if theme already exists and displays error message
"""
theme_dir = os.path.join(self.path, themeName)
if os.path.exists(theme_dir):
QtGui.QMessageBox.critical(self,
translate('OpenLP.ThemeManager', 'Theme Exists'),
translate('OpenLP.ThemeManager',
'A theme with this name already exists.'),
(QtGui.QMessageBox.Ok), QtGui.QMessageBox.Ok)
return False
return True
def saveTheme(self, theme, imageFrom, imageTo): def saveTheme(self, theme, imageFrom, imageTo):
""" """
Called by thememaintenance Dialog to save the theme Called by thememaintenance Dialog to save the theme
@ -623,23 +642,8 @@ class ThemeManager(QtGui.QWidget):
theme_file = os.path.join(theme_dir, name + u'.xml') theme_file = os.path.join(theme_dir, name + u'.xml')
log.debug(theme_file) log.debug(theme_file)
editedServiceTheme = False editedServiceTheme = False
result = QtGui.QMessageBox.Yes #result = QtGui.QMessageBox.Yes
if self.saveThemeName != name: #if result == QtGui.QMessageBox.Yes:
if os.path.exists(theme_file):
result = QtGui.QMessageBox.question(self,
translate('OpenLP.ThemeManager', 'Theme Exists'),
translate('OpenLP.ThemeManager',
'A theme with this name already '
'exists. Would you like to overwrite it?'),
(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
if self.saveThemeName != u'':
for plugin in self.parent.pluginManager.plugins:
if plugin.usesTheme(self.saveThemeName):
plugin.renameTheme(self.saveThemeName, name)
if unicode(self.serviceComboBox.currentText()) == name:
editedServiceTheme = True
if result == QtGui.QMessageBox.Yes:
# Save the theme, overwriting the existing theme if necessary. # Save the theme, overwriting the existing theme if necessary.
if imageTo and self.oldBackgroundImage and \ if imageTo and self.oldBackgroundImage and \
imageTo != self.oldBackgroundImage: imageTo != self.oldBackgroundImage:
@ -667,33 +671,28 @@ class ThemeManager(QtGui.QWidget):
self.generateAndSaveImage(self.path, name, theme) self.generateAndSaveImage(self.path, name, theme)
self.loadThemes() self.loadThemes()
# Check if we need to set a new service theme # Check if we need to set a new service theme
if editedServiceTheme: # if editedServiceTheme:
newThemeIndex = self.serviceComboBox.findText(name) # newThemeIndex = self.serviceComboBox.findText(name)
if newThemeIndex != -1: # if newThemeIndex != -1:
self.serviceComboBox.setCurrentIndex(newThemeIndex) # self.serviceComboBox.setCurrentIndex(newThemeIndex)
if self.editingDefault: # if self.editingDefault:
if self.saveThemeName != name: # if self.saveThemeName != name:
newThemeItem = self.themeListWidget.findItems(name, # newThemeItem = self.themeListWidget.findItems(name,
QtCore.Qt.MatchExactly)[0] # QtCore.Qt.MatchExactly)[0]
newThemeIndex = self.themeListWidget.indexFromItem( # newThemeIndex = self.themeListWidget.indexFromItem(
newThemeItem).row() # newThemeItem).row()
self.global_theme = unicode( # self.global_theme = unicode(
self.themeListWidget.item(newThemeIndex).text()) # self.themeListWidget.item(newThemeIndex).text())
newName = unicode(translate('OpenLP.ThemeManager', # newName = unicode(translate('OpenLP.ThemeManager',
'%s (default)')) % self.global_theme # '%s (default)')) % self.global_theme
self.themeListWidget.item(newThemeIndex).setText(newName) # self.themeListWidget.item(newThemeIndex).setText(newName)
QtCore.QSettings().setValue( # QtCore.QSettings().setValue(
self.settingsSection + u'/global theme', # self.settingsSection + u'/global theme',
QtCore.QVariant(self.global_theme)) # QtCore.QVariant(self.global_theme))
Receiver.send_message(u'theme_update_global', # Receiver.send_message(u'theme_update_global',
self.global_theme) # self.global_theme)
self.editingDefault = False # self.editingDefault = False
self.pushThemes() self.pushThemes()
return True
else:
# Don't close the dialog - allow the user to change the name of
# the theme or to cancel the theme dialog completely.
return False
def generateAndSaveImage(self, dir, name, theme): def generateAndSaveImage(self, dir, name, theme):
log.debug(u'generateAndSaveImage %s %s', dir, name) log.debug(u'generateAndSaveImage %s %s', dir, name)
@ -758,15 +757,12 @@ class ThemeManager(QtGui.QWidget):
Check to see if theme has been selected and the destructive action Check to see if theme has been selected and the destructive action
is allowed. is allowed.
""" """
self.global_theme = unicode(QtCore.QSettings().value(
self.settingsSection + u'/global theme',
QtCore.QVariant(u'')).toString())
if check_item_selected(self.themeListWidget, if check_item_selected(self.themeListWidget,
unicode(translate('OpenLP.ThemeManager', unicode(translate('OpenLP.ThemeManager',
'You must select a theme to %s.')) % action): 'You must select a theme to %s.')) % action):
item = self.themeListWidget.currentItem() item = self.themeListWidget.currentItem()
theme = unicode(item.text()) theme = unicode(item.text())
# confirm deletion # confirm destructive action
answer = QtGui.QMessageBox.question(self, answer = QtGui.QMessageBox.question(self,
unicode(translate('OpenLP.ThemeManager', '%s Confirmation')) unicode(translate('OpenLP.ThemeManager', '%s Confirmation'))
% action, % action,
@ -776,13 +772,7 @@ class ThemeManager(QtGui.QWidget):
QtGui.QMessageBox.No), QtGui.QMessageBox.No) QtGui.QMessageBox.No), QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.No: if answer == QtGui.QMessageBox.No:
return False return False
# should be the same unless default # check for use in the system else where.
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:
if testPlugin: if testPlugin:
for plugin in self.parent.pluginManager.plugins: for plugin in self.parent.pluginManager.plugins:
if plugin.usesTheme(theme): if plugin.usesTheme(theme):

View File

@ -197,7 +197,7 @@ class SongMediaItem(MediaManagerItem):
elif search_type == 3: elif search_type == 3:
log.debug(u'Theme Search') log.debug(u'Theme Search')
search_results = self.parent.manager.get_all_objects(Song, search_results = self.parent.manager.get_all_objects(Song,
Song.theme_name.like(u'%' + search_keywords + u'%'), Song.theme_name == search_keywords,
Song.search_lyrics.asc()) Song.search_lyrics.asc())
self.displayResultsSong(search_results) self.displayResultsSong(search_results)