correct overridden media option

This commit is contained in:
rimach 2012-03-16 22:52:15 +01:00
parent 0ece4fdfa3
commit 360df826e1
4 changed files with 96 additions and 67 deletions

View File

@ -24,17 +24,21 @@
# 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
log = logging.getLogger(__name__)
class MediaState(object):
"""
An enumeration for possible States of the Media Player (copied partially
from Phonon::State)
An enumeration for possible States of the Media Player
"""
Loading = 0
Stopped = 1
Off = 0
Loaded = 1
Playing = 2
Paused = 4
Off = 6
Paused = 3
Stopped = 4
class MediaType(object):
@ -62,4 +66,51 @@ class MediaInfo(object):
end_time = 0
media_type = MediaType()
def get_media_players():
"""
This method extract the configured media players and overridden player from
the settings
``playersList``
this is a python list with all active media players
``overriddenPlayer``
here an special media player is choosen for all media actions
"""
log.debug(u'get_media_players')
players = str(QtCore.QSettings().value(u'media/players',
QtCore.QVariant(u'webkit')).toString())
if len(players) == 0:
players = u'webkit'
reg_ex = QtCore.QRegExp(".*\[(.*)\].*")
canOverride = True if QtCore.QSettings().value(u'media/override player',
QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked else False
if canOverride:
if reg_ex.exactMatch(players):
overriddenPlayer = u'%s' % reg_ex.cap(1)
else:
overriddenPlayer = u'auto'
else:
overriddenPlayer = u''
playersList = players.replace('[', '').replace(']', '').split(u',')
return [playersList, overriddenPlayer]
def set_media_players(playersList, overriddenPlayer=u'auto'):
"""
This method saves the configured media players and overridden player to the
settings
``playersList``
this is a python list with all active media players
``overriddenPlayer``
here an special media player is choosen for all media actions
"""
log.debug(u'set_media_players')
players = u','.join(playersList)
canOverride = True if QtCore.QSettings().value(u'media/override player',
QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked else False
if canOverride and overriddenPlayer != u'auto':
players = players.replace(overriddenPlayer, u'[%s]' % overriddenPlayer)
QtCore.QSettings().setValue(u'media/players', QtCore.QVariant(players))
from mediacontroller import MediaController

View File

@ -32,7 +32,8 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, Receiver, translate
from openlp.core.lib.mediaplayer import MediaPlayer
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui.media import MediaState, MediaInfo, MediaType
from openlp.core.ui.media import MediaState, MediaInfo, MediaType, \
get_media_players, set_media_players
from openlp.core.utils import AppLocation
log = logging.getLogger(__name__)
@ -47,7 +48,6 @@ class MediaController(object):
self.parent = parent
self.mediaPlayers = {}
self.controller = []
self.overriddenPlayer = ''
self.curDisplayMediaPlayer = {}
# Timer for video state
self.timer = QtCore.QTimer()
@ -58,23 +58,21 @@ class MediaController(object):
QtCore.QObject.connect(self.timer,
QtCore.SIGNAL("timeout()"), self.video_state)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_playback_play'), self.video_play)
QtCore.SIGNAL(u'playbackPlay'), self.video_play)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_playback_pause'), self.video_pause)
QtCore.SIGNAL(u'playbackPause'), self.video_pause)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_playback_stop'), self.video_stop)
QtCore.SIGNAL(u'playbackStop'), self.video_stop)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'seek_slider'), self.video_seek)
QtCore.SIGNAL(u'seekSlider'), self.video_seek)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'volume_slider'), self.video_volume)
QtCore.SIGNAL(u'volumeSlider'), self.video_volume)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_hide'), self.video_hide)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_blank'), self.video_blank)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_unblank'), self.video_unblank)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_override_player'), self.override_player)
# Signals for background video
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'songs_hide'), self.video_hide)
@ -84,11 +82,7 @@ class MediaController(object):
QtCore.SIGNAL(u'mediaitem_media_rebuild'), self.set_active_players)
def set_active_players(self):
playerSettings = str(QtCore.QSettings().value(u'media/players',
QtCore.QVariant(u'webkit')).toString())
if len(playerSettings) == 0:
playerSettings = u'webkit'
savedPlayers = playerSettings.split(u',')
savedPlayers = get_media_players()[0]
for player in self.mediaPlayers.keys():
if player in savedPlayers:
self.mediaPlayers[player].isActive = True
@ -129,18 +123,14 @@ class MediaController(object):
controller = controller_class(self)
self.register_controllers(controller)
if self.mediaPlayers:
playerSettings = str(QtCore.QSettings().value(u'media/players',
QtCore.QVariant(u'webkit')).toString())
savedPlayers = playerSettings.split(u',')
savedPlayers, overriddenPlayer = get_media_players()
invalidMediaPlayers = [mediaPlayer for mediaPlayer in savedPlayers \
if not mediaPlayer in self.mediaPlayers or \
not self.mediaPlayers[mediaPlayer].check_available()]
if len(invalidMediaPlayers) > 0:
for invalidPlayer in invalidMediaPlayers:
savedPlayers.remove(invalidPlayer)
newPlayerSetting = u','.join(savedPlayers)
QtCore.QSettings().setValue(u'media/players',
QtCore.QVariant(newPlayerSetting))
set_media_players(savedPlayers, overriddenPlayer)
self.set_active_players()
return True
else:
@ -361,13 +351,9 @@ class MediaController(object):
"""
Select the correct media Player type from the prioritized Player list
"""
playerSettings = str(QtCore.QSettings().value(u'media/players',
QtCore.QVariant(u'webkit')).toString())
usedPlayers = playerSettings.split(u',')
if QtCore.QSettings().value(u'media/override player',
QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
if self.overriddenPlayer != '':
usedPlayers = [self.overriddenPlayer]
usedPlayers, overriddenPlayer = get_media_players()
if overriddenPlayer != '' and overriddenPlayer != 'auto':
usedPlayers = [overriddenPlayer]
if controller.media_info.file_info.isFile():
suffix = u'*.%s' % \
controller.media_info.file_info.suffix().toLower()
@ -577,16 +563,6 @@ class MediaController(object):
video_list.append(item)
return video_list
def override_player(self, override_player_index):
playerSettings = str(QtCore.QSettings().value(u'media/players',
QtCore.QVariant(u'webkit')).toString())
usedPlayers = playerSettings.split(u',')
if override_player_index >= 0 and \
override_player_index < len(usedPlayers):
self.overridenPlayer = usedPlayers[override_player_index]
else:
self.overriddenPlayer = ''
def finalise(self):
self.timer.stop()
for controller in self.controller:

View File

@ -37,6 +37,7 @@ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
media_item_combo_box
from openlp.core.ui import Controller, Display
from openlp.core.ui.media import get_media_players, set_media_players
log = logging.getLogger(__name__)
@ -142,8 +143,11 @@ class MediaMediaItem(MediaManagerItem):
self.overridePlayerChanged)
def overridePlayerChanged(self, index):
# index - 1, because the first item is "Automatic".
Receiver.send_message(u'media_override_player', index - 1)
player = get_media_players()[0]
if index == 0:
set_media_players(player)
else:
set_media_players(player, player[index-1])
def onResetClick(self):
"""
@ -239,29 +243,31 @@ class MediaMediaItem(MediaManagerItem):
self.plugin.mediaController.setup_display( \
self.mediaController.previewDisplay)
def populateDisplayTypes(self):
"""
Load the combobox with the enabled media players,
allowing user to select a specific player if settings allow
"""
# block signals to avoid unnecessary overridePlayerChanged Signales
# while combo box creation
self.displayTypeComboBox.blockSignals(True)
self.displayTypeComboBox.clear()
playerSettings = str(QtCore.QSettings().value(u'media/players',
QtCore.QVariant(u'webkit')).toString())
usedPlayers = playerSettings.split(u',')
usedPlayers, overridePlayer = get_media_players()
mediaPlayers = self.plugin.mediaController.mediaPlayers
currentIndex = 0
for player in usedPlayers:
# load the drop down selection
self.displayTypeComboBox.addItem(mediaPlayers[player].original_name)
if overridePlayer == player:
currentIndex = len(self.displayTypeComboBox)
if self.displayTypeComboBox.count() > 1:
self.displayTypeComboBox.insertItem(0, self.automatic)
self.displayTypeComboBox.setCurrentIndex(0)
if QtCore.QSettings().value(self.settingsSection + u'/override player',
QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
self.displayTypeComboBox.setCurrentIndex(currentIndex)
if overridePlayer != '':
self.mediaWidget.show()
else:
self.mediaWidget.hide()
self.displayTypeComboBox.blockSignals(False)
def onDeleteClick(self):
"""

