2008-11-22 15:16:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-11-29 05:36:16 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
2008-11-22 15:16:02 +00:00
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2010-12-26 11:04:47 +00:00
|
|
|
# Copyright (c) 2008-2011 Raoul Snyman #
|
2011-05-26 16:25:54 +00:00
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan #
|
|
|
|
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
|
2011-05-26 17:11:22 +00:00
|
|
|
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
|
2011-05-26 16:25:54 +00:00
|
|
|
# Põldaru, Christian Richter, Philip Ridout, Jeffrey Smith, Maikel #
|
|
|
|
# Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
|
2009-09-08 19:58:05 +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 #
|
|
|
|
###############################################################################
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Provides the generic functions for interfacing plugins with the Media Manager.
|
|
|
|
"""
|
2010-05-27 20:56:34 +00:00
|
|
|
import logging
|
2009-06-27 15:33:03 +00:00
|
|
|
import os
|
2011-05-15 19:18:50 +00:00
|
|
|
import re
|
2008-11-22 15:16:02 +00:00
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
2009-06-26 16:17:55 +00:00
|
|
|
|
2011-04-04 14:38:17 +00:00
|
|
|
from openlp.core.lib import SettingsManager, OpenLPToolbar, ServiceItem, \
|
|
|
|
StringContent, build_icon, translate, Receiver, ListWidgetWithDnD
|
|
|
|
from openlp.core.lib.ui import UiStrings, context_menu_action, \
|
2011-04-30 17:36:13 +00:00
|
|
|
context_menu_separator, critical_error_message_box
|
2009-06-26 16:17:55 +00:00
|
|
|
|
2010-02-27 15:31:23 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2008-11-22 15:16:02 +00:00
|
|
|
class MediaManagerItem(QtGui.QWidget):
|
|
|
|
"""
|
|
|
|
MediaManagerItem is a helper widget for plugins.
|
2009-07-01 20:21:13 +00:00
|
|
|
|
|
|
|
None of the following *need* to be used, feel free to override
|
2009-10-24 16:40:36 +00:00
|
|
|
them completely in your plugin's implementation. Alternatively,
|
2009-09-03 21:41:34 +00:00
|
|
|
call them from your plugin before or after you've done extra
|
|
|
|
things that you need to.
|
2009-07-01 20:21:13 +00:00
|
|
|
|
2009-09-03 21:41:34 +00:00
|
|
|
**Constructor Parameters**
|
2009-07-01 20:21:13 +00:00
|
|
|
|
2009-09-03 21:41:34 +00:00
|
|
|
``parent``
|
|
|
|
The parent widget. Usually this will be the *Media Manager*
|
|
|
|
itself. This needs to be a class descended from ``QWidget``.
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2010-09-15 17:55:27 +00:00
|
|
|
``plugin``
|
|
|
|
The plugin widget. Usually this will be the *Plugin*
|
|
|
|
itself. This needs to be a class descended from ``Plugin``.
|
|
|
|
|
2009-09-03 21:41:34 +00:00
|
|
|
``icon``
|
|
|
|
Either a ``QIcon``, a resource path, or a file name. This is
|
|
|
|
the icon which is displayed in the *Media Manager*.
|
2009-07-04 05:52:30 +00:00
|
|
|
|
2009-09-03 21:41:34 +00:00
|
|
|
**Member Variables**
|
|
|
|
|
|
|
|
When creating a descendant class from this class for your plugin,
|
|
|
|
the following member variables should be set.
|
|
|
|
|
2011-02-17 02:33:12 +00:00
|
|
|
``self.onNewPrompt``
|
|
|
|
|
2009-09-03 21:41:34 +00:00
|
|
|
Defaults to *'Select Image(s)'*.
|
|
|
|
|
2011-02-17 02:33:12 +00:00
|
|
|
``self.onNewFileMasks``
|
2009-09-03 21:41:34 +00:00
|
|
|
Defaults to *'Images (*.jpg *jpeg *.gif *.png *.bmp)'*. This
|
|
|
|
assumes that the new action is to load a file. If not, you
|
|
|
|
need to override the ``OnNew`` method.
|
|
|
|
|
|
|
|
``self.PreviewFunction``
|
|
|
|
This must be a method which returns a QImage to represent the
|
|
|
|
item (usually a preview). No scaling is required, that is
|
|
|
|
performed automatically by OpenLP when necessary. If this
|
|
|
|
method is not defined, a default will be used (treat the
|
|
|
|
filename as an image).
|
2008-11-22 15:16:02 +00:00
|
|
|
"""
|
2009-06-23 20:59:38 +00:00
|
|
|
log.info(u'Media Item loaded')
|
|
|
|
|
2010-09-15 17:55:27 +00:00
|
|
|
def __init__(self, parent=None, plugin=None, icon=None):
|
2008-11-22 15:16:02 +00:00
|
|
|
"""
|
|
|
|
Constructor to create the media manager item.
|
|
|
|
"""
|
2011-05-28 18:47:14 +00:00
|
|
|
QtGui.QWidget.__init__(self, parent)
|
2011-06-01 18:58:27 +00:00
|
|
|
self.hide()
|
2011-05-15 19:18:50 +00:00
|
|
|
self.whitespace = re.compile(r'\W+', re.UNICODE)
|
2011-05-28 09:53:37 +00:00
|
|
|
self.plugin = plugin
|
2010-09-16 21:10:36 +00:00
|
|
|
visible_title = self.plugin.getString(StringContent.VisibleName)
|
2010-10-07 17:52:40 +00:00
|
|
|
self.title = unicode(visible_title[u'title'])
|
2010-09-16 21:10:36 +00:00
|
|
|
self.settingsSection = self.plugin.name.lower()
|
2011-01-25 04:42:15 +00:00
|
|
|
self.icon = None
|
|
|
|
if icon:
|
|
|
|
self.icon = build_icon(icon)
|
2010-07-07 16:03:30 +00:00
|
|
|
self.toolbar = None
|
2009-11-04 17:48:46 +00:00
|
|
|
self.remoteTriggered = None
|
2010-04-06 19:16:14 +00:00
|
|
|
self.singleServiceItem = True
|
2011-04-02 09:52:32 +00:00
|
|
|
self.quickPreviewAllowed = False
|
2011-05-15 18:33:00 +00:00
|
|
|
self.hasSearch = False
|
2010-07-07 16:03:30 +00:00
|
|
|
self.pageLayout = QtGui.QVBoxLayout(self)
|
|
|
|
self.pageLayout.setSpacing(0)
|
2011-01-05 16:50:28 +00:00
|
|
|
self.pageLayout.setMargin(0)
|
2009-09-26 09:11:39 +00:00
|
|
|
self.requiredIcons()
|
2009-03-02 21:57:49 +00:00
|
|
|
self.setupUi()
|
|
|
|
self.retranslateUi()
|
2011-05-27 09:34:14 +00:00
|
|
|
self.auto_select_id = -1
|
2010-09-30 05:12:06 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2011-05-28 09:53:37 +00:00
|
|
|
QtCore.SIGNAL(u'%s_service_load' % self.plugin.name.lower()),
|
2011-05-20 21:30:28 +00:00
|
|
|
self.serviceLoad)
|
2011-05-24 20:47:05 +00:00
|
|
|
|
2009-09-26 09:11:39 +00:00
|
|
|
def requiredIcons(self):
|
|
|
|
"""
|
2011-05-21 20:29:43 +00:00
|
|
|
This method is called to define the icons for the plugin.
|
2009-09-26 09:11:39 +00:00
|
|
|
It provides a default set and the plugin is able to override
|
|
|
|
the if required.
|
|
|
|
"""
|
2010-03-23 19:04:15 +00:00
|
|
|
self.hasImportIcon = False
|
2009-09-26 09:11:39 +00:00
|
|
|
self.hasNewIcon = True
|
|
|
|
self.hasEditIcon = True
|
|
|
|
self.hasFileIcon = False
|
|
|
|
self.hasDeleteIcon = True
|
2010-06-17 01:56:05 +00:00
|
|
|
self.addToServiceItem = False
|
2009-09-26 09:11:39 +00:00
|
|
|
|
2009-03-02 21:57:49 +00:00
|
|
|
def retranslateUi(self):
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
|
|
|
This method is called automatically to provide OpenLP with the
|
|
|
|
opportunity to translate the ``MediaManagerItem`` to another
|
|
|
|
language.
|
|
|
|
"""
|
2009-03-02 21:57:49 +00:00
|
|
|
pass
|
|
|
|
|
2008-11-22 21:41:20 +00:00
|
|
|
def addToolbar(self):
|
|
|
|
"""
|
2009-09-04 22:50:19 +00:00
|
|
|
A method to help developers easily add a toolbar to the media
|
|
|
|
manager item.
|
2008-11-22 21:41:20 +00:00
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
if self.toolbar is None:
|
|
|
|
self.toolbar = OpenLPToolbar(self)
|
|
|
|
self.pageLayout.addWidget(self.toolbar)
|
2008-11-25 16:26:49 +00:00
|
|
|
|
2009-09-21 19:57:36 +00:00
|
|
|
def addToolbarButton(
|
2009-11-30 20:29:26 +00:00
|
|
|
self, title, tooltip, icon, slot=None, checkable=False):
|
2008-11-25 16:26:49 +00:00
|
|
|
"""
|
|
|
|
A method to help developers easily add a button to the toolbar.
|
2009-09-04 22:50:19 +00:00
|
|
|
|
|
|
|
``title``
|
|
|
|
The title of the button.
|
|
|
|
|
|
|
|
``tooltip``
|
|
|
|
The tooltip to be displayed when the mouse hovers over the
|
|
|
|
button.
|
|
|
|
|
|
|
|
``icon``
|
|
|
|
The icon of the button. This can be an instance of QIcon, or a
|
2011-02-05 18:01:08 +00:00
|
|
|
string containing either the absolute path to the image, or an
|
2009-09-04 22:50:19 +00:00
|
|
|
internal resource path starting with ':/'.
|
|
|
|
|
|
|
|
``slot``
|
|
|
|
The method to call when the button is clicked.
|
2011-01-18 20:14:44 +00:00
|
|
|
|
|
|
|
``checkable``
|
|
|
|
If *True* the button has two, *off* and *on*, states. Default is
|
|
|
|
*False*, which means the buttons has only one state.
|
2008-11-25 16:26:49 +00:00
|
|
|
"""
|
2009-09-04 22:50:19 +00:00
|
|
|
# NB different order (when I broke this out, I didn't want to
|
|
|
|
# break compatability), but it makes sense for the icon to
|
|
|
|
# come before the tooltip (as you have to have an icon, but
|
|
|
|
# not neccesarily a tooltip)
|
2011-01-08 02:44:12 +00:00
|
|
|
return self.toolbar.addToolbarButton(title, icon, tooltip, slot,
|
|
|
|
checkable)
|
2008-11-25 16:26:49 +00:00
|
|
|
|
2008-11-30 20:01:19 +00:00
|
|
|
def addToolbarSeparator(self):
|
|
|
|
"""
|
|
|
|
A very simple method to add a separator to the toolbar.
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
self.toolbar.addSeparator()
|
2009-03-02 21:57:49 +00:00
|
|
|
|
2009-06-23 20:53:06 +00:00
|
|
|
def setupUi(self):
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
|
|
|
This method sets up the interface on the button. Plugin
|
|
|
|
developers use this to add and create toolbars, and the rest
|
|
|
|
of the interface of the media manager item.
|
|
|
|
"""
|
2009-06-23 20:53:06 +00:00
|
|
|
# Add a toolbar
|
|
|
|
self.addToolbar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Allow the plugin to define buttons at start of bar
|
2009-09-11 19:29:57 +00:00
|
|
|
self.addStartHeaderBar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Add the middle of the tool bar (pre defined)
|
2009-09-16 04:59:38 +00:00
|
|
|
self.addMiddleHeaderBar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Allow the plugin to define buttons at end of bar
|
2009-09-16 04:59:38 +00:00
|
|
|
self.addEndHeaderBar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Add the list view
|
2009-09-16 04:59:38 +00:00
|
|
|
self.addListViewToToolBar()
|
|
|
|
|
|
|
|
def addMiddleHeaderBar(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Create buttons for the media item toolbar
|
|
|
|
"""
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions = []
|
2010-03-23 19:04:15 +00:00
|
|
|
## Import Button ##
|
|
|
|
if self.hasImportIcon:
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.Import,
|
|
|
|
u':/general/general_import.png', self.onImportClick])
|
2010-09-10 19:47:33 +00:00
|
|
|
## Load Button ##
|
2009-06-27 05:46:05 +00:00
|
|
|
if self.hasFileIcon:
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.Load,
|
|
|
|
u':/general/general_open.png', self.onFileClick])
|
2009-06-27 05:46:05 +00:00
|
|
|
## New Button ##
|
|
|
|
if self.hasNewIcon:
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.New,
|
|
|
|
u':/general/general_new.png', self.onNewClick])
|
2009-06-27 05:46:05 +00:00
|
|
|
## Edit Button ##
|
|
|
|
if self.hasEditIcon:
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.Edit,
|
|
|
|
u':/general/general_edit.png', self.onEditClick])
|
2009-06-27 05:46:05 +00:00
|
|
|
## Delete Button ##
|
2009-09-26 09:11:39 +00:00
|
|
|
if self.hasDeleteIcon:
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.Delete,
|
|
|
|
u':/general/general_delete.png', self.onDeleteClick])
|
2009-07-01 20:21:13 +00:00
|
|
|
## Preview ##
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.Preview,
|
|
|
|
u':/general/general_preview.png', self.onPreviewClick])
|
2011-02-02 13:22:43 +00:00
|
|
|
## Live Button ##
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.Live,
|
|
|
|
u':/general/general_live.png', self.onLiveClick])
|
2009-07-01 20:21:13 +00:00
|
|
|
## Add to service Button ##
|
2011-02-11 04:04:05 +00:00
|
|
|
toolbar_actions.append([StringContent.Service,
|
|
|
|
u':/general/general_add.png', self.onAddClick])
|
|
|
|
for action in toolbar_actions:
|
2011-02-27 06:58:23 +00:00
|
|
|
if action[0] == StringContent.Preview:
|
|
|
|
self.addToolbarSeparator()
|
2011-02-11 04:04:05 +00:00
|
|
|
self.addToolbarButton(
|
|
|
|
self.plugin.getString(action[0])[u'title'],
|
|
|
|
self.plugin.getString(action[0])[u'tooltip'],
|
|
|
|
action[1], action[2])
|
2009-09-16 04:59:38 +00:00
|
|
|
|
|
|
|
def addListViewToToolBar(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Creates the main widget for listing items the media item is tracking
|
|
|
|
"""
|
2011-01-12 19:31:46 +00:00
|
|
|
# Add the List widget
|
2011-02-18 15:23:33 +00:00
|
|
|
self.listView = ListWidgetWithDnD(self, self.plugin.name)
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.setSpacing(1)
|
|
|
|
self.listView.setSelectionMode(
|
2009-09-21 17:56:36 +00:00
|
|
|
QtGui.QAbstractItemView.ExtendedSelection)
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.setAlternatingRowColors(True)
|
|
|
|
self.listView.setDragEnabled(True)
|
2010-09-13 19:08:26 +00:00
|
|
|
self.listView.setObjectName(u'%sListView' % self.plugin.name)
|
2011-01-12 19:31:46 +00:00
|
|
|
# Add to pageLayout
|
2010-07-07 16:03:30 +00:00
|
|
|
self.pageLayout.addWidget(self.listView)
|
2011-01-12 19:31:46 +00:00
|
|
|
# define and add the context menu
|
2011-05-13 12:55:04 +00:00
|
|
|
self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
2009-06-27 05:46:05 +00:00
|
|
|
if self.hasEditIcon:
|
2010-06-12 20:22:58 +00:00
|
|
|
context_menu_action(
|
2011-05-13 13:00:20 +00:00
|
|
|
self.listView, u':/general/general_edit.png',
|
|
|
|
self.plugin.getString(StringContent.Edit)[u'title'],
|
2011-05-13 14:39:37 +00:00
|
|
|
self.onEditClick)
|
2011-05-13 13:00:20 +00:00
|
|
|
context_menu_separator(self.listView)
|
|
|
|
if self.hasDeleteIcon:
|
2010-06-12 20:22:58 +00:00
|
|
|
context_menu_action(
|
2011-05-13 13:00:20 +00:00
|
|
|
self.listView, u':/general/general_delete.png',
|
|
|
|
self.plugin.getString(StringContent.Delete)[u'title'],
|
2011-05-13 14:39:37 +00:00
|
|
|
self.onDeleteClick, [QtCore.Qt.Key_Delete])
|
2011-05-13 13:00:20 +00:00
|
|
|
context_menu_separator(self.listView)
|
|
|
|
context_menu_action(
|
|
|
|
self.listView, u':/general/general_preview.png',
|
|
|
|
self.plugin.getString(StringContent.Preview)[u'title'],
|
2011-05-13 14:39:37 +00:00
|
|
|
self.onPreviewClick, [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return])
|
2011-05-13 13:00:20 +00:00
|
|
|
context_menu_action(
|
|
|
|
self.listView, u':/general/general_live.png',
|
|
|
|
self.plugin.getString(StringContent.Live)[u'title'],
|
2011-05-13 14:39:37 +00:00
|
|
|
self.onLiveClick, [QtCore.Qt.ShiftModifier + QtCore.Qt.Key_Enter,
|
|
|
|
QtCore.Qt.ShiftModifier + QtCore.Qt.Key_Return])
|
2011-05-13 13:00:20 +00:00
|
|
|
context_menu_action(
|
|
|
|
self.listView, u':/general/general_add.png',
|
|
|
|
self.plugin.getString(StringContent.Service)[u'title'],
|
2011-05-13 14:39:37 +00:00
|
|
|
self.onAddClick, [QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal])
|
2011-05-13 13:00:20 +00:00
|
|
|
if self.addToServiceItem:
|
2010-06-12 20:22:58 +00:00
|
|
|
context_menu_action(
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView, u':/general/general_add.png',
|
2011-05-13 13:00:20 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
2011-05-13 14:39:37 +00:00
|
|
|
'&Add to selected Service Item'), self.onAddEditClick)
|
2011-05-13 13:00:20 +00:00
|
|
|
# Create the context menu and add all actions from the listView.
|
|
|
|
self.menu = QtGui.QMenu()
|
|
|
|
self.menu.addActions(self.listView.actions())
|
2010-11-26 09:49:06 +00:00
|
|
|
QtCore.QObject.connect(self.listView,
|
|
|
|
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
|
|
|
|
self.onClickPressed)
|
2011-04-02 09:52:32 +00:00
|
|
|
QtCore.QObject.connect(self.listView,
|
|
|
|
QtCore.SIGNAL(u'itemSelectionChanged()'),
|
|
|
|
self.onSelectionChange)
|
2011-05-13 12:55:04 +00:00
|
|
|
QtCore.QObject.connect(self.listView,
|
|
|
|
QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
|
|
|
|
self.contextMenu)
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def initialise(self):
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
|
|
|
Implement this method in your descendent media manager item to
|
2010-06-10 01:57:59 +00:00
|
|
|
do any UI or other initialisation. This method is called automatically.
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
2009-07-04 05:52:30 +00:00
|
|
|
pass
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2009-09-11 19:29:57 +00:00
|
|
|
def addStartHeaderBar(self):
|
2009-09-11 04:54:22 +00:00
|
|
|
"""
|
2009-09-11 19:29:57 +00:00
|
|
|
Slot at start of toolbar for plugin to addwidgets
|
2009-09-11 04:54:22 +00:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2009-09-11 19:29:57 +00:00
|
|
|
def addEndHeaderBar(self):
|
2009-09-11 04:54:22 +00:00
|
|
|
"""
|
2009-09-11 19:29:57 +00:00
|
|
|
Slot at end of toolbar for plugin to add widgets
|
2009-09-11 04:54:22 +00:00
|
|
|
"""
|
2009-06-27 05:46:05 +00:00
|
|
|
pass
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2009-06-27 05:46:05 +00:00
|
|
|
def onFileClick(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Add a file to the list widget to make it available for showing
|
|
|
|
"""
|
2009-10-23 18:48:49 +00:00
|
|
|
files = QtGui.QFileDialog.getOpenFileNames(
|
2011-02-17 02:33:12 +00:00
|
|
|
self, self.onNewPrompt,
|
2010-04-30 22:38:15 +00:00
|
|
|
SettingsManager.get_last_dir(self.settingsSection),
|
2011-02-17 02:33:12 +00:00
|
|
|
self.onNewFileMasks)
|
2010-03-23 19:04:15 +00:00
|
|
|
log.info(u'New files(s) %s', unicode(files))
|
2010-03-09 19:43:11 +00:00
|
|
|
if files:
|
2011-01-01 12:49:38 +00:00
|
|
|
Receiver.send_message(u'cursor_busy')
|
2011-04-30 17:36:13 +00:00
|
|
|
names = []
|
|
|
|
for count in range(0, self.listView.count()):
|
|
|
|
names.append(self.listView.item(count).text())
|
|
|
|
newFiles = []
|
|
|
|
for file in files:
|
|
|
|
filename = os.path.split(unicode(file))[1]
|
|
|
|
if filename in names:
|
|
|
|
critical_error_message_box(
|
|
|
|
UiStrings().Duplicate,
|
|
|
|
unicode(translate('OpenLP.MediaManagerItem',
|
|
|
|
'Duplicate file name %s.\nFilename already exists in '
|
|
|
|
'list')) % filename)
|
|
|
|
else:
|
|
|
|
newFiles.append(file)
|
|
|
|
self.loadList(newFiles)
|
2010-05-29 19:50:50 +00:00
|
|
|
lastDir = os.path.split(unicode(files[0]))[0]
|
|
|
|
SettingsManager.set_last_dir(self.settingsSection, lastDir)
|
2010-04-30 22:38:15 +00:00
|
|
|
SettingsManager.set_list(self.settingsSection,
|
|
|
|
self.settingsSection, self.getFileList())
|
2011-01-01 12:49:38 +00:00
|
|
|
Receiver.send_message(u'cursor_normal')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2011-05-13 13:00:20 +00:00
|
|
|
def contextMenu(self, point):
|
|
|
|
item = self.listView.itemAt(point)
|
2011-05-13 14:39:37 +00:00
|
|
|
# Decide if we have to show the context menu or not.
|
2011-05-13 13:00:20 +00:00
|
|
|
if item is None:
|
|
|
|
return
|
|
|
|
if not item.flags() & QtCore.Qt.ItemIsSelectable:
|
|
|
|
return
|
|
|
|
self.menu.exec_(self.listView.mapToGlobal(point))
|
|
|
|
|
2009-06-27 19:55:55 +00:00
|
|
|
def getFileList(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Return the current list of files
|
|
|
|
"""
|
2009-06-27 19:55:55 +00:00
|
|
|
count = 0
|
2009-07-04 05:52:30 +00:00
|
|
|
filelist = []
|
2010-07-07 16:03:30 +00:00
|
|
|
while count < self.listView.count():
|
|
|
|
bitem = self.listView.item(count)
|
2010-06-09 21:15:37 +00:00
|
|
|
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
|
2009-07-04 05:52:30 +00:00
|
|
|
filelist.append(filename)
|
2009-06-27 19:55:55 +00:00
|
|
|
count += 1
|
|
|
|
return filelist
|
|
|
|
|
2011-02-03 23:25:52 +00:00
|
|
|
def validate(self, image, thumb):
|
2010-04-05 08:13:45 +00:00
|
|
|
"""
|
2011-02-03 23:25:52 +00:00
|
|
|
Validates whether an image still exists and, if it does, is the
|
|
|
|
thumbnail representation of the image up to date.
|
2010-04-05 08:13:45 +00:00
|
|
|
"""
|
2011-03-08 07:38:25 +00:00
|
|
|
if not os.path.exists(unicode(image)):
|
2010-07-10 22:21:14 +00:00
|
|
|
return False
|
|
|
|
if os.path.exists(thumb):
|
2011-03-08 07:38:25 +00:00
|
|
|
imageDate = os.stat(unicode(image)).st_mtime
|
|
|
|
thumbDate = os.stat(unicode(thumb)).st_mtime
|
2011-02-03 23:25:52 +00:00
|
|
|
# If image has been updated rebuild icon
|
|
|
|
if imageDate > thumbDate:
|
|
|
|
self.iconFromFile(image, thumb)
|
2010-07-10 22:21:14 +00:00
|
|
|
else:
|
2011-02-03 23:25:52 +00:00
|
|
|
self.iconFromFile(image, thumb)
|
2010-07-10 22:21:14 +00:00
|
|
|
return True
|
2010-04-05 08:13:45 +00:00
|
|
|
|
2011-02-03 23:25:52 +00:00
|
|
|
def iconFromFile(self, image, thumb):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
2011-02-03 23:25:52 +00:00
|
|
|
Create a thumbnail icon from a given image.
|
2010-06-19 17:31:42 +00:00
|
|
|
|
2011-02-03 23:25:52 +00:00
|
|
|
``image``
|
|
|
|
The image file to create the icon from.
|
2010-06-19 17:31:42 +00:00
|
|
|
|
|
|
|
``thumb``
|
|
|
|
The filename to save the thumbnail to
|
|
|
|
"""
|
2011-02-03 23:25:52 +00:00
|
|
|
icon = build_icon(unicode(image))
|
2010-05-25 16:16:43 +00:00
|
|
|
pixmap = icon.pixmap(QtCore.QSize(88, 50))
|
2010-04-05 08:13:45 +00:00
|
|
|
ext = os.path.splitext(thumb)[1].lower()
|
|
|
|
pixmap.save(thumb, ext[1:])
|
|
|
|
return icon
|
|
|
|
|
2009-06-23 20:53:06 +00:00
|
|
|
def loadList(self, list):
|
2009-10-23 18:48:49 +00:00
|
|
|
raise NotImplementedError(u'MediaManagerItem.loadList needs to be '
|
|
|
|
u'defined by the plugin')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2009-06-27 05:46:05 +00:00
|
|
|
def onNewClick(self):
|
2011-02-03 23:25:52 +00:00
|
|
|
"""
|
|
|
|
Hook for plugins to define behaviour for adding new items.
|
|
|
|
"""
|
|
|
|
pass
|
2009-06-27 05:46:05 +00:00
|
|
|
|
|
|
|
def onEditClick(self):
|
2011-02-03 23:25:52 +00:00
|
|
|
"""
|
|
|
|
Hook for plugins to define behaviour for editing items.
|
|
|
|
"""
|
|
|
|
pass
|
2009-06-27 05:46:05 +00:00
|
|
|
|
2009-06-23 20:53:06 +00:00
|
|
|
def onDeleteClick(self):
|
2009-10-23 18:48:49 +00:00
|
|
|
raise NotImplementedError(u'MediaManagerItem.onDeleteClick needs to '
|
|
|
|
u'be defined by the plugin')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2011-05-26 06:23:22 +00:00
|
|
|
def onFocus(self):
|
|
|
|
"""
|
|
|
|
Run when a tab in the media manager gains focus. This gives the media
|
|
|
|
item a chance to focus any elements it wants to.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2010-11-27 20:51:54 +00:00
|
|
|
def generateSlideData(self, serviceItem, item=None, xmlVersion=False):
|
2009-10-23 18:48:49 +00:00
|
|
|
raise NotImplementedError(u'MediaManagerItem.generateSlideData needs '
|
|
|
|
u'to be defined by the plugin')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2010-11-26 09:49:06 +00:00
|
|
|
def onClickPressed(self):
|
|
|
|
"""
|
|
|
|
Allows the list click action to be determined dynamically
|
|
|
|
"""
|
|
|
|
if QtCore.QSettings().value(u'advanced/double click live',
|
|
|
|
QtCore.QVariant(False)).toBool():
|
|
|
|
self.onLiveClick()
|
|
|
|
else:
|
|
|
|
self.onPreviewClick()
|
|
|
|
|
2011-04-02 09:52:32 +00:00
|
|
|
def onSelectionChange(self):
|
|
|
|
"""
|
|
|
|
Allows the change of current item in the list to be actioned
|
|
|
|
"""
|
|
|
|
if QtCore.QSettings().value(u'advanced/single click preview',
|
|
|
|
QtCore.QVariant(False)).toBool() and self.quickPreviewAllowed \
|
2011-05-31 03:52:17 +00:00
|
|
|
and self.listView.selectedIndexes() \
|
|
|
|
and self.auto_select_id == -1:
|
2011-04-02 09:52:32 +00:00
|
|
|
self.onPreviewClick(True)
|
|
|
|
|
|
|
|
def onPreviewClick(self, keepFocus=False):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Preview an item by building a service item then adding that service
|
|
|
|
item to the preview slide controller.
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
if not self.listView.selectedIndexes() and not self.remoteTriggered:
|
2011-04-15 21:43:59 +00:00
|
|
|
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
2010-07-21 06:24:32 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
2011-01-12 19:31:46 +00:00
|
|
|
'You must select one or more items to preview.'))
|
2009-12-06 13:55:07 +00:00
|
|
|
else:
|
2010-12-28 11:18:56 +00:00
|
|
|
log.debug(u'%s Preview requested', self.plugin.name)
|
2010-11-27 20:51:54 +00:00
|
|
|
serviceItem = self.buildServiceItem()
|
|
|
|
if serviceItem:
|
|
|
|
serviceItem.from_plugin = True
|
2011-05-28 09:53:37 +00:00
|
|
|
self.plugin.previewController.addServiceItem(serviceItem)
|
2011-04-02 09:52:32 +00:00
|
|
|
if keepFocus:
|
|
|
|
self.listView.setFocus()
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def onLiveClick(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Send an item live by building a service item then adding that service
|
|
|
|
item to the live slide controller.
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
if not self.listView.selectedIndexes():
|
2011-04-15 21:43:59 +00:00
|
|
|
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
2010-07-21 06:24:32 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
2010-06-19 04:05:39 +00:00
|
|
|
'You must select one or more items to send live.'))
|
2009-12-06 13:55:07 +00:00
|
|
|
else:
|
2011-05-14 09:48:58 +00:00
|
|
|
self.goLive()
|
|
|
|
|
|
|
|
def goLive(self, item_id=None):
|
|
|
|
log.debug(u'%s Live requested', self.plugin.name)
|
|
|
|
item = None
|
|
|
|
if item_id:
|
2011-05-14 21:25:22 +00:00
|
|
|
item = self.createItemFromId(item_id)
|
2011-05-14 09:48:58 +00:00
|
|
|
serviceItem = self.buildServiceItem(item)
|
|
|
|
if serviceItem:
|
2011-05-14 12:26:05 +00:00
|
|
|
if not item_id:
|
2010-11-27 20:51:54 +00:00
|
|
|
serviceItem.from_plugin = True
|
2011-05-28 09:53:37 +00:00
|
|
|
self.plugin.liveController.addServiceItem(serviceItem)
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2011-05-14 21:25:22 +00:00
|
|
|
def createItemFromId(self, item_id):
|
|
|
|
item = QtGui.QListWidgetItem()
|
|
|
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(item_id))
|
|
|
|
return item
|
2009-06-23 20:53:06 +00:00
|
|
|
|
|
|
|
def onAddClick(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Add a selected item to the current service
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
if not self.listView.selectedIndexes() and not self.remoteTriggered:
|
2011-04-15 21:43:59 +00:00
|
|
|
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
2010-07-21 06:24:32 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
2011-05-20 05:01:49 +00:00
|
|
|
'You must select one or more items to add.'))
|
2009-12-06 13:55:07 +00:00
|
|
|
else:
|
2010-11-28 19:38:27 +00:00
|
|
|
# Is it posssible to process multiple list items to generate
|
|
|
|
# multiple service items?
|
2010-04-22 21:22:09 +00:00
|
|
|
if self.singleServiceItem or self.remoteTriggered:
|
2010-12-28 11:18:56 +00:00
|
|
|
log.debug(u'%s Add requested', self.plugin.name)
|
2011-05-21 17:43:37 +00:00
|
|
|
self.addToService(replace=self.remoteTriggered)
|
2010-04-04 13:53:39 +00:00
|
|
|
else:
|
2010-07-07 16:03:30 +00:00
|
|
|
items = self.listView.selectedIndexes()
|
2010-04-04 13:53:39 +00:00
|
|
|
for item in items:
|
2011-05-21 17:43:37 +00:00
|
|
|
self.addToService(item)
|
2011-05-19 23:09:42 +00:00
|
|
|
|
2011-05-21 17:43:37 +00:00
|
|
|
def addToService(self, item=None, replace=None):
|
|
|
|
serviceItem = self.buildServiceItem(item, True)
|
|
|
|
if serviceItem:
|
|
|
|
serviceItem.from_plugin = False
|
2011-05-28 09:53:37 +00:00
|
|
|
self.plugin.serviceManager.addServiceItem(serviceItem,
|
2011-05-21 17:43:37 +00:00
|
|
|
replace=replace)
|
2009-07-08 16:40:42 +00:00
|
|
|
|
2010-03-16 20:22:28 +00:00
|
|
|
def onAddEditClick(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Add a selected item to an existing item in the current service.
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
if not self.listView.selectedIndexes() and not self.remoteTriggered:
|
2011-04-15 21:43:59 +00:00
|
|
|
QtGui.QMessageBox.information(self, UiStrings().NISp,
|
2010-07-21 06:24:32 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
2011-02-16 17:54:31 +00:00
|
|
|
'You must select one or more items.'))
|
2010-03-16 20:22:28 +00:00
|
|
|
else:
|
2010-12-28 11:18:56 +00:00
|
|
|
log.debug(u'%s Add requested', self.plugin.name)
|
2011-05-28 09:53:37 +00:00
|
|
|
serviceItem = self.plugin.serviceManager.getServiceItem()
|
2010-11-27 20:51:54 +00:00
|
|
|
if not serviceItem:
|
2011-04-15 21:43:59 +00:00
|
|
|
QtGui.QMessageBox.information(self, UiStrings().NISs,
|
2010-07-21 06:24:32 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
2010-06-19 04:05:39 +00:00
|
|
|
'You must select an existing service item to add to.'))
|
2011-02-02 12:28:48 +00:00
|
|
|
elif self.plugin.name.lower() == serviceItem.name.lower():
|
2010-11-27 20:51:54 +00:00
|
|
|
self.generateSlideData(serviceItem)
|
2011-05-28 09:53:37 +00:00
|
|
|
self.plugin.serviceManager.addServiceItem(serviceItem,
|
2010-04-20 22:00:55 +00:00
|
|
|
replace=True)
|
2010-03-20 08:34:36 +00:00
|
|
|
else:
|
2010-11-20 18:14:43 +00:00
|
|
|
# Turn off the remote edit update message indicator
|
2010-03-20 08:34:36 +00:00
|
|
|
QtGui.QMessageBox.information(self,
|
2010-07-26 15:19:11 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
|
|
|
'Invalid Service Item'),
|
2010-07-21 06:24:32 +00:00
|
|
|
unicode(translate('OpenLP.MediaManagerItem',
|
2010-06-19 04:05:39 +00:00
|
|
|
'You must select a %s service item.')) % self.title)
|
2010-03-16 20:22:28 +00:00
|
|
|
|
2010-11-27 15:25:00 +00:00
|
|
|
def buildServiceItem(self, item=None, xmlVersion=False):
|
2009-07-08 16:40:42 +00:00
|
|
|
"""
|
|
|
|
Common method for generating a service item
|
|
|
|
"""
|
2011-05-28 09:53:37 +00:00
|
|
|
serviceItem = ServiceItem(self.plugin)
|
|
|
|
serviceItem.add_icon(self.plugin.icon_path)
|
2010-11-27 20:51:54 +00:00
|
|
|
if self.generateSlideData(serviceItem, item, xmlVersion):
|
|
|
|
return serviceItem
|
2009-08-31 21:53:35 +00:00
|
|
|
else:
|
2010-07-26 15:19:11 +00:00
|
|
|
return None
|
2010-09-30 05:12:06 +00:00
|
|
|
|
|
|
|
def serviceLoad(self, message):
|
|
|
|
"""
|
|
|
|
Method to add processing when a service has been loaded and
|
|
|
|
individual service items need to be processed by the plugins
|
|
|
|
"""
|
2010-12-29 09:14:13 +00:00
|
|
|
pass
|
2011-02-01 00:33:50 +00:00
|
|
|
|
2011-05-15 12:11:08 +00:00
|
|
|
def check_search_result(self):
|
|
|
|
"""
|
|
|
|
Checks if the listView is empty and adds a "No Search Results" item.
|
|
|
|
"""
|
|
|
|
if self.listView.count():
|
|
|
|
return
|
|
|
|
message = translate('OpenLP.MediaManagerItem', 'No Search Results')
|
|
|
|
item = QtGui.QListWidgetItem(message)
|
|
|
|
item.setFlags(QtCore.Qt.NoItemFlags)
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setItalic(True)
|
|
|
|
item.setFont(font)
|
|
|
|
self.listView.addItem(item)
|
|
|
|
|
2011-02-01 00:33:50 +00:00
|
|
|
def _getIdOfItemToGenerate(self, item, remoteItem):
|
|
|
|
"""
|
|
|
|
Utility method to check items being submitted for slide generation.
|
|
|
|
|
|
|
|
``item``
|
|
|
|
The item to check.
|
|
|
|
|
|
|
|
``remoteItem``
|
|
|
|
The id to assign if the slide generation was remotely triggered.
|
|
|
|
"""
|
|
|
|
if item is None:
|
|
|
|
if self.remoteTriggered is None:
|
|
|
|
item = self.listView.currentItem()
|
|
|
|
if item is None:
|
|
|
|
return False
|
|
|
|
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
|
|
|
else:
|
|
|
|
item_id = remoteItem
|
|
|
|
else:
|
|
|
|
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
2011-04-29 08:45:36 +00:00
|
|
|
return item_id
|
2011-05-14 09:48:58 +00:00
|
|
|
|
2011-05-27 09:34:14 +00:00
|
|
|
def save_auto_select_id(self):
|
|
|
|
"""
|
|
|
|
Sorts out, what item to select after loading a list.
|
|
|
|
"""
|
|
|
|
# The item to select has not been set.
|
|
|
|
if self.auto_select_id == -1:
|
|
|
|
item = self.listView.currentItem()
|
|
|
|
if item:
|
|
|
|
self.auto_select_id = item.data(QtCore.Qt.UserRole).toInt()[0]
|
|
|
|
|
2011-05-14 09:48:58 +00:00
|
|
|
def search(self, string):
|
|
|
|
"""
|
|
|
|
Performs a plugin specific search for items containing ``string``
|
|
|
|
"""
|
|
|
|
raise NotImplementedError(
|
2011-05-15 20:53:25 +00:00
|
|
|
u'Plugin.search needs to be defined by the plugin')
|