2008-11-22 15:16:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-28 22:06:43 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 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 #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2016-12-31 11:01:36 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
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
|
|
|
|
2017-08-07 20:50:01 +00:00
|
|
|
from PyQt5 import QtCore, QtWidgets
|
2009-06-26 16:17:55 +00:00
|
|
|
|
2014-03-16 21:25:23 +00:00
|
|
|
from openlp.core.common import Registry, RegistryProperties, Settings, UiStrings, translate
|
2017-08-26 15:06:11 +00:00
|
|
|
from openlp.core.common.path import Path, path_to_str, str_to_path
|
2017-08-07 20:50:01 +00:00
|
|
|
from openlp.core.lib import ServiceItem, StringContent, ServiceItemContext
|
2011-12-30 21:40:13 +00:00
|
|
|
from openlp.core.lib.searchedit import SearchEdit
|
2013-01-11 00:19:11 +00:00
|
|
|
from openlp.core.lib.ui import create_widget_action, critical_error_message_box
|
2017-08-07 20:50:01 +00:00
|
|
|
from openlp.core.ui.lib.filedialog import FileDialog
|
2016-04-17 19:09:46 +00:00
|
|
|
from openlp.core.ui.lib.listwidgetwithdnd import ListWidgetWithDnD
|
2016-04-17 19:32:15 +00:00
|
|
|
from openlp.core.ui.lib.toolbar import OpenLPToolbar
|
2013-01-11 00:19:11 +00:00
|
|
|
|
2010-02-27 15:31:23 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-02-01 19:58:18 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
|
2008-11-22 15:16:02 +00:00
|
|
|
"""
|
|
|
|
MediaManagerItem is a helper widget for plugins.
|
2009-07-01 20:21:13 +00:00
|
|
|
|
2013-03-07 08:05:43 +00:00
|
|
|
None of the following *need* to be used, feel free to override them completely in your plugin's implementation.
|
|
|
|
Alternatively, 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``
|
2013-03-07 08:05:43 +00:00
|
|
|
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``
|
2013-03-07 08:05:43 +00:00
|
|
|
The plugin widget. Usually this will be the *Plugin* itself. This needs to be a class descended from ``Plugin``.
|
2010-09-15 17:55:27 +00:00
|
|
|
|
2009-09-03 21:41:34 +00:00
|
|
|
**Member Variables**
|
|
|
|
|
2013-03-07 08:05:43 +00:00
|
|
|
When creating a descendant class from this class for your plugin, the following member variables should be set.
|
2009-09-03 21:41:34 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
``self.on_new_prompt``
|
2011-02-17 02:33:12 +00:00
|
|
|
|
2009-09-03 21:41:34 +00:00
|
|
|
Defaults to *'Select Image(s)'*.
|
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
``self.on_new_file_masks``
|
2013-03-07 08:05:43 +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.
|
2009-09-03 21:41:34 +00:00
|
|
|
|
|
|
|
``self.PreviewFunction``
|
2013-03-07 08:05:43 +00:00
|
|
|
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
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.info('Media Item loaded')
|
2009-06-23 20:59:38 +00:00
|
|
|
|
2013-03-07 13:14:31 +00:00
|
|
|
def __init__(self, parent=None, plugin=None):
|
2008-11-22 15:16:02 +00:00
|
|
|
"""
|
|
|
|
Constructor to create the media manager item.
|
|
|
|
"""
|
2013-10-02 21:07:20 +00:00
|
|
|
super(MediaManagerItem, self).__init__(parent)
|
|
|
|
self.plugin = plugin
|
|
|
|
self._setup()
|
|
|
|
self.setup_item()
|
|
|
|
|
|
|
|
def _setup(self):
|
|
|
|
"""
|
|
|
|
Run some initial setup. This method is separate from __init__ in order to mock it out in tests.
|
|
|
|
"""
|
2011-06-01 18:58:27 +00:00
|
|
|
self.hide()
|
2011-06-01 22:47:42 +00:00
|
|
|
self.whitespace = re.compile(r'[\W_]+', re.UNICODE)
|
2013-03-19 19:43:22 +00:00
|
|
|
visible_title = self.plugin.get_string(StringContent.VisibleName)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.title = str(visible_title['title'])
|
2013-01-27 09:57:03 +00:00
|
|
|
Registry().register(self.plugin.name, self)
|
2013-03-19 19:43:22 +00:00
|
|
|
self.settings_section = self.plugin.name
|
2010-07-07 16:03:30 +00:00
|
|
|
self.toolbar = None
|
2013-03-19 22:00:50 +00:00
|
|
|
self.remote_triggered = None
|
|
|
|
self.single_service_item = True
|
|
|
|
self.quick_preview_allowed = False
|
2013-03-22 21:05:42 +00:00
|
|
|
self.has_search = False
|
2015-11-07 00:49:40 +00:00
|
|
|
self.page_layout = QtWidgets.QVBoxLayout(self)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.page_layout.setSpacing(0)
|
2015-11-07 00:49:40 +00:00
|
|
|
self.page_layout.setContentsMargins(0, 0, 0, 0)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.required_icons()
|
2009-03-02 21:57:49 +00:00
|
|
|
self.setupUi()
|
|
|
|
self.retranslateUi()
|
2013-03-20 18:35:28 +00:00
|
|
|
self.auto_select_id = -1
|
2011-05-24 20:47:05 +00:00
|
|
|
|
2013-10-02 21:07:20 +00:00
|
|
|
def setup_item(self):
|
|
|
|
"""
|
|
|
|
Override this for additional Plugin setup
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def required_icons(self):
|
2009-09-26 09:11:39 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +00:00
|
|
|
This method is called to define the icons for the plugin. It provides a default set and the plugin is able to
|
|
|
|
override the if required.
|
2009-09-26 09:11:39 +00:00
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
self.has_import_icon = False
|
|
|
|
self.has_new_icon = True
|
|
|
|
self.has_edit_icon = True
|
|
|
|
self.has_file_icon = False
|
|
|
|
self.has_delete_icon = True
|
|
|
|
self.add_to_service_item = 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
|
|
|
"""
|
2013-03-07 08:05:43 +00:00
|
|
|
This method is called automatically to provide OpenLP with the opportunity to translate the ``MediaManagerItem``
|
|
|
|
to another language.
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
2009-03-02 21:57:49 +00:00
|
|
|
pass
|
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_toolbar(self):
|
2008-11-22 21:41:20 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +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)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.page_layout.addWidget(self.toolbar)
|
2008-11-25 16:26:49 +00:00
|
|
|
|
2009-06-23 20:53:06 +00:00
|
|
|
def setupUi(self):
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +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-09-04 22:50:19 +00:00
|
|
|
"""
|
2009-06-23 20:53:06 +00:00
|
|
|
# Add a toolbar
|
2013-03-19 22:00:50 +00:00
|
|
|
self.add_toolbar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Allow the plugin to define buttons at start of bar
|
2013-03-19 22:00:50 +00:00
|
|
|
self.add_start_header_bar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Add the middle of the tool bar (pre defined)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.add_middle_header_bar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Allow the plugin to define buttons at end of bar
|
2013-03-19 22:00:50 +00:00
|
|
|
self.add_end_header_bar()
|
2011-01-18 20:15:56 +00:00
|
|
|
# Add the list view
|
2013-03-19 22:00:50 +00:00
|
|
|
self.add_list_view_to_toolbar()
|
2009-09-16 04:59:38 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_middle_header_bar(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 = []
|
2014-04-12 20:19:22 +00:00
|
|
|
# Import Button
|
2013-03-19 22:00:50 +00:00
|
|
|
if self.has_import_icon:
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['Import', StringContent.Import,
|
2013-12-24 07:19:57 +00:00
|
|
|
':/general/general_import.png', self.on_import_click])
|
2014-04-12 20:19:22 +00:00
|
|
|
# Load Button
|
2013-03-19 22:00:50 +00:00
|
|
|
if self.has_file_icon:
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['Load', StringContent.Load, ':/general/general_open.png', self.on_file_click])
|
2014-04-12 20:19:22 +00:00
|
|
|
# New Button
|
2013-03-19 22:00:50 +00:00
|
|
|
if self.has_new_icon:
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['New', StringContent.New, ':/general/general_new.png', self.on_new_click])
|
2014-04-12 20:19:22 +00:00
|
|
|
# Edit Button
|
2013-03-19 22:00:50 +00:00
|
|
|
if self.has_edit_icon:
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['Edit', StringContent.Edit, ':/general/general_edit.png', self.on_edit_click])
|
2014-04-12 20:19:22 +00:00
|
|
|
# Delete Button
|
2013-03-19 22:00:50 +00:00
|
|
|
if self.has_delete_icon:
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['Delete', StringContent.Delete,
|
2013-12-24 07:19:57 +00:00
|
|
|
':/general/general_delete.png', self.on_delete_click])
|
2014-04-12 20:19:22 +00:00
|
|
|
# Preview
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['Preview', StringContent.Preview,
|
2013-12-24 07:19:57 +00:00
|
|
|
':/general/general_preview.png', self.on_preview_click])
|
2014-04-12 20:19:22 +00:00
|
|
|
# Live Button
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['Live', StringContent.Live, ':/general/general_live.png', self.on_live_click])
|
2014-04-12 20:19:22 +00:00
|
|
|
# Add to service Button
|
2013-08-31 18:17:38 +00:00
|
|
|
toolbar_actions.append(['Service', StringContent.Service, ':/general/general_add.png', self.on_add_click])
|
2011-02-11 04:04:05 +00:00
|
|
|
for action in toolbar_actions:
|
2011-02-27 06:58:23 +00:00
|
|
|
if action[0] == StringContent.Preview:
|
2012-03-03 13:52:57 +00:00
|
|
|
self.toolbar.addSeparator()
|
2016-05-15 17:33:42 +00:00
|
|
|
self.toolbar.add_toolbar_action('{name}{action}Action'.format(name=self.plugin.name, action=action[0]),
|
2013-12-24 07:19:57 +00:00
|
|
|
text=self.plugin.get_string(action[1])['title'], icon=action[2],
|
|
|
|
tooltip=self.plugin.get_string(action[1])['tooltip'],
|
|
|
|
triggers=action[3])
|
2009-09-16 04:59:38 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_list_view_to_toolbar(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
|
2013-03-19 22:00:50 +00:00
|
|
|
self.list_view = ListWidgetWithDnD(self, self.plugin.name)
|
2016-05-15 17:33:42 +00:00
|
|
|
self.list_view.setObjectName('{name}ListView'.format(name=self.plugin.name))
|
2013-03-19 22:00:50 +00:00
|
|
|
# Add to page_layout
|
|
|
|
self.page_layout.addWidget(self.list_view)
|
|
|
|
if self.has_edit_icon:
|
|
|
|
create_widget_action(self.list_view,
|
2013-12-24 07:19:57 +00:00
|
|
|
text=self.plugin.get_string(StringContent.Edit)['title'],
|
|
|
|
icon=':/general/general_edit.png',
|
|
|
|
triggers=self.on_edit_click)
|
2013-03-19 22:00:50 +00:00
|
|
|
create_widget_action(self.list_view, separator=True)
|
|
|
|
create_widget_action(self.list_view,
|
2016-05-15 17:33:42 +00:00
|
|
|
'listView{plugin}{preview}Item'.format(plugin=self.plugin.name.title(),
|
|
|
|
preview=StringContent.Preview.title()),
|
2013-12-24 07:19:57 +00:00
|
|
|
text=self.plugin.get_string(StringContent.Preview)['title'],
|
|
|
|
icon=':/general/general_preview.png',
|
|
|
|
can_shortcuts=True,
|
|
|
|
triggers=self.on_preview_click)
|
2013-03-19 22:00:50 +00:00
|
|
|
create_widget_action(self.list_view,
|
2016-05-15 17:33:42 +00:00
|
|
|
'listView{plugin}{live}Item'.format(plugin=self.plugin.name.title(),
|
|
|
|
live=StringContent.Live.title()),
|
2013-12-24 07:19:57 +00:00
|
|
|
text=self.plugin.get_string(StringContent.Live)['title'],
|
|
|
|
icon=':/general/general_live.png',
|
|
|
|
can_shortcuts=True,
|
|
|
|
triggers=self.on_live_click)
|
2013-03-19 22:00:50 +00:00
|
|
|
create_widget_action(self.list_view,
|
2016-05-15 17:33:42 +00:00
|
|
|
'listView{plugin}{service}Item'.format(plugin=self.plugin.name.title(),
|
|
|
|
service=StringContent.Service.title()),
|
2013-12-24 07:19:57 +00:00
|
|
|
can_shortcuts=True,
|
|
|
|
text=self.plugin.get_string(StringContent.Service)['title'],
|
|
|
|
icon=':/general/general_add.png',
|
|
|
|
triggers=self.on_add_click)
|
2015-01-30 21:15:03 +00:00
|
|
|
if self.has_delete_icon:
|
|
|
|
create_widget_action(self.list_view, separator=True)
|
|
|
|
create_widget_action(self.list_view,
|
2016-05-15 17:33:42 +00:00
|
|
|
'listView{plugin}{delete}Item'.format(plugin=self.plugin.name.title(),
|
|
|
|
delete=StringContent.Delete.title()),
|
2015-01-30 21:15:03 +00:00
|
|
|
text=self.plugin.get_string(StringContent.Delete)['title'],
|
|
|
|
icon=':/general/general_delete.png',
|
|
|
|
can_shortcuts=True, triggers=self.on_delete_click)
|
2013-03-19 22:00:50 +00:00
|
|
|
if self.add_to_service_item:
|
|
|
|
create_widget_action(self.list_view, separator=True)
|
|
|
|
create_widget_action(self.list_view,
|
2013-12-24 07:19:57 +00:00
|
|
|
text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'),
|
|
|
|
icon=':/general/general_add.png',
|
|
|
|
triggers=self.on_add_edit_click)
|
2013-03-19 22:00:50 +00:00
|
|
|
self.add_custom_context_actions()
|
|
|
|
# Create the context menu and add all actions from the list_view.
|
2015-11-07 00:49:40 +00:00
|
|
|
self.menu = QtWidgets.QMenu()
|
2013-03-19 22:00:50 +00:00
|
|
|
self.menu.addActions(self.list_view.actions())
|
|
|
|
self.list_view.doubleClicked.connect(self.on_double_clicked)
|
|
|
|
self.list_view.itemSelectionChanged.connect(self.on_selection_change)
|
|
|
|
self.list_view.customContextMenuRequested.connect(self.context_menu)
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_search_to_toolbar(self):
|
2011-12-30 21:40:13 +00:00
|
|
|
"""
|
|
|
|
Creates a search field with button and related signal handling.
|
|
|
|
"""
|
2015-11-07 00:49:40 +00:00
|
|
|
self.search_widget = QtWidgets.QWidget(self)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.search_widget.setObjectName('search_widget')
|
2015-11-07 00:49:40 +00:00
|
|
|
self.search_layout = QtWidgets.QVBoxLayout(self.search_widget)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.search_layout.setObjectName('search_layout')
|
2015-11-07 00:49:40 +00:00
|
|
|
self.search_text_layout = QtWidgets.QFormLayout()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.search_text_layout.setObjectName('search_text_layout')
|
2015-11-07 00:49:40 +00:00
|
|
|
self.search_text_label = QtWidgets.QLabel(self.search_widget)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.search_text_label.setObjectName('search_text_label')
|
2016-11-11 21:23:03 +00:00
|
|
|
self.search_text_edit = SearchEdit(self.search_widget, self.settings_section)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.search_text_edit.setObjectName('search_text_edit')
|
2013-03-19 22:00:50 +00:00
|
|
|
self.search_text_label.setBuddy(self.search_text_edit)
|
|
|
|
self.search_text_layout.addRow(self.search_text_label, self.search_text_edit)
|
|
|
|
self.search_layout.addLayout(self.search_text_layout)
|
2015-11-07 00:49:40 +00:00
|
|
|
self.search_button_layout = QtWidgets.QHBoxLayout()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.search_button_layout.setObjectName('search_button_layout')
|
2013-03-19 22:00:50 +00:00
|
|
|
self.search_button_layout.addStretch()
|
2015-11-07 00:49:40 +00:00
|
|
|
self.search_text_button = QtWidgets.QPushButton(self.search_widget)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.search_text_button.setObjectName('search_text_button')
|
2013-03-19 22:00:50 +00:00
|
|
|
self.search_button_layout.addWidget(self.search_text_button)
|
|
|
|
self.search_layout.addLayout(self.search_button_layout)
|
|
|
|
self.page_layout.addWidget(self.search_widget)
|
2011-12-30 21:40:13 +00:00
|
|
|
# Signals and slots
|
2013-03-19 22:00:50 +00:00
|
|
|
self.search_text_edit.returnPressed.connect(self.on_search_text_button_clicked)
|
|
|
|
self.search_text_button.clicked.connect(self.on_search_text_button_clicked)
|
|
|
|
self.search_text_edit.textChanged.connect(self.on_search_text_edit_changed)
|
2011-12-30 21:40:13 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_custom_context_actions(self):
|
2011-07-01 16:55:07 +00:00
|
|
|
"""
|
2013-12-24 07:19:57 +00:00
|
|
|
Implement this method in your descendant media manager item to add any context menu items.
|
|
|
|
This method is called automatically.
|
2011-07-01 16:55:07 +00:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2009-06-23 20:53:06 +00:00
|
|
|
def initialise(self):
|
2009-09-04 22:50:19 +00:00
|
|
|
"""
|
2013-12-24 07:19:57 +00:00
|
|
|
Implement this method in your descendant media manager item to 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
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_start_header_bar(self):
|
2009-09-11 04:54:22 +00:00
|
|
|
"""
|
2013-12-24 07:19:57 +00:00
|
|
|
Slot at start of toolbar for plugin to add widgets
|
2009-09-11 04:54:22 +00:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def add_end_header_bar(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
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_file_click(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Add a file to the list widget to make it available for showing
|
|
|
|
"""
|
2017-08-07 20:50:01 +00:00
|
|
|
file_paths, selected_filter = FileDialog.getOpenFileNames(
|
|
|
|
self, self.on_new_prompt,
|
2017-08-26 15:06:11 +00:00
|
|
|
Settings().value(self.settings_section + '/last directory'),
|
2017-08-07 20:50:01 +00:00
|
|
|
self.on_new_file_masks)
|
|
|
|
log.info('New files(s) {file_paths}'.format(file_paths=file_paths))
|
|
|
|
if file_paths:
|
2013-02-03 19:23:12 +00:00
|
|
|
self.application.set_busy_cursor()
|
2017-08-07 20:50:01 +00:00
|
|
|
self.validate_and_load([path_to_str(path) for path in file_paths])
|
2013-02-03 19:23:12 +00:00
|
|
|
self.application.set_normal_cursor()
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def load_file(self, data):
|
2011-07-27 18:28:35 +00:00
|
|
|
"""
|
2013-01-11 00:19:11 +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
|
|
|
|
2014-01-11 21:29:01 +00:00
|
|
|
:param data: A dictionary containing the list of files to be loaded and the target
|
2011-07-27 18:28:35 +00:00
|
|
|
"""
|
2012-07-01 19:22:11 +00:00
|
|
|
new_files = []
|
|
|
|
error_shown = False
|
2013-01-30 10:57:06 +00:00
|
|
|
for file_name in data['files']:
|
2013-08-31 18:17:38 +00:00
|
|
|
file_type = file_name.split('.')[-1]
|
2013-03-19 22:00:50 +00:00
|
|
|
if file_type.lower() not in self.on_new_file_masks:
|
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'),
|
2013-12-24 07:19:57 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
2016-05-15 17:33:42 +00:00
|
|
|
'Invalid File {name}.\n'
|
|
|
|
'Suffix not supported').format(name=file_name))
|
2012-10-03 18:52:52 +00:00
|
|
|
error_shown = True
|
2011-08-02 05:07:09 +00:00
|
|
|
else:
|
2013-02-01 19:58:18 +00:00
|
|
|
new_files.append(file_name)
|
2012-07-01 19:22:11 +00:00
|
|
|
if new_files:
|
2013-03-19 22:00:50 +00:00
|
|
|
self.validate_and_load(new_files, data['target'])
|
2011-07-27 18:28:35 +00:00
|
|
|
|
2013-01-30 10:57:06 +00:00
|
|
|
def dnd_move_internal(self, target):
|
2013-01-29 12:02:20 +00:00
|
|
|
"""
|
|
|
|
Handle internal moving of media manager items
|
2015-03-06 22:18:51 +00:00
|
|
|
|
2014-01-11 21:29:01 +00:00
|
|
|
:param target: The target of the DnD action
|
2013-01-29 12:02:20 +00:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def validate_and_load(self, files, target_group=None):
|
2011-07-27 18:28:35 +00:00
|
|
|
"""
|
|
|
|
Process a list for files either from the File Dialog or from Drag and
|
|
|
|
Drop
|
|
|
|
|
2014-01-11 21:29:01 +00:00
|
|
|
:param files: The files to be loaded.
|
|
|
|
:param target_group: The QTreeWidgetItem of the group that will be the parent of the added files
|
2011-07-27 18:28:35 +00:00
|
|
|
"""
|
2012-07-01 19:22:11 +00:00
|
|
|
full_list = []
|
2013-03-19 22:00:50 +00:00
|
|
|
for count in range(self.list_view.count()):
|
|
|
|
full_list.append(self.list_view.item(count).data(QtCore.Qt.UserRole))
|
2012-07-01 19:22:11 +00:00
|
|
|
duplicates_found = False
|
|
|
|
files_added = False
|
2013-01-30 10:57:06 +00:00
|
|
|
for file_path in files:
|
2015-01-20 21:56:05 +00:00
|
|
|
if file_path in full_list:
|
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
|
2013-03-20 09:24:34 +00:00
|
|
|
full_list.append(file_path)
|
2012-07-01 19:22:11 +00:00
|
|
|
if full_list and files_added:
|
2013-01-29 13:21:07 +00:00
|
|
|
if target_group is None:
|
2013-03-19 22:00:50 +00:00
|
|
|
self.list_view.clear()
|
|
|
|
self.load_list(full_list, target_group)
|
2013-10-28 21:23:17 +00:00
|
|
|
last_dir = os.path.split(files[0])[0]
|
2017-08-26 15:06:11 +00:00
|
|
|
Settings().setValue(self.settings_section + '/last directory', Path(last_dir))
|
|
|
|
Settings().setValue('{section}/{section} files'.format(section=self.settings_section), self.get_file_list())
|
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,
|
2013-12-24 07:19:57 +00:00
|
|
|
translate('OpenLP.MediaManagerItem',
|
|
|
|
'Duplicate files were found on import and were ignored.'))
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def context_menu(self, point):
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
Display a context menu
|
2014-01-11 21:29:01 +00:00
|
|
|
|
|
|
|
:param point: The point the cursor was at
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
item = self.list_view.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
|
2015-11-07 00:49:40 +00:00
|
|
|
self.menu.exec(self.list_view.mapToGlobal(point))
|
2011-05-13 13:00:20 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def get_file_list(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Return the current list of files
|
2017-08-26 15:06:11 +00:00
|
|
|
|
|
|
|
:rtype: list[openlp.core.common.path.Path]
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
2017-08-26 15:06:11 +00:00
|
|
|
file_paths = []
|
2013-08-31 18:17:38 +00:00
|
|
|
for index in range(self.list_view.count()):
|
2013-12-24 07:19:57 +00:00
|
|
|
list_item = self.list_view.item(index)
|
|
|
|
filename = list_item.data(QtCore.Qt.UserRole)
|
2017-08-26 15:06:11 +00:00
|
|
|
file_paths.append(str_to_path(filename))
|
|
|
|
return file_paths
|
2009-06-27 19:55:55 +00:00
|
|
|
|
2013-12-24 07:19:57 +00:00
|
|
|
def load_list(self, load_list, target_group):
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
Load a list. Needs to be implemented by the plugin.
|
2014-01-11 21:29:01 +00:00
|
|
|
|
|
|
|
:param load_list: List object to load
|
|
|
|
:param target_group: Group to load
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
raise NotImplementedError('MediaManagerItem.loadList needs to be defined by the plugin')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_new_click(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
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_edit_click(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
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_delete_click(self):
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
Delete an item. Needs to be implemented by the plugin.
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
raise NotImplementedError('MediaManagerItem.on_delete_click needs to be defined by the plugin')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-04-18 09:27:11 +00:00
|
|
|
def on_focus(self):
|
2011-05-26 06:23:22 +00:00
|
|
|
"""
|
|
|
|
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-03-19 22:00:50 +00:00
|
|
|
def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False,
|
2013-12-24 07:19:57 +00:00
|
|
|
context=ServiceItemContext.Live):
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
Generate the slide data. Needs to be implemented by the plugin.
|
2014-01-11 21:29:01 +00:00
|
|
|
:param service_item: The service Item to be processed
|
|
|
|
:param item: The database item to be used to build the service item
|
|
|
|
:param xml_version:
|
|
|
|
:param remote: Was this remote triggered (False)
|
|
|
|
:param context: The service context
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
raise NotImplementedError('MediaManagerItem.generate_slide_data needs to be defined by the plugin')
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_double_clicked(self):
|
2010-11-26 09:49:06 +00:00
|
|
|
"""
|
|
|
|
Allows the list click action to be determined dynamically
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
if Settings().value('advanced/double click live'):
|
2013-03-19 22:00:50 +00:00
|
|
|
self.on_live_click()
|
2015-03-06 22:18:51 +00:00
|
|
|
elif not Settings().value('advanced/single click preview'):
|
|
|
|
# NOTE: The above check is necessary to prevent bug #1419300
|
2013-03-19 22:00:50 +00:00
|
|
|
self.on_preview_click()
|
2010-11-26 09:49:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_selection_change(self):
|
2011-04-02 09:52:32 +00:00
|
|
|
"""
|
|
|
|
Allows the change of current item in the list to be actioned
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
if Settings().value('advanced/single click preview') and self.quick_preview_allowed \
|
2014-01-11 21:29:01 +00:00
|
|
|
and self.list_view.selectedIndexes() and self.auto_select_id == -1:
|
2013-03-19 22:00:50 +00:00
|
|
|
self.on_preview_click(True)
|
2011-04-02 09:52:32 +00:00
|
|
|
|
2013-03-20 18:35:28 +00:00
|
|
|
def on_preview_click(self, keep_focus=False):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +00:00
|
|
|
Preview an item by building a service item then adding that service item to the preview slide controller.
|
2014-01-11 21:29:01 +00:00
|
|
|
|
|
|
|
:param keep_focus: Do we keep focus (False)
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
if not self.list_view.selectedIndexes() and not self.remote_triggered:
|
2015-11-07 00:49:40 +00:00
|
|
|
QtWidgets.QMessageBox.information(self, UiStrings().NISp,
|
|
|
|
translate('OpenLP.MediaManagerItem',
|
|
|
|
'You must select one or more items to preview.'))
|
2009-12-06 13:55:07 +00:00
|
|
|
else:
|
2013-12-24 07:19:57 +00:00
|
|
|
log.debug('%s Preview requested' % self.plugin.name)
|
2016-06-26 23:14:24 +00:00
|
|
|
Registry().set_flag('has doubleclick added item to service', False)
|
2013-03-19 22:00:50 +00:00
|
|
|
service_item = self.build_service_item()
|
2013-03-06 22:23:01 +00:00
|
|
|
if service_item:
|
|
|
|
service_item.from_plugin = True
|
|
|
|
self.preview_controller.add_service_item(service_item)
|
2014-05-19 19:19:05 +00:00
|
|
|
if not keep_focus:
|
|
|
|
self.preview_controller.preview_widget.setFocus()
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_live_click(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +00:00
|
|
|
Send an item live by building a service item then adding that service item to the live slide controller.
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
if not self.list_view.selectedIndexes():
|
2015-11-07 00:49:40 +00:00
|
|
|
QtWidgets.QMessageBox.information(self, UiStrings().NISp,
|
|
|
|
translate('OpenLP.MediaManagerItem',
|
|
|
|
'You must select one or more items to send live.'))
|
2009-12-06 13:55:07 +00:00
|
|
|
else:
|
2013-03-19 22:00:50 +00:00
|
|
|
self.go_live()
|
2011-05-14 09:48:58 +00:00
|
|
|
|
2013-03-22 21:05:42 +00:00
|
|
|
def go_live_remote(self, message):
|
|
|
|
"""
|
|
|
|
Remote Call wrapper
|
2013-04-14 15:59:57 +00:00
|
|
|
|
2014-01-11 21:29:01 +00:00
|
|
|
:param message: The passed data item_id:Remote.
|
2013-03-22 21:05:42 +00:00
|
|
|
"""
|
|
|
|
self.go_live(message[0], remote=message[1])
|
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def go_live(self, item_id=None, remote=False):
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
Make the currently selected item go live.
|
2014-01-11 21:29:01 +00:00
|
|
|
|
|
|
|
:param item_id: item to make live
|
|
|
|
:param remote: From Remote
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('%s Live requested', self.plugin.name)
|
2011-05-14 09:48:58 +00:00
|
|
|
item = None
|
|
|
|
if item_id:
|
2013-03-19 22:00:50 +00:00
|
|
|
item = self.create_item_from_id(item_id)
|
|
|
|
service_item = self.build_service_item(item, remote=remote)
|
2013-03-06 22:23:01 +00:00
|
|
|
if service_item:
|
2011-05-14 12:26:05 +00:00
|
|
|
if not item_id:
|
2013-03-06 22:23:01 +00:00
|
|
|
service_item.from_plugin = True
|
2012-10-18 20:38:01 +00:00
|
|
|
if remote:
|
2013-03-06 22:23:01 +00:00
|
|
|
service_item.will_auto_start = True
|
|
|
|
self.live_controller.add_service_item(service_item)
|
2014-05-19 19:19:05 +00:00
|
|
|
self.live_controller.preview_widget.setFocus()
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def create_item_from_id(self, item_id):
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
Create a media item from an item id.
|
2014-01-11 21:29:01 +00:00
|
|
|
|
|
|
|
:param item_id: Id to make live
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
2015-11-07 00:49:40 +00:00
|
|
|
item = QtWidgets.QListWidgetItem()
|
2012-05-17 15:13:09 +00:00
|
|
|
item.setData(QtCore.Qt.UserRole, item_id)
|
2011-05-14 21:25:22 +00:00
|
|
|
return item
|
2009-06-23 20:53:06 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_add_click(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Add a selected item to the current service
|
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
if not self.list_view.selectedIndexes():
|
2015-11-07 00:49:40 +00:00
|
|
|
QtWidgets.QMessageBox.information(self, UiStrings().NISp,
|
|
|
|
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-03-19 22:00:50 +00:00
|
|
|
if self.single_service_item:
|
2016-05-15 17:33:42 +00:00
|
|
|
log.debug('{plugin} Add requested'.format(plugin=self.plugin.name))
|
2013-03-19 22:00:50 +00:00
|
|
|
self.add_to_service(replace=self.remote_triggered)
|
2010-04-04 13:53:39 +00:00
|
|
|
else:
|
2013-03-19 22:00:50 +00:00
|
|
|
items = self.list_view.selectedIndexes()
|
2014-10-29 21:04:17 +00:00
|
|
|
drop_position = self.service_manager.get_drop_position()
|
2010-04-04 13:53:39 +00:00
|
|
|
for item in items:
|
2014-10-29 21:04:17 +00:00
|
|
|
self.add_to_service(item, position=drop_position)
|
|
|
|
if drop_position != -1:
|
|
|
|
drop_position += 1
|
2011-05-19 23:09:42 +00:00
|
|
|
|
2013-03-22 21:05:42 +00:00
|
|
|
def add_to_service_remote(self, message):
|
|
|
|
"""
|
|
|
|
Remote Call wrapper
|
2013-04-14 15:59:57 +00:00
|
|
|
|
2014-01-11 21:29:01 +00:00
|
|
|
:param message: The passed data item:Remote.
|
2013-03-22 21:05:42 +00:00
|
|
|
"""
|
|
|
|
self.add_to_service(message[0], remote=message[1])
|
2011-05-19 23:09:42 +00:00
|
|
|
|
2014-10-29 21:04:17 +00:00
|
|
|
def add_to_service(self, item=None, replace=None, remote=False, position=-1):
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
Add this item to the current service.
|
2014-01-11 21:29:01 +00:00
|
|
|
|
|
|
|
:param item: Item to be processed
|
|
|
|
:param replace: Replace the existing item
|
|
|
|
:param remote: Triggered from remote
|
2014-10-29 21:04:17 +00:00
|
|
|
:param position: Position to place item
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
service_item = self.build_service_item(item, True, remote=remote, context=ServiceItemContext.Service)
|
2013-03-06 22:23:01 +00:00
|
|
|
if service_item:
|
|
|
|
service_item.from_plugin = False
|
2014-10-29 21:04:17 +00:00
|
|
|
self.service_manager.add_service_item(service_item, replace=replace, position=position)
|
2009-07-08 16:40:42 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def on_add_edit_click(self):
|
2010-06-19 17:31:42 +00:00
|
|
|
"""
|
|
|
|
Add a selected item to an existing item in the current service.
|
|
|
|
"""
|
2013-03-19 22:00:50 +00:00
|
|
|
if not self.list_view.selectedIndexes() and not self.remote_triggered:
|
2015-11-07 00:49:40 +00:00
|
|
|
QtWidgets.QMessageBox.information(self, UiStrings().NISp,
|
|
|
|
translate('OpenLP.MediaManagerItem',
|
|
|
|
'You must select one or more items.'))
|
2010-03-16 20:22:28 +00:00
|
|
|
else:
|
2016-05-15 17:33:42 +00:00
|
|
|
log.debug('{plugin} Add requested'.format(plugin=self.plugin.name))
|
2013-03-06 22:23:01 +00:00
|
|
|
service_item = self.service_manager.get_service_item()
|
|
|
|
if not service_item:
|
2015-11-07 00:49:40 +00:00
|
|
|
QtWidgets.QMessageBox.information(self, UiStrings().NISs,
|
|
|
|
translate('OpenLP.MediaManagerItem',
|
|
|
|
'You must select an existing service item to add to.'))
|
2013-03-06 22:23:01 +00:00
|
|
|
elif self.plugin.name == service_item.name:
|
2013-03-19 22:00:50 +00:00
|
|
|
self.generate_slide_data(service_item)
|
2013-03-06 22:23:01 +00:00
|
|
|
self.service_manager.add_service_item(service_item, 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
|
2015-11-07 00:49:40 +00:00
|
|
|
QtWidgets.QMessageBox.information(self, translate('OpenLP.MediaManagerItem', 'Invalid Service Item'),
|
|
|
|
translate('OpenLP.MediaManagerItem',
|
2016-05-15 17:33:42 +00:00
|
|
|
'You must select a {title} '
|
|
|
|
'service item.').format(title=self.title))
|
2010-03-16 20:22:28 +00:00
|
|
|
|
2013-03-20 18:35:28 +00:00
|
|
|
def build_service_item(self, item=None, xml_version=False, remote=False, context=ServiceItemContext.Live):
|
2009-07-08 16:40:42 +00:00
|
|
|
"""
|
|
|
|
Common method for generating a service item
|
2014-01-11 21:29:01 +00:00
|
|
|
:param item: Service Item to be built.
|
|
|
|
:param xml_version: version of XML (False)
|
|
|
|
:param remote: Remote triggered (False)
|
|
|
|
:param context: The context on which this is called
|
2009-07-08 16:40:42 +00:00
|
|
|
"""
|
2013-03-06 22:23:01 +00:00
|
|
|
service_item = ServiceItem(self.plugin)
|
2013-03-19 20:05:13 +00:00
|
|
|
service_item.add_icon(self.plugin.icon_path)
|
2013-03-20 18:35:28 +00:00
|
|
|
if self.generate_slide_data(service_item, item, xml_version, remote, context):
|
2013-03-06 22:23:01 +00:00
|
|
|
return service_item
|
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
|
|
|
|
2013-04-21 15:53:51 +00:00
|
|
|
def service_load(self, item):
|
2010-09-30 05:12:06 +00:00
|
|
|
"""
|
2013-03-07 08:05:43 +00:00
|
|
|
Method to add processing when a service has been loaded and individual service items need to be processed by the
|
|
|
|
plugins.
|
2013-04-21 15:53:51 +00:00
|
|
|
|
2014-01-11 21:29:01 +00:00
|
|
|
:param item: The item to be processed and returned.
|
2010-09-30 05:12:06 +00:00
|
|
|
"""
|
2013-04-21 15:53:51 +00:00
|
|
|
return item
|
2011-02-01 00:33:50 +00:00
|
|
|
|
2013-03-20 18:35:28 +00:00
|
|
|
def _get_id_of_item_to_generate(self, item, remote_item):
|
2011-02-01 00:33:50 +00:00
|
|
|
"""
|
|
|
|
Utility method to check items being submitted for slide generation.
|
|
|
|
|
2014-01-11 21:29:01 +00:00
|
|
|
:param item: The item to check.
|
|
|
|
:param remote_item: The id to assign if the slide generation was remotely triggered.
|
2011-02-01 00:33:50 +00:00
|
|
|
"""
|
|
|
|
if item is None:
|
2013-03-19 22:00:50 +00:00
|
|
|
if self.remote_triggered is None:
|
|
|
|
item = self.list_view.currentItem()
|
2011-02-01 00:33:50 +00:00
|
|
|
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:
|
2013-03-20 18:35:28 +00:00
|
|
|
item_id = remote_item
|
2011-02-01 00:33:50 +00:00
|
|
|
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
|
2011-05-14 09:48:58 +00:00
|
|
|
|
2013-03-19 22:00:50 +00:00
|
|
|
def save_auto_select_id(self):
|
2011-05-27 09:34:14 +00:00
|
|
|
"""
|
|
|
|
Sorts out, what item to select after loading a list.
|
|
|
|
"""
|
|
|
|
# The item to select has not been set.
|
2013-03-20 18:35:28 +00:00
|
|
|
if self.auto_select_id == -1:
|
2013-03-19 22:00:50 +00:00
|
|
|
item = self.list_view.currentItem()
|
2011-05-27 09:34:14 +00:00
|
|
|
if item:
|
2013-03-20 18:35:28 +00:00
|
|
|
self.auto_select_id = item.data(QtCore.Qt.UserRole)
|
2011-05-27 09:34:14 +00:00
|
|
|
|
2013-03-20 18:35:28 +00:00
|
|
|
def search(self, string, show_error=True):
|
2011-05-14 09:48:58 +00:00
|
|
|
"""
|
|
|
|
Performs a plugin specific search for items containing ``string``
|
2014-01-11 21:29:01 +00:00
|
|
|
|
|
|
|
:param string: String to be displayed
|
|
|
|
:param show_error: Should the error be shown (True)
|
2011-05-14 09:48:58 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
raise NotImplementedError('Plugin.search needs to be defined by the plugin')
|