openlp/openlp/core/lib/mediamanageritem.py

691 lines
28 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-12-28 22:06:43 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# 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, #
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, #
# 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 #
###############################################################################
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
from PyQt4 import QtCore, QtGui
2013-01-23 20:29:43 +00:00
from openlp.core.lib import OpenLPToolbar, ServiceItem, StringContent, build_icon, translate, Receiver, \
ListWidgetWithDnD, ServiceItemContext, Settings, Registry, UiStrings
2011-12-30 21:40:13 +00:00
from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import create_widget_action, critical_error_message_box
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
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``.
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-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).
"""
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):
"""
Constructor to create the media manager item.
"""
QtGui.QWidget.__init__(self)
self.hide()
2011-06-01 22:47:42 +00:00
self.whitespace = re.compile(r'[\W_]+', re.UNICODE)
2011-05-28 09:53:37 +00:00
self.plugin = plugin
visible_title = self.plugin.getString(StringContent.VisibleName)
self.title = unicode(visible_title[u'title'])
2013-01-27 09:57:03 +00:00
Registry().register(self.plugin.name, self)
self.settingsSection = self.plugin.name
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
self.quickPreviewAllowed = False
self.hasSearch = False
2010-07-07 16:03:30 +00:00
self.pageLayout = QtGui.QVBoxLayout(self)
self.pageLayout.setSpacing(0)
self.pageLayout.setMargin(0)
2009-09-26 09:11:39 +00:00
self.requiredIcons()
self.setupUi()
self.retranslateUi()
self.autoSelectId = -1
2012-12-28 22:06:43 +00:00
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_service_load' % self.plugin.name),
self.serviceLoad)
2009-09-26 09:11:39 +00:00
def requiredIcons(self):
"""
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.
"""
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
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.
"""
pass
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.
"""
2010-07-07 16:03:30 +00:00
if self.toolbar is None:
self.toolbar = OpenLPToolbar(self)
self.pageLayout.addWidget(self.toolbar)
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
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
"""
toolbar_actions = []
## Import Button ##
if self.hasImportIcon:
toolbar_actions.append([u'Import', 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:
toolbar_actions.append([u'Load', StringContent.Load,
u':/general/general_open.png', self.onFileClick])
2009-06-27 05:46:05 +00:00
## New Button ##
if self.hasNewIcon:
toolbar_actions.append([u'New', StringContent.New,
u':/general/general_new.png', self.onNewClick])
2009-06-27 05:46:05 +00:00
## Edit Button ##
if self.hasEditIcon:
toolbar_actions.append([u'Edit', 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:
toolbar_actions.append([u'Delete', StringContent.Delete,
u':/general/general_delete.png', self.onDeleteClick])
2009-07-01 20:21:13 +00:00
## Preview ##
toolbar_actions.append([u'Preview', StringContent.Preview,
u':/general/general_preview.png', self.onPreviewClick])
2011-02-02 13:22:43 +00:00
## Live Button ##
toolbar_actions.append([u'Live', StringContent.Live,
u':/general/general_live.png', self.onLiveClick])
2009-07-01 20:21:13 +00:00
## Add to service Button ##
toolbar_actions.append([u'Service', StringContent.Service,
u':/general/general_add.png', self.onAddClick])
for action in toolbar_actions:
if action[0] == StringContent.Preview:
self.toolbar.addSeparator()
2012-12-28 22:06:43 +00:00
self.toolbar.addToolbarAction(u'%s%sAction' % (self.plugin.name, action[0]),
text=self.plugin.getString(action[1])[u'title'], icon=action[2],
tooltip=self.plugin.getString(action[1])[u'tooltip'],
triggers=action[3])
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)
2012-12-28 22:06:43 +00:00
self.listView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
2010-07-07 16:03:30 +00:00
self.listView.setAlternatingRowColors(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:
create_widget_action(self.listView,
text=self.plugin.getString(StringContent.Edit)[u'title'],
icon=u':/general/general_edit.png',
triggers=self.onEditClick)
create_widget_action(self.listView, separator=True)
2011-05-13 13:00:20 +00:00
if self.hasDeleteIcon:
create_widget_action(self.listView,
text=self.plugin.getString(StringContent.Delete)[u'title'],
icon=u':/general/general_delete.png',
shortcuts=[QtCore.Qt.Key_Delete], triggers=self.onDeleteClick)
create_widget_action(self.listView, separator=True)
create_widget_action(self.listView,
text=self.plugin.getString(StringContent.Preview)[u'title'],
icon=u':/general/general_preview.png',
shortcuts=[QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return],
triggers=self.onPreviewClick)
create_widget_action(self.listView,
text=self.plugin.getString(StringContent.Live)[u'title'],
icon=u':/general/general_live.png',
shortcuts=[QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter,
QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return],
triggers=self.onLiveClick)
create_widget_action(self.listView,
text=self.plugin.getString(StringContent.Service)[u'title'],
icon=u':/general/general_add.png',
shortcuts=[QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal],
triggers=self.onAddClick)
2011-05-13 13:00:20 +00:00
if self.addToServiceItem:
2012-11-11 19:33:53 +00:00
create_widget_action(self.listView, separator=True)
2012-12-28 22:06:43 +00:00
create_widget_action(self.listView,
text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'),
2012-11-11 19:33:53 +00:00
icon=u':/general/general_add.png',
triggers=self.onAddEditClick)
2011-07-01 16:59:56 +00:00
self.addCustomContextActions()
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())
2012-12-28 22:06:43 +00:00
QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onDoubleClicked)
2012-12-28 22:06:43 +00:00
QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'itemSelectionChanged()'),
self.onSelectionChange)
2012-12-28 22:06:43 +00:00
QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'customContextMenuRequested(QPoint)'),
2011-05-13 12:55:04 +00:00
self.contextMenu)
2009-06-23 20:53:06 +00:00
2011-12-30 21:40:13 +00:00
def addSearchToToolBar(self):
"""
Creates a search field with button and related signal handling.
"""
self.searchWidget = QtGui.QWidget(self)
self.searchWidget.setObjectName(u'searchWidget')
self.searchLayout = QtGui.QVBoxLayout(self.searchWidget)
self.searchLayout.setObjectName(u'searchLayout')
self.searchTextLayout = QtGui.QFormLayout()
self.searchTextLayout.setObjectName(u'searchTextLayout')
self.searchTextLabel = QtGui.QLabel(self.searchWidget)
self.searchTextLabel.setObjectName(u'searchTextLabel')
self.searchTextEdit = SearchEdit(self.searchWidget)
self.searchTextEdit.setObjectName(u'searchTextEdit')
self.searchTextLabel.setBuddy(self.searchTextEdit)
self.searchTextLayout.addRow(self.searchTextLabel, self.searchTextEdit)
self.searchLayout.addLayout(self.searchTextLayout)
self.searchButtonLayout = QtGui.QHBoxLayout()
self.searchButtonLayout.setObjectName(u'searchButtonLayout')
self.searchButtonLayout.addStretch()
self.searchTextButton = QtGui.QPushButton(self.searchWidget)
self.searchTextButton.setObjectName(u'searchTextButton')
self.searchButtonLayout.addWidget(self.searchTextButton)
self.searchLayout.addLayout(self.searchButtonLayout)
self.pageLayout.addWidget(self.searchWidget)
# Signals and slots
2012-12-28 22:06:43 +00:00
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'returnPressed()'), self.onSearchTextButtonClicked)
QtCore.QObject.connect(self.searchTextButton, QtCore.SIGNAL(u'clicked()'), self.onSearchTextButtonClicked)
QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'textChanged(const QString&)'),
2011-12-30 21:40:13 +00:00
self.onSearchTextEditChanged)
2011-07-01 16:59:56 +00:00
def addCustomContextActions(self):
"""
Implement this method in your descendent media manager item to
add any context menu items. This method is called automatically.
"""
pass
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
"""
pass
2009-06-23 20:53:06 +00:00
def addStartHeaderBar(self):
2009-09-11 04:54:22 +00:00
"""
Slot at start of toolbar for plugin to addwidgets
2009-09-11 04:54:22 +00:00
"""
pass
def addEndHeaderBar(self):
2009-09-11 04:54:22 +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
"""
2012-12-28 22:06:43 +00:00
files = QtGui.QFileDialog.getOpenFileNames(self, self.onNewPrompt,
2013-01-17 22:22:05 +00:00
Settings().value(self.settingsSection + u'/last directory'), self.onNewFileMasks)
2012-05-17 18:57:01 +00:00
log.info(u'New files(s) %s', 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-07-27 18:28:35 +00:00
self.validateAndLoad(files)
2011-01-01 12:49:38 +00:00
Receiver.send_message(u'cursor_normal')
2009-06-23 20:53:06 +00:00
2011-08-02 05:07:09 +00:00
def loadFile(self, files):
2011-07-27 18:28:35 +00:00
"""
Turn file from Drag and Drop into an array so the Validate code can run it.
2011-07-27 18:28:35 +00:00
2011-08-02 05:07:09 +00:00
``files``
The list of files to be loaded
2011-07-27 18:28:35 +00:00
"""
2012-07-01 19:22:11 +00:00
new_files = []
error_shown = False
2011-08-02 05:07:09 +00:00
for file in files:
type = file.split(u'.')[-1]
if type.lower() not in self.onNewFileMasks:
2012-07-01 19:22:11 +00:00
if not error_shown:
2012-12-28 22:06:43 +00:00
critical_error_message_box(translate('OpenLP.MediaManagerItem', 'Invalid File Type'),
translate('OpenLP.MediaManagerItem', 'Invalid File %s.\nSuffix not supported') % file)
2012-10-03 18:52:52 +00:00
error_shown = True
2011-08-02 05:07:09 +00:00
else:
2012-07-01 19:22:11 +00:00
new_files.append(file)
if new_files:
self.validateAndLoad(new_files)
2011-07-27 18:28:35 +00:00
def validateAndLoad(self, files):
"""
Process a list for files either from the File Dialog or from Drag and
Drop
``files``
The files to be loaded.
2011-07-27 18:28:35 +00:00
"""
names = []
2012-07-01 19:22:11 +00:00
full_list = []
for count in range(self.listView.count()):
2012-05-17 18:57:01 +00:00
names.append(self.listView.item(count).text())
2012-10-03 16:38:06 +00:00
full_list.append(self.listView.item(count).data(QtCore.Qt.UserRole))
2012-07-01 19:22:11 +00:00
duplicates_found = False
files_added = False
2011-07-27 18:28:35 +00:00
for file in files:
filename = os.path.split(unicode(file))[1]
if filename in names:
2012-07-01 19:22:11 +00:00
duplicates_found = True
2011-07-27 18:28:35 +00:00
else:
2012-07-01 19:22:11 +00:00
files_added = True
full_list.append(file)
if full_list and files_added:
self.listView.clear()
2012-07-01 19:22:11 +00:00
self.loadList(full_list)
last_dir = os.path.split(unicode(files[0]))[0]
2013-01-17 22:22:05 +00:00
Settings().setValue(self.settingsSection + u'/last directory', last_dir)
Settings().setValue(u'%s/%s files' % (self.settingsSection, self.settingsSection), self.getFileList())
2012-07-01 19:22:11 +00:00
if duplicates_found:
2012-12-28 22:06:43 +00:00
critical_error_message_box(UiStrings().Duplicate,
translate('OpenLP.MediaManagerItem', 'Duplicate files were found on import and were ignored.'))
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)
# 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
2012-07-01 19:22:11 +00:00
file_list = []
2010-07-07 16:03:30 +00:00
while count < self.listView.count():
bitem = self.listView.item(count)
2012-05-19 15:10:05 +00:00
filename = bitem.data(QtCore.Qt.UserRole)
2012-07-01 19:22:11 +00:00
file_list.append(filename)
2009-06-27 19:55:55 +00:00
count += 1
2012-07-01 19:22:11 +00:00
return file_list
2009-06-27 19:55:55 +00:00
2009-06-23 20:53:06 +00:00
def loadList(self, list):
2012-12-28 22:06:43 +00:00
raise NotImplementedError(u'MediaManagerItem.loadList needs to be 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):
2012-12-28 22:06:43 +00:00
raise NotImplementedError(u'MediaManagerItem.onDeleteClick needs to be defined by the plugin')
2009-06-23 20:53:06 +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
2013-01-27 09:57:03 +00:00
def generateSlideData(self, serviceItem, item=None, xmlVersion=False, remote=False,
context=ServiceItemContext.Live):
2012-12-28 22:06:43 +00:00
raise NotImplementedError(u'MediaManagerItem.generateSlideData needs to be defined by the plugin')
2009-06-23 20:53:06 +00:00
def onDoubleClicked(self):
"""
Allows the list click action to be determined dynamically
"""
if Settings().value(u'advanced/double click live'):
self.onLiveClick()
else:
self.onPreviewClick()
def onSelectionChange(self):
"""
Allows the change of current item in the list to be actioned
"""
if Settings().value(u'advanced/single click preview') and self.quickPreviewAllowed \
2012-12-28 22:06:43 +00:00
and self.listView.selectedIndexes() and self.autoSelectId == -1:
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:
QtGui.QMessageBox.information(self, UiStrings().NISp,
2012-12-28 22:06:43 +00:00
translate('OpenLP.MediaManagerItem', 'You must select one or more items to preview.'))
2009-12-06 13:55:07 +00:00
else:
log.debug(u'%s Preview requested', self.plugin.name)
serviceItem = self.buildServiceItem()
if serviceItem:
serviceItem.from_plugin = True
2013-01-27 20:36:18 +00:00
self.preview_controller.add_service_item(serviceItem)
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():
QtGui.QMessageBox.information(self, UiStrings().NISp,
2012-12-28 22:06:43 +00:00
translate('OpenLP.MediaManagerItem', 'You must select one or more items to send live.'))
2009-12-06 13:55:07 +00:00
else:
self.goLive()
def goLive(self, item_id=None, remote=False):
log.debug(u'%s Live requested', self.plugin.name)
item = None
if item_id:
item = self.createItemFromId(item_id)
serviceItem = self.buildServiceItem(item, remote=remote)
if serviceItem:
2011-05-14 12:26:05 +00:00
if not item_id:
serviceItem.from_plugin = True
2012-10-18 20:38:01 +00:00
if remote:
serviceItem.will_auto_start = True
2013-01-27 20:36:18 +00:00
self.live_controller.add_service_item(serviceItem)
2009-06-23 20:53:06 +00:00
def createItemFromId(self, item_id):
item = QtGui.QListWidgetItem()
2012-05-17 15:13:09 +00:00
item.setData(QtCore.Qt.UserRole, 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
"""
2013-01-27 09:57:03 +00:00
if not self.listView.selectedIndexes():
QtGui.QMessageBox.information(self, UiStrings().NISp,
2012-12-28 22:06:43 +00:00
translate('OpenLP.MediaManagerItem', 'You must select one or more items to add.'))
2009-12-06 13:55:07 +00:00
else:
2013-01-23 21:05:25 +00:00
# Is it possible to process multiple list items to generate
2010-11-28 19:38:27 +00:00
# multiple service items?
2013-01-27 09:57:03 +00:00
if self.singleServiceItem:
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
def addToService(self, item=None, replace=None, remote=False):
2012-12-28 22:06:43 +00:00
serviceItem = self.buildServiceItem(item, True, remote=remote, context=ServiceItemContext.Service)
2011-05-21 17:43:37 +00:00
if serviceItem:
serviceItem.from_plugin = False
2013-01-27 20:36:18 +00:00
self.service_manager.add_service_item(serviceItem, 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:
QtGui.QMessageBox.information(self, UiStrings().NISp,
2012-12-28 22:06:43 +00:00
translate('OpenLP.MediaManagerItem', 'You must select one or more items.'))
2010-03-16 20:22:28 +00:00
else:
log.debug(u'%s Add requested', self.plugin.name)
2013-01-27 20:36:18 +00:00
serviceItem = self.service_manager.get_service_item()
if not serviceItem:
QtGui.QMessageBox.information(self, UiStrings().NISs,
2012-12-28 22:06:43 +00:00
translate('OpenLP.MediaManagerItem', 'You must select an existing service item to add to.'))
elif self.plugin.name == serviceItem.name:
self.generateSlideData(serviceItem)
2013-01-27 20:36:18 +00:00
self.service_manager.add_service_item(serviceItem, replace=True)
2010-03-20 08:34:36 +00:00
else:
# Turn off the remote edit update message indicator
2012-12-28 22:06:43 +00:00
QtGui.QMessageBox.information(self, translate('OpenLP.MediaManagerItem', 'Invalid Service Item'),
translate('OpenLP.MediaManagerItem', 'You must select a %s service item.') % self.title)
2010-03-16 20:22:28 +00:00
2012-12-28 22:06:43 +00:00
def buildServiceItem(self, item=None, xmlVersion=False, remote=False, context=ServiceItemContext.Live):
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.iconPath)
2013-01-27 09:57:03 +00:00
if self.generateSlideData(serviceItem, item, xmlVersion, remote, context):
return serviceItem
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
def checkSearchResult(self):
2011-05-15 12:11:08 +00:00
"""
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
2012-05-19 09:13:32 +00:00
item_id = item.data(QtCore.Qt.UserRole)
2011-02-01 00:33:50 +00:00
else:
item_id = remoteItem
else:
2012-05-19 09:13:32 +00:00
item_id = item.data(QtCore.Qt.UserRole)
2011-04-29 08:45:36 +00:00
return item_id
def saveAutoSelectId(self):
"""
Sorts out, what item to select after loading a list.
"""
# The item to select has not been set.
if self.autoSelectId == -1:
item = self.listView.currentItem()
if item:
2012-05-19 09:13:32 +00:00
self.autoSelectId = item.data(QtCore.Qt.UserRole)
def search(self, string, showError=True):
"""
Performs a plugin specific search for items containing ``string``
"""
2012-12-28 22:06:43 +00:00
raise NotImplementedError(u'Plugin.search needs to be defined by the plugin')
def _get_main_window(self):
"""
Adds the main window to the class dynamically
"""
if not hasattr(self, u'_main_window'):
self._main_window = Registry().get(u'main_window')
return self._main_window
main_window = property(_get_main_window)
def _get_renderer(self):
"""
Adds the Renderer to the class dynamically
"""
if not hasattr(self, u'_renderer'):
self._renderer = Registry().get(u'renderer')
return self._renderer
renderer = property(_get_renderer)
def _get_live_controller(self):
"""
Adds the live controller to the class dynamically
"""
if not hasattr(self, u'_live_controller'):
self._live_controller = Registry().get(u'live_controller')
return self._live_controller
live_controller = property(_get_live_controller)
def _get_preview_controller(self):
"""
Adds the preview controller to the class dynamically
"""
if not hasattr(self, u'_preview_controller'):
self._preview_controller = Registry().get(u'preview_controller')
return self._preview_controller
preview_controller = property(_get_preview_controller)
def _get_plugin_manager(self):
"""
Adds the plugin manager to the class dynamically
"""
if not hasattr(self, u'_plugin_manager'):
self._plugin_manager = Registry().get(u'plugin_manager')
return self._plugin_manager
plugin_manager = property(_get_plugin_manager)
def _get_media_controller(self):
"""
Adds the media controller to the class dynamically
"""
if not hasattr(self, u'_media_controller'):
self._media_controller = Registry().get(u'media_controller')
return self._media_controller
media_controller = property(_get_media_controller)
def _get_service_manager(self):
"""
2013-01-26 07:39:07 +00:00
Adds the service manager to the class dynamically
"""
if not hasattr(self, u'_service_manager'):
self._service_manager = Registry().get(u'service_manager')
return self._service_manager
2013-01-26 07:39:07 +00:00
service_manager = property(_get_service_manager)