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: 482 lines
11 files modified
openlp/plugins/presentations/lib/__init__.py (+0/-3)
openlp/plugins/presentations/lib/impresscontroller.py (+20/-11)
openlp/plugins/presentations/lib/mediaitem.py (+2/-1)
openlp/plugins/presentations/lib/powerpointcontroller.py (+15/-10)
openlp/plugins/presentations/lib/pptviewcontroller.py (+18/-5)
openlp/plugins/presentations/lib/pptviewlib/README.TXT (+3/-0)
openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp (+8/-0)
openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h (+1/-0)
openlp/plugins/presentations/lib/presentationcontroller.py (+17/-2)
openlp/plugins/presentations/lib/presentationtab.py (+27/-37)
openlp/plugins/presentations/presentationplugin.py (+29/-24)
To merge this branch: bzr merge lp:~j-corwin/openlp/present
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Review via email: mp+12683@code.launchpad.net

This proposal supersedes a proposal from 2009-09-30.

To post a comment you must log in.
Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

Make presentation controllers self contained.

pptviewlib.dll excluded this time. I'll attempt this in a separate push attempt since it's required as the powerpoint viewer won't work now without the latest version.

Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
Revision history for this message
Tim Bentley (trb143) wrote :

Approved

review: Approve
lp:~j-corwin/openlp/present updated
581. By Jonathan Corwin

