← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~crichter/openlp/bug-955992 into lp:openlp

 

rimach has proposed merging lp:~crichter/openlp/bug-955992 into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)
Related bugs:
  Bug #955992 in OpenLP: "Media Player override doesnt work"
  https://bugs.launchpad.net/openlp/+bug/955992

For more details, see:
https://code.launchpad.net/~crichter/openlp/bug-955992/+merge/98272

- move writing and reading of media settings into separate methods
- add overridden player to settings
- if overridden player is choosed, only thisone can be used.
-- 
https://code.launchpad.net/~crichter/openlp/bug-955992/+merge/98272
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/ui/media/__init__.py'
--- openlp/core/ui/media/__init__.py	2011-11-11 16:45:25 +0000
+++ openlp/core/ui/media/__init__.py	2012-03-19 19:35:21 +0000
@@ -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 @@
     end_time = 0
     media_type = MediaType()
 
+def get_media_players():
+    """
+    This method extract the configured media players and overridden player from
+    the settings
+
+    ``players_list``
+        this is a python list with all active media players
+    ``overridden_player``
+        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(".*\[(.*)\].*")
+    can_override = True if QtCore.QSettings().value(u'media/override player',
+        QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked else False
+    if can_override:
+        if reg_ex.exactMatch(players):
+            overridden_player = u'%s' % reg_ex.cap(1)
+        else:
+            overridden_player = u'auto'
+    else:
+        overridden_player = u''
+    players_list = players.replace('[', '').replace(']', '').split(u',')
+    return players_list, overridden_player
+
+
+def set_media_players(players_list, overridden_player=u'auto'):
+    """
+    This method saves the configured media players and overridden player to the
+    settings
+
+    ``players_list``
+        this is a python list with all active media players
+    ``overridden_player``
+        here an special media player is choosen for all media actions
+    """
+    log.debug(u'set_media_players')
+    players = u','.join(players_list)
+    can_override = True if QtCore.QSettings().value(u'media/override player',
+        QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked else False
+    if can_override and overridden_player != u'auto':
+        players = players.replace(overridden_player, u'[%s]' % overridden_player)
+    QtCore.QSettings().setValue(u'media/players', QtCore.QVariant(players))
+
 from mediacontroller import MediaController

=== modified file 'openlp/core/ui/media/mediacontroller.py'
--- openlp/core/ui/media/mediacontroller.py	2012-03-17 16:42:53 +0000
+++ openlp/core/ui/media/mediacontroller.py	2012-03-19 19:35:21 +0000
@@ -32,7 +32,8 @@
 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 @@
         self.parent = parent
         self.mediaPlayers = {}
         self.controller = []
-        self.overriddenPlayer = ''
         self.curDisplayMediaPlayer = {}
         # Timer for video state
         self.timer = QtCore.QTimer()
@@ -73,8 +73,6 @@
             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 @@
             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 @@
             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:
@@ -367,13 +357,9 @@
         """
         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()
@@ -584,16 +570,6 @@
                         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:

=== modified file 'openlp/plugins/media/lib/mediaitem.py'
--- openlp/plugins/media/lib/mediaitem.py	2012-03-15 06:15:21 +0000
+++ openlp/plugins/media/lib/mediaitem.py	2012-03-19 19:35:21 +0000
@@ -37,6 +37,7 @@
 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 @@
             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 @@
         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):
         """

=== modified file 'openlp/plugins/media/lib/mediatab.py'
--- openlp/plugins/media/lib/mediatab.py	2012-03-12 10:53:17 +0000
+++ openlp/plugins/media/lib/mediatab.py	2012-03-19 19:35:21 +0000
@@ -29,7 +29,7 @@
 
 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 @@
                 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 @@
         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 @@
         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 @@
     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'


Follow ups