Add missing customs in service to media manager

This commit is contained in:
Jonathan Corwin 2012-12-22 22:40:58 +00:00
parent d007aae886
commit 9f5c5f7133
4 changed files with 67 additions and 10 deletions

View File

@ -125,8 +125,6 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
if not self._validate(): if not self._validate():
return False return False
sxml = CustomXMLBuilder() sxml = CustomXMLBuilder()
sxml.new_document()
sxml.add_lyrics_to_song()
for count in range(self.slideListView.count()): for count in range(self.slideListView.count()):
sxml.add_verse_to_lyrics(u'custom', unicode(count + 1), sxml.add_verse_to_lyrics(u'custom', unicode(count + 1),
unicode(self.slideListView.item(count).text())) unicode(self.slideListView.item(count).text()))

View File

@ -49,18 +49,25 @@ class CustomTab(SettingsTab):
self.displayFooterCheckBox = QtGui.QCheckBox(self.customModeGroupBox) self.displayFooterCheckBox = QtGui.QCheckBox(self.customModeGroupBox)
self.displayFooterCheckBox.setObjectName(u'displayFooterCheckBox') self.displayFooterCheckBox.setObjectName(u'displayFooterCheckBox')
self.customModeLayout.addRow(self.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.addWidget(self.customModeGroupBox)
self.leftLayout.addStretch() self.leftLayout.addStretch()
self.rightLayout.addStretch() self.rightLayout.addStretch()
QtCore.QObject.connect(self.displayFooterCheckBox, QtCore.QObject.connect(self.displayFooterCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'), QtCore.SIGNAL(u'stateChanged(int)'),
self.onDisplayFooterCheckBoxChanged) 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): def retranslateUi(self):
self.customModeGroupBox.setTitle(translate('CustomPlugin.CustomTab', self.customModeGroupBox.setTitle(translate('CustomPlugin.CustomTab',
'Custom Display')) 'Custom Display'))
self.displayFooterCheckBox.setText( self.displayFooterCheckBox.setText(
translate('CustomPlugin.CustomTab', 'Display footer')) 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): def onDisplayFooterCheckBoxChanged(self, check_state):
self.displayFooter = False self.displayFooter = False
@ -68,12 +75,24 @@ class CustomTab(SettingsTab):
if check_state == QtCore.Qt.Checked: if check_state == QtCore.Qt.Checked:
self.displayFooter = True 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): def load(self):
self.displayFooter = Settings().value( settings = Settings()
self.settingsSection + u'/display footer', settings.beginGroup(self.settingsSection)
QtCore.QVariant(True)).toBool() 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.displayFooterCheckBox.setChecked(self.displayFooter)
self.add_from_service_checkbox.setChecked(self.update_load)
settings.endGroup()
def save(self): def save(self):
Settings().setValue(self.settingsSection + u'/display footer', settings = Settings()
QtCore.QVariant(self.displayFooter)) 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()

View File

@ -62,6 +62,8 @@ class CustomXMLBuilder(object):
""" """
# Create the minidom document # Create the minidom document
self.custom_xml = Document() self.custom_xml = Document()
self.new_document()
self.add_lyrics_to_song()
def new_document(self): def new_document(self):
""" """

View File

@ -32,12 +32,12 @@ import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from sqlalchemy.sql import or_, func from sqlalchemy.sql import or_, func
from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, check_item_selected, translate, \
check_item_selected, translate, ServiceItemContext ServiceItemContext, PluginStatus
from openlp.core.lib.ui import UiStrings from openlp.core.lib.ui import UiStrings
from openlp.core.lib.settings import Settings from openlp.core.lib.settings import Settings
from openlp.plugins.custom.forms import EditCustomForm 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 from openlp.plugins.custom.lib.db import CustomSlide
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -86,6 +86,11 @@ class CustomMediaItem(MediaManagerItem):
QtCore.SIGNAL(u'custom_load_list'), self.loadList) QtCore.SIGNAL(u'custom_load_list'), self.loadList)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick) 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): def retranslateUi(self):
self.searchTextLabel.setText(u'%s:' % UiStrings().Search) self.searchTextLabel.setText(u'%s:' % UiStrings().Search)
@ -104,6 +109,7 @@ class CustomMediaItem(MediaManagerItem):
self.searchTextEdit.setCurrentSearchType(Settings().value( self.searchTextEdit.setCurrentSearchType(Settings().value(
u'%s/last search type' % self.settingsSection, u'%s/last search type' % self.settingsSection,
QtCore.QVariant(CustomSearch.Titles)).toInt()[0]) QtCore.QVariant(CustomSearch.Titles)).toInt()[0])
self.config_updated()
def loadList(self, custom_slides): def loadList(self, custom_slides):
# Sort out what custom we want to select after loading the list. # 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.CanPreview)
service_item.add_capability(ItemCapabilities.CanLoop) service_item.add_capability(ItemCapabilities.CanLoop)
service_item.add_capability(ItemCapabilities.CanSoftBreak) service_item.add_capability(ItemCapabilities.CanSoftBreak)
service_item.add_capability(ItemCapabilities.OnLoadUpdate)
customSlide = self.plugin.manager.get_object(CustomSlide, item_id) customSlide = self.plugin.manager.get_object(CustomSlide, item_id)
title = customSlide.title title = customSlide.title
credit = customSlide.credits credit = customSlide.credits
@ -256,6 +263,37 @@ class CustomMediaItem(MediaManagerItem):
elif not text: elif not text:
self.onClearTextButtonClick() 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): def onClearTextButtonClick(self):
""" """
Clear the search text. Clear the search text.