forked from openlp/openlp
Proper theme name editing (Bug #594909)
This commit is contained in:
commit
767214bb13
@ -269,8 +269,22 @@ class Plugin(QtCore.QObject):
|
||||
if self.settings_tab:
|
||||
self.settingsForm.insertTab(self.settings_tab, self.weight)
|
||||
|
||||
def canDeleteTheme(self, theme):
|
||||
def usesTheme(self, theme):
|
||||
"""
|
||||
Called to ask the plugin if a theme can be deleted
|
||||
Called to find out if a plugin is currently using a theme.
|
||||
|
||||
Returns True if the theme is being used, otherwise returns False.
|
||||
"""
|
||||
return True
|
||||
return False
|
||||
|
||||
def renameTheme(self, oldTheme, newTheme):
|
||||
"""
|
||||
Renames a theme a plugin is using making the plugin use the new name.
|
||||
|
||||
``oldTheme``
|
||||
The name of the theme the plugin should stop using.
|
||||
|
||||
``newTheme``
|
||||
The new name the plugin should now use.
|
||||
"""
|
||||
pass
|
||||
|
@ -48,6 +48,7 @@ class ThemeManager(QtGui.QWidget):
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
self.parent = parent
|
||||
self.settingsSection = u'themes'
|
||||
self.serviceComboBox = self.parent.ServiceManagerContents.ThemeComboBox
|
||||
self.Layout = QtGui.QVBoxLayout(self)
|
||||
self.Layout.setSpacing(0)
|
||||
self.Layout.setMargin(0)
|
||||
@ -182,9 +183,13 @@ class ThemeManager(QtGui.QWidget):
|
||||
Loads the settings for the theme that is to be edited and launches the
|
||||
theme editing form so the user can make their changes.
|
||||
"""
|
||||
self.editingDefault = False
|
||||
if check_item_selected(self.ThemeListWidget, translate('ThemeManager',
|
||||
'You must select a theme to edit.')):
|
||||
item = self.ThemeListWidget.currentItem()
|
||||
themeName = unicode(item.text())
|
||||
if themeName != unicode(item.data(QtCore.Qt.UserRole).toString()):
|
||||
self.editingDefault = True
|
||||
theme = self.getThemeData(
|
||||
unicode(item.data(QtCore.Qt.UserRole).toString()))
|
||||
self.amendThemeForm.loadTheme(theme)
|
||||
@ -208,41 +213,48 @@ class ThemeManager(QtGui.QWidget):
|
||||
QtGui.QMessageBox.critical(self,
|
||||
translate('ThemeManager', 'Error'),
|
||||
translate('ThemeManager',
|
||||
'You are unable to delete the default theme.'),
|
||||
'You are unable to delete the default theme.'),
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
|
||||
else:
|
||||
for plugin in self.parent.plugin_manager.plugins:
|
||||
if not plugin.canDeleteTheme(theme):
|
||||
if plugin.usesTheme(theme):
|
||||
QtGui.QMessageBox.critical(self,
|
||||
translate('ThemeManager', 'Error'),
|
||||
unicode(translate('ThemeManager',
|
||||
'Theme %s is use in %s plugin.')) % \
|
||||
(theme, plugin.name))
|
||||
'Theme %s is use in %s plugin.')) % \
|
||||
(theme, plugin.name))
|
||||
return
|
||||
if unicode(self.parent.ServiceManagerContents.ThemeComboBox \
|
||||
.currentText()) == theme:
|
||||
if unicode(self.serviceComboBox.currentText()) == theme:
|
||||
QtGui.QMessageBox.critical(self,
|
||||
translate('ThemeManager', 'Error'),
|
||||
unicode(translate('ThemeManager',
|
||||
'Theme %s is use by the service manager.')) % theme)
|
||||
'Theme %s is use by the service manager.')) % theme)
|
||||
return
|
||||
self.themelist.remove(theme)
|
||||
th = theme + u'.png'
|
||||
row = self.ThemeListWidget.row(item)
|
||||
self.ThemeListWidget.takeItem(row)
|
||||
try:
|
||||
os.remove(os.path.join(self.path, th))
|
||||
os.remove(os.path.join(self.thumbPath, th))
|
||||
encoding = get_filesystem_encoding()
|
||||
shutil.rmtree(
|
||||
os.path.join(self.path, theme).encode(encoding))
|
||||
except OSError:
|
||||
#if not present do not worry
|
||||
pass
|
||||
# As we do not reload the themes push out the change
|
||||
# Reaload the list as the internal lists and events need
|
||||
# to be triggered
|
||||
self.pushThemes()
|
||||
self.deleteTheme(theme)
|
||||
|
||||
def deleteTheme(self, theme):
|
||||
"""
|
||||
Delete a theme.
|
||||
|
||||
``theme``
|
||||
The theme to delete.
|
||||
"""
|
||||
self.themelist.remove(theme)
|
||||
th = theme + u'.png'
|
||||
try:
|
||||
os.remove(os.path.join(self.path, th))
|
||||
os.remove(os.path.join(self.thumbPath, th))
|
||||
encoding = get_filesystem_encoding()
|
||||
shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
|
||||
except OSError:
|
||||
#if not present do not worry
|
||||
pass
|
||||
# As we do not reload the themes push out the change
|
||||
# Reaload the list as the internal lists and events need
|
||||
# to be triggered
|
||||
self.pushThemes()
|
||||
|
||||
def onExportTheme(self):
|
||||
"""
|
||||
@ -532,16 +544,23 @@ class ThemeManager(QtGui.QWidget):
|
||||
os.mkdir(os.path.join(self.path, name))
|
||||
theme_file = os.path.join(theme_dir, name + u'.xml')
|
||||
log.debug(theme_file)
|
||||
editedServiceTheme = False
|
||||
result = QtGui.QMessageBox.Yes
|
||||
if self.saveThemeName != name:
|
||||
if os.path.exists(theme_file):
|
||||
result = QtGui.QMessageBox.question(self,
|
||||
translate('ThemeManager', 'Theme Exists'),
|
||||
translate('ThemeManager',
|
||||
'A theme with this name already exists. '
|
||||
'Would you like to overwrite it?'),
|
||||
translate('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.plugin_manager.plugins:
|
||||
if plugin.usesTheme(self.saveThemeName):
|
||||
plugin.renameTheme(self.saveThemeName, name)
|
||||
if unicode(self.serviceComboBox.currentText()) == name:
|
||||
editedServiceTheme = True
|
||||
self.deleteTheme(self.saveThemeName)
|
||||
if result == QtGui.QMessageBox.Yes:
|
||||
# Save the theme, overwriting the existing theme if necessary.
|
||||
outfile = None
|
||||
@ -563,6 +582,26 @@ class ThemeManager(QtGui.QWidget):
|
||||
log.exception(u'Failed to save theme image')
|
||||
self.generateAndSaveImage(self.path, name, theme_xml)
|
||||
self.loadThemes()
|
||||
# Check if we need to set a new service theme
|
||||
if editedServiceTheme:
|
||||
newThemeIndex = self.serviceComboBox.findText(name)
|
||||
if newThemeIndex != -1:
|
||||
self.serviceComboBox.setCurrentIndex(newThemeIndex)
|
||||
if self.editingDefault:
|
||||
newThemeItem = self.ThemeListWidget.findItems(name,
|
||||
QtCore.Qt.MatchExactly)[0]
|
||||
newThemeIndex = self.ThemeListWidget.indexFromItem(
|
||||
newThemeItem).row()
|
||||
self.global_theme = unicode(
|
||||
self.ThemeListWidget.item(newThemeIndex).text())
|
||||
newName = unicode(translate('ThemeManager', '%s (default)')) % \
|
||||
self.global_theme
|
||||
self.ThemeListWidget.item(newThemeIndex).setText(newName)
|
||||
QtCore.QSettings().setValue(
|
||||
self.settingsSection + u'/global theme',
|
||||
QtCore.QVariant(self.global_theme))
|
||||
Receiver.send_message(u'theme_update_global', self.global_theme)
|
||||
self.pushThemes()
|
||||
else:
|
||||
# Don't close the dialog - allow the user to change the name of
|
||||
# the theme or to cancel the theme dialog completely.
|
||||
|
@ -95,7 +95,26 @@ class BiblePlugin(Plugin):
|
||||
'displayed on the screen during the service.')
|
||||
return about_text
|
||||
|
||||
def canDeleteTheme(self, theme):
|
||||
def usesTheme(self, theme):
|
||||
"""
|
||||
Called to find out if the bible plugin is currently using a theme.
|
||||
|
||||
Returns True if the theme is being used, otherwise returns False.
|
||||
"""
|
||||
if self.settings_tab.bible_theme == theme:
|
||||
return False
|
||||
return True
|
||||
return True
|
||||
return False
|
||||
|
||||
def renameTheme(self, oldTheme, newTheme):
|
||||
"""
|
||||
Rename the theme the bible plugin is using making the plugin use the
|
||||
new name.
|
||||
|
||||
``oldTheme``
|
||||
The name of the theme the plugin should stop using. Unused for
|
||||
this particular plugin.
|
||||
|
||||
``newTheme``
|
||||
The new name the plugin should now use.
|
||||
"""
|
||||
self.settings_tab.bible_theme = newTheme
|
||||
|
@ -69,8 +69,30 @@ class CustomPlugin(Plugin):
|
||||
'songs plugin.<br>')
|
||||
return about_text
|
||||
|
||||
def canDeleteTheme(self, theme):
|
||||
if not self.custommanager.get_all_objects_filtered(CustomSlide,
|
||||
def usesTheme(self, theme):
|
||||
"""
|
||||
Called to find out if the custom plugin is currently using a theme.
|
||||
|
||||
Returns True if the theme is being used, otherwise returns False.
|
||||
"""
|
||||
if self.custommanager.get_all_objects_filtered(CustomSlide,
|
||||
CustomSlide.theme_name == theme):
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
def renameTheme(self, oldTheme, newTheme):
|
||||
"""
|
||||
Renames a theme the custom plugin is using making the plugin use the
|
||||
new name.
|
||||
|
||||
``oldTheme``
|
||||
The name of the theme the plugin should stop using.
|
||||
|
||||
``newTheme``
|
||||
The new name the plugin should now use.
|
||||
"""
|
||||
customsUsingTheme = self.custommanager.get_all_objects_filtered(
|
||||
CustomSlide, CustomSlide.theme_name == oldTheme)
|
||||
for custom in customsUsingTheme:
|
||||
custom.theme_name = newTheme
|
||||
self.custommanager.save_object(custom)
|
||||
|
@ -37,8 +37,6 @@ import logging
|
||||
import os
|
||||
import time
|
||||
|
||||
from openlp.core.lib import resize_image
|
||||
|
||||
if os.name == u'nt':
|
||||
from win32com.client import Dispatch
|
||||
import pywintypes
|
||||
|
@ -30,7 +30,6 @@ from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
||||
SettingsManager, translate, check_item_selected
|
||||
from openlp.core.utils import AppLocation
|
||||
from openlp.plugins.presentations.lib import MessageListener
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -192,8 +192,30 @@ class SongsPlugin(Plugin):
|
||||
'This plugin allows songs to be managed and displayed.')
|
||||
return about_text
|
||||
|
||||
def canDeleteTheme(self, theme):
|
||||
if not self.manager.get_all_objects_filtered(Song,
|
||||
def usesTheme(self, theme):
|
||||
"""
|
||||
Called to find out if the song plugin is currently using a theme.
|
||||
|
||||
Returns True if the theme is being used, otherwise returns False.
|
||||
"""
|
||||
if self.manager.get_all_objects_filtered(Song,
|
||||
Song.theme_name == theme):
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
def renameTheme(self, oldTheme, newTheme):
|
||||
"""
|
||||
Renames a theme the song plugin is using making the plugin use the new
|
||||
name.
|
||||
|
||||
``oldTheme``
|
||||
The name of the theme the plugin should stop using.
|
||||
|
||||
``newTheme``
|
||||
The new name the plugin should now use.
|
||||
"""
|
||||
songsUsingTheme = self.manager.get_all_objects_filtered(Song,
|
||||
Song.theme_name == oldTheme)
|
||||
for song in songsUsingTheme:
|
||||
song.theme_name = newTheme
|
||||
self.custommanager.save_object(song)
|
||||
|
Loading…
Reference in New Issue
Block a user