2009-05-15 05:15:53 +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 #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2010-12-26 11:04:47 +00:00
|
|
|
# Copyright (c) 2008-2011 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
|
2010-07-24 22:10:47 +00:00
|
|
|
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
|
|
|
|
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
|
|
|
|
# Carsten Tinggaard, Frode Woldsund #
|
2009-09-08 19:58:05 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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-05-15 05:15:53 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2010-04-03 07:10:31 +00:00
|
|
|
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
2010-12-27 22:57:35 +00:00
|
|
|
ItemCapabilities, SettingsManager, translate, check_item_selected, \
|
2011-01-06 23:47:28 +00:00
|
|
|
Receiver
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2010-02-27 09:55:44 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2009-06-25 21:09:52 +00:00
|
|
|
class MediaListView(BaseListWithDnD):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
self.PluginName = u'Media'
|
|
|
|
BaseListWithDnD.__init__(self, parent)
|
2009-05-15 05:15:53 +00:00
|
|
|
|
|
|
|
class MediaMediaItem(MediaManagerItem):
|
|
|
|
"""
|
2009-05-16 10:24:03 +00:00
|
|
|
This is the custom media manager item for Media Slides.
|
2009-05-15 05:15:53 +00:00
|
|
|
"""
|
2010-02-27 09:55:44 +00:00
|
|
|
log.info(u'%s MediaMediaItem loaded', __name__)
|
2009-05-15 05:15:53 +00:00
|
|
|
|
2010-09-15 17:55:27 +00:00
|
|
|
def __init__(self, parent, plugin, icon):
|
2009-07-04 05:52:30 +00:00
|
|
|
self.IconPath = u'images/image'
|
2010-04-30 16:30:25 +00:00
|
|
|
self.background = False
|
2009-06-25 21:09:52 +00:00
|
|
|
# this next is a class, not an instance of a class - it will
|
|
|
|
# be instanced by the base MediaManagerItem
|
|
|
|
self.ListViewWithDnD_class = MediaListView
|
2010-04-27 16:27:57 +00:00
|
|
|
self.PreviewFunction = QtGui.QPixmap(
|
|
|
|
u':/media/media_video.png').toImage()
|
2010-09-15 17:55:27 +00:00
|
|
|
MediaManagerItem.__init__(self, parent, self, icon)
|
2010-04-06 19:16:14 +00:00
|
|
|
self.singleServiceItem = False
|
2010-10-27 19:40:38 +00:00
|
|
|
self.serviceItemIconName = u':/media/image_clapperboard.png'
|
2009-05-15 05:15:53 +00:00
|
|
|
|
2009-10-31 16:17:26 +00:00
|
|
|
def retranslateUi(self):
|
2010-06-19 03:43:10 +00:00
|
|
|
self.OnNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media')
|
2010-12-31 02:17:41 +00:00
|
|
|
self.OnNewFileMasks = unicode(translate('MediaPlugin.MediaItem',
|
|
|
|
'Videos (%s);;Audio (%s);;All files (*)')) % \
|
|
|
|
(self.parent.video_list, self.parent.audio_list)
|
2011-01-05 16:50:28 +00:00
|
|
|
self.replaceAction.setText(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Replace Background'))
|
|
|
|
self.replaceAction.setToolTip(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Replace Live Background'))
|
|
|
|
self.resetAction.setText(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Reset Background'))
|
|
|
|
self.resetAction.setToolTip(
|
|
|
|
translate('ImagePlugin.MediaItem', 'Reset Live Background'))
|
2009-10-29 18:25:34 +00:00
|
|
|
|
2009-09-26 09:11:39 +00:00
|
|
|
def requiredIcons(self):
|
|
|
|
MediaManagerItem.requiredIcons(self)
|
|
|
|
self.hasFileIcon = True
|
|
|
|
self.hasNewIcon = False
|
|
|
|
self.hasEditIcon = False
|
|
|
|
|
2010-06-30 16:30:25 +00:00
|
|
|
def addListViewToToolBar(self):
|
|
|
|
MediaManagerItem.addListViewToToolBar(self)
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
|
2011-01-05 16:50:28 +00:00
|
|
|
self.listView.addAction(self.replaceAction)
|
2010-04-30 16:30:25 +00:00
|
|
|
|
|
|
|
def addEndHeaderBar(self):
|
2010-12-29 09:14:13 +00:00
|
|
|
# Replace backgrounds do not work at present so remove functionality.
|
2011-01-05 16:50:28 +00:00
|
|
|
self.replaceAction = self.addToolbarButton(u'', u'',
|
|
|
|
u':/slides/slide_blank.png', self.onReplaceClick, False)
|
|
|
|
self.resetAction = self.addToolbarButton(u'', u'',
|
|
|
|
u':/system/system_close.png', self.onResetClick, False)
|
|
|
|
self.resetAction.setVisible(False)
|
2010-04-30 16:30:25 +00:00
|
|
|
|
2010-07-19 20:05:25 +00:00
|
|
|
def onResetClick(self):
|
2011-01-05 16:50:28 +00:00
|
|
|
self.resetAction.setVisible(False)
|
2010-07-28 17:21:32 +00:00
|
|
|
self.parent.liveController.display.resetVideo()
|
2010-07-02 18:21:45 +00:00
|
|
|
|
2010-07-19 20:05:25 +00:00
|
|
|
def onReplaceClick(self):
|
2010-07-07 16:03:30 +00:00
|
|
|
if check_item_selected(self.listView,
|
2011-01-03 19:50:25 +00:00
|
|
|
translate('MediaPlugin.MediaItem',
|
2010-07-21 06:24:32 +00:00
|
|
|
'You must select a media file to replace the background with.')):
|
2010-07-07 16:03:30 +00:00
|
|
|
item = self.listView.currentItem()
|
2010-06-30 17:05:12 +00:00
|
|
|
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
|
2011-01-03 19:50:25 +00:00
|
|
|
if os.path.exists(filename):
|
|
|
|
(path, name) = os.path.split(filename)
|
|
|
|
self.parent.liveController.display.video(filename, 0, True)
|
2011-01-05 19:58:31 +00:00
|
|
|
self.resetAction.setVisible(True)
|
2011-01-03 19:50:25 +00:00
|
|
|
else:
|
2011-01-05 07:07:19 +00:00
|
|
|
Receiver.send_message(u'openlp_error_message', {
|
|
|
|
u'title': translate('MediaPlugin.MediaItem',
|
2011-01-05 18:27:39 +00:00
|
|
|
'Live Background Error'),
|
2011-01-05 07:18:12 +00:00
|
|
|
u'message': unicode(translate('MediaPlugin.MediaItem',
|
2011-01-05 18:27:39 +00:00
|
|
|
'There was a problem replacing your background, '
|
2011-01-05 21:31:22 +00:00
|
|
|
'the media file "%s" no longer exists.')) % filename})
|
2010-04-30 16:30:25 +00:00
|
|
|
|
2010-11-27 15:25:00 +00:00
|
|
|
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
2010-04-05 07:22:21 +00:00
|
|
|
if item is None:
|
2010-07-07 16:03:30 +00:00
|
|
|
item = self.listView.currentItem()
|
2010-04-05 07:22:21 +00:00
|
|
|
if item is None:
|
|
|
|
return False
|
2010-06-09 21:15:37 +00:00
|
|
|
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
|
2010-12-29 09:27:13 +00:00
|
|
|
if os.path.exists(filename):
|
|
|
|
service_item.title = unicode(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Media'))
|
|
|
|
service_item.add_capability(ItemCapabilities.RequiresMedia)
|
|
|
|
# force a nonexistent theme
|
|
|
|
service_item.theme = -1
|
|
|
|
frame = u':/media/image_clapperboard.png'
|
|
|
|
(path, name) = os.path.split(filename)
|
|
|
|
service_item.add_from_command(path, name, frame)
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
# File is no longer present
|
|
|
|
QtGui.QMessageBox.critical(
|
|
|
|
self, translate('MediaPlugin.MediaItem',
|
|
|
|
'Missing Media File'),
|
|
|
|
unicode(translate('MediaPlugin.MediaItem',
|
|
|
|
'The file %s no longer exists.')) % filename)
|
|
|
|
return False
|
2009-05-15 05:15:53 +00:00
|
|
|
|
2009-07-04 05:52:30 +00:00
|
|
|
def initialise(self):
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.setSelectionMode(
|
2009-09-14 22:10:08 +00:00
|
|
|
QtGui.QAbstractItemView.ExtendedSelection)
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.setIconSize(QtCore.QSize(88, 50))
|
2010-06-08 15:38:09 +00:00
|
|
|
self.loadList(SettingsManager.load_list(self.settingsSection,
|
|
|
|
self.settingsSection))
|
2009-07-04 05:52:30 +00:00
|
|
|
|
|
|
|
def onDeleteClick(self):
|
2010-06-16 01:23:57 +00:00
|
|
|
"""
|
|
|
|
Remove a media item from the list
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
if check_item_selected(self.listView, translate('MediaPlugin.MediaItem',
|
2010-07-21 06:24:32 +00:00
|
|
|
'You must select a media file to delete.')):
|
2010-07-07 16:03:30 +00:00
|
|
|
row_list = [item.row() for item in self.listView.selectedIndexes()]
|
2010-06-28 18:20:05 +00:00
|
|
|
row_list.sort(reverse=True)
|
|
|
|
for row in row_list:
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.takeItem(row)
|
2010-06-28 20:00:35 +00:00
|
|
|
SettingsManager.set_list(self.settingsSection,
|
|
|
|
self.settingsSection, self.getFileList())
|
2009-07-04 05:52:30 +00:00
|
|
|
|
|
|
|
def loadList(self, list):
|
|
|
|
for file in list:
|
2010-05-27 14:41:47 +00:00
|
|
|
filename = os.path.split(unicode(file))[1]
|
2009-07-04 05:52:30 +00:00
|
|
|
item_name = QtGui.QListWidgetItem(filename)
|
2010-04-05 06:45:01 +00:00
|
|
|
img = QtGui.QPixmap(u':/media/media_video.png').toImage()
|
2009-11-30 20:29:26 +00:00
|
|
|
item_name.setIcon(build_icon(img))
|
2009-07-04 05:52:30 +00:00
|
|
|
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
|
2010-12-29 09:14:13 +00:00
|
|
|
self.listView.addItem(item_name)
|