openlp/openlp/plugins/media/lib/mediaitem.py

136 lines
5.8 KiB
Python
Raw Normal View History

2009-05-15 05:15:53 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# 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-05-15 05:15:53 +00:00
import logging
import os
from PyQt4 import QtCore, QtGui
2009-09-25 00:43:42 +00:00
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, buildIcon
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):
"""
This is the custom media manager item for Media Slides.
2009-05-15 05:15:53 +00:00
"""
global log
log = logging.getLogger(u'MediaMediaItem')
2009-05-15 05:15:53 +00:00
log.info(u'Media Media Item loaded')
def __init__(self, parent, icon, title):
self.TranslationContext = u'MediaPlugin'
2009-10-28 01:36:24 +00:00
self.PluginNameShort = u'Media'
self.IconPath = u'images/image'
2009-10-07 16:16:21 +00:00
self.ConfigSection = u'media'
self.OnNewPrompt = u'Select Media(s)'
2009-10-07 16:16:21 +00:00
self.OnNewFileMasks = \
u'Videos (*.avi *.mpeg *.mpg *.mp4);;Audio (*.ogg *.mp3 *.wma);;All files (*)'
# this next is a class, not an instance of a class - it will
# be instanced by the base MediaManagerItem
self.ListViewWithDnD_class = MediaListView
#self.ServiceItemIconName = u':/media/media_image.png'
2009-06-30 20:35:53 +00:00
self.PreviewFunction = self.video_get_preview
2009-05-15 05:15:53 +00:00
MediaManagerItem.__init__(self, parent, icon, title)
2009-10-19 17:51:21 +00:00
self.MainDisplay = self.parent.live_controller.parent.mainDisplay
2009-05-15 05:15:53 +00:00
def initPluginNameVisible(self):
2009-10-28 01:36:24 +00:00
self.PluginNameVisible = self.trUtf8(self.PluginNameShort)
2009-05-15 05:15:53 +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
2009-06-30 20:35:53 +00:00
def video_get_preview(self, filename):
2009-09-15 21:59:20 +00:00
#
# For now cross platform is an icon. Phonon does not support
# individual frame access (yet?) and GStreamer is not available
# on Windows
#
image = QtGui.QPixmap(u':/media/media_video.png').toImage()
return image
2009-05-15 05:15:53 +00:00
def generateSlideData(self, service_item):
indexes = self.ListView.selectedIndexes()
2009-09-15 21:59:20 +00:00
if len(indexes) > 1:
return False
service_item.title = u'Media'
2009-05-15 05:15:53 +00:00
for index in indexes:
2009-10-19 17:51:21 +00:00
filename = self.ListView.getFilename(index)
frame = QtGui.QImage(unicode(filename))
(path, name) = os.path.split(filename)
2009-09-21 17:56:36 +00:00
service_item.add_from_image(path, name, frame)
return True
2009-05-15 05:15:53 +00:00
def onPreviewClick(self):
2009-05-15 05:15:53 +00:00
log.debug(u'Media Preview Button pressed')
2009-06-30 20:35:53 +00:00
items = self.ListView.selectedIndexes()
2009-05-15 05:15:53 +00:00
for item in items:
2009-10-19 17:51:21 +00:00
baseItem = self.ListView.item(item.row())
2009-10-29 17:16:24 +00:00
itemText = unicode(baseItem.data(QtCore.Qt.UserRole).toString())
2009-10-19 17:51:21 +00:00
print itemText
2009-05-15 05:15:53 +00:00
2009-10-19 17:51:21 +00:00
def onLiveClick(self):
log.debug(u'Media Live Button pressed')
2009-10-19 17:51:21 +00:00
items = self.ListView.selectedIndexes()
if len(items) > 0:
firstPass = True
for item in items:
baseItem = self.ListView.item(item.row())
filename = unicode(baseItem.data(QtCore.Qt.UserRole).toString())
if firstPass:
self.MainDisplay.queueMedia(filename, firstPass)
firstPass = False
else:
self.MainDisplay.queueMedia(filename, firstPass)
self.MainDisplay.playMedia()
2009-05-15 05:15:53 +00:00
def initialise(self):
self.ListView.setSelectionMode(
QtGui.QAbstractItemView.ExtendedSelection)
self.ListView.setIconSize(QtCore.QSize(88,50))
self.loadList(self.parent.config.load_list(self.ConfigSection))
def onDeleteClick(self):
item = self.ListView.currentItem()
if item is not None:
row = self.ListView.row(item)
self.ListView.takeItem(row)
self.parent.config.set_list(
2009-09-15 21:59:20 +00:00
self.ConfigSection, self.getFileList())
def loadList(self, list):
for file in list:
(path, filename) = os.path.split(unicode(file))
item_name = QtGui.QListWidgetItem(filename)
img = self.video_get_preview(file)
item_name.setIcon(buildIcon(img))
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
self.ListView.addItem(item_name)