openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #00521
[Merge] lp:~j-corwin/openlp/present into lp:openlp
Jonathan Corwin has proposed merging lp:~j-corwin/openlp/present into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Controllers cleanup if presentation deleted.
Prevent ppt files with same name.
Only create thumbnails if out of date
--
https://code.launchpad.net/~j-corwin/openlp/present/+merge/13099
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/presentations/lib/impresscontroller.py'
--- openlp/plugins/presentations/lib/impresscontroller.py 2009-10-07 23:09:24 +0000
+++ openlp/plugins/presentations/lib/impresscontroller.py 2009-10-08 23:30:22 +0000
@@ -109,19 +109,16 @@
if os.name == u'nt':
desktop = self.get_com_desktop()
url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
- thumbdir = u'file:///' + self.thumbnailpath.replace(
- u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
else:
desktop = self.get_uno_desktop()
url = uno.systemPathToFileUrl(presentation)
- thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
if desktop is None:
return
try:
properties = []
properties = tuple(properties)
- doc = desktop.loadComponentFromURL(url, u'_blank', 0, properties)
- self.document = doc
+ self.document = desktop.loadComponentFromURL(url, u'_blank',
+ 0, properties)
self.presentation = self.document.getPresentation()
self.presentation.Display = self.plugin.render_manager.current_display + 1
self.presentation.start()
@@ -130,6 +127,20 @@
except:
log.exception(u'Failed to load presentation')
return
+ self.create_thumbnails()
+
+ def create_thumbnails(self):
+ """
+ Create thumbnail images for presentation
+ """
+ if self.check_thumbnails():
+ return
+
+ if os.name == u'nt':
+ thumbdir = u'file:///' + self.thumbnailpath.replace(
+ u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
+ else:
+ thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
props = []
if os.name == u'nt':
prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
@@ -139,6 +150,7 @@
prop.Value = u'impress_png_Export'
props.append(prop)
props = tuple(props)
+ doc = self.document
pages = doc.getDrawPages()
for idx in range(pages.getCount()):
page = pages.getByIndex(idx)
@@ -255,4 +267,4 @@
The slide an image is required for, starting at 1
"""
return os.path.join(self.thumbnailpath,
- self.thumbnailprefix + slide_no + u'.png')
+ self.thumbnailprefix + unicode(slide_no) + u'.png')
=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
--- openlp/plugins/presentations/lib/mediaitem.py 2009-09-30 19:26:51 +0000
+++ openlp/plugins/presentations/lib/mediaitem.py 2009-10-08 23:30:22 +0000
@@ -98,11 +98,22 @@
self.DisplayTypeComboBox.addItem(item)
def loadList(self, list):
+ currlist = self.getFileList()
+ titles = []
+ for file in currlist:
+ titles.append(os.path.split(file)[1])
for file in list:
+ if currlist.count(file) > 0:
+ continue
(path, filename) = os.path.split(unicode(file))
- item_name = QtGui.QListWidgetItem(filename)
- item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
- self.ListView.addItem(item_name)
+ if titles.count(filename) > 0:
+ QtGui.QMessageBox.critical(self, u'File exists',
+ u'A presentation with that filename already exists.',
+ QtGui.QMessageBox.Ok)
+ else:
+ item_name = QtGui.QListWidgetItem(filename)
+ item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
+ self.ListView.addItem(item_name)
def onDeleteClick(self):
item = self.ListView.currentItem()
@@ -111,7 +122,10 @@
row = self.ListView.row(item)
self.ListView.takeItem(row)
self.parent.config.set_list(
- self.ConfigSection, self.ListData.getFileList())
+ self.ConfigSection, self.getFileList())
+ filepath = unicode((item.data(QtCore.Qt.UserRole)).toString())
+ for cidx in self.controllers:
+ self.controllers[cidx].presentation_deleted(filepath)
def generateSlideData(self, service_item):
items = self.ListView.selectedIndexes()
=== modified file 'openlp/plugins/presentations/lib/powerpointcontroller.py'
--- openlp/plugins/presentations/lib/powerpointcontroller.py 2009-10-07 22:49:48 +0000
+++ openlp/plugins/presentations/lib/powerpointcontroller.py 2009-10-08 23:30:22 +0000
@@ -107,12 +107,25 @@
self.store_filename(presentation)
self.process.Presentations.Open(presentation, False, False, True)
self.presentation = self.process.Presentations(self.process.Presentations.Count)
+ self.create_thumbnails()
+ self.start_presentation()
+
+ def create_thumbnails(self):
+ """
+ Create the thumbnail images for the current presentation.
+ Note an alternative and quicker method would be do
+ self.presentation.Slides[n].Copy()
+ thumbnail = QApplication.clipboard.image()
+ But for now we want a physical file since it makes
+ life easier elsewhere
+ """
+ if self.check_thumbnails():
+ return
self.presentation.Export(os.path.join(self.thumbnailpath, '')
, 'png', 600, 480)
- # self.presentation.Slides[n].Copy()
- # thumbnail = QClipboard.image()
- self.start_presentation()
+
+
def close_presentation(self):
"""
Close presentation and clean up objects
@@ -207,4 +220,4 @@
The slide an image is required for, starting at 1
"""
return os.path.join(self.thumbnailpath,
- self.thumbnailprefix + slide_no + u'.png')
+ self.thumbnailprefix + unicode(slide_no) + u'.png')
=== modified file 'openlp/plugins/presentations/lib/pptviewcontroller.py'
--- openlp/plugins/presentations/lib/pptviewcontroller.py 2009-10-07 22:49:48 +0000
+++ openlp/plugins/presentations/lib/pptviewcontroller.py 2009-10-08 23:30:22 +0000
@@ -198,5 +198,5 @@
The slide an image is required for, starting at 1
"""
return os.path.join(self.thumbnailpath,
- self.thumbnailprefix + slide_no + u'.bmp')
+ self.thumbnailprefix + unicode(slide_no) + u'.bmp')
=== modified file 'openlp/plugins/presentations/lib/presentationcontroller.py'
--- openlp/plugins/presentations/lib/presentationcontroller.py 2009-10-07 22:49:48 +0000
+++ openlp/plugins/presentations/lib/presentationcontroller.py 2009-10-08 23:30:22 +0000
@@ -20,6 +20,7 @@
import logging
import os
+import shutil
from PyQt4 import QtCore
@@ -35,7 +36,7 @@
Make sure it inhetits PresentationController
Then fill in the blanks. If possible try and make sure it loads
on all platforms, using for example os.name checks, although
- __init__ and check_available should always work.
+ __init__, check_available and presentation_deleted should always work.
See impresscontroller, powerpointcontroller or pptviewcontroller
for examples.
@@ -61,6 +62,9 @@
``check_available()``
Returns True if presentation application is installed/can run on this machine
+
+ ``presentation_deleted()``
+ Deletes presentation specific files, e.g. thumbnails
``load_presentation(presentation)``
Load a presentation file
@@ -136,11 +140,8 @@
self.thumbnailroot = os.path.join(plugin.config.get_data_path(),
name, u'thumbnails')
self.thumbnailprefix = u'slide'
- try:
+ if not os.path.isdir(self.thumbnailroot):
os.makedirs(self.thumbnailroot)
- except:
- pass
-
def check_available(self):
"""
@@ -148,6 +149,14 @@
"""
return False
+ def presentation_deleted(self, presentation):
+ """
+ Cleans up/deletes any controller specific files created for
+ a file, e.g. thumbnails
+ """
+ self.store_filename(presentation)
+ shutil.rmtree(self.thumbnailpath)
+
def start_process(self):
"""
Loads a running version of the presentation application in the background.
@@ -179,10 +188,20 @@
self.filepath = presentation
self.filename = os.path.split(presentation)[1]
self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename)
- try:
+ if not os.path.isdir(self.thumbnailpath):
os.mkdir(self.thumbnailpath)
- except:
- pass
+
+ def check_thumbnails(self):
+ """
+ Returns true if the thumbnail images look to exist and are more
+ recent than the powerpoint
+ """
+ lastimage = self.get_slide_preview_file(self.get_slide_count())
+ if not os.path.isfile(lastimage):
+ return False
+ imgdate = os.stat(lastimage).st_mtime
+ pptdate = os.stat(self.filepath).st_mtime
+ return imgdate >= pptdate
def close_presentation(self):
"""
Follow ups