cleanup, add settings tab

This commit is contained in:
rimach crichter@web.de 2011-05-23 21:37:44 +02:00
parent 578e0fea3f
commit d54ef615b4
7 changed files with 190 additions and 159 deletions

View File

@ -51,10 +51,13 @@ class MediaController(object):
def __init__(self, parent): def __init__(self, parent):
self.parent = parent self.parent = parent
self.isActive = False self.isActive = False
self.canBackground = False
self.state = MediaState.Off self.state = MediaState.Off
self.hasOwnWidget = False self.hasOwnWidget = False
self.audio_extensions_list = []
self.video_extensions_list = []
def setup(self, display): def setup(self, display, hasAudio):
""" """
Create the related widgets for the current display Create the related widgets for the current display
""" """

View File

@ -54,11 +54,11 @@ class MediaManager(object):
self.curDisplayMediaController = {} self.curDisplayMediaController = {}
#Create Backend Controllers #Create Backend Controllers
if WebkitController.is_available(): if WebkitController.is_available():
self.backends['webkit'] = WebkitController(self) self.backends[u'Webkit'] = WebkitController(self)
if PhononController.is_available(): if PhononController.is_available():
self.backends['phonon'] = PhononController(self) self.backends[u'Phonon'] = PhononController(self)
if VlcController.is_available(): if VlcController.is_available():
self.backends['vlc'] = VlcController(self) self.backends[u'Vlc'] = VlcController(self)
#Timer for video state #Timer for video state
self.Timer = QtCore.QTimer() self.Timer = QtCore.QTimer()
self.Timer.setInterval(200) self.Timer.setInterval(200)
@ -117,21 +117,26 @@ class MediaManager(object):
After a new display is configured, all media related widget After a new display is configured, all media related widget
will be created too will be created too
""" """
hasAudio = True
if not self.withLivePreview and \ if not self.withLivePreview and \
display == self.parent.liveController.previewDisplay: display == self.parent.liveController.previewDisplay:
return return
if display == self.parent.previewController.previewDisplay or \
display == self.parent.liveController.previewDisplay:
hasAudio = False
for backend in self.backends.values(): for backend in self.backends.values():
backend.setup(display) backend.setup(display, hasAudio)
def resize(self, controller): def resize(self, controller):
""" """
After Mainwindow changes or Splitter moved all related media After Mainwindow changes or Splitter moved all related media
widgets have to be resized widgets have to be resized
""" """
pass for display in self.curDisplayMediaController.keys():
#TODO if display == self.parent.previewController.previewDisplay or \
#for display in self.curDisplayMediaController.keys(): display == self.parent.liveController.previewDisplay:
# self.curDisplayMediaController[display].resize(display, controller) display.resize(display.parent.slidePreview.size())
self.curDisplayMediaController[display].resize(display, controller)
def video(self, msg): def video(self, msg):
""" """
@ -154,18 +159,23 @@ class MediaManager(object):
if self.withLivePreview: if self.withLivePreview:
display = controller.previewDisplay display = controller.previewDisplay
if self.check_file_type(display, videoPath, False): if self.check_file_type(display, videoPath, False):
#check size of all media_widgets
self.resize(controller)
self.curDisplayMediaController[display] \ self.curDisplayMediaController[display] \
.load(display, videoPath, volume) .load(display, videoPath, volume)
display = controller.display display = controller.display
if self.check_file_type(display, videoPath, isBackground): if self.check_file_type(display, videoPath, isBackground):
#check size of all media_widgets
self.resize(controller)
isValid = self.curDisplayMediaController[display] \ isValid = self.curDisplayMediaController[display] \
.load(display, videoPath, volume) .load(display, videoPath, volume)
controller.display.webLoaded = True
else: else:
display = controller.previewDisplay display = controller.previewDisplay
self.check_file_type(display, videoPath, isBackground) if self.check_file_type(display, videoPath, isBackground):
isValid = self.curDisplayMediaController[display] \ #check size of all media_widgets
.load(display, videoPath, volume) self.resize(controller)
isValid = self.curDisplayMediaController[display] \
.load(display, videoPath, volume)
if not isValid: if not isValid:
#Media could not be loaded correctly #Media could not be loaded correctly
critical_error_message_box( critical_error_message_box(
@ -173,10 +183,8 @@ class MediaManager(object):
unicode(translate('MediaPlugin.MediaItem', unicode(translate('MediaPlugin.MediaItem',
'Unsupported File'))) 'Unsupported File')))
return return
#check size of all media_widgets # controller.display.webLoaded = True
self.resize(controller)
#now start playing #now start playing
print self.curDisplayMediaController[display]
self.video_play(controller) self.video_play(controller)
def check_file_type(self, display, videoPath, isBackground): def check_file_type(self, display, videoPath, isBackground):
@ -184,20 +192,30 @@ class MediaManager(object):
Used to choose the right media backend type Used to choose the right media backend type
from the prioritized backend list from the prioritized backend list
""" """
if videoPath.endswith(u'.swf') or isBackground: usedBackends = QtCore.QSettings().value(u'media/backends',
self.curDisplayMediaController[display] = self.backends['webkit'] QtCore.QVariant(u'Webkit')).toString().split(u',')
elif QtCore.QSettings().value(u'media/use webkit', media_path = QtCore.QFileInfo(videoPath)
QtCore.QVariant(True)).toInt()[0] == 0: if media_path.isFile():
self.curDisplayMediaController[display] = self.backends['webkit'] suffix = u'*.%s' % media_path.suffix()
elif QtCore.QSettings().value(u'media/use vlc', for title in usedBackends:
QtCore.QVariant(True)).toInt()[0] == 0: backend = self.backends[str(title)]
self.curDisplayMediaController[display] = self.backends['vlc'] if suffix in backend.video_extensions_list:
elif QtCore.QSettings().value(u'media/use phonon', if isBackground:
QtCore.QVariant(True)).toInt()[0] == 0: if backend.canBackground:
self.curDisplayMediaController[display] = self.backends['phonon'] self.curDisplayMediaController[display] = backend
else: return True
return False else:
return True self.curDisplayMediaController[display] = backend
return True
return False
# # Special FileType Check
# if videoPath.endswith(u'.swf') or isBackground:
# self.curDisplayMediaController[display] = self.backends[u'Webkit']
# else:
# # search extension in available backends
# # currently only use the first available backend
# self.curDisplayMediaController[display] = self.backends[str(usedBackends[0])]
# return True
def video_play(self, controller): def video_play(self, controller):
""" """
@ -324,3 +342,19 @@ class MediaManager(object):
self.curDisplayMediaController[display].play(display) self.curDisplayMediaController[display].play(display)
self.curDisplayMediaController[display] \ self.curDisplayMediaController[display] \
.set_visible(display, True) .set_visible(display, True)
def get_audio_extensions_list(self):
audio_list = []
for backend in self.backends.values():
for item in backend.audio_extensions_list:
if not item in audio_list:
audio_list.append(item)
return audio_list
def get_video_extensions_list(self):
video_list = []
for backend in self.backends.values():
for item in backend.video_extensions_list:
if not item in video_list:
video_list.append(item)
return video_list

