From 6a8f54b5f8f15f7c7fe830b5c9284655bd99da33 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sun, 11 Dec 2011 21:59:10 +0000 Subject: [PATCH] Start disabled presentations only when necessary. Try and shutdown Impress at the end correctly --- openlp/core/lib/settingstab.py | 6 ++++ openlp/core/ui/settingsdialog.py | 2 +- openlp/core/ui/settingsform.py | 7 +++++ .../presentations/lib/impresscontroller.py | 8 ++++++ .../lib/presentationcontroller.py | 17 +++++++---- .../presentations/lib/presentationtab.py | 28 +++++++++++++------ 6 files changed, 53 insertions(+), 15 deletions(-) diff --git a/openlp/core/lib/settingstab.py b/openlp/core/lib/settingstab.py index 46263efca..f36f9f561 100644 --- a/openlp/core/lib/settingstab.py +++ b/openlp/core/lib/settingstab.py @@ -125,3 +125,9 @@ class SettingsTab(QtGui.QWidget): """ pass + + def tabVisible(self): + """ + Tab has just been made visible to the user + """ + pass diff --git a/openlp/core/ui/settingsdialog.py b/openlp/core/ui/settingsdialog.py index 296337f0f..643ab0a6e 100644 --- a/openlp/core/ui/settingsdialog.py +++ b/openlp/core/ui/settingsdialog.py @@ -55,7 +55,7 @@ class Ui_SettingsDialog(object): QtCore.QMetaObject.connectSlotsByName(settingsDialog) QtCore.QObject.connect(self.settingListWidget, QtCore.SIGNAL(u'currentRowChanged(int)'), - self.stackedLayout.setCurrentIndex) + self.tabChanged) def retranslateUi(self, settingsDialog): settingsDialog.setWindowTitle(translate('OpenLP.SettingsForm', diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 37da93b5b..b25a3a856 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -116,3 +116,10 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): for plugin in self.plugins: if plugin.settings_tab: plugin.settings_tab.postSetUp() + + def tabChanged(self, tabIndex): + """ + A different settings tab is selected + """ + self.stackedLayout.setCurrentIndex(tabIndex) + self.stackedLayout.currentWidget().tabVisible() diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 36f684ad4..8355da5a8 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -184,7 +184,15 @@ class ImpressController(PresentationController): if not desktop: return docs = desktop.getComponents() + cnt = 0 if docs.hasElements(): + list = docs.createEnumeration() + while list.hasMoreElements(): + doc = list.nextElement() + if doc.getImplementationName() != \ + u'com.sun.star.comp.framework.BackingComp': + cnt = cnt + 1 + if cnt > 0: log.debug(u'OpenOffice not terminated as docs are still open') else: try: diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index a9d384c81..7ff04179f 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -378,7 +378,7 @@ class PresentationController(object): self.name = name self.document_class = document_class self.settings_section = self.plugin.settingsSection - self.available = self.check_available() + self.available = None self.temp_folder = os.path.join( AppLocation.get_section_data_path(self.settings_section), name) self.thumbnail_folder = os.path.join( @@ -392,14 +392,19 @@ class PresentationController(object): """ Return whether the controller is currently enabled """ - if self.available: - return QtCore.QSettings().value( - self.settings_section + u'/' + self.name, - QtCore.QVariant(QtCore.Qt.Checked)).toInt()[0] == \ - QtCore.Qt.Checked + if QtCore.QSettings().value( + self.settings_section + u'/' + self.name, + QtCore.QVariant(QtCore.Qt.Checked)).toInt()[0] == \ + QtCore.Qt.Checked: + return self.is_available() else: return False + def is_available(self): + if self.available is None: + self.available = self.check_available() + return self.available + def check_available(self): """ Presentation app is able to run on this machine diff --git a/openlp/plugins/presentations/lib/presentationtab.py b/openlp/plugins/presentations/lib/presentationtab.py index b0c3de7a8..c11f36c20 100644 --- a/openlp/plugins/presentations/lib/presentationtab.py +++ b/openlp/plugins/presentations/lib/presentationtab.py @@ -55,7 +55,6 @@ class PresentationTab(SettingsTab): for key in self.controllers: controller = self.controllers[key] checkbox = QtGui.QCheckBox(self.ControllersGroupBox) - checkbox.setEnabled(controller.available) checkbox.setObjectName(controller.name + u'CheckBox') self.PresenterCheckboxes[controller.name] = checkbox self.ControllersLayout.addWidget(checkbox) @@ -81,17 +80,20 @@ class PresentationTab(SettingsTab): for key in self.controllers: controller = self.controllers[key] checkbox = self.PresenterCheckboxes[controller.name] - if controller.available: - checkbox.setText(controller.name) - else: - checkbox.setText( - unicode(translate('PresentationPlugin.PresentationTab', - '%s (unavailable)')) % controller.name) + self.setControllerText(checkbox, controller) self.AdvancedGroupBox.setTitle(UiStrings().Advanced) self.OverrideAppCheckBox.setText( translate('PresentationPlugin.PresentationTab', 'Allow presentation application to be overriden')) + def setControllerText(self, checkbox, controller): + if checkbox.isEnabled(): + checkbox.setText(controller.name) + else: + checkbox.setText( + unicode(translate('PresentationPlugin.PresentationTab', + '%s (unavailable)')) % controller.name) + def load(self): """ Load the settings. @@ -113,7 +115,7 @@ class PresentationTab(SettingsTab): changed = False for key in self.controllers: controller = self.controllers[key] - if controller.available: + if controller.is_available(): checkbox = self.PresenterCheckboxes[controller.name] setting_key = self.settingsSection + u'/' + controller.name if QtCore.QSettings().value(setting_key) != \ @@ -133,3 +135,13 @@ class PresentationTab(SettingsTab): changed = True if changed: Receiver.send_message(u'mediaitem_presentation_rebuild') + + def tabVisible(self): + """ + Tab has just been made visible to the user + """ + for key in self.controllers: + controller = self.controllers[key] + checkbox = self.PresenterCheckboxes[controller.name] + checkbox.setEnabled(controller.is_available()) + self.setControllerText(checkbox, controller)