openlp/openlp/core/ui/media/__init__.py

121 lines
4.4 KiB
Python
Raw Normal View History

2011-07-10 21:43:07 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
2014-01-14 19:25:18 +00:00
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# 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, #
2012-11-07 21:37:01 +00:00
# Frode Woldsund, Martin Zibricky #
2011-07-10 21:43:07 +00:00
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
2012-03-16 21:52:15 +00:00
import logging
from openlp.core.lib.settings import Settings
2012-03-16 21:52:15 +00:00
from PyQt4 import QtCore
log = logging.getLogger(__name__)
2011-07-10 21:43:07 +00:00
class MediaState(object):
"""
2012-03-16 21:52:15 +00:00
An enumeration for possible States of the Media Player
2011-07-10 21:43:07 +00:00
"""
2012-03-16 21:52:15 +00:00
Off = 0
Loaded = 1
2011-07-10 21:43:07 +00:00
Playing = 2
2012-03-16 21:52:15 +00:00
Paused = 3
Stopped = 4
2011-07-10 21:43:07 +00:00
2011-09-22 18:22:35 +00:00
2011-07-10 21:43:07 +00:00
class MediaType(object):
"""
2011-10-24 20:04:29 +00:00
An enumeration of possibible Media Types
2011-07-10 21:43:07 +00:00
"""
2011-08-29 19:55:58 +00:00
Unused = 0
Audio = 1
Video = 2
2011-08-29 21:51:03 +00:00
CD = 3
DVD = 4
2011-08-29 19:55:58 +00:00
Folder = 5
2011-07-10 21:43:07 +00:00
2011-09-22 18:22:35 +00:00
2011-07-10 21:43:07 +00:00
class MediaInfo(object):
"""
This class hold the media related infos
"""
file_info = None
volume = 100
2011-08-29 19:55:58 +00:00
is_flash = False
2011-07-10 21:43:07 +00:00
is_background = False
length = 0
start_time = 0
end_time = 0
media_type = MediaType()
2012-03-16 21:52:15 +00:00
def get_media_players():
"""
This method extract the configured media players and overridden player from
2012-04-28 11:13:16 +00:00
the settings.
2012-03-16 21:52:15 +00:00
2012-03-19 19:27:02 +00:00
``players_list``
2012-04-28 11:31:42 +00:00
A list with all active media players.
2012-04-28 11:13:16 +00:00
2012-03-19 19:27:02 +00:00
``overridden_player``
2012-04-28 11:13:16 +00:00
Here an special media player is chosen for all media actions.
2012-03-16 21:52:15 +00:00
"""
log.debug(u'get_media_players')
players = unicode(Settings().value(u'media/players').toString())
2012-03-21 19:30:18 +00:00
if not players:
2012-03-16 21:52:15 +00:00
players = u'webkit'
reg_ex = QtCore.QRegExp(".*\[(.*)\].*")
if Settings().value(u'media/override player',
2012-03-21 19:30:18 +00:00
QtCore.QVariant(QtCore.Qt.Unchecked)).toInt()[0] == QtCore.Qt.Checked:
2012-03-16 21:52:15 +00:00
if reg_ex.exactMatch(players):
2012-03-19 19:27:02 +00:00
overridden_player = u'%s' % reg_ex.cap(1)
2012-03-16 21:52:15 +00:00
else:
2012-03-19 19:27:02 +00:00
overridden_player = u'auto'
2012-03-16 21:52:15 +00:00
else:
2012-03-19 19:27:02 +00:00
overridden_player = u''
2012-03-21 19:30:18 +00:00
players_list = players.replace(u'[', u'').replace(u']', u'').split(u',')
2012-03-19 19:27:02 +00:00
return players_list, overridden_player
2012-03-16 21:52:15 +00:00
2012-04-28 11:13:16 +00:00
2012-03-19 19:27:02 +00:00
def set_media_players(players_list, overridden_player=u'auto'):
2012-03-16 21:52:15 +00:00
"""
This method saves the configured media players and overridden player to the
settings
2012-03-19 19:27:02 +00:00
``players_list``
2012-04-28 11:13:16 +00:00
A list with all active media players.
2012-03-19 19:27:02 +00:00
``overridden_player``
2012-04-28 11:13:16 +00:00
Here an special media player is chosen for all media actions.
2012-03-16 21:52:15 +00:00
"""
log.debug(u'set_media_players')
2012-03-19 19:27:02 +00:00
players = u','.join(players_list)
if Settings().value(u'media/override player',
2012-03-21 19:30:18 +00:00
QtCore.QVariant(QtCore.Qt.Unchecked)).toInt()[0] == \
QtCore.Qt.Checked and overridden_player != u'auto':
2012-03-19 19:27:02 +00:00
players = players.replace(overridden_player, u'[%s]' % overridden_player)
Settings().setValue(u'media/players', QtCore.QVariant(players))
2012-03-16 21:52:15 +00:00
2011-08-29 21:51:03 +00:00
from mediacontroller import MediaController