Clean up media extension lists and move the controller. Fix reload of suffixes to happen after media or presentaions changes

This commit is contained in:
Tim Bentley 2012-10-07 08:25:55 +01:00
parent 1c0685d08b
commit 34284ea8ae
10 changed files with 63 additions and 33 deletions

View File

@ -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.

View File

@ -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):

View File

@ -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')

View File

@ -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):
"""

View File

@ -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

View File

@ -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)

View File

@ -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')
self.settingsForm.resetSupportedSuffixes()
Receiver.send_message(u'mediaitem_media_rebuild')
Receiver.send_message(u'mediaitem_suffexes')

View File

@ -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):
"""

View File

@ -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,

View File

@ -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):
"""