View File

@ -104,25 +104,36 @@ class MediaTab(SettingsTab):
def onUsePhononCheckBoxChanged(self, check_state): def onUsePhononCheckBoxChanged(self, check_state):
if check_state == QtCore.Qt.Checked: if check_state == QtCore.Qt.Checked:
self.usePhonon = self.backendOrderlistWidget.count() self.usePhonon = True
if u'Phonon' not in self.usedBackends:
self.usedBackends.append(u'Phonon')
else: else:
self.usePhonon = -1 self.usePhonon = False
self.usedBackends.takeAt(self.usedBackends.indexOf(u'Phonon'))
self.updateBackendList() self.updateBackendList()
def onUseVlcCheckBoxChanged(self, check_state): def onUseVlcCheckBoxChanged(self, check_state):
if check_state == QtCore.Qt.Checked: if check_state == QtCore.Qt.Checked:
self.useVlc = self.backendOrderlistWidget.count() self.useVlc = True
if u'Vlc' not in self.usedBackends:
self.usedBackends.append(u'Vlc')
else: else:
self.useVlc = -1 self.useVlc = False
self.usedBackends.takeAt(self.usedBackends.indexOf(u'Vlc'))
self.updateBackendList() self.updateBackendList()
def updateBackendList(self):
self.backendOrderlistWidget.clear()
for backend in self.usedBackends:
self.backendOrderlistWidget.addItem(backend)
def onOrderingUpButtonPressed(self): def onOrderingUpButtonPressed(self):
currentRow = self.backendOrderlistWidget.currentRow() currentRow = self.backendOrderlistWidget.currentRow()
if currentRow > 0: if currentRow > 0:
item = self.backendOrderlistWidget.takeItem(currentRow) item = self.backendOrderlistWidget.takeItem(currentRow)
self.backendOrderlistWidget.insertItem(currentRow-1, item) self.backendOrderlistWidget.insertItem(currentRow-1, item)
self.backendOrderlistWidget.setCurrentRow(currentRow-1) self.backendOrderlistWidget.setCurrentRow(currentRow-1)
self.updateOrdering() self.usedBackends.move(currentRow, currentRow-1)
def onOrderingDownButtonPressed(self): def onOrderingDownButtonPressed(self):
currentRow = self.backendOrderlistWidget.currentRow() currentRow = self.backendOrderlistWidget.currentRow()
@ -130,60 +141,25 @@ class MediaTab(SettingsTab):
item = self.backendOrderlistWidget.takeItem(currentRow) item = self.backendOrderlistWidget.takeItem(currentRow)
self.backendOrderlistWidget.insertItem(currentRow+1, item) self.backendOrderlistWidget.insertItem(currentRow+1, item)
self.backendOrderlistWidget.setCurrentRow(currentRow+1) self.backendOrderlistWidget.setCurrentRow(currentRow+1)
self.updateOrdering() self.usedBackends.move(currentRow, currentRow+1)
def updateOrdering(self):
for num in range (0, self.backendOrderlistWidget.count()):
item = self.backendOrderlistWidget.item(num)
if item.text == u'Webkit':
self.useWebkit = num
elif item.text == u'Phonon':
self.usePhonon = num
elif item.text == u'Vlc':
self.useVlc = num
def updateBackendList(self):
self.backendOrderlistWidget.clear()
for num in range(0, 3):
if self.useWebkit == num:
self.backendOrderlistWidget.addItem(u'Webkit')
elif self.usePhonon == num:
self.backendOrderlistWidget.addItem(u'Phonon')
elif self.useVlc == num:
self.backendOrderlistWidget.addItem(u'Vlc')
def load(self): def load(self):
self.useWebkit = QtCore.QSettings().value( self.usedBackends = QtCore.QSettings().value(
self.settingsSection + u'/use webkit', self.settingsSection + u'/backends',
QtCore.QVariant(True)).toInt()[0] QtCore.QVariant(u'Webkit')).toString().split(u',')
self.usePhonon = QtCore.QSettings().value( self.useWebkit = u'Webkit' in self.usedBackends
self.settingsSection + u'/use phonon', self.usePhonon = u'Phonon' in self.usedBackends
QtCore.QVariant(True)).toInt()[0] self.useVlc = u'Vlc' in self.usedBackends
self.useVlc = QtCore.QSettings().value( self.usePhononCheckBox.setChecked(self.usePhonon)
self.settingsSection + u'/use vlc', self.useVlcCheckBox.setChecked(self.useVlc)
QtCore.QVariant(True)).toInt()[0] self.updateBackendList()
self.usePhononCheckBox.setChecked((self.usePhonon != -1))
self.useVlcCheckBox.setChecked((self.useVlc != -1))
def save(self): def save(self):
changedValues = False oldBackendString = QtCore.QSettings().value(
oldUseWebkit = QtCore.QSettings().value( self.settingsSection + u'/backends',
u'media/use webkit', QtCore.QVariant(True)).toInt()[0] QtCore.QVariant(True)).toString()
if oldUseWebkit != self.useWebkit: newBackendString = self.usedBackends.join(u',')
QtCore.QSettings().setValue(self.settingsSection + u'/use webkit', if oldBackendString != newBackendString:
QtCore.QVariant(self.useWebkit)) QtCore.QSettings().setValue(self.settingsSection + u'/backends',
changedValues = True QtCore.QVariant(newBackendString))
oldUsePhonon = QtCore.QSettings().value(
u'media/use phonon', QtCore.QVariant(True)).toInt()[0]
if oldUsePhonon != self.usePhonon:
QtCore.QSettings().setValue(self.settingsSection + u'/use phonon',
QtCore.QVariant(self.usePhonon))
changedValues = True
oldUseVlc = QtCore.QSettings().value(
u'media/use vlc', QtCore.QVariant(True)).toInt()[0]
if oldUseVlc != self.useVlc:
QtCore.QSettings().setValue(self.settingsSection + u'/use vlc',
QtCore.QVariant(self.useVlc))
changedValues = True
if changedValues:
Receiver.send_message(u'config_screen_changed') Receiver.send_message(u'config_screen_changed')

