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
``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
``slidecontroller_{live|preview}_changed``
@ -83,7 +83,7 @@ class EventReceiver(QtCore.QObject):
``slidecontroller_{live|preview}_text_request``
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
``slidecontroller_{live|preview}_blank``
@ -106,23 +106,23 @@ class EventReceiver(QtCore.QObject):
``servicemanager_set_item``
Go live on a specific item, by index
``servicemanager_list_request``
Request the service list. Responds with servicemanager_list_response
containing a array of dictionaries
``maindisplay_blank``
Blank the maindisplay window
Blank the maindisplay window
``maindisplay_hide``
Hide the maindisplay window
Hide the maindisplay window
``maindisplay_show``
Return the maindisplay window
Return the maindisplay window
``maindisplay_active``
The maindisplay has been made active
``maindisplay_status_text``
Changes the bottom status bar text on the maindisplay window
@ -193,9 +193,17 @@ class EventReceiver(QtCore.QObject):
``{plugin}_add_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``
Displays an alert message
``bibles_nobook``
Attempt to find book resulted in no match

View File

@ -32,7 +32,8 @@ import os
from PyQt4 import QtCore, QtGui
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__)
@ -119,6 +120,9 @@ class MediaManagerItem(QtGui.QWidget):
self.requiredIcons()
self.setupUi()
self.retranslateUi()
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'%s_service_load' % self.parent.name.lower()),
self.serviceLoad)
def requiredIcons(self):
"""
@ -540,3 +544,11 @@ class MediaManagerItem(QtGui.QWidget):
return service_item
else:
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
AllowsAdditions = 6
NoLineBreaks = 7
OnLoadUpdate = 8
AddIfNewItem = 9
class ServiceItem(object):
"""
@ -98,6 +101,7 @@ class ServiceItem(object):
self.main = None
self.footer = None
self.bg_image_bytes = None
self._new_item()
def _new_item(self):
"""

View File

@ -223,6 +223,8 @@ class ServiceManager(QtGui.QWidget):
QtCore.SIGNAL(u'config_updated'), self.regenerateServiceItems)
QtCore.QObject.connect(Receiver.get_receiver(),
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
self.service_theme = unicode(QtCore.QSettings().value(
self.parent.serviceSettingsSection + u'/service theme',
@ -711,6 +713,9 @@ class ServiceManager(QtGui.QWidget):
serviceitem.set_from_service(item, self.servicePath)
self.validateItem(serviceitem)
self.addServiceItem(serviceitem)
if serviceitem.is_capable(ItemCapabilities.OnLoadUpdate):
Receiver.send_message(u'%s_service_load' %
serviceitem.name.lower(), serviceitem)
try:
if os.path.isfile(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
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):
"""
Add a Service item to the list
@ -817,7 +830,7 @@ class ServiceManager(QtGui.QWidget):
self.repaintServiceList(sitem + 1, 0)
self.parent.LiveController.replaceServiceManagerItem(item)
else:
#nothing selected for dnd
# nothing selected for dnd
if self.droppos == 0:
if isinstance(item, list):
for inditem in item:
@ -834,7 +847,7 @@ class ServiceManager(QtGui.QWidget):
u'order': self.droppos,
u'expanded':expand})
self.repaintServiceList(self.droppos, 0)
#if rebuilding list make sure live is fixed.
# if rebuilding list make sure live is fixed.
if rebuild:
self.parent.LiveController.replaceServiceManagerItem(item)
self.droppos = 0
@ -914,7 +927,7 @@ class ServiceManager(QtGui.QWidget):
else:
pos = parentitem.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
return pos, count
@ -940,7 +953,7 @@ class ServiceManager(QtGui.QWidget):
if link.hasText():
plugin = event.mimeData().text()
item = self.serviceManagerList.itemAt(event.pos())
#ServiceManager started the drag and drop
# ServiceManager started the drag and drop
if plugin == u'ServiceManager':
startpos, startCount = self.findServiceItem()
if item is None:
@ -952,22 +965,22 @@ class ServiceManager(QtGui.QWidget):
self.serviceItems.insert(endpos, serviceItem)
self.repaintServiceList(endpos, startCount)
else:
#we are not over anything so drop
# we are not over anything so drop
replace = False
if item is None:
self.droppos = len(self.serviceItems)
else:
#we are over somthing so lets investigate
# we are over somthing so lets investigate
pos = self._getParentItemData(item) - 1
serviceItem = self.serviceItems[pos]
if (plugin == serviceItem[u'service_item'].name and
serviceItem[u'service_item'].is_capable(
ItemCapabilities.AllowsAdditions)):
action = self.dndMenu.exec_(QtGui.QCursor.pos())
#New action required
# New action required
if action == self.newAction:
self.droppos = self._getParentItemData(item)
#Append to existing action
# Append to existing action
if action == self.addToAction:
self.droppos = self._getParentItemData(item)
item.setSelected(True)

View File

@ -324,6 +324,8 @@ class SongMediaItem(MediaManagerItem):
service_item.add_capability(ItemCapabilities.AllowsEdit)
service_item.add_capability(ItemCapabilities.AllowsPreview)
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)
service_item.theme = song.theme_name
service_item.editId = item_id
@ -371,3 +373,10 @@ class SongMediaItem(MediaManagerItem):
song.title, author_audit, song.copyright, unicode(song.ccli_number)
]
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')