2009-03-13 06:13:11 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
"""
|
|
|
|
OpenLP - Open Source Lyrics Projection
|
|
|
|
Copyright (c) 2008 Raoul Snyman
|
|
|
|
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2009-05-21 16:07:01 +00:00
|
|
|
from openlp.core.lib import MediaManagerItem, SongXMLParser, ServiceItem, translate
|
2009-03-14 07:08:15 +00:00
|
|
|
from openlp.plugins.custom.lib import TextListData
|
2009-03-13 06:13:11 +00:00
|
|
|
|
2009-05-12 21:06:35 +00:00
|
|
|
class CustomList(QtGui.QListView):
|
|
|
|
|
|
|
|
def __init__(self,parent=None,name=None):
|
|
|
|
QtGui.QListView.__init__(self,parent)
|
|
|
|
|
|
|
|
def mouseMoveEvent(self, event):
|
|
|
|
"""
|
|
|
|
Drag and drop event does not care what data is selected
|
|
|
|
as the recepient will use events to request the data move
|
|
|
|
just tell it what plugin to call
|
|
|
|
"""
|
|
|
|
if event.buttons() != QtCore.Qt.LeftButton:
|
|
|
|
return
|
|
|
|
drag = QtGui.QDrag(self)
|
|
|
|
mimeData = QtCore.QMimeData()
|
|
|
|
drag.setMimeData(mimeData)
|
|
|
|
mimeData.setText(u'Custom')
|
|
|
|
dropAction = drag.start(QtCore.Qt.CopyAction)
|
|
|
|
if dropAction == QtCore.Qt.CopyAction:
|
|
|
|
self.close()
|
|
|
|
|
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):
|
|
|
|
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 setupUi(self):
|
|
|
|
# Add a toolbar
|
|
|
|
self.addToolbar()
|
|
|
|
# Create buttons for the toolbar
|
|
|
|
## New Custom Button ##
|
2009-03-14 07:08:40 +00:00
|
|
|
self.addToolbarButton(
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'New Custom Item'),
|
|
|
|
translate(u'CustomMediaItem',u'Add a new Custom Item'),
|
|
|
|
u':/custom/custom_new.png', self.onCustomNewClick, u'CustomNewItem')
|
2009-03-13 06:13:11 +00:00
|
|
|
## Edit Custom Button ##
|
2009-03-14 07:08:40 +00:00
|
|
|
self.addToolbarButton(
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'Edit Custom Item'),
|
|
|
|
translate(u'CustomMediaItem',u'Edit the selected Custom Item'),
|
|
|
|
u':/custom/custom_edit.png', self.onCustomEditClick, u'CustomEditItem')
|
2009-03-13 06:13:11 +00:00
|
|
|
## Delete Custom Button ##
|
2009-03-14 07:08:40 +00:00
|
|
|
self.addToolbarButton(
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'Delete Custom Item'),
|
|
|
|
translate(u'CustomMediaItem',u'Delete the selected Custom Item'),
|
|
|
|
u':/custom/custom_delete.png', self.onCustomDeleteClick, u'CustomDeleteItem')
|
2009-03-13 06:13:11 +00:00
|
|
|
## Separator Line ##
|
|
|
|
self.addToolbarSeparator()
|
|
|
|
## Preview Custom Button ##
|
2009-03-14 07:08:40 +00:00
|
|
|
self.addToolbarButton(
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'Preview Custom Item'),
|
|
|
|
translate(u'CustomMediaItem',u'Preview the selected Custom Item'),
|
|
|
|
u':/system/system_preview.png', self.onCustomPreviewClick, u'CustomPreviewItem')
|
2009-03-13 06:13:11 +00:00
|
|
|
## Live Custom Button ##
|
2009-03-14 07:08:40 +00:00
|
|
|
self.addToolbarButton(
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'Go Live'),
|
|
|
|
translate(u'CustomMediaItem', u'Send the selected Custom live'),
|
|
|
|
u':/system/system_live.png', self.onCustomLiveClick, u'CustomLiveItem')
|
2009-03-13 06:13:11 +00:00
|
|
|
## Add Custom Button ##
|
2009-03-14 07:08:40 +00:00
|
|
|
self.addToolbarButton(
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'Add Custom To Service'),
|
|
|
|
translate(u'CustomMediaItem',u'Add the selected Custom(s) to the service'),
|
|
|
|
u':/system/system_add.png', self.onCustomAddClick, u'CustomAddItem')
|
2009-03-15 19:31:33 +00:00
|
|
|
# Add the Customlist widget
|
2009-03-13 06:13:11 +00:00
|
|
|
self.CustomWidget = QtGui.QWidget(self)
|
|
|
|
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
|
|
|
sizePolicy.setHeightForWidth(self.CustomWidget.sizePolicy().hasHeightForWidth())
|
|
|
|
self.CustomWidget.setSizePolicy(sizePolicy)
|
2009-03-15 19:31:33 +00:00
|
|
|
self.CustomWidget.setObjectName(u'CustomWidget')
|
2009-03-13 06:13:11 +00:00
|
|
|
# Add the Custom widget to the page layout
|
|
|
|
self.PageLayout.addWidget(self.CustomWidget)
|
2009-05-12 21:06:35 +00:00
|
|
|
self.CustomListView = CustomList()
|
2009-03-13 06:13:11 +00:00
|
|
|
self.CustomListView.setAlternatingRowColors(True)
|
2009-03-14 07:08:15 +00:00
|
|
|
self.CustomListData = TextListData()
|
|
|
|
self.CustomListView.setModel(self.CustomListData)
|
2009-05-09 07:01:33 +00:00
|
|
|
self.CustomListView.setDragEnabled(True)
|
2009-03-13 06:13:11 +00:00
|
|
|
self.PageLayout.addWidget(self.CustomListView)
|
|
|
|
# Signals
|
2009-06-07 19:34:24 +00:00
|
|
|
QtCore.QObject.connect(self.CustomListView,
|
|
|
|
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onCustomPreviewClick)
|
2009-03-14 07:08:15 +00:00
|
|
|
#define and add the context menu
|
2009-03-13 06:13:11 +00:00
|
|
|
self.CustomListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
|
2009-03-14 07:08:15 +00:00
|
|
|
self.CustomListView.addAction(self.contextMenuAction(self.CustomListView,
|
2009-06-07 19:34:24 +00:00
|
|
|
':/custom/custom_edit.png', translate(u'CustomMediaItem', u'&Edit Custom'),
|
2009-03-14 07:08:15 +00:00
|
|
|
self.onCustomEditClick))
|
|
|
|
self.CustomListView.addAction(self.contextMenuSeparator(self.CustomListView))
|
2009-03-13 06:13:11 +00:00
|
|
|
self.CustomListView.addAction(self.contextMenuAction(
|
|
|
|
self.CustomListView, ':/system/system_preview.png',
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'&Preview Custom'), self.onCustomPreviewClick))
|
2009-03-13 06:13:11 +00:00
|
|
|
self.CustomListView.addAction(self.contextMenuAction(
|
|
|
|
self.CustomListView, ':/system/system_live.png',
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'&Show Live'), self.onCustomLiveClick))
|
2009-03-13 06:13:11 +00:00
|
|
|
self.CustomListView.addAction(self.contextMenuAction(
|
|
|
|
self.CustomListView, ':/system/system_add.png',
|
2009-06-07 19:34:24 +00:00
|
|
|
translate(u'CustomMediaItem',u'&Add to Service'), self.onCustomAddClick))
|
2009-04-25 06:11:15 +00:00
|
|
|
|
2009-03-14 07:09:10 +00:00
|
|
|
# def retranslateUi(self):
|
2009-06-07 19:34:24 +00:00
|
|
|
# self.ClearTextButton.setText(translate(u'CustomMediaItem', u'Clear'))
|
|
|
|
# self.SearchTextButton.setText(translate(u'CustomMediaItem', u'Search'))
|
2009-04-25 06:11:15 +00:00
|
|
|
|
2009-03-13 06:13:11 +00:00
|
|
|
def initialise(self):
|
|
|
|
self.loadCustomList(self.parent.custommanager.get_all_slides())
|
2009-04-25 06:11:15 +00:00
|
|
|
|
2009-03-13 06:13:11 +00:00
|
|
|
def loadCustomList(self, list):
|
2009-03-14 07:09:10 +00:00
|
|
|
self.CustomListData.resetStore()
|
2009-03-13 06:13:11 +00:00
|
|
|
for CustomSlide in list:
|
2009-03-14 07:08:15 +00:00
|
|
|
self.CustomListData.addRow(CustomSlide.id,CustomSlide.title)
|
2009-03-13 06:13:11 +00:00
|
|
|
|
|
|
|
def onClearTextButtonClick(self):
|
|
|
|
"""
|
|
|
|
Clear the search text.
|
|
|
|
"""
|
|
|
|
self.SearchTextEdit.clear()
|
|
|
|
|
|
|
|
def onSearchTextEditChanged(self, text):
|
2009-06-07 19:34:24 +00:00
|
|
|
# only search if > 3 characters
|
|
|
|
if len(text) > 3:
|
2009-03-13 06:13:11 +00:00
|
|
|
self.onSearchTextButtonClick()
|
|
|
|
|
|
|
|
def onSearchTextButtonClick(self):
|
2009-06-16 18:21:24 +00:00
|
|
|
search_keywords = unicode(self.SearchTextEdit.displayText())
|
2009-03-13 06:13:11 +00:00
|
|
|
search_results = []
|
|
|
|
search_type = self.SearchTypeComboBox.currentText()
|
|
|
|
search_results = self.Custommanager.search_Custom_lyrics(search_keywords)
|
|
|
|
self._display_results(search_results)
|
|
|
|
|
|
|
|
def onCustomNewClick(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
|
|
|
|
|
|
|
def onCustomEditClick(self):
|
2009-03-14 07:08:15 +00:00
|
|
|
indexes = self.CustomListView.selectedIndexes()
|
|
|
|
for index in indexes:
|
|
|
|
self.parent.edit_custom_form.loadCustom(self.CustomListData.getId(index))
|
|
|
|
self.parent.edit_custom_form.exec_()
|
|
|
|
self.initialise()
|
2009-03-13 06:13:11 +00:00
|
|
|
|
|
|
|
def onCustomDeleteClick(self):
|
2009-03-15 06:35:07 +00:00
|
|
|
indexes = self.CustomListView.selectedIndexes()
|
|
|
|
for index in indexes:
|
|
|
|
id = self.CustomListData.getId(index)
|
|
|
|
self.parent.custommanager.delete_custom(id)
|
|
|
|
self.CustomListData.deleteRow(index)
|
2009-03-13 06:13:11 +00:00
|
|
|
|
|
|
|
def onCustomPreviewClick(self):
|
2009-05-04 13:48:12 +00:00
|
|
|
log.debug(u'Custom Preview Requested')
|
2009-05-02 11:16:08 +00:00
|
|
|
service_item = ServiceItem(self.parent)
|
2009-06-07 19:34:24 +00:00
|
|
|
service_item.addIcon(u':/media/media_song.png')
|
2009-05-02 11:16:08 +00:00
|
|
|
self.generateSlideData(service_item)
|
|
|
|
self.parent.preview_controller.addServiceItem(service_item)
|
|
|
|
|
|
|
|
def onCustomLiveClick(self):
|
2009-05-04 13:48:12 +00:00
|
|
|
log.debug(u'Custom Live Requested')
|
2009-05-02 11:16:08 +00:00
|
|
|
service_item = ServiceItem(self.parent)
|
2009-06-07 19:34:24 +00:00
|
|
|
service_item.addIcon(u':/media/media_song.png')
|
2009-05-02 11:16:08 +00:00
|
|
|
self.generateSlideData(service_item)
|
|
|
|
self.parent.live_controller.addServiceItem(service_item)
|
|
|
|
|
|
|
|
def onCustomAddClick(self):
|
2009-05-04 13:48:12 +00:00
|
|
|
log.debug(u'Custom Add Requested')
|
2009-05-02 11:16:08 +00:00
|
|
|
service_item = ServiceItem(self.parent)
|
2009-06-07 19:34:24 +00:00
|
|
|
service_item.addIcon(u':/media/media_song.png')
|
2009-05-02 11:16:08 +00:00
|
|
|
self.generateSlideData(service_item)
|
2009-05-02 18:56:27 +00:00
|
|
|
self.parent.service_manager.addServiceItem(service_item)
|
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-03 15:38:14 +00:00
|
|
|
indexes = self.CustomListView.selectedIndexes()
|
2009-04-25 06:11:15 +00:00
|
|
|
for index in indexes:
|
|
|
|
id = self.CustomListData.getId(index)
|
|
|
|
customSlide = self.parent.custommanager.get_custom(id)
|
|
|
|
title = customSlide.title
|
2009-04-30 21:02:28 +00:00
|
|
|
credit = customSlide.credits
|
2009-04-29 19:21:18 +00:00
|
|
|
theme = customSlide.theme_name
|
2009-05-02 18:56:27 +00:00
|
|
|
if len(theme) is not 0 :
|
2009-05-02 11:16:08 +00:00
|
|
|
service_item.theme = theme
|
2009-04-25 06:11:15 +00:00
|
|
|
songXML=SongXMLParser(customSlide.text)
|
|
|
|
verseList = songXML.get_verses()
|
|
|
|
for verse in verseList:
|
2009-05-02 11:16:08 +00:00
|
|
|
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-06-16 18:21:24 +00:00
|
|
|
service_item.raw_footer = raw_footer
|