Allow Service Item to be updated from Song Plugin on Edit

bzr-revno: 1072
This commit is contained in:
Tim Bentley 2010-10-07 05:47:43 +01:00
commit c262e5e07e
6 changed files with 176 additions and 32 deletions

View File

@ -193,6 +193,14 @@ class EventReceiver(QtCore.QObject):
``{plugin}_add_service_item`` ``{plugin}_add_service_item``
Ask the plugin to push the selected items to the service item Ask the plugin to push the selected items to the service item
``{plugin}_service_load``
Ask the plugin to process an individual service item after it has been
loaded
``service_item_update``
Passes back to the service manager the service item after it has been
processed by the plugin
``alerts_text`` ``alerts_text``
Displays an alert message Displays an alert message

View File

@ -33,7 +33,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import context_menu_action, context_menu_separator, \ from openlp.core.lib import context_menu_action, context_menu_separator, \
SettingsManager, OpenLPToolbar, ServiceItem, StringContent, build_icon, \ SettingsManager, OpenLPToolbar, ServiceItem, StringContent, build_icon, \
translate translate, Receiver
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -115,6 +115,9 @@ class MediaManagerItem(QtGui.QWidget):
self.requiredIcons() self.requiredIcons()
self.setupUi() self.setupUi()
self.retranslateUi() self.retranslateUi()
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'%s_service_load' % self.parent.name.lower()),
self.serviceLoad)
def requiredIcons(self): def requiredIcons(self):
""" """
@ -531,3 +534,11 @@ class MediaManagerItem(QtGui.QWidget):
return service_item return service_item
else: else:
return None return None
def serviceLoad(self, message):
"""
Method to add processing when a service has been loaded and
individual service items need to be processed by the plugins
"""
pass

View File

@ -58,6 +58,9 @@ class ItemCapabilities(object):
AllowsLoop = 5 AllowsLoop = 5
AllowsAdditions = 6 AllowsAdditions = 6
NoLineBreaks = 7 NoLineBreaks = 7
OnLoadUpdate = 8
AddIfNewItem = 9
class ServiceItem(object): class ServiceItem(object):
""" """
@ -98,6 +101,9 @@ class ServiceItem(object):
self.main = None self.main = None
self.footer = None self.footer = None
self.bg_image_bytes = None self.bg_image_bytes = None
self._new_item()
self.search_string = u''
self.data_string = u''
def _new_item(self): def _new_item(self):
""" """
@ -255,7 +261,9 @@ class ServiceItem(object):
u'audit':self.audit, u'audit':self.audit,
u'notes':self.notes, u'notes':self.notes,
u'from_plugin':self.from_plugin, u'from_plugin':self.from_plugin,
u'capabilities':self.capabilities u'capabilities':self.capabilities,
u'search':self.search_string,
u'data':self.data_string
} }
service_data = [] service_data = []
if self.service_item_type == ServiceItemType.Text: if self.service_item_type == ServiceItemType.Text:
@ -293,6 +301,10 @@ class ServiceItem(object):
self.notes = header[u'notes'] self.notes = header[u'notes']
self.from_plugin = header[u'from_plugin'] self.from_plugin = header[u'from_plugin']
self.capabilities = header[u'capabilities'] self.capabilities = header[u'capabilities']
# Added later so may not be present in older services.
if u'search' in header:
self.search_string = header[u'search']
self.data_string = header[u'data']
if self.service_item_type == ServiceItemType.Text: if self.service_item_type == ServiceItemType.Text:
for slide in serviceitem[u'serviceitem'][u'data']: for slide in serviceitem[u'serviceitem'][u'data']:
self._raw_frames.append(slide) self._raw_frames.append(slide)

View File

