2010-09-10 19:21:14 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-29 13:35:16 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2010-09-10 19:21:14 +00:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
2010-09-10 19:21:14 +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 #
|
|
|
|
###############################################################################
|
2013-02-01 20:52:42 +00:00
|
|
|
"""
|
|
|
|
The media manager dock.
|
|
|
|
"""
|
2010-09-10 19:21:14 +00:00
|
|
|
import logging
|
|
|
|
|
2010-09-16 21:10:36 +00:00
|
|
|
from openlp.core.lib import StringContent
|
2010-09-15 17:55:27 +00:00
|
|
|
|
2010-09-10 19:21:14 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-02-01 20:52:42 +00:00
|
|
|
|
2010-09-10 19:21:14 +00:00
|
|
|
class MediaDockManager(object):
|
|
|
|
"""
|
|
|
|
Provide a repository for MediaManagerItems
|
|
|
|
"""
|
|
|
|
def __init__(self, media_dock):
|
|
|
|
"""
|
|
|
|
Initialise the media dock
|
|
|
|
"""
|
|
|
|
self.media_dock = media_dock
|
|
|
|
|
|
|
|
def add_dock(self, media_item, icon, weight):
|
|
|
|
"""
|
|
|
|
Add a MediaManagerItem to the dock
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param media_item: The item to add to the dock
|
|
|
|
:param icon: An icon for this dock item
|
|
|
|
:param weight:
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
2013-03-19 19:43:22 +00:00
|
|
|
visible_title = media_item.plugin.get_string(StringContent.VisibleName)
|
2013-08-31 18:17:38 +00:00
|
|
|
log.info('Adding %s dock' % visible_title)
|
|
|
|
self.media_dock.addItem(media_item, icon, visible_title['title'])
|
2010-09-10 19:21:14 +00:00
|
|
|
|
|
|
|
def insert_dock(self, media_item, icon, weight):
|
|
|
|
"""
|
|
|
|
This should insert a dock item at a given location
|
|
|
|
This does not work as it gives a Segmentation error.
|
|
|
|
For now add at end of stack if not present
|
|
|
|
"""
|
2013-03-19 19:43:22 +00:00
|
|
|
visible_title = media_item.plugin.get_string(StringContent.VisibleName)
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('Inserting %s dock' % visible_title['title'])
|
2010-09-10 19:21:14 +00:00
|
|
|
match = False
|
2012-05-01 11:00:02 +00:00
|
|
|
for dock_index in range(self.media_dock.count()):
|
2013-03-19 19:43:22 +00:00
|
|
|
if self.media_dock.widget(dock_index).settings_section == media_item.plugin.name:
|
2010-09-10 19:21:14 +00:00
|
|
|
match = True
|
|
|
|
break
|
|
|
|
if not match:
|
2013-08-31 18:17:38 +00:00
|
|
|
self.media_dock.addItem(media_item, icon, visible_title['title'])
|
2010-09-10 19:21:14 +00:00
|
|
|
|
2010-09-14 17:46:21 +00:00
|
|
|
def remove_dock(self, media_item):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
|
|
|
Removes a MediaManagerItem from the dock
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param media_item: The item to add to the dock
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
2013-03-19 19:43:22 +00:00
|
|
|
visible_title = media_item.plugin.get_string(StringContent.VisibleName)
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('remove %s dock' % visible_title['title'])
|
2012-05-01 11:00:02 +00:00
|
|
|
for dock_index in range(self.media_dock.count()):
|
2010-09-10 19:21:14 +00:00
|
|
|
if self.media_dock.widget(dock_index):
|
2013-03-19 19:43:22 +00:00
|
|
|
if self.media_dock.widget(dock_index).settings_section == media_item.plugin.name:
|
2011-04-12 19:32:17 +00:00
|
|
|
self.media_dock.widget(dock_index).setVisible(False)
|
2011-02-24 05:47:38 +00:00
|
|
|
self.media_dock.removeItem(dock_index)
|