View File

@ -26,6 +26,7 @@
############################################################################### ###############################################################################
import logging import logging
import mimetypes
from datetime import datetime from datetime import datetime
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -59,8 +60,37 @@ class PhononController(MediaController):
u'video/x-matroska': [u'.mpv', u'.mkv'], u'video/x-matroska': [u'.mpv', u'.mkv'],
u'video/x-wmv': [u'.wmv'], u'video/x-wmv': [u'.wmv'],
u'video/x-ms-wmv': [u'.wmv']} u'video/x-ms-wmv': [u'.wmv']}
mimetypes.init()
for mimetype in Phonon.BackendCapabilities.availableMimeTypes():
mimetype = unicode(mimetype)
if mimetype.startswith(u'audio/'):
self._addToList(self.audio_extensions_list, mimetype)
elif mimetype.startswith(u'video/'):
self._addToList(self.video_extensions_list, mimetype)
def setup(self, display): def _addToList(self, list, mimetype):
# Add all extensions which mimetypes provides us for supported types.
extensions = mimetypes.guess_all_extensions(unicode(mimetype))
for extension in extensions:
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.parent.parent.serviceManager.supportedSuffixes(extension[1:])
log.info(u'MediaPlugin: %s extensions: %s' % (mimetype,
u' '.join(extensions)))
# Add extensions for this mimetype from self.additional_extensions.
# This hack clears mimetypes' and operating system's shortcomings
# by providing possibly missing extensions.
if mimetype in self.additional_extensions.keys():
for extension in self.additional_extensions[mimetype]:
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.parent.parent.serviceManager.supportedSuffixes(extension[1:])
log.info(u'MediaPlugin: %s additional extensions: %s' % (mimetype,
u' '.join(self.additional_extensions[mimetype])))
def setup(self, display, hasAudio):
display.phononWidget = Phonon.VideoWidget(display) display.phononWidget = Phonon.VideoWidget(display)
display.phononWidget.setVisible(False) display.phononWidget.setVisible(False)
display.phononWidget.resize(display.size()) display.phononWidget.resize(display.size())

