From 19fac1e84a824a5edf03710466171b6ce0116262 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 15 Dec 2011 22:13:45 +0200 Subject: [PATCH 1/2] Cleaned up some code to conform to our coding standards. Added an appStartup() method to the media plugin to detect the settings of an older version of the media plugin, and update the settings. --- openlp/plugins/media/lib/mediaitem.py | 6 +-- openlp/plugins/media/lib/mediatab.py | 68 +++++++++++++-------------- openlp/plugins/media/mediaplugin.py | 25 ++++++++++ 3 files changed, 62 insertions(+), 37 deletions(-) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 0d5d8eeff..8a7eb86eb 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -54,7 +54,7 @@ class MediaMediaItem(MediaManagerItem): self.iconPath = u'images/image' self.background = False self.previewFunction = CLAPPERBOARD - self.Automatic = u'' + self.automatic = u'' MediaManagerItem.__init__(self, parent, plugin, icon) self.singleServiceItem = False self.hasSearch = True @@ -101,7 +101,7 @@ class MediaMediaItem(MediaManagerItem): self.replaceAction.setToolTip(UiStrings().ReplaceLiveBG) self.resetAction.setText(UiStrings().ResetBG) self.resetAction.setToolTip(UiStrings().ResetLiveBG) - self.Automatic = translate('MediaPlugin.MediaItem', + self.automatic = translate('MediaPlugin.MediaItem', 'Automatic') self.displayTypeLabel.setText( translate('MediaPlugin.MediaItem', 'Use Player:')) @@ -253,7 +253,7 @@ class MediaMediaItem(MediaManagerItem): # load the drop down selection self.displayTypeComboBox.addItem(title) if self.displayTypeComboBox.count() > 1: - self.displayTypeComboBox.insertItem(0, self.Automatic) + 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: diff --git a/openlp/plugins/media/lib/mediatab.py b/openlp/plugins/media/lib/mediatab.py index 4e39bc419..1b75016cc 100644 --- a/openlp/plugins/media/lib/mediatab.py +++ b/openlp/plugins/media/lib/mediatab.py @@ -35,7 +35,7 @@ class MediaTab(SettingsTab): MediaTab is the Media settings tab in the settings dialog. """ def __init__(self, parent, title, visible_title, media_players, icon_path): - self.media_players = media_players + self.mediaPlayers = media_players SettingsTab.__init__(self, parent, title, visible_title, icon_path) def setupUi(self): @@ -45,13 +45,13 @@ class MediaTab(SettingsTab): self.mediaPlayerGroupBox.setObjectName(u'mediaPlayerGroupBox') self.mediaPlayerLayout = QtGui.QVBoxLayout(self.mediaPlayerGroupBox) self.mediaPlayerLayout.setObjectName(u'mediaPlayerLayout') - self.PlayerCheckBoxes = {} - for key in self.media_players: - player = self.media_players[key] + self.playerCheckBoxes = {} + for key, player in self.mediaPlayers.iteritems(): + player = self.mediaPlayers[key] checkbox = QtGui.QCheckBox(self.mediaPlayerGroupBox) checkbox.setEnabled(player.available) checkbox.setObjectName(player.name + u'CheckBox') - self.PlayerCheckBoxes[player.name] = checkbox + self.playerCheckBoxes[player.name] = checkbox self.mediaPlayerLayout.addWidget(checkbox) self.leftLayout.addWidget(self.mediaPlayerGroupBox) self.playerOrderGroupBox = QtGui.QGroupBox(self.leftColumn) @@ -88,19 +88,19 @@ class MediaTab(SettingsTab): self.orderingButtonLayout.addWidget(self.orderingUpButton) self.playerOrderLayout.addWidget(self.orderingButtonsWidget) self.leftLayout.addWidget(self.playerOrderGroupBox) - self.AdvancedGroupBox = QtGui.QGroupBox(self.leftColumn) - self.AdvancedGroupBox.setObjectName(u'AdvancedGroupBox') - self.AdvancedLayout = QtGui.QVBoxLayout(self.AdvancedGroupBox) - self.AdvancedLayout.setObjectName(u'AdvancedLayout') - self.OverridePlayerCheckBox = QtGui.QCheckBox(self.AdvancedGroupBox) - self.OverridePlayerCheckBox.setObjectName(u'OverridePlayerCheckBox') - self.AdvancedLayout.addWidget(self.OverridePlayerCheckBox) - self.leftLayout.addWidget(self.AdvancedGroupBox) + self.advancedGroupBox = QtGui.QGroupBox(self.leftColumn) + self.advancedGroupBox.setObjectName(u'advancedGroupBox') + self.advancedLayout = QtGui.QVBoxLayout(self.advancedGroupBox) + self.advancedLayout.setObjectName(u'advancedLayout') + self.overridePlayerCheckBox = QtGui.QCheckBox(self.advancedGroupBox) + self.overridePlayerCheckBox.setObjectName(u'overridePlayerCheckBox') + self.advancedLayout.addWidget(self.overridePlayerCheckBox) + self.leftLayout.addWidget(self.advancedGroupBox) self.leftLayout.addStretch() self.rightLayout.addStretch() - for key in self.media_players: - player = self.media_players[key] - checkbox = self.PlayerCheckBoxes[player.name] + for key in self.mediaPlayers: + player = self.mediaPlayers[key] + checkbox = self.playerCheckBoxes[player.name] QtCore.QObject.connect(checkbox, QtCore.SIGNAL(u'stateChanged(int)'), self.onPlayerCheckBoxChanged) @@ -112,9 +112,9 @@ class MediaTab(SettingsTab): def retranslateUi(self): self.mediaPlayerGroupBox.setTitle( translate('MediaPlugin.MediaTab', 'Available Media Players')) - for key in self.media_players: - player = self.media_players[key] - checkbox = self.PlayerCheckBoxes[player.name] + for key in self.mediaPlayers: + player = self.mediaPlayers[key] + checkbox = self.playerCheckBoxes[player.name] if player.available: checkbox.setText(player.name) else: @@ -127,8 +127,8 @@ class MediaTab(SettingsTab): translate('MediaPlugin.MediaTab', 'Down')) self.orderingUpButton.setText( translate('MediaPlugin.MediaTab', 'Up')) - self.AdvancedGroupBox.setTitle(UiStrings().Advanced) - self.OverridePlayerCheckBox.setText( + self.advancedGroupBox.setTitle(UiStrings().Advanced) + self.overridePlayerCheckBox.setText( translate('MediaPlugin.MediaTab', 'Allow media player to be overriden')) @@ -144,12 +144,12 @@ class MediaTab(SettingsTab): def updatePlayerList(self): self.playerOrderlistWidget.clear() for player in self.usedPlayers: - if player in self.PlayerCheckBoxes.keys(): + if player in self.playerCheckBoxes.keys(): if len(self.usedPlayers) == 1: # at least one media player have to stay active - self.PlayerCheckBoxes[u'%s' % player].setEnabled(False) + self.playerCheckBoxes[u'%s' % player].setEnabled(False) else: - self.PlayerCheckBoxes[u'%s' % player].setEnabled(True) + self.playerCheckBoxes[u'%s' % player].setEnabled(True) self.playerOrderlistWidget.addItem(player) def onOrderingUpButtonPressed(self): @@ -172,34 +172,34 @@ class MediaTab(SettingsTab): self.usedPlayers = QtCore.QSettings().value( self.settingsSection + u'/players', QtCore.QVariant(u'webkit')).toString().split(u',') - for key in self.media_players: - player = self.media_players[key] - checkbox = self.PlayerCheckBoxes[player.name] + for key in self.mediaPlayers: + player = self.mediaPlayers[key] + checkbox = self.playerCheckBoxes[player.name] if player.available and player.name in self.usedPlayers: checkbox.setChecked(True) self.updatePlayerList() - self.OverridePlayerCheckBox.setChecked(QtCore.QSettings().value( + self.overridePlayerCheckBox.setChecked(QtCore.QSettings().value( self.settingsSection + u'/override player', QtCore.QVariant(QtCore.Qt.Unchecked)).toInt()[0]) def save(self): override_changed = False player_string_changed = False - oldPlayerString = QtCore.QSettings().value( + old_players = QtCore.QSettings().value( self.settingsSection + u'/players', QtCore.QVariant(u'webkit')).toString() - newPlayerString = self.usedPlayers.join(u',') - if oldPlayerString != newPlayerString: + new_players = self.usedPlayers.join(u',') + if old_players != new_players: # clean old Media stuff QtCore.QSettings().setValue(self.settingsSection + u'/players', - QtCore.QVariant(newPlayerString)) + QtCore.QVariant(new_players)) player_string_changed = True override_changed = True setting_key = self.settingsSection + u'/override player' if QtCore.QSettings().value(setting_key) != \ - self.OverridePlayerCheckBox.checkState(): + self.overridePlayerCheckBox.checkState(): QtCore.QSettings().setValue(setting_key, - QtCore.QVariant(self.OverridePlayerCheckBox.checkState())) + QtCore.QVariant(self.overridePlayerCheckBox.checkState())) override_changed = True if override_changed: Receiver.send_message(u'mediaitem_media_rebuild') diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 2825d899e..851779477 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -27,6 +27,8 @@ import logging +from PyQt4 import QtCore + from openlp.core.lib import Plugin, StringContent, build_icon, translate from openlp.plugins.media.lib import MediaMediaItem, MediaTab @@ -117,3 +119,26 @@ class MediaPlugin(Plugin): Add html code to htmlbuilder """ return self.mediaController.get_media_display_html() + + def appStartup(self): + """ + Do a couple of things when the app starts up. In this particular case + we want to check if we have the old "Use Phonon" setting, and convert + it to "enable Phonon" and "make it the first one in the list". + """ + has_phonon = u'phonon' in self.mediaController.mediaPlayers.keys() + settings = QtCore.QSettings() + settings.beginGroup(self.settingsSection) + if settings.contains(u'use phonon'): + log.info(u'Found old Phonon setting') + if settings.value(u'use phonon').toBool() and has_phonon: + log.debug(u'Converting old setting to new setting') + players = unicode(settings.value(u'players').toString()) + new_players = [] + if players: + new_players = [player for player in players.split(u',') \ + if player != u'phonon'] + new_players.insert(0, u'phonon') + settings.setValue(u'players', \ + QtCore.QVariant(u','.join(new_players))) + settings.remove(u'use phonon') From d8009518007ed0c28e6ec068cb83aaad85b83af6 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 15 Dec 2011 23:06:50 +0200 Subject: [PATCH 2/2] Actually read directly from the media controller, and then update the settings tab. --- openlp/plugins/media/mediaplugin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 851779477..3b790dd93 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -126,19 +126,22 @@ class MediaPlugin(Plugin): we want to check if we have the old "Use Phonon" setting, and convert it to "enable Phonon" and "make it the first one in the list". """ - has_phonon = u'phonon' in self.mediaController.mediaPlayers.keys() settings = QtCore.QSettings() settings.beginGroup(self.settingsSection) if settings.contains(u'use phonon'): log.info(u'Found old Phonon setting') + players = self.mediaController.mediaPlayers.keys() + has_phonon = u'phonon' in players if settings.value(u'use phonon').toBool() and has_phonon: log.debug(u'Converting old setting to new setting') - players = unicode(settings.value(u'players').toString()) new_players = [] if players: - new_players = [player for player in players.split(u',') \ + new_players = [player for player in players \ if player != u'phonon'] new_players.insert(0, u'phonon') + self.mediaController.mediaPlayers[u'phonon'].isActive = True settings.setValue(u'players', \ QtCore.QVariant(u','.join(new_players))) + self.settings_tab.load() settings.remove(u'use phonon') + settings.endGroup()