~suutari-olli/openlp/click-slide-to-go-live-from-blank

« back to all changes in this revision

Viewing changes to openlp/core/ui/mediadockmanager.py

Merged trunk on 28.4.16, removed broken test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
 
 
4
 
###############################################################################
5
 
# OpenLP - Open Source Lyrics Projection                                      #
6
 
# --------------------------------------------------------------------------- #
7
 
# Copyright (c) 2008-2016 OpenLP Developers                                   #
8
 
# --------------------------------------------------------------------------- #
9
 
# This program is free software; you can redistribute it and/or modify it     #
10
 
# under the terms of the GNU General Public License as published by the Free  #
11
 
# Software Foundation; version 2 of the License.                              #
12
 
#                                                                             #
13
 
# This program is distributed in the hope that it will be useful, but WITHOUT #
14
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
15
 
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    #
16
 
# more details.                                                               #
17
 
#                                                                             #
18
 
# You should have received a copy of the GNU General Public License along     #
19
 
# with this program; if not, write to the Free Software Foundation, Inc., 59  #
20
 
# Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
21
 
###############################################################################
22
 
"""
23
 
The media manager dock.
24
 
"""
25
 
import logging
26
 
 
27
 
from openlp.core.lib import StringContent
28
 
 
29
 
log = logging.getLogger(__name__)
30
 
 
31
 
 
32
 
class MediaDockManager(object):
33
 
    """
34
 
    Provide a repository for MediaManagerItems
35
 
    """
36
 
    def __init__(self, media_dock):
37
 
        """
38
 
        Initialise the media dock
39
 
        """
40
 
        self.media_dock = media_dock
41
 
 
42
 
    def add_item_to_dock(self, media_item):
43
 
        """
44
 
        Add a MediaManagerItem to the dock
45
 
        If the item has been added before, it's silently skipped
46
 
 
47
 
        :param media_item: The item to add to the dock
48
 
        """
49
 
        visible_title = media_item.plugin.get_string(StringContent.VisibleName)
50
 
        log.debug('Inserting %s dock' % visible_title['title'])
51
 
        match = False
52
 
        for dock_index in range(self.media_dock.count()):
53
 
            if self.media_dock.widget(dock_index).settings_section == media_item.plugin.name:
54
 
                match = True
55
 
                break
56
 
        if not match:
57
 
            self.media_dock.addItem(media_item, visible_title['title'])
58
 
 
59
 
    def remove_dock(self, media_item):
60
 
        """
61
 
        Removes a MediaManagerItem from the dock
62
 
 
63
 
        :param media_item: The item to add to the dock
64
 
        """
65
 
        visible_title = media_item.plugin.get_string(StringContent.VisibleName)
66
 
        log.debug('remove %s dock' % visible_title['title'])
67
 
        for dock_index in range(self.media_dock.count()):
68
 
            if self.media_dock.widget(dock_index):
69
 
                if self.media_dock.widget(dock_index).settings_section == media_item.plugin.name:
70
 
                    self.media_dock.widget(dock_index).setVisible(False)
71
 
                    self.media_dock.removeItem(dock_index)