2009-03-13 06:13:11 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2009 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten #
|
|
|
|
# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
2009-03-13 06:13:11 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2009-09-25 00:43:42 +00:00
|
|
|
from openlp.core.lib import MediaManagerItem, SongXMLParser, BaseListWithDnD
|
2009-03-13 06:13:11 +00:00
|
|
|
|
2009-08-15 11:02:24 +00:00
|
|
|
class CustomListView(BaseListWithDnD):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
self.PluginName = u'Custom'
|
|
|
|
BaseListWithDnD.__init__(self, parent)
|
2009-05-12 21:06:35 +00:00
|
|
|
|
2009-03-13 06:13:11 +00:00
|
|
|
class CustomMediaItem(MediaManagerItem):
|
|
|
|
"""
|
|
|
|
This is the custom media manager item for Custom Slides.
|
|
|
|
"""
|
|
|
|
global log
|
2009-03-15 19:31:33 +00:00
|
|
|
log=logging.getLogger(u'CustomMediaItem')
|
|
|
|
log.info(u'Custom Media Item loaded')
|
2009-03-13 06:13:11 +00:00
|
|
|
|
|
|
|
def __init__(self, parent, icon, title):
|
2009-06-26 18:54:05 +00:00
|
|
|
self.TranslationContext = u'CustomPlugin'
|
|
|
|
self.PluginTextShort = u'Custom'
|
|
|
|
self.ConfigSection = u'custom'
|
2009-09-11 04:54:22 +00:00
|
|
|
self.IconPath = u'custom/custom'
|
|
|
|
self.hasFileIcon = False
|
|
|
|
self.hasNewIcon = True
|
|
|
|
self.hasEditIcon = True
|
|
|
|
# this next is a class, not an instance of a class - it will
|
|
|
|
# be instanced by the base MediaManagerItem
|
|
|
|
self.ListViewWithDnD_class = CustomListView
|
|
|
|
self.ServiceItemIconName = u':/custom/custom_image.png'
|
|
|
|
self.servicePath = None
|
2009-03-13 06:13:11 +00:00
|
|
|
MediaManagerItem.__init__(self, parent, icon, title)
|
2009-05-02 11:16:08 +00:00
|
|
|
self.parent = parent
|
2009-03-13 06:13:11 +00:00
|
|
|
|
|
|
|
def initialise(self):
|
2009-08-15 11:02:24 +00:00
|
|
|
self.loadCustomListView(self.parent.custommanager.get_all_slides())
|
2009-04-25 06:11:15 +00:00
|
|
|
|
2009-08-15 11:02:24 +00:00
|
|
|
def loadCustomListView(self, list):
|
2009-06-27 19:55:55 +00:00
|
|
|
self.ListView.clear()
|
2009-03-13 06:13:11 +00:00
|
|
|
for CustomSlide in list:
|
2009-06-17 05:11:16 +00:00
|
|
|
custom_name = QtGui.QListWidgetItem(CustomSlide.title)
|
2009-09-21 17:56:36 +00:00
|
|
|
custom_name.setData(
|
|
|
|
QtCore.Qt.UserRole, QtCore.QVariant(CustomSlide.id))
|
2009-06-27 19:55:55 +00:00
|
|
|
self.ListView.addItem(custom_name)
|
2009-03-13 06:13:11 +00:00
|
|
|
|
2009-09-11 04:54:22 +00:00
|
|
|
def onNewClick(self):
|
2009-04-25 06:11:15 +00:00
|
|
|
self.parent.edit_custom_form.loadCustom(0)
|
2009-03-13 06:13:11 +00:00
|
|
|
self.parent.edit_custom_form.exec_()
|
2009-04-25 06:11:15 +00:00
|
|
|
self.initialise()
|
2009-03-13 06:13:11 +00:00
|
|
|
|
2009-09-11 04:54:22 +00:00
|
|
|
def onEditClick(self):
|
2009-06-27 19:55:55 +00:00
|
|
|
item = self.ListView.currentItem()
|
2009-06-19 18:41:38 +00:00
|
|
|
if item is not None:
|
|
|
|
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
self.parent.edit_custom_form.loadCustom(item_id)
|
|
|
|
self.parent.edit_custom_form.exec_()
|
|
|
|
self.initialise()
|
2009-03-13 06:13:11 +00:00
|
|
|
|
2009-09-11 04:54:22 +00:00
|
|
|
def onDeleteClick(self):
|
2009-06-27 19:55:55 +00:00
|
|
|
item = self.ListView.currentItem()
|
2009-06-19 18:41:38 +00:00
|
|
|
if item is not None:
|
|
|
|
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
self.parent.custommanager.delete_custom(item_id)
|
2009-06-27 19:55:55 +00:00
|
|
|
row = self.ListView.row(item)
|
|
|
|
self.ListView.takeItem(row)
|
2009-03-13 06:13:11 +00:00
|
|
|
|
2009-05-02 11:16:08 +00:00
|
|
|
def generateSlideData(self, service_item):
|
|
|
|
raw_slides =[]
|
|
|
|
raw_footer = []
|
2009-04-25 06:11:15 +00:00
|
|
|
slide = None
|
2009-04-29 19:21:18 +00:00
|
|
|
theme = None
|
2009-06-27 19:55:55 +00:00
|
|
|
item = self.ListView.currentItem()
|
2009-08-31 21:53:35 +00:00
|
|
|
if item is None:
|
|
|
|
return False
|
2009-06-17 05:11:16 +00:00
|
|
|
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
customSlide = self.parent.custommanager.get_custom(item_id)
|
|
|
|
title = customSlide.title
|
|
|
|
credit = customSlide.credits
|
|
|
|
theme = customSlide.theme_name
|
|
|
|
if len(theme) is not 0 :
|
|
|
|
service_item.theme = theme
|
2009-09-22 17:43:07 +00:00
|
|
|
songXML = SongXMLParser(customSlide.text)
|
2009-06-17 05:11:16 +00:00
|
|
|
verseList = songXML.get_verses()
|
|
|
|
for verse in verseList:
|
|
|
|
raw_slides.append(verse[1])
|
|
|
|
raw_footer.append(title + u' '+ credit)
|
2009-05-04 08:15:48 +00:00
|
|
|
if theme is not None:
|
|
|
|
service_item.title = title
|
2009-06-05 19:00:57 +00:00
|
|
|
for slide in raw_slides:
|
|
|
|
service_item.add_from_text(slide[:30], slide)
|
2009-05-04 08:15:48 +00:00
|
|
|
service_item.raw_footer = raw_footer
|
2009-08-31 21:53:35 +00:00
|
|
|
return True
|