From 34284ea8aedb554071070aaf80aa7949e7ca6a3d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 7 Oct 2012 08:25:55 +0100 Subject: [PATCH] Clean up media extension lists and move the controller. Fix reload of suffixes to happen after media or presentaions changes --- openlp/core/ui/mainwindow.py | 2 ++ openlp/core/ui/media/mediacontroller.py | 18 ++++++++++++++++-- openlp/core/ui/media/playertab.py | 8 +++++--- openlp/core/ui/servicemanager.py | 10 +++++++++- openlp/core/ui/settingsform.py | 15 +++++++++++++-- openlp/plugins/media/lib/mediaitem.py | 15 ++++++++------- openlp/plugins/media/lib/mediatab.py | 4 +++- openlp/plugins/media/mediaplugin.py | 8 -------- openlp/plugins/presentations/lib/mediaitem.py | 13 ++++--------- .../presentations/lib/presentationtab.py | 3 +++ 10 files changed, 63 insertions(+), 33 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index d8c1d319b..ed27e82b1 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -587,6 +587,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.imageManager = ImageManager() # Set up the interface self.setupUi(self) + # Register the active media players and suffixes + self.mediaController.check_available_media_players() # Load settings after setupUi so default UI sizes are overwritten self.loadSettings() # Once settings are loaded update the menu with the recent files. diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index 362c1684e..632766ed1 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -55,7 +55,6 @@ class MediaController(object): # Timer for video state self.timer = QtCore.QTimer() self.timer.setInterval(200) - self._check_available_media_players() # Signals QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.video_state) @@ -82,12 +81,26 @@ class MediaController(object): QtCore.SIGNAL(u'songs_unblank'), self.video_unblank) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mediaitem_media_rebuild'), self._set_active_players) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'mediaitem_suffexes'), + self._generate_extensions_lists) def _set_active_players(self): + """ + Set the active players and available media files + """ savedPlayers = get_media_players()[0] for player in self.mediaPlayers.keys(): self.mediaPlayers[player].isActive = player in savedPlayers + def _generate_extensions_lists(self): + self.audio_extensions_list = self.get_audio_extensions_list() + for ext in self.audio_extensions_list: + self.mainWindow.serviceManagerContents.supportedSuffixes(ext[2:]) + self.video_extensions_list = self.get_video_extensions_list() + for ext in self.video_extensions_list: + self.mainWindow.serviceManagerContents.supportedSuffixes(ext[2:]) + def register_players(self, player): """ Register each media Player controller (Webkit, Phonon, etc) and store @@ -98,7 +111,7 @@ class MediaController(object): """ self.mediaPlayers[player.name] = player - def _check_available_media_players(self): + def check_available_media_players(self): """ Check to see if we have any media Player's available. If Not do not install the plugin. @@ -142,6 +155,7 @@ class MediaController(object): savedPlayers.remove(invalidPlayer) set_media_players(savedPlayers, overriddenPlayer) self._set_active_players() + self._generate_extensions_lists() return True def video_state(self): diff --git a/openlp/core/ui/media/playertab.py b/openlp/core/ui/media/playertab.py index d69624b59..3dedca7fb 100644 --- a/openlp/core/ui/media/playertab.py +++ b/openlp/core/ui/media/playertab.py @@ -44,14 +44,15 @@ class PlayerTab(SettingsTab): """ MediaTab is the Media settings tab in the settings dialog. """ - def __init__(self, parent, mediaPlayers): - self.mediaPlayers = mediaPlayers + def __init__(self, parent, mainWindow): + self.settingsForm = parent + self.mainWindow = mainWindow + self.mediaPlayers = mainWindow.mediaController.mediaPlayers self.savedUsedPlayers = None self.iconPath = u':/system/system_settings.png' player_translated = translate('OpenLP.PlayerTab', 'Players') SettingsTab.__init__(self, parent, u'Players', player_translated) - def setupUi(self): self.setObjectName(u'MediaTab') SettingsTab.setupUi(self) @@ -243,6 +244,7 @@ class PlayerTab(SettingsTab): set_media_players(self.usedPlayers, override_player) player_string_changed = True if player_string_changed: + self.settingsForm.resetSupportedSuffixes() Receiver.send_message(u'mediaitem_media_rebuild') Receiver.send_message(u'config_screen_changed') diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 9cedca87d..9ef57e86e 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -382,6 +382,13 @@ class ServiceManager(QtGui.QWidget): u'advanced/expand service item', QtCore.QVariant(u'False')).toBool() + def resetSupportedSuffixes(self): + """ + Resets the Suffexes list. + + """ + self.suffixes = [] + def supportedSuffixes(self, suffix): """ Adds Suffixes supported to the master list. Called from Plugins. @@ -389,7 +396,8 @@ class ServiceManager(QtGui.QWidget): ``suffix`` New Suffix to be supported """ - self.suffixes.append(suffix) + if not suffix in self.suffixes: + self.suffixes.append(suffix) def onNewServiceClicked(self): """ diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 475963aff..492d6de03 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -47,6 +47,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Initialise the settings form """ + self.mainWindow = mainWindow QtGui.QDialog.__init__(self, parent) self.setupUi(self) # General tab @@ -56,8 +57,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): # Advanced tab self.advancedTab = AdvancedTab(self) # Advanced tab - self.playerTab = PlayerTab(self, mainWindow.mediaController - .mediaPlayers) + self.playerTab = PlayerTab(self, mainWindow) def exec_(self): # load all the settings @@ -98,6 +98,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Process the form saving the settings """ + self.resetSuffexes = True for tabIndex in range(self.stackedLayout.count()): self.stackedLayout.widget(tabIndex).save() # Must go after all settings are save @@ -129,3 +130,13 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ self.stackedLayout.setCurrentIndex(tabIndex) self.stackedLayout.currentWidget().tabVisible() + + def resetSupportedSuffixes(self): + """ + Control the resetting of the serviceManager suffex list as can be + called by a number of settings tab and only needs to be called once + per save. + """ + if self.resetSuffexes: + self.mainWindow.serviceManagerContents.resetSupportedSuffixes() + self.resetSuffexes = False \ No newline at end of file diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 3eebbdf75..65d616ca8 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -87,7 +87,7 @@ class MediaMediaItem(MediaManagerItem): QtCore.SIGNAL(u'video_background_replaced'), self.videobackgroundReplaced) QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'mediaitem_media_rebuild'), self.rebuild) + QtCore.SIGNAL(u'mediaitem_media_rebuild'), self.rebuild_players) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_screen_changed'), self.displaySetup) # Allow DnD from the desktop @@ -95,10 +95,11 @@ class MediaMediaItem(MediaManagerItem): def retranslateUi(self): self.onNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media') - self.onNewFileMasks = unicode(translate('MediaPlugin.MediaItem', - 'Videos (%s);;Audio (%s);;%s (*)')) % ( - u' '.join(self.plugin.video_extensions_list), - u' '.join(self.plugin.audio_extensions_list), UiStrings().AllFiles) + #self.onNewFileMasks = unicode(translate('MediaPlugin.MediaItem', + # 'Videos (%s);;Audio (%s);;%s (*)')) % ( + # u' '.join(self.plugin.video_extensions_list), + # u' '.join(self.plugin.audio_extensions_list), + # UiStrings().AllFiles) self.replaceAction.setText(UiStrings().ReplaceBG) self.replaceAction.setToolTip(UiStrings().ReplaceLiveBG) self.resetAction.setText(UiStrings().ResetBG) @@ -235,7 +236,7 @@ class MediaMediaItem(MediaManagerItem): self.loadList(SettingsManager.load_list(self.settingsSection, u'media')) self.populateDisplayTypes() - def rebuild(self): + def rebuild_players(self): """ Rebuild the tab in the media manager when changes are made in the settings @@ -300,7 +301,7 @@ class MediaMediaItem(MediaManagerItem): filename = os.path.split(unicode(track))[1] item_name = QtGui.QListWidgetItem(filename) if u'*.%s' % (filename.split(u'.')[-1].lower()) in \ - self.plugin.audio_extensions_list: + self.plugin.mediaController.audio_extensions_list: item_name.setIcon(AUDIOICON) else: item_name.setIcon(CLAPPERICON) diff --git a/openlp/plugins/media/lib/mediatab.py b/openlp/plugins/media/lib/mediatab.py index f0c3999f3..52fdef4bb 100644 --- a/openlp/plugins/media/lib/mediatab.py +++ b/openlp/plugins/media/lib/mediatab.py @@ -96,4 +96,6 @@ class MediaTab(SettingsTab): Settings().setValue(setting_key, QtCore.QVariant(self.autoStartCheckBox.checkState())) if override_changed: - Receiver.send_message(u'mediaitem_media_rebuild') \ No newline at end of file + self.settingsForm.resetSupportedSuffixes() + Receiver.send_message(u'mediaitem_media_rebuild') + Receiver.send_message(u'mediaitem_suffexes') \ No newline at end of file diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 5d50a8f4b..9de5e9a31 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -47,14 +47,6 @@ class MediaPlugin(Plugin): self.icon = build_icon(self.iconPath) # passed with drag and drop messages self.dnd_id = u'Media' - self.audio_extensions_list = \ - self.mediaController.get_audio_extensions_list() - for ext in self.audio_extensions_list: - self.serviceManager.supportedSuffixes(ext[2:]) - self.video_extensions_list = \ - self.mediaController.get_video_extensions_list() - for ext in self.video_extensions_list: - self.serviceManager.supportedSuffixes(ext[2:]) def createSettingsTab(self, parent): """ diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 290882e26..cbf2d73b1 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -61,7 +61,10 @@ class PresentationMediaItem(MediaManagerItem): self.hasSearch = True self.singleServiceItem = False QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'mediaitem_presentation_rebuild'), self.rebuild) + QtCore.SIGNAL(u'mediaitem_presentation_rebuild'), + self.populateDisplayTypes) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'mediaitem_suffexes'), self.buildFileMaskString) # Allow DnD from the desktop self.listView.activateDnD() @@ -130,14 +133,6 @@ class PresentationMediaItem(MediaManagerItem): self.loadList(files, True) self.populateDisplayTypes() - def rebuild(self): - """ - Rebuild the tab in the media manager when changes are made in - the settings - """ - self.populateDisplayTypes() - self.buildFileMaskString() - def populateDisplayTypes(self): """ Load the combobox with the enabled presentation controllers, diff --git a/openlp/plugins/presentations/lib/presentationtab.py b/openlp/plugins/presentations/lib/presentationtab.py index a09e19a94..bf6d020f9 100644 --- a/openlp/plugins/presentations/lib/presentationtab.py +++ b/openlp/plugins/presentations/lib/presentationtab.py @@ -40,6 +40,7 @@ class PresentationTab(SettingsTab): """ Constructor """ + self.settingsForm = parent self.controllers = controllers SettingsTab.__init__(self, parent, title, visible_title, icon_path) self.activated = False @@ -141,7 +142,9 @@ class PresentationTab(SettingsTab): QtCore.QVariant(self.OverrideAppCheckBox.checkState())) changed = True if changed: + self.settingsForm.resetSupportedSuffixes() Receiver.send_message(u'mediaitem_presentation_rebuild') + Receiver.send_message(u'mediaitem_suffexes') def tabVisible(self): """