View File

@ -46,11 +46,37 @@ class VlcController(MediaController):
def __init__(self, parent): def __init__(self, parent):
MediaController.__init__(self, parent) MediaController.__init__(self, parent)
self.parent = parent self.parent = parent
self.video_extensions_list = [
u'*.3gp'
, u'*.asf', u'*.wmv'
, u'*.au'
, u'*.avi'
, u'*.flv'
, u'*.mov'
, u'*.mp4'
, u'*.ogm', u'*.ogg'
, u'*.mkv', u'*.mka'
, u'*.ts', u'*.mpg'
, u'*.mpg', u'*.mp3', u'*.mp2'
, u'*.nsc'
, u'*.nsv'
, u'*.nut'
, u'*.ra', u'*.ram', u'*.rm', u'*.rv' ,u'*.rmbv'
, u'*.a52', u'*.dts', u'*.aac', u'*.flac' ,u'*.dv', u'*.vid'
, u'*.tta', u'*.tac'
, u'*.ty'
, u'*.wav', u'*.dts'
, u'*.xa'
, u'*.iso'
]
def setup(self, display): def setup(self, display, hasAudio):
display.vlcWidget = QtGui.QFrame(display) display.vlcWidget = QtGui.QFrame(display)
# creating a basic vlc instance # creating a basic vlc instance
display.vlcInstance = vlc.Instance() if hasAudio:
display.vlcInstance = vlc.Instance()
else:
display.vlcInstance = vlc.Instance('--no-audio')
display.vlcInstance.set_log_verbosity(2) display.vlcInstance.set_log_verbosity(2)
# creating an empty vlc media player # creating an empty vlc media player
display.vlcMediaPlayer = display.vlcInstance.media_player_new() display.vlcMediaPlayer = display.vlcInstance.media_player_new()

View File

