forked from openlp/openlp
Refactors in UNO and EasiSlides
bzr-revno: 1238
This commit is contained in:
commit
f486a4835b
@ -47,6 +47,8 @@ from openlp.core.lib import Receiver, translate
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
IMAGES_FILTER = None
|
IMAGES_FILTER = None
|
||||||
|
UNO_CONNECTION_TYPE = u'pipe'
|
||||||
|
#UNO_CONNECTION_TYPE = u'socket'
|
||||||
|
|
||||||
class VersionThread(QtCore.QThread):
|
class VersionThread(QtCore.QThread):
|
||||||
"""
|
"""
|
||||||
@ -375,9 +377,37 @@ def string_is_unicode(test_string):
|
|||||||
log.exception("Error encoding string to unicode")
|
log.exception("Error encoding string to unicode")
|
||||||
return return_string
|
return return_string
|
||||||
|
|
||||||
|
def get_uno_command():
|
||||||
|
"""
|
||||||
|
Returns the UNO command to launch an openoffice.org instance.
|
||||||
|
"""
|
||||||
|
if UNO_CONNECTION_TYPE == u'pipe':
|
||||||
|
return u'openoffice.org -nologo -norestore -minimized -invisible ' \
|
||||||
|
+ u'-nofirststartwizard -accept=pipe,name=openlp_pipe;urp;'
|
||||||
|
else:
|
||||||
|
return u'openoffice.org -nologo -norestore -minimized ' \
|
||||||
|
+ u'-invisible -nofirststartwizard ' \
|
||||||
|
+ u'-accept=socket,host=localhost,port=2002;urp;'
|
||||||
|
|
||||||
|
def get_uno_instance(resolver):
|
||||||
|
"""
|
||||||
|
Returns a running openoffice.org instance.
|
||||||
|
|
||||||
|
``resolver``
|
||||||
|
The UNO resolver to use to find a running instance.
|
||||||
|
"""
|
||||||
|
log.debug(u'get UNO Desktop Openoffice - resolve')
|
||||||
|
if UNO_CONNECTION_TYPE == u'pipe':
|
||||||
|
return resolver.resolve(u'uno:pipe,name=openlp_pipe;' \
|
||||||
|
+ u'urp;StarOffice.ComponentContext')
|
||||||
|
else:
|
||||||
|
return resolver.resolve(u'uno:socket,host=localhost,port=2002;' \
|
||||||
|
+ u'urp;StarOffice.ComponentContext')
|
||||||
|
|
||||||
from languagemanager import LanguageManager
|
from languagemanager import LanguageManager
|
||||||
from actions import ActionList
|
from actions import ActionList
|
||||||
|
|
||||||
__all__ = [u'AppLocation', u'check_latest_version', u'add_actions',
|
__all__ = [u'AppLocation', u'check_latest_version', u'add_actions',
|
||||||
u'get_filesystem_encoding', u'LanguageManager', u'ActionList',
|
u'get_filesystem_encoding', u'LanguageManager', u'ActionList',
|
||||||
u'get_web_page', u'file_is_unicode', u'string_is_unicode']
|
u'get_web_page', u'file_is_unicode', u'string_is_unicode',
|
||||||
|
u'get_uno_command', u'get_uno_instance', u'delete_file']
|
||||||
|
@ -51,7 +51,7 @@ else:
|
|||||||
|
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
from openlp.core.utils import delete_file
|
from openlp.core.utils import delete_file, get_uno_command, get_uno_instance
|
||||||
from presentationcontroller import PresentationController, PresentationDocument
|
from presentationcontroller import PresentationController, PresentationDocument
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -75,7 +75,6 @@ class ImpressController(PresentationController):
|
|||||||
self.process = None
|
self.process = None
|
||||||
self.desktop = None
|
self.desktop = None
|
||||||
self.manager = None
|
self.manager = None
|
||||||
self.uno_connection_type = u'pipe' #u'socket'
|
|
||||||
|
|
||||||
def check_available(self):
|
def check_available(self):
|
||||||
"""
|
"""
|
||||||
@ -100,14 +99,7 @@ class ImpressController(PresentationController):
|
|||||||
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
|
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
|
||||||
else:
|
else:
|
||||||
# -headless
|
# -headless
|
||||||
if self.uno_connection_type == u'pipe':
|
cmd = get_uno_command()
|
||||||
cmd = u'openoffice.org -nologo -norestore -minimized ' \
|
|
||||||
+ u'-invisible -nofirststartwizard ' \
|
|
||||||
+ u'-accept=pipe,name=openlp_pipe;urp;'
|
|
||||||
else:
|
|
||||||
cmd = u'openoffice.org -nologo -norestore -minimized ' \
|
|
||||||
+ u'-invisible -nofirststartwizard ' \
|
|
||||||
+ u'-accept=socket,host=localhost,port=2002;urp;'
|
|
||||||
self.process = QtCore.QProcess()
|
self.process = QtCore.QProcess()
|
||||||
self.process.startDetached(cmd)
|
self.process.startDetached(cmd)
|
||||||
self.process.waitForStarted()
|
self.process.waitForStarted()
|
||||||
@ -118,7 +110,7 @@ class ImpressController(PresentationController):
|
|||||||
which will be used to manage impress
|
which will be used to manage impress
|
||||||
"""
|
"""
|
||||||
log.debug(u'get UNO Desktop Openoffice')
|
log.debug(u'get UNO Desktop Openoffice')
|
||||||
ctx = None
|
uno_instance = None
|
||||||
loop = 0
|
loop = 0
|
||||||
log.debug(u'get UNO Desktop Openoffice - getComponentContext')
|
log.debug(u'get UNO Desktop Openoffice - getComponentContext')
|
||||||
context = uno.getComponentContext()
|
context = uno.getComponentContext()
|
||||||
@ -126,27 +118,19 @@ class ImpressController(PresentationController):
|
|||||||
u'UnoUrlResolver')
|
u'UnoUrlResolver')
|
||||||
resolver = context.ServiceManager.createInstanceWithContext(
|
resolver = context.ServiceManager.createInstanceWithContext(
|
||||||
u'com.sun.star.bridge.UnoUrlResolver', context)
|
u'com.sun.star.bridge.UnoUrlResolver', context)
|
||||||
while ctx is None and loop < 3:
|
while uno_instance is None and loop < 3:
|
||||||
try:
|
try:
|
||||||
log.debug(u'get UNO Desktop Openoffice - resolve')
|
uno_instance = get_uno_instance(resolver)
|
||||||
if self.uno_connection_type == u'pipe':
|
|
||||||
ctx = resolver.resolve(u'uno:' \
|
|
||||||
+ u'pipe,name=openlp_pipe;' \
|
|
||||||
+ u'urp;StarOffice.ComponentContext')
|
|
||||||
else:
|
|
||||||
ctx = resolver.resolve(u'uno:' \
|
|
||||||
+ u'socket,host=localhost,port=2002;' \
|
|
||||||
+ u'urp;StarOffice.ComponentContext')
|
|
||||||
except:
|
except:
|
||||||
log.exception(u'Unable to find running instance ')
|
log.exception(u'Unable to find running instance ')
|
||||||
self.start_process()
|
self.start_process()
|
||||||
loop += 1
|
loop += 1
|
||||||
try:
|
try:
|
||||||
self.manager = ctx.ServiceManager
|
self.manager = uno_instance.ServiceManager
|
||||||
log.debug(u'get UNO Desktop Openoffice - createInstanceWithContext'
|
log.debug(u'get UNO Desktop Openoffice - createInstanceWithContext'
|
||||||
u' - Desktop')
|
u' - Desktop')
|
||||||
desktop = self.manager.createInstanceWithContext(
|
desktop = self.manager.createInstanceWithContext(
|
||||||
"com.sun.star.frame.Desktop", ctx )
|
"com.sun.star.frame.Desktop", uno_instance)
|
||||||
return desktop
|
return desktop
|
||||||
except:
|
except:
|
||||||
log.exception(u'Failed to get UNO desktop')
|
log.exception(u'Failed to get UNO desktop')
|
||||||
|
@ -535,4 +535,3 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
else:
|
else:
|
||||||
self.booksDeleteButton.setEnabled(True)
|
self.booksDeleteButton.setEnabled(True)
|
||||||
self.booksEditButton.setEnabled(True)
|
self.booksEditButton.setEnabled(True)
|
||||||
|
|
||||||
|
@ -81,44 +81,43 @@ class EasiSlidesImport(SongImport):
|
|||||||
|
|
||||||
def _parse_song(self, song):
|
def _parse_song(self, song):
|
||||||
self._success = True
|
self._success = True
|
||||||
self._add_title(song)
|
self._add_title(self.title, song.Title1, True)
|
||||||
self._add_alttitle(song)
|
self._add_alttitle(self.alternate_title, song.Title2)
|
||||||
self._add_number(song)
|
self._add_number(self.song_number, song.SongNumber)
|
||||||
|
if self.song_number == u'0':
|
||||||
|
self.song_number = u''
|
||||||
self._add_authors(song)
|
self._add_authors(song)
|
||||||
self._add_copyright(song)
|
self._add_copyright(song)
|
||||||
self._add_book(song)
|
self._add_book(self.song_book_name, song.BookReference)
|
||||||
self._parse_and_add_lyrics(song)
|
self._parse_and_add_lyrics(song)
|
||||||
return self._success
|
return self._success
|
||||||
|
|
||||||
def _add_title(self, song):
|
def _add_unicode_attribute(self, self_attribute, import_attribute,
|
||||||
try:
|
mandatory=False):
|
||||||
self.title = unicode(song.Title1).strip()
|
"""
|
||||||
except UnicodeDecodeError:
|
Add imported values to the song model converting them to unicode at the
|
||||||
log.exception(u'Unicode decode error while decoding Title1')
|
same time. If the unicode decode fails or a mandatory attribute is not
|
||||||
self._success = False
|
present _success is set to False so the importer can react
|
||||||
except AttributeError:
|
appropriately.
|
||||||
log.exception(u'no Title1')
|
|
||||||
self._success = False
|
|
||||||
|
|
||||||
def _add_alttitle(self, song):
|
``self_attribute``
|
||||||
try:
|
The attribute in the song model to populate.
|
||||||
self.alternate_title = unicode(song.Title2).strip()
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
log.exception(u'Unicode decode error while decoding Title2')
|
|
||||||
self._success = False
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _add_number(self, song):
|
``import_attribute``
|
||||||
|
The imported value to convert to unicode and save to the song.
|
||||||
|
|
||||||
|
``mandatory``
|
||||||
|
Signals that this attribute must exist in a valid song.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
number = unicode(song.SongNumber)
|
self_attribute = unicode(import_attribute).strip()
|
||||||
if number != u'0':
|
|
||||||
self.song_number = number
|
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
log.exception(u'Unicode decode error while decoding SongNumber')
|
log.exception(u'UnicodeDecodeError decoding %s' % import_attribute)
|
||||||
self._success = False
|
self._success = False
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
log.exception(u'No attribute %s' % import_attribute)
|
||||||
|
if mandatory:
|
||||||
|
self._success = False
|
||||||
|
|
||||||
def _add_authors(self, song):
|
def _add_authors(self, song):
|
||||||
try:
|
try:
|
||||||
@ -158,15 +157,6 @@ class EasiSlidesImport(SongImport):
|
|||||||
pass
|
pass
|
||||||
self.add_copyright(u' '.join(copyright))
|
self.add_copyright(u' '.join(copyright))
|
||||||
|
|
||||||
def _add_book(self, song):
|
|
||||||
try:
|
|
||||||
self.song_book_name = unicode(song.BookReference).strip()
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
log.exception(u'Unicode decode error while decoding BookReference')
|
|
||||||
self._success = False
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _parse_and_add_lyrics(self, song):
|
def _parse_and_add_lyrics(self, song):
|
||||||
try:
|
try:
|
||||||
lyrics = unicode(song.Contents).strip()
|
lyrics = unicode(song.Contents).strip()
|
||||||
|
@ -29,6 +29,7 @@ import os
|
|||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
from openlp.core.lib import Receiver
|
from openlp.core.lib import Receiver
|
||||||
|
from openlp.core.utils import get_uno_command, get_uno_instance
|
||||||
from songimport import SongImport
|
from songimport import SongImport
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -61,7 +62,6 @@ class OooImport(SongImport):
|
|||||||
self.document = None
|
self.document = None
|
||||||
self.process_started = False
|
self.process_started = False
|
||||||
self.filenames = kwargs[u'filenames']
|
self.filenames = kwargs[u'filenames']
|
||||||
self.uno_connection_type = u'pipe' #u'socket'
|
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
|
QtCore.SIGNAL(u'openlp_stop_wizard'), self.stop_import)
|
||||||
|
|
||||||
@ -105,25 +105,18 @@ class OooImport(SongImport):
|
|||||||
context = uno.getComponentContext()
|
context = uno.getComponentContext()
|
||||||
resolver = context.ServiceManager.createInstanceWithContext(
|
resolver = context.ServiceManager.createInstanceWithContext(
|
||||||
u'com.sun.star.bridge.UnoUrlResolver', context)
|
u'com.sun.star.bridge.UnoUrlResolver', context)
|
||||||
ctx = None
|
uno_instance = None
|
||||||
loop = 0
|
loop = 0
|
||||||
while ctx is None and loop < 5:
|
while uno_instance is None and loop < 5:
|
||||||
try:
|
try:
|
||||||
if self.uno_connection_type == u'pipe':
|
uno_instance = get_uno_instance(resolver)
|
||||||
ctx = resolver.resolve(u'uno:' \
|
|
||||||
+ u'pipe,name=openlp_pipe;' \
|
|
||||||
+ u'urp;StarOffice.ComponentContext')
|
|
||||||
else:
|
|
||||||
ctx = resolver.resolve(u'uno:' \
|
|
||||||
+ u'socket,host=localhost,port=2002;' \
|
|
||||||
+ u'urp;StarOffice.ComponentContext')
|
|
||||||
except:
|
except:
|
||||||
log.exception("Failed to resolve uno connection")
|
log.exception("Failed to resolve uno connection")
|
||||||
self.start_ooo_process()
|
self.start_ooo_process()
|
||||||
loop += 1
|
loop += 1
|
||||||
manager = ctx.ServiceManager
|
manager = uno_instance.ServiceManager
|
||||||
self.desktop = manager.createInstanceWithContext(
|
self.desktop = manager.createInstanceWithContext(
|
||||||
"com.sun.star.frame.Desktop", ctx)
|
"com.sun.star.frame.Desktop", uno_instance)
|
||||||
|
|
||||||
def start_ooo_process(self):
|
def start_ooo_process(self):
|
||||||
try:
|
try:
|
||||||
@ -132,14 +125,7 @@ class OooImport(SongImport):
|
|||||||
self.manager._FlagAsMethod(u'Bridge_GetStruct')
|
self.manager._FlagAsMethod(u'Bridge_GetStruct')
|
||||||
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
|
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
|
||||||
else:
|
else:
|
||||||
if self.uno_connection_type == u'pipe':
|
cmd = get_uno_command()
|
||||||
cmd = u'openoffice.org -nologo -norestore -minimized ' \
|
|
||||||
+ u'-invisible -nofirststartwizard ' \
|
|
||||||
+ u'-accept=pipe,name=openlp_pipe;urp;'
|
|
||||||
else:
|
|
||||||
cmd = u'openoffice.org -nologo -norestore -minimized ' \
|
|
||||||
+ u'-invisible -nofirststartwizard ' \
|
|
||||||
+ u'-accept=socket,host=localhost,port=2002;urp;'
|
|
||||||
process = QtCore.QProcess()
|
process = QtCore.QProcess()
|
||||||
process.startDetached(cmd)
|
process.startDetached(cmd)
|
||||||
process.waitForStarted()
|
process.waitForStarted()
|
||||||
|
Loading…
Reference in New Issue
Block a user