Theme Deletes only work for unused themes

This commit is contained in:
Tim Bentley 2010-03-04 19:03:09 +00:00
parent bb0a3f7293
commit 9ada2f00b0
7 changed files with 41 additions and 0 deletions

View File

@ -254,3 +254,9 @@ class Plugin(QtCore.QObject):
self.mediadock.insert_dock(self.media_item, self.icon, self.weight)
if self.settings_tab:
self.settings.insertTab(self.settings_tab, self.weight)
def can_delete_theme(self, theme):
"""
Called to ask the plugin if a theme can be deleted
"""
return True

View File

@ -180,6 +180,19 @@ class ThemeManager(QtGui.QWidget):
self.trUtf8('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.can_delete_theme(theme):
QtGui.QMessageBox.critical(
self, self.trUtf8('Error'),
self.trUtf8('theme %s is use in %s plugin' % (theme, plugin.name)),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return
if unicode(self.parent.ServiceManagerContents.ThemeComboBox.currentText()) == theme:
QtGui.QMessageBox.critical(
self, self.trUtf8('Error'),
self.trUtf8('theme %s is use Service Manager' % theme),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return
self.themelist.remove(theme)
th = theme + u'.png'
row = self.ThemeListWidget.row(item)

View File

@ -92,3 +92,9 @@ class BiblePlugin(Plugin):
'plugin allows bible verses from different sources to be '
'displayed on the screen during the service.')
return about_text
def can_delete_theme(self, theme):
if self.settings_tab.bible_theme == theme:
return False
return True

View File

@ -72,3 +72,8 @@ class CustomPlugin(Plugin):
'songs are. This plugin provides greater freedom over the '
'songs plugin.<br>')
return about_text
def can_delete_theme(self, theme):
if len(self.custommanager.get_customs_for_theme(theme)) == 0:
return True
return False

View File

@ -105,3 +105,6 @@ class CustomManager():
return False
else:
return True
def get_customs_for_theme(self, theme):
return self.session.query(CustomSlide).filter(CustomSlide.theme_name == theme).all()

View File

@ -237,3 +237,6 @@ class SongManager():
self.session.rollback()
log.exception(u'Could not delete book from song database')
return False
def get_songs_for_theme(self, theme):
return self.session.query(Song).filter(Song.theme_name == theme).all()

View File

@ -179,3 +179,8 @@ class SongsPlugin(Plugin):
about_text = self.trUtf8('<b>Song Plugin</b> <br>This plugin allows '
'Songs to be managed and displayed.<br>')
return about_text
def can_delete_theme(self, theme):
if len(self.songmanager.get_songs_for_theme(theme)) == 0:
return True
return False