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 #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2009-12-31 12:52:01 +00:00
|
|
|
# Copyright (c) 2008-2010 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
|
2010-03-21 23:58:01 +00:00
|
|
|
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
|
|
|
|
# Thompson, Jon Tibble, Carsten Tinggaard #
|
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-05-31 22:06:16 +00:00
|
|
|
SettingsManager, translate
|
2010-04-27 16:27:57 +00:00
|
|
|
from openlp.core.utils import AppLocation
|
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
|
|
|
# We have to explicitly create separate classes for each plugin
|
|
|
|
# in order for DnD to the Service manager to work correctly.
|
|
|
|
class PresentationListView(BaseListWithDnD):
|
|
|
|
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.
|
|
|
|
It can present files using Openoffice
|
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):
|
|
|
|
self.controllers = controllers
|
2009-10-28 01:36:24 +00:00
|
|
|
self.PluginNameShort = u'Presentation'
|
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
|
2009-03-19 17:31:33 +00:00
|
|
|
MediaManagerItem.__init__(self, parent, icon, title)
|
2010-03-05 08:36:32 +00:00
|
|
|
self.message_listener = MessageListener(self)
|
2010-03-21 23:58:01 +00:00
|
|
|
|
2009-10-29 01:48:43 +00:00
|
|
|
def initPluginNameVisible(self):
|
2010-06-06 13:42:24 +00:00
|
|
|
self.PluginNameVisible = translate(u'PresentationPlugin.MediaItem',
|
|
|
|
u'Presentation')
|
2009-10-29 01:48:43 +00:00
|
|
|
|
2009-10-31 16:17:26 +00:00
|
|
|
def retranslateUi(self):
|
2010-06-06 13:42:24 +00:00
|
|
|
self.OnNewPrompt = translate(u'PresentationPlugin.MediaItem',
|
|
|
|
u'Select Presentation(s)')
|
|
|
|
self.Automatic = translate(u'PresentationPlugin.MediaItem',
|
|
|
|
u'Automatic')
|
2010-01-29 11:59:13 +00:00
|
|
|
fileType = u''
|
|
|
|
for controller in self.controllers:
|
|
|
|
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-02-09 11:20:19 +00:00
|
|
|
fileType += u'*%s ' % type
|
2010-05-06 16:49:12 +00:00
|
|
|
self.parent.service_manager.supportedSuffixes(type)
|
2010-06-06 13:42:24 +00:00
|
|
|
self.OnNewFileMasks = translate(u'PresentationPlugin.MediaItem',
|
|
|
|
u'Presentations (%s)' % fileType)
|
2009-10-29 18:25:34 +00:00
|
|
|
|
2009-09-26 09:11:39 +00:00
|
|
|
def requiredIcons(self):
|
|
|
|
MediaManagerItem.requiredIcons(self)
|
|
|
|
self.hasFileIcon = True
|
|
|
|
self.hasNewIcon = False
|
|
|
|
self.hasEditIcon = False
|
|
|
|
|
2009-09-11 19:29:57 +00:00
|
|
|
def addEndHeaderBar(self):
|
2009-06-27 05:46:05 +00:00
|
|
|
self.PresentationWidget = QtGui.QWidget(self)
|
2009-09-21 17:56:36 +00:00
|
|
|
sizePolicy = QtGui.QSizePolicy(
|
|
|
|
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
2009-06-27 05:46:05 +00:00
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
2009-09-21 17:56:36 +00:00
|
|
|
sizePolicy.setHeightForWidth(
|
|
|
|
self.PresentationWidget.sizePolicy().hasHeightForWidth())
|
2009-06-27 05:46:05 +00:00
|
|
|
self.PresentationWidget.setSizePolicy(sizePolicy)
|
|
|
|
self.PresentationWidget.setObjectName(u'PresentationWidget')
|
|
|
|
self.DisplayLayout = QtGui.QGridLayout(self.PresentationWidget)
|
|
|
|
self.DisplayLayout.setObjectName(u'DisplayLayout')
|
|
|
|
self.DisplayTypeComboBox = QtGui.QComboBox(self.PresentationWidget)
|
|
|
|
self.DisplayTypeComboBox.setObjectName(u'DisplayTypeComboBox')
|
|
|
|
self.DisplayLayout.addWidget(self.DisplayTypeComboBox, 0, 1, 1, 2)
|
|
|
|
self.DisplayTypeLabel = QtGui.QLabel(self.PresentationWidget)
|
|
|
|
self.DisplayTypeLabel.setObjectName(u'SearchTypeLabel')
|
|
|
|
self.DisplayLayout.addWidget(self.DisplayTypeLabel, 0, 0, 1, 1)
|
2010-06-06 13:42:24 +00:00
|
|
|
self.DisplayTypeLabel.setText(
|
2010-06-21 16:43:59 +00:00
|
|
|
translate('PresentationPlugin.MediaItem', 'Present using:'))
|
2009-06-27 05:46:05 +00:00
|
|
|
# Add the Presentation widget to the page layout
|
|
|
|
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-04-19 18:20:44 +00:00
|
|
|
self.servicePath = os.path.join(
|
2010-04-30 22:38:15 +00:00
|
|
|
AppLocation.get_section_data_path(self.settingsSection),
|
2010-04-27 16:27:57 +00:00
|
|
|
u'thumbnails')
|
2010-05-25 16:16:43 +00:00
|
|
|
self.ListView.setIconSize(QtCore.QSize(88, 50))
|
2010-04-19 18:20:44 +00:00
|
|
|
if not os.path.exists(self.servicePath):
|
|
|
|
os.mkdir(self.servicePath)
|
2010-04-30 01:31:41 +00:00
|
|
|
list = SettingsManager.load_list(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.settingsSection, u'presentations')
|
2009-08-11 19:21:52 +00:00
|
|
|
self.loadList(list)
|
|
|
|
for item in self.controllers:
|
|
|
|
#load the drop down selection
|
2009-09-30 19:26:51 +00:00
|
|
|
if self.controllers[item].enabled:
|
|
|
|
self.DisplayTypeComboBox.addItem(item)
|
2010-03-05 19:50:51 +00:00
|
|
|
if self.DisplayTypeComboBox.count() > 1:
|
2010-03-06 23:33:10 +00:00
|
|
|
self.DisplayTypeComboBox.insertItem(0, self.Automatic)
|
2010-03-05 08:36:32 +00:00
|
|
|
self.DisplayTypeComboBox.setCurrentIndex(0)
|
2009-03-19 17:31:33 +00:00
|
|
|
|
2009-06-27 15:33:03 +00:00
|
|
|
def loadList(self, list):
|
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:
|
2009-10-23 18:48:49 +00:00
|
|
|
QtGui.QMessageBox.critical(
|
2010-06-06 13:42:24 +00:00
|
|
|
self, translate(u'PresentationPlugin.MediaItem',
|
|
|
|
u'File exists'),
|
|
|
|
translate(u'PresentationPlugin.MediaItem',
|
|
|
|
u'A presentation with that filename already exists.'),
|
2009-10-08 23:24:26 +00:00
|
|
|
QtGui.QMessageBox.Ok)
|
|
|
|
else:
|
2010-04-19 18:20:44 +00:00
|
|
|
icon = None
|
|
|
|
for controller in self.controllers:
|
2010-04-27 16:27:57 +00:00
|
|
|
thumbPath = os.path.join(
|
2010-04-30 01:31:41 +00:00
|
|
|
AppLocation.get_section_data_path(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.settingsSection),
|
2010-04-21 17:36:29 +00:00
|
|
|
u'thumbnails', controller, filename)
|
|
|
|
thumb = os.path.join(thumbPath, u'slide1.png')
|
2010-04-27 16:27:57 +00:00
|
|
|
preview = os.path.join(
|
2010-04-30 01:31:41 +00:00
|
|
|
AppLocation.get_section_data_path(
|
2010-04-30 22:38:15 +00:00
|
|
|
self.settingsSection),
|
2010-04-21 17:21:56 +00:00
|
|
|
controller, u'thumbnails', filename, u'slide1.png')
|
2010-04-19 18:20:44 +00:00
|
|
|
if os.path.exists(preview):
|
|
|
|
if os.path.exists(thumb):
|
|
|
|
if self.validate(preview, thumb):
|
|
|
|
icon = build_icon(thumb)
|
|
|
|
else:
|
2010-04-27 16:27:57 +00:00
|
|
|
icon = build_icon(
|
|
|
|
u':/general/general_delete.png')
|
2010-04-19 18:20:44 +00:00
|
|
|
else:
|
2010-04-21 17:36:29 +00:00
|
|
|
os.makedirs(thumbPath)
|
2010-04-19 18:20:44 +00:00
|
|
|
icon = self.IconFromFile(preview, thumb)
|
|
|
|
if not icon:
|
|
|
|
icon = build_icon(u':/general/general_delete.png')
|
2009-10-08 23:24:26 +00:00
|
|
|
item_name = QtGui.QListWidgetItem(filename)
|
|
|
|
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
|
2010-04-19 18:20:44 +00:00
|
|
|
item_name.setIcon(icon)
|
2009-10-08 23:24:26 +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
|
|
|
|
"""
|
|
|
|
if self.checkItemSelected(translate(u'PresentationPlugin.MediaItem',
|
|
|
|
u'You must select an item to delete.')):
|
|
|
|
item = self.ListView.currentItem()
|
2009-08-11 19:21:52 +00:00
|
|
|
row = self.ListView.row(item)
|
|
|
|
self.ListView.takeItem(row)
|
2010-04-30 22:38:15 +00:00
|
|
|
SettingsManager.set_list(self.settingsSection,
|
|
|
|
self.settingsSection, self.getFileList())
|
2010-06-09 21:15:37 +00:00
|
|
|
filepath = unicode(item.data(QtCore.Qt.UserRole).toString())
|
2010-04-05 11:06:37 +00:00
|
|
|
#not sure of this has errors
|
|
|
|
#John please can you look at .
|
2009-10-08 23:24:26 +00:00
|
|
|
for cidx in self.controllers:
|
2010-04-06 17:52:09 +00:00
|
|
|
doc = self.controllers[cidx].add_doc(filepath)
|
|
|
|
doc.presentation_deleted()
|
|
|
|
doc.close_presentation()
|
2009-05-18 16:04:34 +00:00
|
|
|
|
2010-04-05 06:45:01 +00:00
|
|
|
def generateSlideData(self, service_item, item=None):
|
2009-08-11 19:21:52 +00:00
|
|
|
items = self.ListView.selectedIndexes()
|
2009-08-31 21:53:35 +00:00
|
|
|
if len(items) > 1:
|
|
|
|
return False
|
2009-08-31 18:27:36 +00:00
|
|
|
service_item.title = unicode(self.DisplayTypeComboBox.currentText())
|
2009-08-11 19:21:52 +00:00
|
|
|
service_item.shortname = unicode(self.DisplayTypeComboBox.currentText())
|
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:
|
|
|
|
bitem = self.ListView.item(item.row())
|
2010-06-09 21:15:37 +00:00
|
|
|
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
|
2010-05-01 13:05:17 +00:00
|
|
|
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_slide_preview_file(1) is None:
|
|
|
|
doc.load_presentation()
|
|
|
|
i = 1
|
2010-03-02 21:01:23 +00:00
|
|
|
img = doc.get_slide_preview_file(i)
|
2010-05-01 13:05:17 +00:00
|
|
|
while img:
|
|
|
|
service_item.add_from_command(path, name, img)
|
|
|
|
i = i + 1
|
|
|
|
img = doc.get_slide_preview_file(i)
|
|
|
|
doc.close_presentation()
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2010-03-05 08:36:32 +00:00
|
|
|
|
|
|
|
def findControllerByType(self, filename):
|
|
|
|
filetype = os.path.splitext(filename)[1]
|
|
|
|
if not filetype:
|
|
|
|
return None
|
|
|
|
for controller in self.controllers:
|
|
|
|
if self.controllers[controller].enabled:
|
|
|
|
if filetype in self.controllers[controller].supports:
|
|
|
|
return controller
|
|
|
|
for controller in self.controllers:
|
|
|
|
if self.controllers[controller].enabled:
|
|
|
|
if filetype in self.controllers[controller].alsosupports:
|
|
|
|
return controller
|
2010-06-21 16:43:59 +00:00
|
|
|
return None
|