View File

@ -29,7 +29,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import SettingsTab, translate, Receiver
from openlp.core.lib.ui import UiStrings, create_up_down_push_button_set
from openlp.core.ui.media import get_media_players, set_media_players
class MediaQCheckBox(QtGui.QCheckBox):
"""
MediaQCheckBox adds an extra property, playerName to the QCheckBox class.
@ -138,7 +138,7 @@ class MediaTab(SettingsTab):
self.usedPlayers.append(player)
else:
if player in self.usedPlayers:
self.usedPlayers.takeAt(self.usedPlayers.indexOf(player))
self.usedPlayers.remove(player)
self.updatePlayerList()
def updatePlayerList(self):
@ -160,7 +160,7 @@ class MediaTab(SettingsTab):
item = self.playerOrderlistWidget.takeItem(row)
self.playerOrderlistWidget.insertItem(row - 1, item)
self.playerOrderlistWidget.setCurrentRow(row - 1)
self.usedPlayers.move(row, row - 1)
self.usedPlayers.insert(row-1, self.usedPlayers.pop(row))
def onDownButtonClicked(self):
row = self.playerOrderlistWidget.currentRow()
@ -169,12 +169,12 @@ class MediaTab(SettingsTab):
item = self.playerOrderlistWidget.takeItem(row)
self.playerOrderlistWidget.insertItem(row + 1, item)
self.playerOrderlistWidget.setCurrentRow(row + 1)
self.usedPlayers.move(row, row + 1)
self.usedPlayers.insert(row+1, self.usedPlayers.pop(row))
def load(self):
self.usedPlayers = QtCore.QSettings().value(
self.settingsSection + u'/players',
QtCore.QVariant(u'webkit')).toString().split(u',')
if self.savedUsedPlayers:
self.usedPlayers = self.savedUsedPlayers
self.usedPlayers = get_media_players()[0]
self.savedUsedPlayers = self.usedPlayers
for key in self.mediaPlayers:
player = self.mediaPlayers[key]
@ -191,14 +191,10 @@ class MediaTab(SettingsTab):
def save(self):
override_changed = False
player_string_changed = False
old_players = QtCore.QSettings().value(
self.settingsSection + u'/players',
QtCore.QVariant(u'webkit')).toString()
new_players = self.usedPlayers.join(u',')
if old_players != new_players:
old_players, override_player = get_media_players()
if self.usedPlayers != old_players:
# clean old Media stuff
QtCore.QSettings().setValue(self.settingsSection + u'/players',
QtCore.QVariant(new_players))
set_media_players(self.usedPlayers, override_player)
player_string_changed = True
override_changed = True
setting_key = self.settingsSection + u'/override player'