2009-03-19 17:31:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
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 #
|
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
|
2010-07-24 22:10:47 +00:00
|
|
|
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
|
|
|
|
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
|
|
|
|
# Carsten Tinggaard, 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 #
|
|
|
|
###############################################################################
|
2009-03-19 17:31:33 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
2009-09-25 00:43:42 +00:00
|
|
|
|
2010-04-27 16:27:57 +00:00
|
|
|
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
2010-12-30 09:13:39 +00:00
|
|
|
SettingsManager, translate, check_item_selected, Receiver, ItemCapabilities
|
2011-02-02 23:12:31 +00:00
|
|
|
from openlp.core.lib.ui import critical_error_message_box
|
2009-09-05 13:30:09 +00:00
|
|
|
from openlp.plugins.presentations.lib import MessageListener
|
2009-06-26 16:39:16 +00:00
|
|
|
|
2010-02-27 15:31:23 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2009-06-26 16:39:16 +00:00
|
|
|
class PresentationListView(BaseListWithDnD):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Class for the list of Presentations
|
2010-11-27 15:25:00 +00:00
|
|
|
|
2010-07-10 22:21:14 +00:00
|
|
|
We have to explicitly create separate classes for each plugin
|
|
|
|
in order for DnD to the Service manager to work correctly.
|
|
|
|
"""
|
2009-06-26 16:39:16 +00:00
|
|
|
def __init__(self, parent=None):
|
2009-08-11 19:21:52 +00:00
|
|
|
self.PluginName = u'Presentations'
|
2009-06-26 16:39:16 +00:00
|
|
|
BaseListWithDnD.__init__(self, parent)
|
2009-03-19 17:31:33 +00:00
|
|
|
|
|
|
|
class PresentationMediaItem(MediaManagerItem):
|
|
|
|
"""
|
2009-08-11 19:21:52 +00:00
|
|
|
This is the Presentation media manager item for Presentation Items.
|
2010-07-10 22:21:14 +00:00
|
|
|
It can present files using Openoffice and Powerpoint
|
2009-03-19 17:31:33 +00:00
|
|
|
"""
|
|
|
|
log.info(u'Presentations Media Item loaded')
|
|
|
|
|
2009-08-11 19:21:52 +00:00
|
|
|
def __init__(self, parent, icon, title, controllers):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Constructor. Setup defaults
|
|
|
|
"""
|
2009-08-11 19:21:52 +00:00
|
|
|
self.controllers = controllers
|
2009-06-27 05:46:05 +00:00
|
|
|
self.IconPath = u'presentations/presentation'
|
2010-03-06 23:33:10 +00:00
|
|
|
self.Automatic = u''
|
2009-06-26 16:39:16 +00:00
|
|
|
# this next is a class, not an instance of a class - it will
|
|
|
|
# be instanced by the base MediaManagerItem
|
|
|
|
self.ListViewWithDnD_class = PresentationListView
|
2010-09-15 17:55:27 +00:00
|
|
|
MediaManagerItem.__init__(self, parent, self, icon)
|
2010-03-05 08:36:32 +00:00
|
|
|
self.message_listener = MessageListener(self)
|
2010-07-21 22:46:25 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'mediaitem_presentation_rebuild'), self.rebuild)
|
2010-11-27 15:25:00 +00:00
|
|
|
|
2009-10-31 16:17:26 +00:00
|
|
|
def retranslateUi(self):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
The name of the plugin media displayed in UI
|
|
|
|
"""
|
2010-06-21 18:28:36 +00:00
|
|
|
self.OnNewPrompt = translate('PresentationPlugin.MediaItem',
|
|
|
|
'Select Presentation(s)')
|
|
|
|
self.Automatic = translate('PresentationPlugin.MediaItem',
|
|
|
|
'Automatic')
|
2011-01-05 16:50:28 +00:00
|
|
|
self.displayTypeLabel.setText(
|
|
|
|
translate('PresentationPlugin.MediaItem', 'Present using:'))
|
2010-07-21 22:46:25 +00:00
|
|
|
|
|
|
|
def buildFileMaskString(self):
|
2010-07-22 07:32:55 +00:00
|
|
|
"""
|
|
|
|
Build the list of file extensions to be used in the Open file dialog
|
|
|
|
"""
|
2010-01-29 11:59:13 +00:00
|
|
|
fileType = u''
|
|
|
|
for controller in self.controllers:
|
2010-07-21 22:46:25 +00:00
|
|
|
if self.controllers[controller].enabled():
|
2010-04-27 16:27:57 +00:00
|
|
|
types = self.controllers[controller].supports + \
|
|
|
|
self.controllers[controller].alsosupports
|
2010-03-05 08:36:32 +00:00
|
|
|
for type in types:
|
2010-01-29 11:59:13 +00:00
|
|
|
if fileType.find(type) == -1:
|
2010-07-31 00:05:27 +00:00
|
|
|
fileType += u'*.%s ' % type
|
2010-07-02 22:18:54 +00:00
|
|
|
self.parent.serviceManager.supportedSuffixes(type)
|
2010-12-31 02:17:41 +00:00
|
|
|
self.OnNewFileMasks = unicode(translate('PresentationPlugin.MediaItem',
|
|
|
|
'Presentations (%s)')) % fileType
|
2009-10-29 18:25:34 +00:00
|
|
|
|
2009-09-26 09:11:39 +00:00
|
|
|
def requiredIcons(self):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Set which icons the media manager tab should show
|
|
|
|
"""
|
2009-09-26 09:11:39 +00:00
|
|
|
MediaManagerItem.requiredIcons(self)
|
|
|
|
self.hasFileIcon = True
|
|
|
|
self.hasNewIcon = False
|
|
|
|
self.hasEditIcon = False
|
|
|
|
|
2009-09-11 19:29:57 +00:00
|
|
|
def addEndHeaderBar(self):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Display custom media manager items for presentations
|
|
|
|
"""
|
2011-01-05 16:50:28 +00:00
|
|
|
self.presentationWidget = QtGui.QWidget(self)
|
|
|
|
self.presentationWidget.setObjectName(u'presentationWidget')
|
|
|
|
self.displayLayout = QtGui.QFormLayout(self.presentationWidget)
|
|
|
|
self.displayLayout.setMargin(self.displayLayout.spacing())
|
|
|
|
self.displayLayout.setObjectName(u'displayLayout')
|
|
|
|
self.displayTypeLabel = QtGui.QLabel(self.presentationWidget)
|
|
|
|
self.displayTypeLabel.setObjectName(u'displayTypeLabel')
|
|
|
|
self.displayTypeComboBox = QtGui.QComboBox(self.presentationWidget)
|
2011-01-09 15:37:45 +00:00
|
|
|
self.displayTypeComboBox.setSizeAdjustPolicy(
|
|
|
|
QtGui.QComboBox.AdjustToMinimumContentsLength)
|
|
|
|
self.displayTypeComboBox.setSizePolicy(
|
|
|
|
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
|
2011-01-05 16:50:28 +00:00
|
|
|
self.displayTypeComboBox.setObjectName(u'displayTypeComboBox')
|
|
|
|
self.displayTypeLabel.setBuddy(self.displayTypeComboBox)
|
|
|
|
self.displayLayout.addRow(self.displayTypeLabel,
|
|
|
|
self.displayTypeComboBox)
|
2009-06-27 05:46:05 +00:00
|
|
|
# Add the Presentation widget to the page layout
|
2011-01-05 16:50:28 +00:00
|
|
|
self.pageLayout.addWidget(self.presentationWidget)
|
2009-05-18 16:04:34 +00:00
|
|
|
|
2009-03-19 17:31:33 +00:00
|
|
|
def initialise(self):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Populate the media manager tab
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.setIconSize(QtCore.QSize(88, 50))
|
2010-04-30 01:31:41 +00:00
|
|
|
list = SettingsManager.load_list(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.settingsSection, u'presentations')
|
2010-07-11 20:22:53 +00:00
|
|
|
self.loadList(list, True)
|
2010-07-21 22:46:25 +00:00
|
|
|
self.populateDisplayTypes()
|
|
|
|
|
|
|
|
def rebuild(self):
|
2010-07-22 07:32:55 +00:00
|
|
|
"""
|
|
|
|
Rebuild the tab in the media manager when changes are made in
|
|
|
|
the settings
|
|
|
|
"""
|
2010-07-21 22:46:25 +00:00
|
|
|
self.populateDisplayTypes()
|
|
|
|
self.buildFileMaskString()
|
|
|
|
|
|
|
|
def populateDisplayTypes(self):
|
2010-07-22 07:32:55 +00:00
|
|
|
"""
|
|
|
|
Load the combobox with the enabled presentation controllers,
|
|
|
|
allowing user to select a specific app if settings allow
|
|
|
|
"""
|
2011-01-05 16:50:28 +00:00
|
|
|
self.displayTypeComboBox.clear()
|
2009-08-11 19:21:52 +00:00
|
|
|
for item in self.controllers:
|
2010-12-29 09:14:13 +00:00
|
|
|
# load the drop down selection
|
2010-07-21 22:46:25 +00:00
|
|
|
if self.controllers[item].enabled():
|
2011-01-05 16:50:28 +00:00
|
|
|
self.displayTypeComboBox.addItem(item)
|
|
|
|
if self.displayTypeComboBox.count() > 1:
|
|
|
|
self.displayTypeComboBox.insertItem(0, self.Automatic)
|
|
|
|
self.displayTypeComboBox.setCurrentIndex(0)
|
2010-11-27 15:25:00 +00:00
|
|
|
if QtCore.QSettings().value(self.settingsSection + u'/override app',
|
2010-07-26 15:19:11 +00:00
|
|
|
QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
|
2011-01-05 16:50:28 +00:00
|
|
|
self.presentationWidget.show()
|
2010-07-21 22:46:25 +00:00
|
|
|
else:
|
2011-01-05 16:50:28 +00:00
|
|
|
self.presentationWidget.hide()
|
2009-03-19 17:31:33 +00:00
|
|
|
|
2010-07-11 20:22:53 +00:00
|
|
|
def loadList(self, list, initialLoad=False):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Add presentations into the media manager
|
|
|
|
This is called both on initial load of the plugin to populate with
|
|
|
|
existing files, and when the user adds new files via the media manager
|
|
|
|
"""
|
2009-10-08 23:24:26 +00:00
|
|
|
currlist = self.getFileList()
|
|
|
|
titles = []
|
|
|
|
for file in currlist:
|
|
|
|
titles.append(os.path.split(file)[1])
|
2009-06-27 15:33:03 +00:00
|
|
|
for file in list:
|
2009-10-08 23:24:26 +00:00
|
|
|
if currlist.count(file) > 0:
|
|
|
|
continue
|
2010-05-27 14:41:47 +00:00
|
|
|
filename = os.path.split(unicode(file))[1]
|
2009-10-08 23:24:26 +00:00
|
|
|
if titles.count(filename) > 0:
|
2010-07-11 20:22:53 +00:00
|
|
|
if not initialLoad:
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2010-07-21 06:24:32 +00:00
|
|
|
translate('PresentationPlugin.MediaItem',
|
|
|
|
'File Exists'),
|
2010-07-11 20:22:53 +00:00
|
|
|
translate('PresentationPlugin.MediaItem',
|
2010-07-31 02:06:44 +00:00
|
|
|
'A presentation with that filename already exists.'))
|
2010-07-10 22:21:14 +00:00
|
|
|
continue
|
|
|
|
controller_name = self.findControllerByType(filename)
|
2010-07-11 20:22:53 +00:00
|
|
|
if controller_name:
|
|
|
|
controller = self.controllers[controller_name]
|
|
|
|
doc = controller.add_doc(unicode(file))
|
|
|
|
thumb = os.path.join(doc.get_thumbnail_folder(), u'icon.png')
|
2010-07-10 22:21:14 +00:00
|
|
|
preview = doc.get_thumbnail_path(1, True)
|
2010-07-11 20:22:53 +00:00
|
|
|
if not preview and not initialLoad:
|
|
|
|
doc.load_presentation()
|
|
|
|
preview = doc.get_thumbnail_path(1, True)
|
|
|
|
doc.close_presentation()
|
2010-12-29 09:37:36 +00:00
|
|
|
if preview and self.validate(preview, thumb):
|
2010-07-11 20:22:53 +00:00
|
|
|
icon = build_icon(thumb)
|
|
|
|
else:
|
|
|
|
icon = build_icon(u':/general/general_delete.png')
|
2009-10-08 23:24:26 +00:00
|
|
|
else:
|
2010-07-11 20:22:53 +00:00
|
|
|
if initialLoad:
|
|
|
|
icon = build_icon(u':/general/general_delete.png')
|
|
|
|
else:
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2010-07-11 20:22:53 +00:00
|
|
|
self, translate('PresentationPlugin.MediaItem',
|
2010-07-21 06:24:32 +00:00
|
|
|
'Unsupported File'),
|
2010-07-11 20:22:53 +00:00
|
|
|
translate('PresentationPlugin.MediaItem',
|
2010-09-06 04:53:48 +00:00
|
|
|
'This type of presentation is not supported.'))
|
2010-07-11 20:22:53 +00:00
|
|
|
continue
|
2010-07-10 22:21:14 +00:00
|
|
|
item_name = QtGui.QListWidgetItem(filename)
|
|
|
|
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
|
|
|
|
item_name.setIcon(icon)
|
2010-07-10 22:33:09 +00:00
|
|
|
self.listView.addItem(item_name)
|
2009-06-27 15:33:03 +00:00
|
|
|
|
2009-08-11 19:21:52 +00:00
|
|
|
def onDeleteClick(self):
|
2010-06-16 01:23:57 +00:00
|
|
|
"""
|
|
|
|
Remove a presentation item from the list
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
if check_item_selected(self.listView,
|
2010-06-24 15:50:40 +00:00
|
|
|
translate('PresentationPlugin.MediaItem',
|
2010-06-21 18:28:36 +00:00
|
|
|
'You must select an item to delete.')):
|
2010-07-07 16:03:30 +00:00
|
|
|
items = self.listView.selectedIndexes()
|
2010-06-28 18:20:05 +00:00
|
|
|
row_list = [item.row() for item in items]
|
|
|
|
row_list.sort(reverse=True)
|
|
|
|
for item in items:
|
|
|
|
filepath = unicode(item.data(
|
|
|
|
QtCore.Qt.UserRole).toString())
|
|
|
|
for cidx in self.controllers:
|
|
|
|
doc = self.controllers[cidx].add_doc(filepath)
|
|
|
|
doc.presentation_deleted()
|
|
|
|
doc.close_presentation()
|
|
|
|
for row in row_list:
|
2010-07-07 16:03:30 +00:00
|
|
|
self.listView.takeItem(row)
|
2010-06-28 20:00:35 +00:00
|
|
|
SettingsManager.set_list(self.settingsSection,
|
|
|
|
self.settingsSection, self.getFileList())
|
2009-05-18 16:04:34 +00:00
|
|
|
|
2010-11-27 15:25:00 +00:00
|
|
|
def generateSlideData(self, service_item, item=None, xmlVersion=False):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Load the relevant information for displaying the presentation
|
|
|
|
in the slidecontroller. In the case of powerpoints, an image
|
|
|
|
for each slide
|
|
|
|
"""
|
2010-07-07 16:03:30 +00:00
|
|
|
items = self.listView.selectedIndexes()
|
2009-08-31 21:53:35 +00:00
|
|
|
if len(items) > 1:
|
|
|
|
return False
|
2011-01-05 16:50:28 +00:00
|
|
|
service_item.title = unicode(self.displayTypeComboBox.currentText())
|
|
|
|
service_item.shortname = unicode(self.displayTypeComboBox.currentText())
|
2010-12-30 09:13:39 +00:00
|
|
|
service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
|
2011-01-29 07:53:21 +00:00
|
|
|
service_item.add_capability(ItemCapabilities.AllowsDetailedTitleDisplay)
|
2010-03-05 08:36:32 +00:00
|
|
|
shortname = service_item.shortname
|
2010-05-01 13:05:17 +00:00
|
|
|
if shortname:
|
|
|
|
for item in items:
|
2010-07-07 16:03:30 +00:00
|
|
|
bitem = self.listView.item(item.row())
|
2010-06-09 21:15:37 +00:00
|
|
|
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
|
2010-12-29 09:14:13 +00:00
|
|
|
if os.path.exists(filename):
|
|
|
|
if shortname == self.Automatic:
|
|
|
|
service_item.shortname = \
|
|
|
|
self.findControllerByType(filename)
|
|
|
|
if not service_item.shortname:
|
|
|
|
return False
|
|
|
|
controller = self.controllers[service_item.shortname]
|
|
|
|
(path, name) = os.path.split(filename)
|
|
|
|
doc = controller.add_doc(filename)
|
|
|
|
if doc.get_thumbnail_path(1, True) is None:
|
|
|
|
doc.load_presentation()
|
|
|
|
i = 1
|
2010-07-10 22:21:14 +00:00
|
|
|
img = doc.get_thumbnail_path(i, True)
|
2011-01-22 10:29:47 +00:00
|
|
|
if img:
|
|
|
|
while img:
|
|
|
|
service_item.add_from_command(path, name, img)
|
|
|
|
i = i + 1
|
|
|
|
img = doc.get_thumbnail_path(i, True)
|
|
|
|
doc.close_presentation()
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
# File is no longer present
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-22 10:29:47 +00:00
|
|
|
translate('PresentationPlugin.MediaItem',
|
|
|
|
'Missing Presentation'),
|
|
|
|
unicode(translate('PresentationPlugin.MediaItem',
|
2011-01-22 10:30:19 +00:00
|
|
|
'The Presentation %s is incomplete,'
|
|
|
|
' please reload.')) % filename)
|
2011-01-22 10:29:47 +00:00
|
|
|
return False
|
2010-12-29 09:14:13 +00:00
|
|
|
else:
|
|
|
|
# File is no longer present
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
translate('PresentationPlugin.MediaItem',
|
2010-12-29 09:27:13 +00:00
|
|
|
'Missing Presentation'),
|
|
|
|
unicode(translate('PresentationPlugin.MediaItem',
|
|
|
|
'The Presentation %s no longer exists.')) % filename)
|
2010-12-29 09:14:13 +00:00
|
|
|
return False
|
2010-05-01 13:05:17 +00:00
|
|
|
else:
|
|
|
|
return False
|
2010-03-05 08:36:32 +00:00
|
|
|
|
|
|
|
def findControllerByType(self, filename):
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
|
|
|
Determine the default application controller to use for the selected
|
2010-11-27 15:25:00 +00:00
|
|
|
file type. This is used if "Automatic" is set as the preferred
|
2010-07-10 22:21:14 +00:00
|
|
|
controller. Find the first (alphabetic) enabled controller which
|
|
|
|
"supports" the extension. If none found, then look for a controller
|
2010-12-29 09:14:13 +00:00
|
|
|
which "also supports" it instead.
|
2010-07-10 22:21:14 +00:00
|
|
|
"""
|
2010-07-31 00:05:27 +00:00
|
|
|
filetype = filename.split(u'.')[1]
|
2010-03-05 08:36:32 +00:00
|
|
|
if not filetype:
|
|
|
|
return None
|
|
|
|
for controller in self.controllers:
|
2010-07-21 22:46:25 +00:00
|
|
|
if self.controllers[controller].enabled():
|
2010-03-05 08:36:32 +00:00
|
|
|
if filetype in self.controllers[controller].supports:
|
|
|
|
return controller
|
|
|
|
for controller in self.controllers:
|
2010-07-21 22:46:25 +00:00
|
|
|
if self.controllers[controller].enabled():
|
2010-03-05 08:36:32 +00:00
|
|
|
if filetype in self.controllers[controller].alsosupports:
|
|
|
|
return controller
|
2010-12-29 09:14:13 +00:00
|
|
|
return None
|