openlp/openlp/plugins/media/mediaplugin.py

133 lines
5.5 KiB
Python

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# 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
from openlp.core.common import Registry, translate
from openlp.core.lib import Plugin, StringContent, build_icon
from openlp.plugins.media.lib import MediaMediaItem, MediaTab
log = logging.getLogger(__name__)
# Some settings starting with "media" are in core, because they are needed for core functionality.
__default_settings__ = {
'media/media auto start': QtCore.Qt.Unchecked,
'media/media files': []
}
class MediaPlugin(Plugin):
log.info('%s MediaPlugin loaded', __name__)
def __init__(self):
super(MediaPlugin, self).__init__('media', __default_settings__, MediaMediaItem)
self.weight = -6
self.icon_path = ':/plugins/plugin_media.png'
self.icon = build_icon(self.icon_path)
# passed with drag and drop messages
self.dnd_id = 'Media'
def create_settings_tab(self, parent):
"""
Create the settings Tab
"""
visible_name = self.get_string(StringContent.VisibleName)
self.settings_tab = MediaTab(parent, self.name, visible_name['title'], self.icon_path)
def about(self):
about_text = translate('MediaPlugin', '<strong>Media Plugin</strong>'
'<br />The media plugin provides playback of audio and video.')
return about_text
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin
"""
## Name PluginList ##
self.text_strings[StringContent.Name] = {
'singular': translate('MediaPlugin', 'Media', 'name singular'),
'plural': translate('MediaPlugin', 'Media', 'name plural')
}
## Name for MediaDockManager, SettingsManager ##
self.text_strings[StringContent.VisibleName] = {
'title': translate('MediaPlugin', 'Media', 'container title')
}
# Middle Header Bar
tooltips = {
'load': translate('MediaPlugin', 'Load new media.'),
'import': '',
'new': translate('MediaPlugin', 'Add new media.'),
'edit': translate('MediaPlugin', 'Edit the selected media.'),
'delete': translate('MediaPlugin', 'Delete the selected media.'),
'preview': translate('MediaPlugin', 'Preview the selected media.'),
'live': translate('MediaPlugin', 'Send the selected media live.'),
'service': translate('MediaPlugin', 'Add the selected media to the service.')
}
self.set_plugin_ui_text_strings(tooltips)
def finalise(self):
"""
Time to tidy up on exit.
"""
log.info('Media Finalising')
self.media_controller.finalise()
Plugin.finalise(self)
def get_display_css(self):
"""
Add css style sheets to htmlbuilder.
"""
return self.media_controller.get_media_display_css()
def get_display_javascript(self):
"""
Add javascript functions to htmlbuilder.
"""
return self.media_controller.get_media_display_javascript()
def get_display_html(self):
"""
Add html code to htmlbuilder.
"""
return self.media_controller.get_media_display_html()
def _get_media_controller(self):
"""
Adds the media controller to the class dynamically
"""
if not hasattr(self, '_media_controller'):
self._media_controller = Registry().get('media_controller')
return self._media_controller
media_controller = property(_get_media_controller)