From 8b79abdfe6981fbfbd97c55f80c7878b357a3bfc Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sun, 22 Aug 2010 23:36:11 +0100 Subject: [PATCH] sof wizard --- openlp/plugins/songs/lib/oooimport.py | 26 +++++++++++++++++++++----- openlp/plugins/songs/lib/sofimport.py | 24 ++++++++++++++++++------ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index 76b4b6c0d..7bc602f99 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -28,6 +28,7 @@ import os from PyQt4 import QtCore +from openlp.core.lib import Receiver from songimport import SongImport if os.name == u'nt': @@ -43,23 +44,30 @@ else: except ImportError: pass -class OooImport(object): +class OooImport(SongImport): """ Import songs from Impress/Powerpoint docs using Impress """ - def __init__(self, songmanager): + def __init__(self, master_manager, **kwargs): """ Initialise the class. Requires a songmanager class which is passed to SongImport for writing song to disk """ self.song = None - self.manager = songmanager + self.master_manager = master_manager self.document = None self.process_started = False + self.filenames = kwargs[u'filenames'] + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'openlp_stop_song_import'), self.stop_import) - def import_docs(self, filenames): + def do_import(self): + self.abort = False self.start_ooo() - for filename in filenames: + for filename in self.filenames: + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return filename = unicode(filename) if os.path.isfile(filename): self.open_ooo_file(filename) @@ -73,6 +81,9 @@ class OooImport(object): self.close_ooo_file() self.close_ooo() + def stop_import(self): + self.abort = True + def start_ooo(self): """ Start OpenOffice.org process @@ -135,6 +146,8 @@ class OooImport(object): "com.sun.star.presentation.PresentationDocument") and not \ self.document.supportsService("com.sun.star.text.TextDocument"): self.close_ooo_file() + else: + self.wizard.incrementProgressBar(u'Processing file ' + filepath) except: pass return @@ -161,6 +174,9 @@ class OooImport(object): slides = doc.getDrawPages() text = u'' for slide_no in range(slides.getCount()): + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return slide = slides.getByIndex(slide_no) slidetext = u'' for idx in range(slide.getCount()): diff --git a/openlp/plugins/songs/lib/sofimport.py b/openlp/plugins/songs/lib/sofimport.py index 54cfd07ac..b2374d672 100644 --- a/openlp/plugins/songs/lib/sofimport.py +++ b/openlp/plugins/songs/lib/sofimport.py @@ -68,18 +68,26 @@ class SofImport(OooImport): It attempts to detect italiced verses, and treats these as choruses in the verse ordering. Again not perfect, but a start. """ - def __init__(self, songmanager): + def __init__(self, master_manager, **kwargs): """ Initialise the class. Requires a songmanager class which is passed to SongImport for writing song to disk """ - OooImport.__init__(self, songmanager) + OooImport.__init__(self,master_manager, **kwargs) - def import_sof(self, filename): + def do_import(self): + self.abort = False self.start_ooo() - self.open_ooo_file(filename) - self.process_sof_file() - self.close_ooo_file() + for filename in self.filenames: + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return + filename = unicode(filename) + if os.path.isfile(filename): + self.open_ooo_file(filename) + if self.document: + self.process_sof_file() + self.close_ooo_file() self.close_ooo() def process_sof_file(self): @@ -90,6 +98,9 @@ class SofImport(OooImport): self.new_song() paragraphs = self.document.getText().createEnumeration() while paragraphs.hasMoreElements(): + if self.abort: + self.wizard.incrementProgressBar(u'Import cancelled') + return paragraph = paragraphs.nextElement() if paragraph.supportsService("com.sun.star.text.Paragraph"): self.process_paragraph(paragraph) @@ -244,6 +255,7 @@ class SofImport(OooImport): if title.endswith(u','): title = title[:-1] self.song.title = title + self.wizard.incrementProgressBar(u'Processing song ' + title) def add_author(self, text): """