From 9f5c5f7133bc7c18df10090d95cb450cf00a78e3 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 22 Dec 2012 22:40:58 +0000 Subject: [PATCH] Add missing customs in service to media manager --- openlp/plugins/custom/forms/editcustomform.py | 2 - openlp/plugins/custom/lib/customtab.py | 29 +++++++++--- openlp/plugins/custom/lib/customxmlhandler.py | 2 + openlp/plugins/custom/lib/mediaitem.py | 44 +++++++++++++++++-- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index e8a587494..6eaf6af4d 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -125,8 +125,6 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): if not self._validate(): return False sxml = CustomXMLBuilder() - sxml.new_document() - sxml.add_lyrics_to_song() for count in range(self.slideListView.count()): sxml.add_verse_to_lyrics(u'custom', unicode(count + 1), unicode(self.slideListView.item(count).text())) diff --git a/openlp/plugins/custom/lib/customtab.py b/openlp/plugins/custom/lib/customtab.py index 71066ec70..b5a894a79 100644 --- a/openlp/plugins/custom/lib/customtab.py +++ b/openlp/plugins/custom/lib/customtab.py @@ -49,18 +49,25 @@ class CustomTab(SettingsTab): self.displayFooterCheckBox = QtGui.QCheckBox(self.customModeGroupBox) self.displayFooterCheckBox.setObjectName(u'displayFooterCheckBox') self.customModeLayout.addRow(self.displayFooterCheckBox) + self.add_from_service_checkbox = QtGui.QCheckBox(self.customModeGroupBox) + self.add_from_service_checkbox.setObjectName(u'add_from_service_checkbox') + self.customModeLayout.addRow(self.add_from_service_checkbox) self.leftLayout.addWidget(self.customModeGroupBox) self.leftLayout.addStretch() self.rightLayout.addStretch() QtCore.QObject.connect(self.displayFooterCheckBox, QtCore.SIGNAL(u'stateChanged(int)'), self.onDisplayFooterCheckBoxChanged) + QtCore.QObject.connect(self.add_from_service_checkbox, + QtCore.SIGNAL(u'stateChanged(int)'), self.on_add_from_service_check_box_changed) def retranslateUi(self): self.customModeGroupBox.setTitle(translate('CustomPlugin.CustomTab', 'Custom Display')) self.displayFooterCheckBox.setText( translate('CustomPlugin.CustomTab', 'Display footer')) + self.add_from_service_checkbox.setText(translate('CustomPlugin.CustomTab', + 'Import missing custom slides from service files')) def onDisplayFooterCheckBoxChanged(self, check_state): self.displayFooter = False @@ -68,12 +75,24 @@ class CustomTab(SettingsTab): if check_state == QtCore.Qt.Checked: self.displayFooter = True + def on_add_from_service_check_box_changed(self, check_state): + self.update_load = False + # we have a set value convert to True/False + if check_state == QtCore.Qt.Checked: + self.update_load = True + def load(self): - self.displayFooter = Settings().value( - self.settingsSection + u'/display footer', - QtCore.QVariant(True)).toBool() + settings = Settings() + settings.beginGroup(self.settingsSection) + self.displayFooter = settings.value(u'/display footer', QtCore.QVariant(True)).toBool() + self.update_load = settings.value(u'add custom from service', QtCore.QVariant(True)).toBool() self.displayFooterCheckBox.setChecked(self.displayFooter) + self.add_from_service_checkbox.setChecked(self.update_load) + settings.endGroup() def save(self): - Settings().setValue(self.settingsSection + u'/display footer', - QtCore.QVariant(self.displayFooter)) + settings = Settings() + settings.beginGroup(self.settingsSection) + settings.setValue(self.settingsSection + u'/display footer', QtCore.QVariant(self.displayFooter)) + settings.setValue(u'add custom from service', QtCore.QVariant(self.update_load)) + settings.endGroup() diff --git a/openlp/plugins/custom/lib/customxmlhandler.py b/openlp/plugins/custom/lib/customxmlhandler.py index f0904dfcd..bd321eb93 100644 --- a/openlp/plugins/custom/lib/customxmlhandler.py +++ b/openlp/plugins/custom/lib/customxmlhandler.py @@ -62,6 +62,8 @@ class CustomXMLBuilder(object): """ # Create the minidom document self.custom_xml = Document() + self.new_document() + self.add_lyrics_to_song() def new_document(self): """ diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 77b1d8c0b..04ec2ce97 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -32,12 +32,12 @@ import logging from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_, func -from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ - check_item_selected, translate, ServiceItemContext +from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, check_item_selected, translate, \ + ServiceItemContext, PluginStatus from openlp.core.lib.ui import UiStrings from openlp.core.lib.settings import Settings from openlp.plugins.custom.forms import EditCustomForm -from openlp.plugins.custom.lib import CustomXMLParser +from openlp.plugins.custom.lib import CustomXMLParser, CustomXMLBuilder from openlp.plugins.custom.lib.db import CustomSlide log = logging.getLogger(__name__) @@ -86,6 +86,11 @@ class CustomMediaItem(MediaManagerItem): QtCore.SIGNAL(u'custom_load_list'), self.loadList) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.config_updated) + + def config_updated(self): + self.add_custom_from_service = Settings().value( + self.settingsSection + u'/add custom from service', QtCore.QVariant(u'True')).toBool() def retranslateUi(self): self.searchTextLabel.setText(u'%s:' % UiStrings().Search) @@ -104,6 +109,7 @@ class CustomMediaItem(MediaManagerItem): self.searchTextEdit.setCurrentSearchType(Settings().value( u'%s/last search type' % self.settingsSection, QtCore.QVariant(CustomSearch.Titles)).toInt()[0]) + self.config_updated() def loadList(self, custom_slides): # Sort out what custom we want to select after loading the list. @@ -201,6 +207,7 @@ class CustomMediaItem(MediaManagerItem): service_item.add_capability(ItemCapabilities.CanPreview) service_item.add_capability(ItemCapabilities.CanLoop) service_item.add_capability(ItemCapabilities.CanSoftBreak) + service_item.add_capability(ItemCapabilities.OnLoadUpdate) customSlide = self.plugin.manager.get_object(CustomSlide, item_id) title = customSlide.title credit = customSlide.credits @@ -256,6 +263,37 @@ class CustomMediaItem(MediaManagerItem): elif not text: self.onClearTextButtonClick() + def serviceLoad(self, item): + """ + Triggered by a song being loaded by the service manager. + """ + log.debug(u'serviceLoad') + if not self.add_custom_from_service: + return + if self.plugin.status != PluginStatus.Active: + return + custom = self.plugin.manager.get_object_filtered(CustomSlide, CustomSlide.title == item.title) + if custom: + return + custom = CustomSlide() + custom.title = item.title + custom.theme_name = item.theme + footer = u' '.join(item.raw_footer) + if footer: + if footer.startswith(item.title): + custom.credits = footer[len(item.title) + 1:] + else: + custom.credits = footer + else: + custom.credits = u'' + custom_xml = CustomXMLBuilder() + for (idx, slide) in enumerate(item._raw_frames): + custom_xml.add_verse_to_lyrics(u'custom', unicode(idx + 1), slide['raw_slide']) + custom.text = unicode(custom_xml.extract_xml(), u'utf-8') + self.plugin.manager.save_object(custom) + self.onSearchTextButtonClicked() + Receiver.send_message(u'service_item_update', u'%s:%s:%s' % (custom.id, item._uuid, False)) + def onClearTextButtonClick(self): """ Clear the search text.