diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index f98590ade..bf8956a7d 100644 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -27,6 +27,7 @@ import logging from openlp.core.state import State from openlp.core.common.i18n import translate +from openlp.core.common.registry import Registry from openlp.core.lib import build_icon from openlp.core.db.manager import DBManager from openlp.core.lib.plugin import Plugin, StringContent @@ -53,6 +54,7 @@ class CustomPlugin(Plugin): self.weight = -5 self.db_manager = DBManager('custom', init_schema) self.icon_path = UiIcons().custom + Registry().register('custom_manager', self.db_manager) self.icon = build_icon(self.icon_path) State().add_service(self.name, self.weight, is_plugin=True) State().update_pre_conditions(self.name, self.check_pre_conditions()) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index bf8bf1bd4..ea8a1bb52 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -119,6 +119,7 @@ class EditCustomForm(QtWidgets.QDialog, Ui_CustomEditDialog): self.custom_slide.theme_name = self.theme_combo_box.currentText() success = self.manager.save_object(self.custom_slide) self.media_item.auto_select_id = self.custom_slide.id + Registry().execute('custom_changed', self.custom_slide.id) return success def on_up_button_clicked(self): diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 891b8ea35..2c3e6e73c 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -112,7 +112,7 @@ class CustomMediaItem(MediaManagerItem): self.load_list(self.plugin.db_manager.get_all_objects(CustomSlide, order_by_ref=CustomSlide.title)) self.config_update() - def load_list(self, custom_slides, target_group=None): + def load_list(self, custom_slides=None, target_group=None): # Sort out what custom we want to select after loading the list. """ @@ -121,6 +121,8 @@ class CustomMediaItem(MediaManagerItem): """ self.save_auto_select_id() self.list_view.clear() + if not custom_slides: + custom_slides = self.plugin.db_manager.get_all_objects(CustomSlide, order_by_ref=CustomSlide.title) custom_slides.sort() for custom_slide in custom_slides: custom_name = QtWidgets.QListWidgetItem(custom_slide.title) @@ -201,6 +203,7 @@ class CustomMediaItem(MediaManagerItem): id_list = [(item.data(QtCore.Qt.UserRole)) for item in self.list_view.selectedIndexes()] for id in id_list: self.plugin.db_manager.delete_object(CustomSlide, id) + Registry().execute('custom_deleted', id) self.on_search_text_button_clicked() def on_focus(self): @@ -257,6 +260,7 @@ class CustomMediaItem(MediaManagerItem): credits=old_custom_slide.credits, theme_name=old_custom_slide.theme_name) self.plugin.db_manager.save_object(new_custom_slide) + Registry().execute('custom_changed', new_custom_slide.id) self.on_search_text_button_clicked() def on_search_text_button_clicked(self): diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 378d89746..49204645d 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -1128,6 +1128,7 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties): clean_song(self.manager, self.song) self.manager.save_object(self.song) self.media_item.auto_select_id = self.song.id + Registry().execute('song_changed', self.song.id) def provide_help(self): """ diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 1568b62b2..32cbe73a0 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -515,27 +515,30 @@ def strip_rtf(text, default_encoding=None): return text, default_encoding -def delete_song(song_id, song_plugin): +def delete_song(song_id, trigger_event=True): """ Deletes a song from the database. Media files associated to the song are removed prior to the deletion of the song. :param song_id: The ID of the song to delete. - :param song_plugin: The song plugin instance. + :param trigger_event: If True the song_deleted event is triggered through the registry """ save_path = '' - media_files = song_plugin.manager.get_all_objects(MediaFile, MediaFile.song_id == song_id) + songs_manager = Registry().get('songs_manager') + media_files = songs_manager.get_all_objects(MediaFile, MediaFile.song_id == song_id) for media_file in media_files: try: media_file.file_path.unlink() except OSError: log.exception('Could not remove file: {name}'.format(name=media_file.file_path)) try: - save_path = AppLocation.get_section_data_path(song_plugin.name) / 'audio' / str(song_id) + save_path = AppLocation.get_section_data_path('songs') / 'audio' / str(song_id) if save_path.exists(): save_path.rmdir() except OSError: log.exception('Could not remove directory: {path}'.format(path=save_path)) - song_plugin.manager.delete_object(Song, song_id) + songs_manager.delete_object(Song, song_id) + if trigger_event: + Registry().execute('song_deleted', song_id) def transpose_lyrics(lyrics, transpose_value): diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 5bb3a8887..4a1271d35 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -546,6 +546,7 @@ class SongMediaItem(MediaManagerItem): new_song.media_files.append(new_media_file) self.plugin.manager.save_object(new_song) new_song.init_on_load() + Registry().execute('song_changed', new_song.id) self.on_song_list_load() def generate_slide_data(self, service_item, *, item=None, context=ServiceItemContext.Service, **kwargs): diff --git a/openlp/plugins/songs/lib/openlyricsxml.py b/openlp/plugins/songs/lib/openlyricsxml.py index c81403073..6d454d732 100644 --- a/openlp/plugins/songs/lib/openlyricsxml.py +++ b/openlp/plugins/songs/lib/openlyricsxml.py @@ -229,7 +229,7 @@ class OpenLyrics(object): self.manager = manager FormattingTags.load_tags() - def song_to_xml(self, song): + def song_to_xml(self, song, version=None): """ Convert the song to OpenLyrics Format. """ @@ -258,6 +258,9 @@ class OpenLyrics(object): 'verseOrder', properties, song.verse_order.lower()) if song.ccli_number: self._add_text_to_element('ccliNo', properties, song.ccli_number) + # Add a custom version + if version: + self._add_text_to_element('version', properties, version) if song.authors_songs: authors = etree.SubElement(properties, 'authors') for author_song in song.authors_songs: @@ -376,7 +379,7 @@ class OpenLyrics(object): end_tags.reverse() return ''.join(start_tags), ''.join(end_tags) - def xml_to_song(self, xml, parse_and_temporary_save=False): + def xml_to_song(self, xml, parse_and_temporary_save=False, update_song_id=None): """ Create and save a song from OpenLyrics format xml to the database. Since we also export XML from external sources (e. g. OpenLyrics import), we cannot ensure, that it completely conforms to the OpenLyrics standard. @@ -398,7 +401,10 @@ class OpenLyrics(object): # Formatting tags are new in OpenLyrics 0.8 if float(song_xml.get('version')) > 0.7: self._process_formatting_tags(song_xml, parse_and_temporary_save) - song = Song() + if update_song_id: + song = self.manager.get_object(Song, update_song_id) + else: + song = Song() # Values will be set when cleaning the song. song.search_lyrics = '' song.verse_order = '' diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 6b4fc9881..e26a727c8 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -121,6 +121,7 @@ class SongsPlugin(Plugin): """ super(SongsPlugin, self).__init__('songs', SongMediaItem, SongsTab) self.manager = DBManager('songs', init_schema, upgrade_mod=upgrade) + Registry().register('songs_manager', self.manager) self.weight = -10 self.icon_path = UiIcons().music self.icon = build_icon(self.icon_path)