From a120719884f6e8d654d74fe0afe52a70693f76e8 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sat, 5 Feb 2011 23:52:05 +0000 Subject: [PATCH] Fix song service load (Bug #696219) --- openlp/plugins/songs/lib/mediaitem.py | 82 +++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 95337b29f..d5cd49cbb 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ from openlp.core.lib import MediaManagerItem, BaseListWithDnD, Receiver, \ - ItemCapabilities, translate, check_item_selected + ItemCapabilities, translate, check_item_selected, PluginStatus from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ SongImportForm from openlp.plugins.songs.lib import OpenLyrics, SongXML @@ -396,46 +396,46 @@ class SongMediaItem(MediaManagerItem): Triggered by a song being loaded by the service item """ log.debug(u'serviceLoad') - if item.data_string: - search_results = self.parent.manager.get_all_objects(Song, - Song.search_title == re.compile(r'\W+', re.UNICODE).sub(u' ', - item.data_string[u'title'].split(u'@')[0].lower()).strip(), - Song.search_title.asc()) - author_list = item.data_string[u'authors'].split(u', ') - # The service item always has an author (at least it has u'' as - # author). However, songs saved in the database do not have to have - # an author. - if u'' in author_list: - author_list.remove(u'') - editId = 0 - add_song = True - if search_results: - for song in search_results: - same_authors = True - # If the author counts are different, we do not have to do - # any further checking. This is also important when a song - # does not have any author (because we can not loop over an - # empty list). - if len(song.authors) == len(author_list): - for author in song.authors: - if author.display_name not in author_list: - same_authors = False - else: - same_authors = False - # All authors are the same, so we can stop here and the song - # does not have to be saved. - if same_authors: - add_song = False - editId = song.id - break - if add_song: - if self.addSongFromService: - editId = self.openLyrics.xml_to_song(item.xml_version) - self.onSearchTextButtonClick() - # Update service with correct song id. - if editId: - Receiver.send_message(u'service_item_update', - u'%s:%s' % (editId, item._uuid)) + if self.plugin.status != PluginStatus.Active or not item.data_string: + return + search_results = self.parent.manager.get_all_objects(Song, + Song.search_title == re.compile(r'\W+', re.UNICODE).sub(u' ', + item.data_string[u'title'].split(u'@')[0].lower()).strip(), + Song.search_title.asc()) + author_list = item.data_string[u'authors'].split(u', ') + # The service item always has an author (at least it has u'' as + # author). However, songs saved in the database do not have to have + # an author. + if u'' in author_list: + author_list.remove(u'') + editId = 0 + add_song = True + if search_results: + for song in search_results: + same_authors = True + # If the author counts are different, we do not have to do any + # further checking. This is also important when a song does not + # have any author (because we can not loop over an empty list). + if len(song.authors) == len(author_list): + for author in song.authors: + if author.display_name not in author_list: + same_authors = False + else: + same_authors = False + # All authors are the same, so we can stop here and the song + # does not have to be saved. + if same_authors: + add_song = False + editId = song.id + break + if add_song: + if self.addSongFromService: + editId = self.openLyrics.xml_to_song(item.xml_version) + self.onSearchTextButtonClick() + # Update service with correct song id. + if editId: + Receiver.send_message(u'service_item_update', + u'%s:%s' % (editId, item._uuid)) def collateSongTitles(self, song_1, song_2): """