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
1=== modified file 'openlp/plugins/presentations/lib/impresscontroller.py'
2--- openlp/plugins/presentations/lib/impresscontroller.py 2009-10-07 23:09:24 +0000
3+++ openlp/plugins/presentations/lib/impresscontroller.py 2009-10-08 23:30:22 +0000
4@@ -109,19 +109,16 @@
5 if os.name == u'nt':
6 desktop = self.get_com_desktop()
7 url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
8- thumbdir = u'file:///' + self.thumbnailpath.replace(
9- u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
10 else:
11 desktop = self.get_uno_desktop()
12 url = uno.systemPathToFileUrl(presentation)
13- thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
14 if desktop is None:
15 return
16 try:
17 properties = []
18 properties = tuple(properties)
19- doc = desktop.loadComponentFromURL(url, u'_blank', 0, properties)
20- self.document = doc
21+ self.document = desktop.loadComponentFromURL(url, u'_blank',
22+ 0, properties)
23 self.presentation = self.document.getPresentation()
24 self.presentation.Display = self.plugin.render_manager.current_display + 1
25 self.presentation.start()
26@@ -130,6 +127,20 @@
27 except:
28 log.exception(u'Failed to load presentation')
29 return
30+ self.create_thumbnails()
31+
32+ def create_thumbnails(self):
33+ """
34+ Create thumbnail images for presentation
35+ """
36+ if self.check_thumbnails():
37+ return
38+
39+ if os.name == u'nt':
40+ thumbdir = u'file:///' + self.thumbnailpath.replace(
41+ u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20')
42+ else:
43+ thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
44 props = []
45 if os.name == u'nt':
46 prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
47@@ -139,6 +150,7 @@
48 prop.Value = u'impress_png_Export'
49 props.append(prop)
50 props = tuple(props)
51+ doc = self.document
52 pages = doc.getDrawPages()
53 for idx in range(pages.getCount()):
54 page = pages.getByIndex(idx)
55@@ -255,4 +267,4 @@
56 The slide an image is required for, starting at 1
57 """
58 return os.path.join(self.thumbnailpath,
59- self.thumbnailprefix + slide_no + u'.png')
60+ self.thumbnailprefix + unicode(slide_no) + u'.png')
61
62=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
63--- openlp/plugins/presentations/lib/mediaitem.py 2009-09-30 19:26:51 +0000
64+++ openlp/plugins/presentations/lib/mediaitem.py 2009-10-08 23:30:22 +0000
65@@ -98,11 +98,22 @@
66 self.DisplayTypeComboBox.addItem(item)
67
68 def loadList(self, list):
69+ currlist = self.getFileList()
70+ titles = []
71+ for file in currlist:
72+ titles.append(os.path.split(file)[1])
73 for file in list:
74+ if currlist.count(file) > 0:
75+ continue
76 (path, filename) = os.path.split(unicode(file))
77- item_name = QtGui.QListWidgetItem(filename)
78- item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
79- self.ListView.addItem(item_name)
80+ if titles.count(filename) > 0:
81+ QtGui.QMessageBox.critical(self, u'File exists',
82+ u'A presentation with that filename already exists.',
83+ QtGui.QMessageBox.Ok)
84+ else:
85+ item_name = QtGui.QListWidgetItem(filename)
86+ item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
87+ self.ListView.addItem(item_name)
88
89 def onDeleteClick(self):
90 item = self.ListView.currentItem()
91@@ -111,7 +122,10 @@
92 row = self.ListView.row(item)
93 self.ListView.takeItem(row)
94 self.parent.config.set_list(
95- self.ConfigSection, self.ListData.getFileList())
96+ self.ConfigSection, self.getFileList())
97+ filepath = unicode((item.data(QtCore.Qt.UserRole)).toString())
98+ for cidx in self.controllers:
99+ self.controllers[cidx].presentation_deleted(filepath)
100
101 def generateSlideData(self, service_item):
102 items = self.ListView.selectedIndexes()
103
104=== modified file 'openlp/plugins/presentations/lib/powerpointcontroller.py'
105--- openlp/plugins/presentations/lib/powerpointcontroller.py 2009-10-07 22:49:48 +0000
106+++ openlp/plugins/presentations/lib/powerpointcontroller.py 2009-10-08 23:30:22 +0000
107@@ -107,12 +107,25 @@
108 self.store_filename(presentation)
109 self.process.Presentations.Open(presentation, False, False, True)
110 self.presentation = self.process.Presentations(self.process.Presentations.Count)
111+ self.create_thumbnails()
112+ self.start_presentation()
113+
114+ def create_thumbnails(self):
115+ """
116+ Create the thumbnail images for the current presentation.
117+ Note an alternative and quicker method would be do
118+ self.presentation.Slides[n].Copy()
119+ thumbnail = QApplication.clipboard.image()
120+ But for now we want a physical file since it makes
121+ life easier elsewhere
122+ """
123+ if self.check_thumbnails():
124+ return
125 self.presentation.Export(os.path.join(self.thumbnailpath, '')
126 , 'png', 600, 480)
127- # self.presentation.Slides[n].Copy()
128- # thumbnail = QClipboard.image()
129- self.start_presentation()
130
131+
132+
133 def close_presentation(self):
134 """
135 Close presentation and clean up objects
136@@ -207,4 +220,4 @@
137 The slide an image is required for, starting at 1
138 """
139 return os.path.join(self.thumbnailpath,
140- self.thumbnailprefix + slide_no + u'.png')
141+ self.thumbnailprefix + unicode(slide_no) + u'.png')
142
143=== modified file 'openlp/plugins/presentations/lib/pptviewcontroller.py'
144--- openlp/plugins/presentations/lib/pptviewcontroller.py 2009-10-07 22:49:48 +0000
145+++ openlp/plugins/presentations/lib/pptviewcontroller.py 2009-10-08 23:30:22 +0000
146@@ -198,5 +198,5 @@
147 The slide an image is required for, starting at 1
148 """
149 return os.path.join(self.thumbnailpath,
150- self.thumbnailprefix + slide_no + u'.bmp')
151+ self.thumbnailprefix + unicode(slide_no) + u'.bmp')
152
153
154=== modified file 'openlp/plugins/presentations/lib/presentationcontroller.py'
155--- openlp/plugins/presentations/lib/presentationcontroller.py 2009-10-07 22:49:48 +0000
156+++ openlp/plugins/presentations/lib/presentationcontroller.py 2009-10-08 23:30:22 +0000
157@@ -20,6 +20,7 @@
158
159 import logging
160 import os
161+import shutil
162
163 from PyQt4 import QtCore
164
165@@ -35,7 +36,7 @@
166 Make sure it inhetits PresentationController
167 Then fill in the blanks. If possible try and make sure it loads
168 on all platforms, using for example os.name checks, although
169- __init__ and check_available should always work.
170+ __init__, check_available and presentation_deleted should always work.
171 See impresscontroller, powerpointcontroller or pptviewcontroller
172 for examples.
173
174@@ -61,6 +62,9 @@
175
176 ``check_available()``
177 Returns True if presentation application is installed/can run on this machine
178+
179+ ``presentation_deleted()``
180+ Deletes presentation specific files, e.g. thumbnails
181
182 ``load_presentation(presentation)``
183 Load a presentation file
184@@ -136,11 +140,8 @@
185 self.thumbnailroot = os.path.join(plugin.config.get_data_path(),
186 name, u'thumbnails')
187 self.thumbnailprefix = u'slide'
188- try:
189+ if not os.path.isdir(self.thumbnailroot):
190 os.makedirs(self.thumbnailroot)
191- except:
192- pass
193-
194
195 def check_available(self):
196 """
197@@ -148,6 +149,14 @@
198 """
199 return False
200
201+ def presentation_deleted(self, presentation):
202+ """
203+ Cleans up/deletes any controller specific files created for
204+ a file, e.g. thumbnails
205+ """
206+ self.store_filename(presentation)
207+ shutil.rmtree(self.thumbnailpath)
208+
209 def start_process(self):
210 """
211 Loads a running version of the presentation application in the background.
212@@ -179,10 +188,20 @@
213 self.filepath = presentation
214 self.filename = os.path.split(presentation)[1]
215 self.thumbnailpath = os.path.join(self.thumbnailroot, self.filename)
216- try:
217+ if not os.path.isdir(self.thumbnailpath):
218 os.mkdir(self.thumbnailpath)
219- except:
220- pass
221+
222+ def check_thumbnails(self):
223+ """
224+ Returns true if the thumbnail images look to exist and are more
225+ recent than the powerpoint
226+ """
227+ lastimage = self.get_slide_preview_file(self.get_slide_count())
228+ if not os.path.isfile(lastimage):
229+ return False
230+ imgdate = os.stat(lastimage).st_mtime
231+ pptdate = os.stat(self.filepath).st_mtime
232+ return imgdate >= pptdate
233
234 def close_presentation(self):
235 """