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 #
|
2011-05-26 16:25:54 +00:00
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan #
|
|
|
|
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
|
2011-05-26 17:11:22 +00:00
|
|
|
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
|
2011-06-12 16:02:52 +00:00
|
|
|
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
2011-06-12 15:41:01 +00:00
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, 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
|
2011-05-26 04:48:13 +00:00
|
|
|
import locale
|
2009-05-15 05:15:53 +00:00
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2011-02-10 18:38:03 +00:00
|
|
|
from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
|
2011-02-14 16:08:17 +00:00
|
|
|
SettingsManager, translate, check_item_selected, Receiver
|
2011-02-10 00:36:00 +00:00
|
|
|
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
2011-07-25 20:56:39 +00:00
|
|
|
from openlp.core.ui import Controller, Display
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2010-02-27 09:55:44 +00:00
|
|
|
log = logging.getLogger(__name__)
|
2011-03-24 19:04:02 +00:00
|
|
|
|
2011-07-27 18:28:35 +00:00
|
|
|
CLAPPERBOARD = QtGui.QPixmap(u':/media/media_video.png').toImage()
|
|
|
|
|
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
|
2011-07-27 18:28:35 +00:00
|
|
|
self.PreviewFunction = CLAPPERBOARD
|
2011-05-28 09:53:37 +00:00
|
|
|
MediaManagerItem.__init__(self, parent, plugin, icon)
|
2010-04-06 19:16:14 +00:00
|
|
|
self.singleServiceItem = False
|
2011-05-15 20:03:45 +00:00
|
|
|
self.hasSearch = True
|
2011-04-29 11:21:14 +00:00
|
|
|
self.mediaObject = None
|
2011-07-25 20:56:39 +00:00
|
|
|
self.mediaController = Controller(parent)
|
|
|
|
self.mediaController.controllerLayout = QtGui.QVBoxLayout()
|
2011-08-29 19:55:58 +00:00
|
|
|
self.plugin.mediaManager.add_controller_items(self.mediaController, \
|
|
|
|
self.mediaController.controllerLayout)
|
|
|
|
self.plugin.mediaManager.set_controls_visible(self.mediaController, \
|
|
|
|
False)
|
|
|
|
self.mediaController.previewDisplay = Display(self.mediaController, \
|
|
|
|
False, self.mediaController, self.plugin.pluginManager.plugins)
|
2011-07-25 20:56:39 +00:00
|
|
|
self.mediaController.previewDisplay.setup()
|
2011-08-29 19:55:58 +00:00
|
|
|
self.plugin.mediaManager.setup_display( \
|
|
|
|
self.mediaController.previewDisplay)
|
2011-07-25 20:56:39 +00:00
|
|
|
self.mediaController.previewDisplay.hide()
|
|
|
|
|
2011-01-23 15:36:15 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'video_background_replaced'),
|
|
|
|
self.videobackgroundReplaced)
|
2011-07-27 18:28:35 +00:00
|
|
|
# Allow DnD from the desktop
|
|
|
|
self.listView.activateDnD()
|
2009-05-15 05:15:53 +00:00
|
|
|
|
2009-10-31 16:17:26 +00:00
|
|
|
def retranslateUi(self):
|
2011-02-17 02:33:12 +00:00
|
|
|
self.onNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media')
|
|
|
|
self.onNewFileMasks = unicode(translate('MediaPlugin.MediaItem',
|
2011-02-20 18:12:55 +00:00
|
|
|
'Videos (%s);;Audio (%s);;%s (*)')) % (
|
2011-05-28 09:53:37 +00:00
|
|
|
u' '.join(self.plugin.video_extensions_list),
|
|
|
|
u' '.join(self.plugin.audio_extensions_list), UiStrings().AllFiles)
|
2011-04-15 21:43:59 +00:00
|
|
|
self.replaceAction.setText(UiStrings().ReplaceBG)
|
|
|
|
self.replaceAction.setToolTip(UiStrings().ReplaceLiveBG)
|
|
|
|
self.resetAction.setText(UiStrings().ResetBG)
|
|
|
|
self.resetAction.setToolTip(UiStrings().ResetLiveBG)
|
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)
|
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-16 17:42:26 +00:00
|
|
|
"""
|
2011-08-29 19:55:58 +00:00
|
|
|
Called to reset the Live background with the media selected,
|
2011-01-16 17:42:26 +00:00
|
|
|
"""
|
2011-07-18 21:25:10 +00:00
|
|
|
self.plugin.liveController.mediaManager.video_reset( \
|
2011-06-08 13:18:05 +00:00
|
|
|
self.plugin.liveController)
|
2011-01-05 16:50:28 +00:00
|
|
|
self.resetAction.setVisible(False)
|
2010-07-02 18:21:45 +00:00
|
|
|
|
2011-01-23 15:36:15 +00:00
|
|
|
def videobackgroundReplaced(self):
|
|
|
|
"""
|
|
|
|
Triggered by main display on change of serviceitem
|
|
|
|
"""
|
|
|
|
self.resetAction.setVisible(False)
|
|
|
|
|
2010-07-19 20:05:25 +00:00
|
|
|
def onReplaceClick(self):
|
2011-01-16 17:42:26 +00:00
|
|
|
"""
|
2011-08-29 19:55:58 +00:00
|
|
|
Called to replace Live background with the media selected.
|
2011-01-16 17:42:26 +00:00
|
|
|
"""
|
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):
|
2011-07-18 21:25:10 +00:00
|
|
|
if self.plugin.liveController.mediaManager.video( \
|
|
|
|
self.plugin.liveController, filename, True, True):
|
2011-07-03 08:13:48 +00:00
|
|
|
self.resetAction.setVisible(True)
|
|
|
|
else:
|
|
|
|
critical_error_message_box(UiStrings().LiveBGError,
|
|
|
|
translate('MediaPlugin.MediaItem',
|
|
|
|
'There was no display item to amend.'))
|
2011-01-03 19:50:25 +00:00
|
|
|
else:
|
2011-04-15 21:43:59 +00:00
|
|
|
critical_error_message_box(UiStrings().LiveBGError,
|
2011-02-16 03:06:34 +00:00
|
|
|
unicode(translate('MediaPlugin.MediaItem',
|
|
|
|
'There was a problem replacing your background, '
|
|
|
|
'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())
|
2011-03-19 15:48:26 +00:00
|
|
|
if not os.path.exists(filename):
|
2010-12-29 09:27:13 +00:00
|
|
|
# File is no longer present
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
translate('MediaPlugin.MediaItem', 'Missing Media File'),
|
2010-12-29 09:27:13 +00:00
|
|
|
unicode(translate('MediaPlugin.MediaItem',
|
|
|
|
'The file %s no longer exists.')) % filename)
|
|
|
|
return False
|
2011-05-24 20:03:57 +00:00
|
|
|
self.mediaLength = 0
|
2011-07-25 20:56:39 +00:00
|
|
|
if self.plugin.mediaManager.video( \
|
|
|
|
self.mediaController, filename, False, False):
|
|
|
|
self.mediaLength = self.mediaController.media_info.length
|
|
|
|
service_item.media_length = self.mediaLength
|
|
|
|
self.plugin.mediaManager.video_reset(self.mediaController)
|
|
|
|
if self.mediaLength > 0:
|
|
|
|
service_item.add_capability(
|
|
|
|
ItemCapabilities.AllowsVariableStartTime)
|
2011-08-29 19:55:58 +00:00
|
|
|
else:
|
|
|
|
return False
|
2011-05-24 20:03:57 +00:00
|
|
|
service_item.media_length = self.mediaLength
|
2011-03-19 15:48:26 +00:00
|
|
|
service_item.title = unicode(self.plugin.nameStrings[u'singular'])
|
|
|
|
service_item.add_capability(ItemCapabilities.RequiresMedia)
|
|
|
|
# force a non-existent 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
|
|
|
|
|
2009-07-04 05:52:30 +00:00
|
|
|
def initialise(self):
|
2011-02-11 04:04:05 +00:00
|
|
|
self.listView.clear()
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.setIconSize(QtCore.QSize(88, 50))
|
2011-06-12 13:01:46 +00:00
|
|
|
self.loadList(SettingsManager.load_list(self.settingsSection, u'media'))
|
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,
|
2011-06-12 13:01:46 +00:00
|
|
|
u'media', self.getFileList())
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2011-07-27 18:28:35 +00:00
|
|
|
def loadList(self, media):
|
2011-05-26 04:48:13 +00:00
|
|
|
# Sort the themes by its filename considering language specific
|
|
|
|
# characters. lower() is needed for windows!
|
2011-07-27 18:28:35 +00:00
|
|
|
media.sort(cmp=locale.strcoll,
|
2011-05-26 04:48:13 +00:00
|
|
|
key=lambda filename: os.path.split(unicode(filename))[1].lower())
|
2011-07-27 18:28:35 +00:00
|
|
|
for track in media:
|
|
|
|
filename = os.path.split(unicode(track))[1]
|
2009-07-04 05:52:30 +00:00
|
|
|
item_name = QtGui.QListWidgetItem(filename)
|
2011-07-27 18:28:35 +00:00
|
|
|
item_name.setIcon(build_icon(CLAPPERBOARD))
|
|
|
|
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(track))
|
|
|
|
item_name.setToolTip(track)
|
2011-05-10 20:39:17 +00:00
|
|
|
self.listView.addItem(item_name)
|
2011-04-29 16:41:26 +00:00
|
|
|
|
2011-05-15 20:03:45 +00:00
|
|
|
def search(self, string):
|
2011-06-12 13:01:46 +00:00
|
|
|
files = SettingsManager.load_list(self.settingsSection, u'media')
|
2011-05-15 20:03:45 +00:00
|
|
|
results = []
|
|
|
|
string = string.lower()
|
2011-06-12 11:51:23 +00:00
|
|
|
for file in files:
|
2011-05-15 20:03:45 +00:00
|
|
|
filename = os.path.split(unicode(file))[1]
|
|
|
|
if filename.lower().find(string) > -1:
|
|
|
|
results.append([file, filename])
|
|
|
|
return results
|