@ -42,13 +42,33 @@ class WebkitController(MediaController):
MediaController.__init__(self, parent) MediaController.__init__(self, parent)
self.parent = parent self.parent = parent
self.isFlash = False self.isFlash = False
self.additional_extensions = { self.canBackground = True
u'video/shockwave': [u'.swf']} self.video_extensions_list = [
u'*.3gp'
, u'*.3gpp'
, u'*.3g2'
, u'*.3gpp2'
, u'*.aac'
, u'*.flv'
, u'*.f4a'
, u'*.f4b'
, u'*.f4p'
, u'*.f4v'
, u'*.mov'
, u'*.m4a'
, u'*.m4b'
, u'*.m4p'
, u'*.m4v'
, u'*.mkv'
, u'*.mp4'
, u'*.mp3'
, u'*.ogg'
, u'*.ogv'
, u'*.webm'
, u'*.swf', u'*.mpg', u'*.wmv'
]
def setup(self, display): def setup(self, display, hasAudio):
# if display == self.parent.previewController.previewDisplay or \
# display == self.parent.liveController.previewDisplay:
# display.webView.resize(display.size())
display.webView.raise_() display.webView.raise_()
self.hasOwnWidget = False self.hasOwnWidget = False
@ -57,21 +77,7 @@ class WebkitController(MediaController):
return True return True
def get_supported_file_types(self): def get_supported_file_types(self):
self.supported_file_types = ['avi'] pass
self.additional_extensions = {
u'audio/ac3': [u'.ac3'],
u'audio/flac': [u'.flac'],
u'audio/x-m4a': [u'.m4a'],
u'audio/midi': [u'.mid', u'.midi'],
u'audio/x-mp3': [u'.mp3'],
u'audio/mpeg': [u'.mp3', u'.mp2', u'.mpga', u'.mpega', u'.m4a'],
u'audio/qcelp': [u'.qcp'],
u'audio/x-wma': [u'.wma'],
u'audio/x-ms-wma': [u'.wma'],
u'video/x-flv': [u'.flv'],
u'video/x-matroska': [u'.mpv', u'.mkv'],
u'video/x-wmv': [u'.wmv'],
u'video/x-ms-wmv': [u'.wmv']}
def load(self, display, path, volume): def load(self, display, path, volume):
log.debug(u'load vid in Webkit Controller') log.debug(u'load vid in Webkit Controller')

View File

@ -25,9 +25,6 @@
############################################################################### ###############################################################################
import logging import logging
import mimetypes
from PyQt4.phonon import Phonon
from openlp.core.lib import Plugin, StringContent, build_icon, translate from openlp.core.lib import Plugin, StringContent, build_icon, translate
from openlp.plugins.media.lib import MediaMediaItem, MediaTab, MediaManager from openlp.plugins.media.lib import MediaMediaItem, MediaTab, MediaManager
@ -45,52 +42,11 @@ class MediaPlugin(Plugin):
self.icon = build_icon(self.icon_path) self.icon = build_icon(self.icon_path)
# passed with drag and drop messages # passed with drag and drop messages
self.dnd_id = u'Media' self.dnd_id = u'Media'
self.additional_extensions = {
u'audio/ac3': [u'.ac3'],
u'audio/flac': [u'.flac'],
u'audio/x-m4a': [u'.m4a'],
u'audio/midi': [u'.mid', u'.midi'],
u'audio/x-mp3': [u'.mp3'],
u'audio/mpeg': [u'.mp3', u'.mp2', u'.mpga', u'.mpega', u'.m4a'],
u'audio/qcelp': [u'.qcp'],
u'audio/x-wma': [u'.wma'],
u'audio/x-ms-wma': [u'.wma'],
u'video/x-flv': [u'.flv'],
u'video/x-matroska': [u'.mpv', u'.mkv'],
u'video/x-wmv': [u'.wmv'],
u'video/x-ms-wmv': [u'.wmv']}
self.audio_extensions_list = []
self.video_extensions_list = []
mimetypes.init()
for mimetype in Phonon.BackendCapabilities.availableMimeTypes():
mimetype = unicode(mimetype)
if mimetype.startswith(u'audio/'):
self._addToList(self.audio_extensions_list, mimetype)
elif mimetype.startswith(u'video/'):
self._addToList(self.video_extensions_list, mimetype)
self.mediaManager = MediaManager(self) self.mediaManager = MediaManager(self)
self.audio_extensions_list = \
def _addToList(self, list, mimetype): self.mediaManager.get_audio_extensions_list()
# Add all extensions which mimetypes provides us for supported types. self.video_extensions_list = \
extensions = mimetypes.guess_all_extensions(unicode(mimetype)) self.mediaManager.get_video_extensions_list()
for extension in extensions:
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.serviceManager.supportedSuffixes(extension[1:])
log.info(u'MediaPlugin: %s extensions: %s' % (mimetype,
u' '.join(extensions)))
# Add extensions for this mimetype from self.additional_extensions.
# This hack clears mimetypes' and operating system's shortcomings
# by providing possibly missing extensions.
if mimetype in self.additional_extensions.keys():
for extension in self.additional_extensions[mimetype]:
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.serviceManager.supportedSuffixes(extension[1:])
log.info(u'MediaPlugin: %s additional extensions: %s' % (mimetype,
u' '.join(self.additional_extensions[mimetype])))
def about(self): def about(self):
about_text = translate('MediaPlugin', '<strong>Media Plugin</strong>' about_text = translate('MediaPlugin', '<strong>Media Plugin</strong>'