Merge lp:~j-corwin/openlp/present into lp:openlp

Proposed by Jonathan Corwin
Status: Merged
Merged at revision: not available
Proposed branch: lp:~j-corwin/openlp/present
Merge into: lp:openlp
Diff against target: 235 lines
5 files modified
openlp/plugins/presentations/lib/impresscontroller.py (+18/-6)
openlp/plugins/presentations/lib/mediaitem.py (+18/-4)
openlp/plugins/presentations/lib/powerpointcontroller.py (+17/-4)
openlp/plugins/presentations/lib/pptviewcontroller.py (+1/-1)
openlp/plugins/presentations/lib/presentationcontroller.py (+27/-8)
To merge this branch: bzr merge lp:~j-corwin/openlp/present
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Tim Bentley Approve
Review via email: mp+13099@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jonathan Corwin (j-corwin) wrote :

Controllers cleanup if presentation deleted.
Prevent ppt files with same name.
Only create thumbnails if out of date

Revision history for this message
Tim Bentley (trb143) wrote :

Looks good

review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
lp:~j-corwin/openlp/present updated
591. By Jon Tibble

Presentation cleanups

592. By Jon Tibble

Bible rendering fixes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
109 if os.name == u'nt':109 if os.name == u'nt':
110 desktop = self.get_com_desktop()110 desktop = self.get_com_desktop()
111 url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')111 url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
112 thumbdir = u'file:///' + self.thumbnailpath.replace(
113 u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
114 else:112 else:
115 desktop = self.get_uno_desktop()113 desktop = self.get_uno_desktop()
116 url = uno.systemPathToFileUrl(presentation)114 url = uno.systemPathToFileUrl(presentation)
117 thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
118 if desktop is None:115 if desktop is None:
119 return116 return
120 try:117 try:
121 properties = []118 properties = []
122 properties = tuple(properties) 119 properties = tuple(properties)
123 doc = desktop.loadComponentFromURL(url, u'_blank', 0, properties)120 self.document = desktop.loadComponentFromURL(url, u'_blank',
124 self.document = doc121 0, properties)
125 self.presentation = self.document.getPresentation()122 self.presentation = self.document.getPresentation()
126 self.presentation.Display = self.plugin.render_manager.current_display + 1123 self.presentation.Display = self.plugin.render_manager.current_display + 1
127 self.presentation.start()124 self.presentation.start()
@@ -130,6 +127,20 @@
130 except:127 except:
131 log.exception(u'Failed to load presentation')128 log.exception(u'Failed to load presentation')
132 return129 return
130 self.create_thumbnails()
131
132 def create_thumbnails(self):
133 """
134 Create thumbnail images for presentation
135 """
136 if self.check_thumbnails():
137 return
138
139 if os.name == u'nt':
140 thumbdir = u'file:///' + self.thumbnailpath.replace(
141 u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
142 else:
143 thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
133 props = []144 props = []
134 if os.name == u'nt':145 if os.name == u'nt':
135 prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')146 prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
@@ -139,6 +150,7 @@
139 prop.Value = u'impress_png_Export'150 prop.Value = u'impress_png_Export'
140 props.append(prop)151 props.append(prop)
141 props = tuple(props)152 props = tuple(props)
153 doc = self.document
142 pages = doc.getDrawPages()154 pages = doc.getDrawPages()
143 for idx in range(pages.getCount()):155 for idx in range(pages.getCount()):
144 page = pages.getByIndex(idx)156 page = pages.getByIndex(idx)
@@ -255,4 +267,4 @@
255 The slide an image is required for, starting at 1267 The slide an image is required for, starting at 1
256 """268 """
257 return os.path.join(self.thumbnailpath,269 return os.path.join(self.thumbnailpath,
258 self.thumbnailprefix + slide_no + u'.png')270 self.thumbnailprefix + unicode(slide_no) + u'.png')
259271
=== 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 @@
98 self.DisplayTypeComboBox.addItem(item)98 self.DisplayTypeComboBox.addItem(item)
9999
100 def loadList(self, list):100 def loadList(self, list):
101 currlist = self.getFileList()
102 titles = []
103 for file in currlist:
104 titles.append(os.path.split(file)[1])
101 for file in list:105 for file in list:
106 if currlist.count(file) > 0:
107 continue
102 (path, filename) = os.path.split(unicode(file))108 (path, filename) = os.path.split(unicode(file))
103 item_name = QtGui.QListWidgetItem(filename)109 if titles.count(filename) > 0:
104 item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))110 QtGui.QMessageBox.critical(self, u'File exists',
105 self.ListView.addItem(item_name)111 u'A presentation with that filename already exists.',
112 QtGui.QMessageBox.Ok)
113 else:
114 item_name = QtGui.QListWidgetItem(filename)
115 item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
116 self.ListView.addItem(item_name)
106117
107 def onDeleteClick(self):118 def onDeleteClick(self):
108 item = self.ListView.currentItem()119 item = self.ListView.currentItem()
@@ -111,7 +122,10 @@
111 row = self.ListView.row(item)122 row = self.ListView.row(item)
112 self.ListView.takeItem(row)123 self.ListView.takeItem(row)
113 self.parent.config.set_list(124 self.parent.config.set_list(
114 self.ConfigSection, self.ListData.getFileList())125 self.ConfigSection, self.getFileList())
126 filepath = unicode((item.data(QtCore.Qt.UserRole)).toString())
127 for cidx in self.controllers:
128 self.controllers[cidx].presentation_deleted(filepath)
115129
116 def generateSlideData(self, service_item):130 def generateSlideData(self, service_item):
117 items = self.ListView.selectedIndexes()131 items = self.ListView.selectedIndexes()
118132
=== 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 @@
107 self.store_filename(presentation)107 self.store_filename(presentation)
108 self.process.Presentations.Open(presentation, False, False, True)108 self.process.Presentations.Open(presentation, False, False, True)
109 self.presentation = self.process.Presentations(self.process.Presentations.Count)109 self.presentation = self.process.Presentations(self.process.Presentations.Count)
110 self.create_thumbnails()
111 self.start_presentation()
112
113 def create_thumbnails(self):
114 """
115 Create the thumbnail images for the current presentation.
116 Note an alternative and quicker method would be do
117 self.presentation.Slides[n].Copy()
118 thumbnail = QApplication.clipboard.image()
119 But for now we want a physical file since it makes
120 life easier elsewhere
121 """
122 if self.check_thumbnails():
123 return
110 self.presentation.Export(os.path.join(self.thumbnailpath, '')124 self.presentation.Export(os.path.join(self.thumbnailpath, '')
111 , 'png', 600, 480)125 , 'png', 600, 480)
112 # self.presentation.Slides[n].Copy()
113 # thumbnail = QClipboard.image()
114 self.start_presentation()
115 126
127
128
116 def close_presentation(self):129 def close_presentation(self):
117 """130 """
118 Close presentation and clean up objects131 Close presentation and clean up objects
@@ -207,4 +220,4 @@
207 The slide an image is required for, starting at 1220 The slide an image is required for, starting at 1
208 """221 """
209 return os.path.join(self.thumbnailpath,222 return os.path.join(self.thumbnailpath,
210 self.thumbnailprefix + slide_no + u'.png')223 self.thumbnailprefix + unicode(slide_no) + u'.png')
211224
=== 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 @@
198 The slide an image is required for, starting at 1198 The slide an image is required for, starting at 1
199 """199 """
200 return os.path.join(self.thumbnailpath,200 return os.path.join(self.thumbnailpath,
201 self.thumbnailprefix + slide_no + u'.bmp')201 self.thumbnailprefix + unicode(slide_no) + u'.bmp')
202202
203203
=== 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 @@
2020
21import logging21import logging
22import os22import os
23import shutil
2324
24from PyQt4 import QtCore25from PyQt4 import QtCore
2526
@@ -35,7 +36,7 @@
35 Make sure it inhetits PresentationController36 Make sure it inhetits PresentationController
36 Then fill in the blanks. If possible try and make sure it loads37 Then fill in the blanks. If possible try and make sure it loads
37 on all platforms, using for example os.name checks, although38 on all platforms, using for example os.name checks, although
38 __init__ and check_available should always work.39 __init__, check_available and presentation_deleted should always work.
39 See impresscontroller, powerpointcontroller or pptviewcontroller40 See impresscontroller, powerpointcontroller or pptviewcontroller
40 for examples.41 for examples.
4142
@@ -61,6 +62,9 @@
6162
62 ``check_available()``63 ``check_available()``
63 Returns True if presentation application is installed/can run on this machine64 Returns True if presentation application is installed/can run on this machine
65
66 ``presentation_deleted()``
67 Deletes presentation specific files, e.g. thumbnails
6468
65 ``load_presentation(presentation)``69 ``load_presentation(presentation)``
66 Load a presentation file70 Load a presentation file
@@ -136,11 +140,8 @@
136 self.thumbnailroot = os.path.join(plugin.config.get_data_path(),140 self.thumbnailroot = os.path.join(plugin.config.get_data_path(),
137 name, u'thumbnails')141 name, u'thumbnails')
138 self.thumbnailprefix = u'slide'142 self.thumbnailprefix = u'slide'
139 try:143 if not os.path.isdir(self.thumbnailroot):
140 os.makedirs(self.thumbnailroot)144 os.makedirs(self.thumbnailroot)
141 except:
142 pass
143
144145
145 def check_available(self):146 def check_available(self):
146 """147 """
@@ -148,6 +149,14 @@
148 """149 """
149 return False150 return False
150151
152 def presentation_deleted(self, presentation):
153 """
154 Cleans up/deletes any controller specific files created for
155 a file, e.g. thumbnails
156 """
157 self.store_filename(presentation)
158 shutil.rmtree(self.thumbnailpath)
159
151 def start_process(self):160 def start_process(self):
152 """161 """
153 Loads a running version of the presentation application in the background.162 Loads a running version of the presentation application in the background.
@@ -179,10 +188,20 @@
179 self.filepath = presentation188 self.filepath = presentation
180 self.filename = os.path.split(presentation)[1]189 self.filename = os.path.split(presentation)[1]
181 self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename)190 self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename)
182 try:191 if not os.path.isdir(self.thumbnailpath):
183 os.mkdir(self.thumbnailpath)192 os.mkdir(self.thumbnailpath)
184 except:193
185 pass194 def check_thumbnails(self):
195 """
196 Returns true if the thumbnail images look to exist and are more
197 recent than the powerpoint
198 """
199 lastimage = self.get_slide_preview_file(self.get_slide_count())
200 if not os.path.isfile(lastimage):
201 return False
202 imgdate = os.stat(lastimage).st_mtime
203 pptdate = os.stat(self.filepath).st_mtime
204 return imgdate >= pptdate
186205
187 def close_presentation(self):206 def close_presentation(self):
188 """207 """