Update service items on service load

This commit is contained in:
Tim Bentley 2010-09-30 06:12:06 +01:00
commit bdc924093e
5 changed files with 63 additions and 17 deletions

View File

@ -75,7 +75,7 @@ class EventReceiver(QtCore.QObject):
Broadcasts that an item has been made live/previewed Broadcasts that an item has been made live/previewed
``slidecontroller_{live|preview}_change`` ``slidecontroller_{live|preview}_change``
Informs the slidecontroller that a slide change has occurred and to Informs the slidecontroller that a slide change has occurred and to
update itself update itself
``slidecontroller_{live|preview}_changed`` ``slidecontroller_{live|preview}_changed``
@ -83,7 +83,7 @@ class EventReceiver(QtCore.QObject):
``slidecontroller_{live|preview}_text_request`` ``slidecontroller_{live|preview}_text_request``
Request the text for the current item in the controller Request the text for the current item in the controller
Returns a slidecontroller_{live|preview}_text_response with an Returns a slidecontroller_{live|preview}_text_response with an
array of dictionaries with the tag and verse text array of dictionaries with the tag and verse text
``slidecontroller_{live|preview}_blank`` ``slidecontroller_{live|preview}_blank``
@ -106,23 +106,23 @@ class EventReceiver(QtCore.QObject):
``servicemanager_set_item`` ``servicemanager_set_item``
Go live on a specific item, by index Go live on a specific item, by index
``servicemanager_list_request`` ``servicemanager_list_request``
Request the service list. Responds with servicemanager_list_response Request the service list. Responds with servicemanager_list_response
containing a array of dictionaries containing a array of dictionaries
``maindisplay_blank`` ``maindisplay_blank``
Blank the maindisplay window Blank the maindisplay window
``maindisplay_hide`` ``maindisplay_hide``
Hide the maindisplay window Hide the maindisplay window
``maindisplay_show`` ``maindisplay_show``
Return the maindisplay window Return the maindisplay window
``maindisplay_active`` ``maindisplay_active``
The maindisplay has been made active The maindisplay has been made active
``maindisplay_status_text`` ``maindisplay_status_text``
Changes the bottom status bar text on the maindisplay window Changes the bottom status bar text on the maindisplay window
@ -193,9 +193,17 @@ 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
``bibles_nobook`` ``bibles_nobook``
Attempt to find book resulted in no match Attempt to find book resulted in no match

View File

@ -32,7 +32,8 @@ import os
from PyQt4 import QtCore, QtGui 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, build_icon, translate SettingsManager, OpenLPToolbar, ServiceItem, build_icon, translate, \
Receiver
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -119,6 +120,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):
""" """
@ -540,3 +544,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,7 @@ 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()
def _new_item(self): def _new_item(self):
""" """

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,6 +806,14 @@ 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 serviceItemUpdate(self, message):
"""
Triggered from plugins to update service items.
"""
print message
for item in self.serviceItems:
print item[u'service_item'].title, item[u'service_item']._uuid
def addServiceItem(self, item, rebuild=False, expand=True, replace=False): def addServiceItem(self, item, rebuild=False, expand=True, replace=False):
""" """
Add a Service item to the list Add a Service item to the list
@ -817,7 +830,7 @@ class ServiceManager(QtGui.QWidget):
self.repaintServiceList(sitem + 1, 0) self.repaintServiceList(sitem + 1, 0)
self.parent.LiveController.replaceServiceManagerItem(item) self.parent.LiveController.replaceServiceManagerItem(item)
else: else:
#nothing selected for dnd # nothing selected for dnd
if self.droppos == 0: if self.droppos == 0:
if isinstance(item, list): if isinstance(item, list):
for inditem in item: for inditem in item:
@ -834,7 +847,7 @@ class ServiceManager(QtGui.QWidget):
u'order': self.droppos, u'order': self.droppos,
u'expanded':expand}) u'expanded':expand})
self.repaintServiceList(self.droppos, 0) self.repaintServiceList(self.droppos, 0)
#if rebuilding list make sure live is fixed. # if rebuilding list make sure live is fixed.
if rebuild: if rebuild:
self.parent.LiveController.replaceServiceManagerItem(item) self.parent.LiveController.replaceServiceManagerItem(item)
self.droppos = 0 self.droppos = 0
@ -914,7 +927,7 @@ class ServiceManager(QtGui.QWidget):
else: else:
pos = parentitem.data(0, QtCore.Qt.UserRole).toInt()[0] pos = parentitem.data(0, QtCore.Qt.UserRole).toInt()[0]
count = item.data(0, QtCore.Qt.UserRole).toInt()[0] count = item.data(0, QtCore.Qt.UserRole).toInt()[0]
#adjust for zero based arrays # adjust for zero based arrays
pos = pos - 1 pos = pos - 1
return pos, count return pos, count
@ -940,7 +953,7 @@ class ServiceManager(QtGui.QWidget):
if link.hasText(): if link.hasText():
plugin = event.mimeData().text() plugin = event.mimeData().text()
item = self.serviceManagerList.itemAt(event.pos()) item = self.serviceManagerList.itemAt(event.pos())
#ServiceManager started the drag and drop # ServiceManager started the drag and drop
if plugin == u'ServiceManager': if plugin == u'ServiceManager':
startpos, startCount = self.findServiceItem() startpos, startCount = self.findServiceItem()
if item is None: if item is None:
@ -952,22 +965,22 @@ class ServiceManager(QtGui.QWidget):
self.serviceItems.insert(endpos, serviceItem) self.serviceItems.insert(endpos, serviceItem)
self.repaintServiceList(endpos, startCount) self.repaintServiceList(endpos, startCount)
else: else:
#we are not over anything so drop # we are not over anything so drop
replace = False replace = False
if item is None: if item is None:
self.droppos = len(self.serviceItems) self.droppos = len(self.serviceItems)
else: else:
#we are over somthing so lets investigate # we are over somthing so lets investigate
pos = self._getParentItemData(item) - 1 pos = self._getParentItemData(item) - 1
serviceItem = self.serviceItems[pos] serviceItem = self.serviceItems[pos]
if (plugin == serviceItem[u'service_item'].name and if (plugin == serviceItem[u'service_item'].name and
serviceItem[u'service_item'].is_capable( serviceItem[u'service_item'].is_capable(
ItemCapabilities.AllowsAdditions)): ItemCapabilities.AllowsAdditions)):
action = self.dndMenu.exec_(QtGui.QCursor.pos()) action = self.dndMenu.exec_(QtGui.QCursor.pos())
#New action required # New action required
if action == self.newAction: if action == self.newAction:
self.droppos = self._getParentItemData(item) self.droppos = self._getParentItemData(item)
#Append to existing action # Append to existing action
if action == self.addToAction: if action == self.addToAction:
self.droppos = self._getParentItemData(item) self.droppos = self._getParentItemData(item)
item.setSelected(True) item.setSelected(True)

View File

@ -324,6 +324,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
@ -371,3 +373,10 @@ class SongMediaItem(MediaManagerItem):
song.title, author_audit, song.copyright, unicode(song.ccli_number) song.title, author_audit, song.copyright, unicode(song.ccli_number)
] ]
return True return True
def serviceLoad(self, item):
"""
Triggered by a song being loaded by the service item
"""
Receiver.send_message(u'service_item_update', u'0:0')