Presentations made it at last

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/presentations/lib/__init__.py'
2--- openlp/plugins/presentations/lib/__init__.py 2009-09-26 20:51:05 +0000
3+++ openlp/plugins/presentations/lib/__init__.py 2009-09-30 19:45:21 +0000
4@@ -23,9 +23,6 @@
5 ###############################################################################
6
7 from presentationcontroller import PresentationController
8-from impresscontroller import ImpressController
9-from powerpointcontroller import PowerpointController
10-from pptviewcontroller import PptviewController
11 from messagelistener import MessageListener
12 from mediaitem import PresentationMediaItem
13 from presentationtab import PresentationTab
14
15=== modified file 'openlp/plugins/presentations/lib/impresscontroller.py'
16--- openlp/plugins/presentations/lib/impresscontroller.py 2009-09-27 12:44:11 +0000
17+++ openlp/plugins/presentations/lib/impresscontroller.py 2009-09-30 19:45:21 +0000
18@@ -38,7 +38,6 @@
19
20 from presentationcontroller import PresentationController
21
22-
23 class ImpressController(PresentationController):
24 """
25 Class to control interactions with Impress presentations.
26@@ -47,6 +46,7 @@
27 """
28 global log
29 log = logging.getLogger(u'ImpressController')
30+ log.info(u'loaded')
31
32 def __init__(self, plugin):
33 """
34@@ -59,16 +59,17 @@
35 self.presentation = None
36 self.controller = None
37
38- def is_available(self):
39- """
40- PPT Viewer is able to run on this machine
41- """
42- log.debug(u'is_available')
43- try:
44- self.start_process()
45+ def check_available(self):
46+ """
47+ Impress is able to run on this machine
48+ """
49+ log.debug(u'check_available')
50+ if os.name == u'nt':
51+ return self.get_com_servicemanager() is not None
52+ else:
53+ # If not windows, and we've got this far then probably
54+ # installed else the import uno would likely have failed
55 return True
56- except:
57- return False
58
59 def start_process(self):
60 """
61@@ -148,13 +149,21 @@
62 def get_com_desktop(self):
63 log.debug(u'getCOMDesktop')
64 try:
65- smgr = Dispatch("com.sun.star.ServiceManager")
66+ smgr = self.get_com_servicemanager()
67 desktop = smgr.createInstance( "com.sun.star.frame.Desktop")
68 return desktop
69 except:
70 log.exception(u'Failed to get COM desktop')
71 return None
72
73+ def get_com_servicemanager(self):
74+ log.debug(u'get_com_servicemanager')
75+ try:
76+ return Dispatch("com.sun.star.ServiceManager")
77+ except:
78+ log.exception(u'Failed to get COM service manager')
79+ return None
80+
81 def close_presentation(self):
82 """
83 Close presentation and clean up objects
84
85=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
86--- openlp/plugins/presentations/lib/mediaitem.py 2009-09-28 20:45:04 +0000
87+++ openlp/plugins/presentations/lib/mediaitem.py 2009-09-30 19:45:21 +0000
88@@ -94,7 +94,8 @@
89 self.loadList(list)
90 for item in self.controllers:
91 #load the drop down selection
92- self.DisplayTypeComboBox.addItem(item)
93+ if self.controllers[item].enabled:
94+ self.DisplayTypeComboBox.addItem(item)
95
96 def loadList(self, list):
97 for file in list:
98
99=== modified file 'openlp/plugins/presentations/lib/powerpointcontroller.py'
100--- openlp/plugins/presentations/lib/powerpointcontroller.py 2009-09-27 21:49:00 +0000
101+++ openlp/plugins/presentations/lib/powerpointcontroller.py 2009-09-30 19:45:21 +0000
102@@ -27,6 +27,7 @@
103
104 if os.name == u'nt':
105 from win32com.client import Dispatch
106+ import _winreg
107
108 from presentationcontroller import PresentationController
109
110@@ -41,7 +42,8 @@
111 """
112 global log
113 log = logging.getLogger(u'PowerpointController')
114-
115+ log.info(u'loaded')
116+
117 def __init__(self, plugin):
118 """
119 Initialise the class
120@@ -51,18 +53,18 @@
121 self.process = None
122 self.presentation = None
123
124- def is_available(self):
125+ def check_available(self):
126 """
127 PowerPoint is able to run on this machine
128 """
129- log.debug(u'is_available')
130- if os.name != u'nt':
131- return False
132- try:
133- self.start_process()
134- return True
135- except:
136- return False
137+ log.debug(u'check_available')
138+ if os.name == u'nt':
139+ try:
140+ _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, u'PowerPoint.Application').Close()
141+ return True
142+ except:
143+ pass
144+ return False
145
146 if os.name == u'nt':
147 def start_process(self):
148@@ -83,6 +85,9 @@
149 return False
150
151 def kill(self):
152+ """
153+ Called at system exit to clean up any running presentations
154+ """
155 self.process.Quit()
156 self.process = None
157
158
159=== modified file 'openlp/plugins/presentations/lib/pptviewcontroller.py'
160--- openlp/plugins/presentations/lib/pptviewcontroller.py 2009-09-26 20:51:05 +0000
161+++ openlp/plugins/presentations/lib/pptviewcontroller.py 2009-09-30 19:45:21 +0000
162@@ -39,37 +39,50 @@
163 """
164 global log
165 log = logging.getLogger(u'PptviewController')
166+ log.info(u'loaded')
167
168 def __init__(self, plugin):
169 """
170 Initialise the class
171 """
172 log.debug(u'Initialising')
173+ self.process = None
174 PresentationController.__init__(self, plugin, u'Powerpoint Viewer')
175- self.process = None
176 self.pptid = None
177 self.thumbnailpath = os.path.join(plugin.config.get_data_path(),
178 u'pptview', u'thumbnails')
179 self.thumbprefix = u'slide'
180
181- def is_available(self):
182+ def check_available(self):
183 """
184 PPT Viewer is able to run on this machine
185 """
186- log.debug(u'is_available')
187+ log.debug(u'check_available')
188 if os.name != u'nt':
189 return False
190 try:
191- self.start_process()
192- return True
193+ return self.check_installed()
194 except:
195 return False
196
197 if os.name == u'nt':
198+ def check_installed(self):
199+ """
200+ Check the viewer is installed
201+ """
202+ log.debug(u'Check installed')
203+ try:
204+ self.start_process()
205+ return self.process.CheckInstalled()
206+ except:
207+ return False
208+
209 def start_process(self):
210 """
211 Loads the PPTVIEWLIB library
212 """
213+ if self.process is not None:
214+ return
215 log.debug(u'start PPTView')
216 self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll')
217
218
219=== modified file 'openlp/plugins/presentations/lib/pptviewlib/README.TXT'
220--- openlp/plugins/presentations/lib/pptviewlib/README.TXT 2009-09-13 15:14:45 +0000
221+++ openlp/plugins/presentations/lib/pptviewlib/README.TXT 2009-09-30 19:45:21 +0000
222@@ -25,6 +25,9 @@
223
224 USAGE
225 -----
226+BOOL CheckInstalled(void);
227+ Returns TRUE if PowerPointViewer is installed. FALSE if not.
228+
229 int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewpath);
230
231 Opens the PowerPoint file, counts the number of slides, sizes and positions accordingly
232
233=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp'
234--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp 2009-09-23 20:40:19 +0000
235+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp 2009-09-30 19:45:21 +0000
236@@ -82,6 +82,14 @@
237 DEBUG("enabled\n");
238 }
239
240+DllExport BOOL CheckInstalled()
241+{
242+ DEBUG("CheckInstalled\n");
243+ char cmdline[MAX_PATH * 2];
244+
245+ return GetPPTViewerPath(cmdline, sizeof(cmdline));
246+}
247+
248 // Open the PointPoint, count the slides and take a snapshot of each slide
249 // for use in previews
250 // previewpath is a prefix for the location to put preview images of each slide.
251
252=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h'
253--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h 2009-09-23 20:40:19 +0000
254+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h 2009-09-30 19:45:21 +0000
255@@ -4,6 +4,7 @@
256 enum PPTVIEWSTATE { PPT_CLOSED, PPT_STARTED, PPT_OPENED, PPT_LOADED, PPT_CLOSING};
257
258 DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewpath);
259+DllExport BOOL CheckInstalled();
260 DllExport void ClosePPT(int id);
261 DllExport int GetCurrentSlide(int id);
262 DllExport int GetSlideCount(int id);
263
264=== modified file 'openlp/plugins/presentations/lib/presentationcontroller.py'
265--- openlp/plugins/presentations/lib/presentationcontroller.py 2009-09-28 19:34:55 +0000
266+++ openlp/plugins/presentations/lib/presentationcontroller.py 2009-09-30 19:45:21 +0000
267@@ -20,6 +20,8 @@
268
269 import logging
270
271+from PyQt4 import QtCore
272+
273 class PresentationController(object):
274 """
275 Base class for presentation controllers to inherit from
276@@ -32,6 +34,13 @@
277 ``name``
278 The name that appears in the options and the media manager
279
280+ ``enabled``
281+ The controller is enabled
282+
283+ ``available``
284+ The controller is available on this machine. Set by init via
285+ call to check_available
286+
287 ``plugin``
288 The presentationplugin object
289
290@@ -40,7 +49,7 @@
291 ``kill()``
292 Called at system exit to clean up any running presentations
293
294- ``is_available()``
295+ ``check_available()``
296 Returns True if presentation application is installed/can run on this machine
297
298 ``load_presentation(presentation)``
299@@ -108,8 +117,14 @@
300 """
301 self.plugin = plugin
302 self.name = name
303+ self.available = self.check_available()
304+ if self.available:
305+ self.enabled = int(plugin.config.get_config(
306+ name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked
307+ else:
308+ self.enabled = False
309
310- def is_available(self):
311+ def check_available(self):
312 """
313 Presentation app is able to run on this machine
314 """
315
316=== modified file 'openlp/plugins/presentations/lib/presentationtab.py'
317--- openlp/plugins/presentations/lib/presentationtab.py 2009-09-26 20:51:05 +0000
318+++ openlp/plugins/presentations/lib/presentationtab.py 2009-09-30 19:45:21 +0000
319@@ -60,24 +60,17 @@
320 self.VerseTypeLayout.setSpacing(8)
321 self.VerseTypeLayout.setMargin(0)
322 self.VerseTypeLayout.setObjectName(u'VerseTypeLayout')
323- self.PowerpointCheckBox = QtGui.QCheckBox(self.VerseDisplayGroupBox)
324- self.PowerpointCheckBox.setTristate(False)
325- if os.name != u'nt':
326- self.PowerpointCheckBox.setEnabled(False)
327- self.PowerpointCheckBox.setObjectName(u'PowerpointCheckBox')
328- self.VerseDisplayLayout.addWidget(self.PowerpointCheckBox, 0, 0, 1, 1)
329- self.PowerpointViewerCheckBox = QtGui.QCheckBox(
330- self.VerseDisplayGroupBox)
331- self.PowerpointViewerCheckBox.setTristate(False)
332- if os.name != u'nt':
333- self.PowerpointViewerCheckBox.setEnabled(False)
334- self.PowerpointViewerCheckBox.setObjectName(u'PowerpointViewerCheckBox')
335- self.VerseDisplayLayout.addWidget(
336- self.PowerpointViewerCheckBox, 1, 0, 1, 1)
337- self.ImpressCheckBox = QtGui.QCheckBox(self.VerseDisplayGroupBox)
338- self.ImpressCheckBox.setTristate(False)
339- self.ImpressCheckBox.setObjectName(u'ImpressCheckBox')
340- self.VerseDisplayLayout.addWidget(self.ImpressCheckBox, 2, 0, 1, 1)
341+ self.PresenterCheckboxes = {}
342+ index = 0
343+ for key in self.controllers:
344+ controller = self.controllers[key]
345+ checkbox = QtGui.QCheckBox(self.VerseDisplayGroupBox)
346+ checkbox.setTristate(False)
347+ checkbox.setEnabled(controller.available)
348+ checkbox.setObjectName(controller.name + u'CheckBox')
349+ self.PresenterCheckboxes[controller.name] = checkbox
350+ index = index + 1
351+ self.VerseDisplayLayout.addWidget(checkbox, index, 0, 1, 1)
352 self.PresentationThemeWidget = QtGui.QWidget(self.VerseDisplayGroupBox)
353 self.PresentationThemeWidget.setObjectName(u'PresentationThemeWidget')
354 self.PresentationThemeLayout = QtGui.QHBoxLayout(
355@@ -103,26 +96,23 @@
356 self.PresentationLayout.addWidget(self.PresentationRightWidget)
357
358 def retranslateUi(self):
359- self.PowerpointCheckBox.setText(
360- translate(u'PresentationTab', 'Powerpoint available:'))
361- self.PowerpointViewerCheckBox.setText(
362- translate(u'PresentationTab', 'PowerpointViewer available:'))
363- self.ImpressCheckBox.setText(
364- translate(u'PresentationTab', 'Impress available:'))
365+ for key in self.controllers:
366+ controller = self.controllers[key]
367+ checkbox = self.PresenterCheckboxes[controller.name]
368+ checkbox.setText(translate(u'PresentationTab',
369+ controller.name + u' available:'))
370
371 def load(self):
372- self.PowerpointCheckBox.setChecked(
373- int(self.config.get_config(u'Powerpoint', 0)))
374- self.PowerpointViewerCheckBox.setChecked(
375- int(self.config.get_config(u'Powerpoint Viewer', 0)))
376- self.ImpressCheckBox.setChecked(
377- int(self.config.get_config(u'Impress', 0)))
378+ for key in self.controllers:
379+ controller = self.controllers[key]
380+ if controller.available:
381+ checkbox = self.PresenterCheckboxes[controller.name]
382+ checkbox.setChecked(
383+ int(self.config.get_config(controller.name, 0)))
384
385 def save(self):
386- self.config.set_config(
387- u'Powerpoint', unicode(self.PowerpointCheckBox.checkState()))
388- self.config.set_config(
389- u'Powerpoint Viewer',
390- unicode(self.PowerpointViewerCheckBox.checkState()))
391- self.config.set_config(
392- u'Impress', unicode(self.ImpressCheckBox.checkState()))
393+ for key in self.controllers:
394+ controller = self.controllers[key]
395+ checkbox = self.PresenterCheckboxes[controller.name]
396+ self.config.set_config(
397+ controller.name, unicode(checkbox.checkState()))
398
399=== modified file 'openlp/plugins/presentations/presentationplugin.py'
400--- openlp/plugins/presentations/presentationplugin.py 2009-09-29 17:05:34 +0000
401+++ openlp/plugins/presentations/presentationplugin.py 2009-09-30 19:45:21 +0000
402@@ -22,11 +22,12 @@
403 # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
404 ###############################################################################
405
406+import os
407 import logging
408
409-from PyQt4 import QtCore
410+from PyQt4 import QtGui
411
412-from openlp.core.lib import Plugin, buildIcon
413+from openlp.core.lib import Plugin
414 from openlp.plugins.presentations.lib import *
415
416 class PresentationPlugin(Plugin):
417@@ -41,7 +42,9 @@
418 Plugin.__init__(self, u'Presentations', u'1.9.0', plugin_helpers)
419 self.weight = -8
420 # Create the plugin icon
421- self.icon = buildIcon(u':/media/media_presentation.png')
422+ self.icon = QtGui.QIcon()
423+ self.icon.addPixmap(QtGui.QPixmap(u':/media/media_presentation.png'),
424+ QtGui.QIcon.Normal, QtGui.QIcon.Off)
425
426 def get_settings_tab(self):
427 """
428@@ -67,25 +70,25 @@
429 If Not do not install the plugin.
430 """
431 log.debug(u'check_pre_conditions')
432- #Lets see if Powerpoint is required (Default is Not wanted)
433- controller = PowerpointController(self)
434- if int(self.config.get_config(
435- controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
436- if controller.is_available():
437- self.registerControllers(controller)
438- #Lets see if Impress is required (Default is Not wanted)
439- controller = ImpressController(self)
440- if int(self.config.get_config(
441- controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
442- if controller.is_available():
443- self.registerControllers(controller)
444- #Lets see if Powerpoint Viewer is required (Default is Not wanted)
445- controller = PptviewController(self)
446- if int(self.config.get_config(
447- controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
448- if controller.is_available():
449- self.registerControllers(controller)
450- #If we have no available controllers disable plugin
451+ dir = os.path.join(os.path.dirname(__file__), u'lib')
452+ for filename in os.listdir(dir):
453+ if filename.endswith(u'controller.py') and \
454+ not filename == 'presentationcontroller.py':
455+ path = os.path.join(dir, filename)
456+ if os.path.isfile(path):
457+ modulename = u'openlp.plugins.presentations.lib.' + \
458+ os.path.splitext(filename)[0]
459+ log.debug(u'Importing controller %s', modulename)
460+ try:
461+ __import__(modulename, globals(), locals(), [])
462+ except ImportError, e:
463+ log.error(u'Failed to import %s on path %s for reason %s', modulename, path, e.args[0])
464+ controller_classes = PresentationController.__subclasses__()
465+ for controller_class in controller_classes:
466+ controller = controller_class(self)
467+ self.registerControllers(controller)
468+ if controller.enabled:
469+ controller.start_process()
470 if len(self.controllers) > 0:
471 return True
472 else:
473@@ -94,5 +97,7 @@
474 def finalise(self):
475 log.debug(u'Finalise')
476 #Ask each controller to tidy up
477- for controller in self.controllers:
478- self.controllers[controller].kill()
479+ for key in self.controllers:
480+ controller = self.controllers[key]
481+ if controller.enabled:
482+ controller.kill()