@ -223,6 +223,8 @@ class ServiceManager(QtGui.QWidget):
QtCore.SIGNAL(u'config_updated'), self.regenerateServiceItems) QtCore.SIGNAL(u'config_updated'), self.regenerateServiceItems)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'theme_update_global'), self.themeChange) QtCore.SIGNAL(u'theme_update_global'), self.themeChange)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'service_item_update'), self.serviceItemUpdate)
# Last little bits of setting up # Last little bits of setting up
self.service_theme = unicode(QtCore.QSettings().value( self.service_theme = unicode(QtCore.QSettings().value(
self.parent.serviceSettingsSection + u'/service theme', self.parent.serviceSettingsSection + u'/service theme',
@ -711,6 +713,9 @@ class ServiceManager(QtGui.QWidget):
serviceitem.set_from_service(item, self.servicePath) serviceitem.set_from_service(item, self.servicePath)
self.validateItem(serviceitem) self.validateItem(serviceitem)
self.addServiceItem(serviceitem) self.addServiceItem(serviceitem)
if serviceitem.is_capable(ItemCapabilities.OnLoadUpdate):
Receiver.send_message(u'%s_service_load' %
serviceitem.name.lower(), serviceitem)
try: try:
if os.path.isfile(p_file): if os.path.isfile(p_file):
os.remove(p_file) os.remove(p_file)
@ -801,7 +806,31 @@ class ServiceManager(QtGui.QWidget):
# does not impact the saved song so True may also be valid # does not impact the saved song so True may also be valid
self.parent.serviceChanged(False, self.serviceName) self.parent.serviceChanged(False, self.serviceName)
def addServiceItem(self, item, rebuild=False, expand=True, replace=False): def serviceItemUpdate(self, message):
"""
Triggered from plugins to update service items.
"""
editId, uuid = message.split(u':')
for item in self.serviceItems:
if item[u'service_item']._uuid == uuid:
item[u'service_item'].editId = editId
def replaceServiceItem(self, newItem):
"""
Using the service item passed replace the one with the same edit id
if found.
"""
newItem.render()
for itemcount, item in enumerate(self.serviceItems):
if item[u'service_item'].editId == newItem.editId and \
item[u'service_item'].name == newItem.name:
newItem.merge(item[u'service_item'])
item[u'service_item'] = newItem
self.repaintServiceList(itemcount + 1, 0)
self.parent.LiveController.replaceServiceManagerItem(newItem)
self.parent.serviceChanged(False, self.serviceName)
def addServiceItem(self, item, rebuild=False, expand=False, replace=False):
""" """
Add a Service item to the list Add a Service item to the list

View File

@ -60,6 +60,7 @@ class SongMediaItem(MediaManagerItem):
# Holds information about whether the edit is remotly triggered and # Holds information about whether the edit is remotly triggered and
# which Song is required. # which Song is required.
self.remoteSong = -1 self.remoteSong = -1
self.editItem = None
def requiredIcons(self): def requiredIcons(self):
MediaManagerItem.requiredIcons(self) MediaManagerItem.requiredIcons(self)
@ -123,7 +124,7 @@ class SongMediaItem(MediaManagerItem):
QtCore.SIGNAL(u'textChanged(const QString&)'), QtCore.SIGNAL(u'textChanged(const QString&)'),
self.onSearchTextEditChanged) self.onSearchTextEditChanged)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'songs_load_list'), self.onSearchTextButtonClick) QtCore.SIGNAL(u'songs_load_list'), self.onSongListLoad)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'config_updated'), self.configUpdated) QtCore.SIGNAL(u'config_updated'), self.configUpdated)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
@ -137,6 +138,12 @@ class SongMediaItem(MediaManagerItem):
self.searchAsYouType = QtCore.QSettings().value( self.searchAsYouType = QtCore.QSettings().value(
self.settingsSection + u'/search as type', self.settingsSection + u'/search as type',
QtCore.QVariant(u'False')).toBool() QtCore.QVariant(u'False')).toBool()
self.updateServiceOnEdit = QtCore.QSettings().value(
self.settingsSection + u'/update service on edit',
QtCore.QVariant(u'False')).toBool()
self.AddSongFromServide = QtCore.QSettings().value(
self.settingsSection + u'/add song from service',
QtCore.QVariant(u'True')).toBool()
def retranslateUi(self): def retranslateUi(self):
self.SearchTextLabel.setText( self.SearchTextLabel.setText(
@ -179,14 +186,26 @@ class SongMediaItem(MediaManagerItem):
Author.display_name.like(u'%' + search_keywords + u'%'), Author.display_name.like(u'%' + search_keywords + u'%'),
Author.display_name.asc()) Author.display_name.asc())
self.displayResultsAuthor(search_results) self.displayResultsAuthor(search_results)
#Called to redisplay the song list screen edith from a search
def onSongListLoad(self):
"""
Handle the exit from the edit dialog and trigger remote updates
of songs
"""
# Called to redisplay the song list screen edit from a search
# or from the exit of the Song edit dialog. If remote editing is active # or from the exit of the Song edit dialog. If remote editing is active
# Trigger it and clean up so it will not update again. # Trigger it and clean up so it will not update again.
if self.remoteTriggered == u'L': if self.remoteTriggered == u'L':
self.onAddClick() self.onAddClick()
if self.remoteTriggered == u'P': if self.remoteTriggered == u'P':
self.onPreviewClick() self.onPreviewClick()
# Push edits to the service manager to update items
if self.editItem and self.updateServiceOnEdit and \
not self.remoteTriggered:
item = self.buildServiceItem(self.editItem)
self.parent.serviceManager.replaceServiceItem(item)
self.onRemoteEditClear() self.onRemoteEditClear()
self.onSearchTextButtonClick()
def displayResultsSong(self, searchresults): def displayResultsSong(self, searchresults):
log.debug(u'display results Song') log.debug(u'display results Song')
@ -271,8 +290,8 @@ class SongMediaItem(MediaManagerItem):
if check_item_selected(self.listView, if check_item_selected(self.listView,
translate('SongsPlugin.MediaItem', translate('SongsPlugin.MediaItem',
'You must select an item to edit.')): 'You must select an item to edit.')):
item = self.listView.currentItem() self.editItem = self.listView.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (self.editItem.data(QtCore.Qt.UserRole)).toInt()[0]
self.edit_song_form.loadSong(item_id, False) self.edit_song_form.loadSong(item_id, False)
self.edit_song_form.exec_() self.edit_song_form.exec_()
@ -322,6 +341,8 @@ class SongMediaItem(MediaManagerItem):
service_item.add_capability(ItemCapabilities.AllowsEdit) service_item.add_capability(ItemCapabilities.AllowsEdit)
service_item.add_capability(ItemCapabilities.AllowsPreview) service_item.add_capability(ItemCapabilities.AllowsPreview)
service_item.add_capability(ItemCapabilities.AllowsLoop) service_item.add_capability(ItemCapabilities.AllowsLoop)
service_item.add_capability(ItemCapabilities.OnLoadUpdate)
service_item.add_capability(ItemCapabilities.AddIfNewItem)
song = self.parent.manager.get_object(Song, item_id) song = self.parent.manager.get_object(Song, item_id)
service_item.theme = song.theme_name service_item.theme = song.theme_name
service_item.editId = item_id service_item.editId = item_id
@ -368,4 +389,31 @@ class SongMediaItem(MediaManagerItem):
service_item.audit = [ service_item.audit = [
song.title, author_audit, song.copyright, unicode(song.ccli_number) song.title, author_audit, song.copyright, unicode(song.ccli_number)
] ]
service_item.data_string = {u'title':song.search_title, u'authors':author_list}
return True return True
def serviceLoad(self, item):
"""
Triggered by a song being loaded by the service item
"""
if item.data_string:
search_results = self.parent.manager.get_all_objects(Song,
Song.search_title.like(u'%' +
item.data_string[u'title'].split(u'@')[0] + u'%'),
Song.search_title.asc())
author_list = item.data_string[u'authors'].split(u',')
editId = 0
uuid = 0
if search_results:
for song in search_results:
count = 0
for author in song.authors:
if author.display_name in author_list:
count += 1
if count == len(author_list):
editId = song.id
uuid = item._uuid
if editId != 0:
Receiver.send_message(u'service_item_update',
u'%s:%s' %(editId, uuid))

