From 9ada2f00b0a3504cc96ab4c8a4e0cd6bc08e7b40 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 4 Mar 2010 19:03:09 +0000 Subject: [PATCH] Theme Deletes only work for unused themes --- openlp/core/lib/plugin.py | 6 ++++++ openlp/core/ui/thememanager.py | 13 +++++++++++++ openlp/plugins/bibles/bibleplugin.py | 6 ++++++ openlp/plugins/custom/customplugin.py | 5 +++++ openlp/plugins/custom/lib/manager.py | 3 +++ openlp/plugins/songs/lib/manager.py | 3 +++ openlp/plugins/songs/songsplugin.py | 5 +++++ 7 files changed, 41 insertions(+) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index e15369145..e98c789d0 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -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 diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index ba541aa6e..b6396c7db 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -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) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 8cf15e942..bd65b6622 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -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 diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index 3e21228df..ac5384390 100644 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -72,3 +72,8 @@ class CustomPlugin(Plugin): 'songs are. This plugin provides greater freedom over the ' 'songs plugin.
') return about_text + + def can_delete_theme(self, theme): + if len(self.custommanager.get_customs_for_theme(theme)) == 0: + return True + return False diff --git a/openlp/plugins/custom/lib/manager.py b/openlp/plugins/custom/lib/manager.py index e88e72b5c..1368b89ee 100644 --- a/openlp/plugins/custom/lib/manager.py +++ b/openlp/plugins/custom/lib/manager.py @@ -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() diff --git a/openlp/plugins/songs/lib/manager.py b/openlp/plugins/songs/lib/manager.py index 74bd4cf82..0e662dcbc 100644 --- a/openlp/plugins/songs/lib/manager.py +++ b/openlp/plugins/songs/lib/manager.py @@ -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() diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index eb6eb2c2a..9ebaa99b2 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -179,3 +179,8 @@ class SongsPlugin(Plugin): about_text = self.trUtf8('Song Plugin
This plugin allows ' 'Songs to be managed and displayed.
') return about_text + + def can_delete_theme(self, theme): + if len(self.songmanager.get_songs_for_theme(theme)) == 0: + return True + return False