openlp/openlp/plugins/custom/lib/mediaitem.py

186 lines
8.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2009-12-31 12:52:01 +00:00
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
2010-03-21 23:58:01 +00:00
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import logging
from PyQt4 import QtCore, QtGui
2010-07-03 01:33:40 +00:00
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, \
2010-06-24 15:50:40 +00:00
Receiver, ItemCapabilities, translate, check_item_selected
2010-07-03 01:33:40 +00:00
from openlp.plugins.custom.lib import CustomXMLParser
2010-06-15 02:08:22 +00:00
from openlp.plugins.custom.lib.db import CustomSlide
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
class CustomListView(BaseListWithDnD):
def __init__(self, parent=None):
self.PluginName = u'Custom'
BaseListWithDnD.__init__(self, parent)
class CustomMediaItem(MediaManagerItem):
"""
This is the custom media manager item for Custom Slides.
"""
log.info(u'Custom Media Item loaded')
def __init__(self, parent, icon, title):
2009-10-28 01:36:24 +00:00
self.PluginNameShort = u'Custom'
2010-07-08 09:14:00 +00:00
self.pluginNameVisible = translate('CustomPlugin.MediaItem', 'Custom')
2009-09-11 04:54:22 +00:00
self.IconPath = u'custom/custom'
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = CustomListView
MediaManagerItem.__init__(self, parent, icon, title)
2010-04-06 19:16:14 +00:00
self.singleServiceItem = False
# Holds information about whether the edit is remotly triggered and
# which Custom is required.
self.remoteCustom = -1
2009-10-29 13:44:33 +00:00
def addEndHeaderBar(self):
QtCore.QObject.connect(Receiver.get_receiver(),
2010-04-16 07:31:01 +00:00
QtCore.SIGNAL(u'custom_edit'), self.onRemoteEdit)
2009-10-29 13:44:33 +00:00
QtCore.QObject.connect(Receiver.get_receiver(),
2010-04-20 22:00:55 +00:00
QtCore.SIGNAL(u'custom_edit_clear' ), self.onRemoteEditClear)
2009-10-29 13:44:33 +00:00
QtCore.QObject.connect(Receiver.get_receiver(),
2010-04-16 07:31:01 +00:00
QtCore.SIGNAL(u'custom_load_list'), self.initialise)
QtCore.QObject.connect(Receiver.get_receiver(),
2010-04-16 07:31:01 +00:00
QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick)
2009-09-26 09:11:39 +00:00
def requiredIcons(self):
MediaManagerItem.requiredIcons(self)
def initialise(self):
2010-06-15 02:08:22 +00:00
self.loadCustomListView(self.parent.custommanager.get_all_objects(
2010-07-18 23:37:24 +00:00
CustomSlide, order_by_ref=CustomSlide.title))
#Called to redisplay the song list screen edith from a search
#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.
if self.remoteTriggered == u'L':
self.onAddClick()
if self.remoteTriggered == u'P':
self.onPreviewClick()
self.onRemoteEditClear()
def loadCustomListView(self, list):
2010-07-07 16:03:30 +00:00
self.listView.clear()
2010-06-22 15:09:49 +00:00
for customSlide in list:
custom_name = QtGui.QListWidgetItem(customSlide.title)
2009-09-21 17:56:36 +00:00
custom_name.setData(
2010-06-22 15:09:49 +00:00
QtCore.Qt.UserRole, QtCore.QVariant(customSlide.id))
2010-07-07 16:03:30 +00:00
self.listView.addItem(custom_name)
2009-09-11 04:54:22 +00:00
def onNewClick(self):
self.parent.edit_custom_form.loadCustom(0)
self.parent.edit_custom_form.exec_()
self.initialise()
2009-10-29 13:44:33 +00:00
def onRemoteEditClear(self):
self.remoteTriggered = None
self.remoteCustom = -1
def onRemoteEdit(self, customid):
"""
Called by ServiceManager or SlideController by event passing
the Song Id in the payload along with an indicator to say which
type of display is required.
"""
fields = customid.split(u':')
2010-06-15 02:08:22 +00:00
valid = self.parent.custommanager.get_object(CustomSlide, fields[1])
2009-11-03 19:01:53 +00:00
if valid:
self.remoteCustom = fields[1]
self.remoteTriggered = fields[0]
self.parent.edit_custom_form.loadCustom(fields[1],
(fields[0] == u'P'))
2009-10-29 13:44:33 +00:00
self.parent.edit_custom_form.exec_()
2009-09-11 04:54:22 +00:00
def onEditClick(self):
"""
Edit a custom item
"""
2010-07-07 16:03:30 +00:00
if check_item_selected(self.listView,
2010-06-24 15:50:40 +00:00
translate('CustomPlugin.MediaItem',
2010-07-06 15:54:15 +00:00
'You haven\'t selected an item to edit.')):
2010-07-07 16:03:30 +00:00
item = self.listView.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.edit_custom_form.loadCustom(item_id, False)
self.parent.edit_custom_form.exec_()
self.initialise()
2009-09-11 04:54:22 +00:00
def onDeleteClick(self):
"""
Remove a custom item from the list and database
"""
2010-07-07 16:03:30 +00:00
if check_item_selected(self.listView,
2010-06-24 15:50:40 +00:00
translate('CustomPlugin.MediaItem',
2010-07-06 15:54:15 +00:00
'You haven\'t selected an item to delete.')):
2010-07-07 16:03:30 +00:00
row_list = [item.row() for item in self.listView.selectedIndexes()]
row_list.sort(reverse=True)
id_list = [(item.data(QtCore.Qt.UserRole)).toInt()[0]
2010-07-07 16:03:30 +00:00
for item in self.listView.selectedIndexes()]
for id in id_list:
2010-07-02 17:00:23 +00:00
self.parent.custommanager.delete_object(CustomSlide, id)
for row in row_list:
2010-07-07 16:03:30 +00:00
self.listView.takeItem(row)
def generateSlideData(self, service_item, item=None):
2010-04-28 14:17:42 +00:00
raw_slides = []
2009-05-02 11:16:08 +00:00
raw_footer = []
slide = None
theme = None
if item is None:
if self.remoteTriggered is None:
2010-07-07 16:03:30 +00:00
item = self.listView.currentItem()
if item is None:
return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
else:
item_id = self.remoteCustom
2009-10-29 13:44:33 +00:00
else:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
2010-04-03 07:10:31 +00:00
service_item.add_capability(ItemCapabilities.AllowsEdit)
service_item.add_capability(ItemCapabilities.AllowsPreview)
2010-04-08 16:00:04 +00:00
service_item.add_capability(ItemCapabilities.AllowsLoop)
2010-06-15 02:08:22 +00:00
customSlide = self.parent.custommanager.get_object(CustomSlide, item_id)
title = customSlide.title
credit = customSlide.credits
2009-10-29 13:44:33 +00:00
service_item.editId = item_id
theme = customSlide.theme_name
2010-03-09 19:43:11 +00:00
if theme:
service_item.theme = theme
2010-07-03 01:33:40 +00:00
customXML = CustomXMLParser(customSlide.text)
verseList = customXML.get_verses()
for verse in verseList:
raw_slides.append(verse[1])
service_item.title = title
for slide in raw_slides:
service_item.add_from_text(slide[:30], slide)
if QtCore.QSettings().value(self.settingsSection + u'/display footer',
2010-04-28 14:17:42 +00:00
QtCore.QVariant(True)).toBool() or credit:
2010-03-09 19:43:11 +00:00
raw_footer.append(title + u' ' + credit)
else:
raw_footer.append(u'')
service_item.raw_footer = raw_footer
2010-06-21 18:28:36 +00:00
return True