View File

@ -51,8 +51,14 @@ class SongsTab(SettingsTab):
self.SearchAsTypeCheckBox.setObjectName(u'SearchAsTypeCheckBox') self.SearchAsTypeCheckBox.setObjectName(u'SearchAsTypeCheckBox')
self.SongsModeLayout.addWidget(self.SearchAsTypeCheckBox) self.SongsModeLayout.addWidget(self.SearchAsTypeCheckBox)
self.SongBarActiveCheckBox = QtGui.QCheckBox(self.SongsModeGroupBox) self.SongBarActiveCheckBox = QtGui.QCheckBox(self.SongsModeGroupBox)
self.SongBarActiveCheckBox.setObjectName(u'SearchAsTypeCheckBox') self.SongBarActiveCheckBox.setObjectName(u'SongBarActiveCheckBox')
self.SongsModeLayout.addWidget(self.SongBarActiveCheckBox) self.SongsModeLayout.addWidget(self.SongBarActiveCheckBox)
self.SongUpdateOnEditCheckBox = QtGui.QCheckBox(self.SongsModeGroupBox)
self.SongUpdateOnEditCheckBox.setObjectName(u'SongUpdateOnEditCheckBox')
self.SongsModeLayout.addWidget(self.SongUpdateOnEditCheckBox)
self.SongAddFromServiceCheckBox = QtGui.QCheckBox(self.SongsModeGroupBox)
self.SongAddFromServiceCheckBox.setObjectName(u'SongAddFromServiceCheckBox')
self.SongsModeLayout.addWidget(self.SongAddFromServiceCheckBox)
self.SongsLayout.setWidget( self.SongsLayout.setWidget(
0, QtGui.QFormLayout.LabelRole, self.SongsModeGroupBox) 0, QtGui.QFormLayout.LabelRole, self.SongsModeGroupBox)
QtCore.QObject.connect(self.SearchAsTypeCheckBox, QtCore.QObject.connect(self.SearchAsTypeCheckBox,
@ -60,7 +66,13 @@ class SongsTab(SettingsTab):
self.onSearchAsTypeCheckBoxChanged) self.onSearchAsTypeCheckBoxChanged)
QtCore.QObject.connect(self.SongBarActiveCheckBox, QtCore.QObject.connect(self.SongBarActiveCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'), QtCore.SIGNAL(u'stateChanged(int)'),
self.SongBarActiveCheckBoxChanged) self.onSongBarActiveCheckBoxChanged)
QtCore.QObject.connect(self.SongUpdateOnEditCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onSongUpdateOnEditCheckBoxChanged)
QtCore.QObject.connect(self.SongBarActiveCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onSongAddFromServiceCheckBoxChanged)
def retranslateUi(self): def retranslateUi(self):
self.SongsModeGroupBox.setTitle( self.SongsModeGroupBox.setTitle(
@ -69,6 +81,10 @@ class SongsTab(SettingsTab):
translate('SongsPlugin.SongsTab', 'Enable search as you type')) translate('SongsPlugin.SongsTab', 'Enable search as you type'))
self.SongBarActiveCheckBox.setText(translate('SongsPlugin.SongsTab', self.SongBarActiveCheckBox.setText(translate('SongsPlugin.SongsTab',
'Display verses on live tool bar')) 'Display verses on live tool bar'))
self.SongUpdateOnEditCheckBox.setText(
translate('SongsPlugin.SongsTab', 'Update service from song edit'))
self.SongAddFromServiceCheckBox.setText(translate('SongsPlugin.SongsTab',
'Add missing songs when opening service'))
def onSearchAsTypeCheckBoxChanged(self, check_state): def onSearchAsTypeCheckBoxChanged(self, check_state):
self.song_search = False self.song_search = False
@ -76,12 +92,24 @@ class SongsTab(SettingsTab):
if check_state == QtCore.Qt.Checked: if check_state == QtCore.Qt.Checked:
self.song_search = True self.song_search = True
def SongBarActiveCheckBoxChanged(self, check_state): def onSongBarActiveCheckBoxChanged(self, check_state):
self.song_bar = False self.song_bar = False
# we have a set value convert to True/False # we have a set value convert to True/False
if check_state == QtCore.Qt.Checked: if check_state == QtCore.Qt.Checked:
self.song_bar = True self.song_bar = True
def onSongUpdateOnEditCheckBoxChanged(self, check_state):
self.update_edit = False
# we have a set value convert to True/False
if check_state == QtCore.Qt.Checked:
self.update_edit = True
def onSongAddFromServiceCheckBoxChanged(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):
settings = QtCore.QSettings() settings = QtCore.QSettings()
settings.beginGroup(self.settingsSection) settings.beginGroup(self.settingsSection)
@ -89,8 +117,14 @@ class SongsTab(SettingsTab):
u'search as type', QtCore.QVariant(False)).toBool() u'search as type', QtCore.QVariant(False)).toBool()
self.song_bar = settings.value( self.song_bar = settings.value(
u'display songbar', QtCore.QVariant(True)).toBool() u'display songbar', QtCore.QVariant(True)).toBool()
self.update_edit = settings.value(
u'update service on edit', QtCore.QVariant(False)).toBool()
self.update_load = settings.value(
u'add song from service', QtCore.QVariant(True)).toBool()
self.SearchAsTypeCheckBox.setChecked(self.song_search) self.SearchAsTypeCheckBox.setChecked(self.song_search)
self.SongBarActiveCheckBox.setChecked(self.song_bar) self.SongBarActiveCheckBox.setChecked(self.song_bar)
self.SongUpdateOnEditCheckBox.setChecked(self.update_edit)
self.SongAddFromServiceCheckBox.setChecked(self.update_load)
settings.endGroup() settings.endGroup()
def save(self): def save(self):
@ -98,4 +132,6 @@ class SongsTab(SettingsTab):
settings.beginGroup(self.settingsSection) settings.beginGroup(self.settingsSection)
settings.setValue(u'search as type', QtCore.QVariant(self.song_search)) settings.setValue(u'search as type', QtCore.QVariant(self.song_search))
settings.setValue(u'display songbar', QtCore.QVariant(self.song_bar)) settings.setValue(u'display songbar', QtCore.QVariant(self.song_bar))
settings.setValue(u'update service on edit', QtCore.QVariant(self.update_edit))
settings.setValue(u'add song from service', QtCore.QVariant(self.update_load))
settings.endGroup() settings.endGroup()