Songs of Fellowship and Generic Document imports work once again

Also repair auto-insert-chorus-into-verse-order for SoF

bzr-revno: 1370
This commit is contained in:
Jonathan Corwin 2011-03-11 15:11:55 +00:00 committed by Jon Tibble
commit 0d64f4e758
3 changed files with 63 additions and 62 deletions

View File

@ -96,7 +96,7 @@ class OooImport(SongImport):
""" """
if os.name == u'nt': if os.name == u'nt':
self.start_ooo_process() self.start_ooo_process()
self.desktop = self.manager.createInstance( self.desktop = self.ooo_manager.createInstance(
u'com.sun.star.frame.Desktop') u'com.sun.star.frame.Desktop')
else: else:
context = uno.getComponentContext() context = uno.getComponentContext()
@ -118,9 +118,9 @@ class OooImport(SongImport):
def start_ooo_process(self): def start_ooo_process(self):
try: try:
if os.name == u'nt': if os.name == u'nt':
self.manager = Dispatch(u'com.sun.star.ServiceManager') self.ooo_manager = Dispatch(u'com.sun.star.ServiceManager')
self.manager._FlagAsMethod(u'Bridge_GetStruct') self.ooo_manager._FlagAsMethod(u'Bridge_GetStruct')
self.manager._FlagAsMethod(u'Bridge_GetValueObject') self.ooo_manager._FlagAsMethod(u'Bridge_GetValueObject')
else: else:
cmd = get_uno_command() cmd = get_uno_command()
process = QtCore.QProcess() process = QtCore.QProcess()
@ -134,9 +134,11 @@ class OooImport(SongImport):
""" """
Open the passed file in OpenOffice.org Impress Open the passed file in OpenOffice.org Impress
""" """
self.filepath = filepath
if os.name == u'nt': if os.name == u'nt':
url = u'file:///' + filepath.replace(u'\\', u'/') url = filepath.replace(u'\\', u'/')
url = url.replace(u':', u'|').replace(u' ', u'%20') url = url.replace(u':', u'|').replace(u' ', u'%20')
url = u'file:///' + url
else: else:
url = uno.systemPathToFileUrl(filepath) url = uno.systemPathToFileUrl(filepath)
properties = [] properties = []
@ -190,10 +192,7 @@ class OooImport(SongImport):
if slidetext.strip() == u'': if slidetext.strip() == u'':
slidetext = u'\f' slidetext = u'\f'
text += slidetext text += slidetext
song = SongImport(self.manager) self.process_songs_text(text)
songs = SongImport.process_songs_text(self.manager, text)
for song in songs:
song.finish()
return return
def process_doc(self): def process_doc(self):
@ -215,6 +214,16 @@ class OooImport(SongImport):
if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH): if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH):
paratext += u'\f' paratext += u'\f'
text += paratext + u'\n' text += paratext + u'\n'
songs = SongImport.process_songs_text(self.manager, text) self.process_songs_text(text)
for song in songs:
song.finish() def process_songs_text(self, text):
songtexts = self.tidy_text(text).split(u'\f')
self.set_defaults()
for songtext in songtexts:
if songtext.strip():
self.process_song_text(songtext.strip())
if self.check_complete():
self.finish()
self.set_defaults()
if self.check_complete():
self.finish()

View File

@ -72,6 +72,7 @@ class SofImport(OooImport):
to SongImport for writing song to disk to SongImport for writing song to disk
""" """
OooImport.__init__(self, manager, **kwargs) OooImport.__init__(self, manager, **kwargs)
self.song = False
def process_ooo_document(self): def process_ooo_document(self):
""" """
@ -94,8 +95,8 @@ class SofImport(OooImport):
if paragraph.supportsService("com.sun.star.text.Paragraph"): if paragraph.supportsService("com.sun.star.text.Paragraph"):
self.process_paragraph(paragraph) self.process_paragraph(paragraph)
if self.song: if self.song:
self.song.finish() self.finish()
self.song = None self.song = False
def process_paragraph(self, paragraph): def process_paragraph(self, paragraph):
""" """
@ -143,7 +144,7 @@ class SofImport(OooImport):
self.blanklines += 1 self.blanklines += 1
if self.blanklines > 1: if self.blanklines > 1:
return return
if self.song.title != u'': if self.title != u'':
self.finish_verse() self.finish_verse()
return return
self.blanklines = 0 self.blanklines = 0
@ -161,17 +162,17 @@ class SofImport(OooImport):
self.skip_to_close_bracket = True self.skip_to_close_bracket = True
return return
if text.startswith(u'Copyright'): if text.startswith(u'Copyright'):
self.song.add_copyright(text) self.add_copyright(text)
return return
if text == u'(Repeat)': if text == u'(Repeat)':
self.finish_verse() self.finish_verse()
self.song.repeat_verse() self.repeat_verse()
return return
if self.song.title == u'': if self.title == u'':
if self.song.copyright == u'': if self.copyright == u'':
self.add_author(text) self.add_sof_author(text)
else: else:
self.song.add_copyright(text) self.add_copyright(text)
return return
self.add_verse_line(text) self.add_verse_line(text)
@ -183,15 +184,15 @@ class SofImport(OooImport):
into line into line
""" """
text = textportion.getString() text = textportion.getString()
text = SongImport.tidy_text(text) text = self.tidy_text(text)
if text.strip() == u'': if text.strip() == u'':
return text return text
if textportion.CharWeight == BOLD: if textportion.CharWeight == BOLD:
boldtext = text.strip() boldtext = text.strip()
if boldtext.isdigit() and self.song.song_number == '': if boldtext.isdigit() and self.song_number == '':
self.add_songnumber(boldtext) self.add_songnumber(boldtext)
return u'' return u''
if self.song.title == u'': if self.title == u'':
text = self.uncap_text(text) text = self.uncap_text(text)
self.add_title(text) self.add_title(text)
return text return text
@ -207,10 +208,11 @@ class SofImport(OooImport):
""" """
if self.song: if self.song:
self.finish_verse() self.finish_verse()
if not self.song.check_complete(): if not self.check_complete():
return return
self.song.finish() self.finish()
self.song = SongImport(self.manager) self.song = True
self.set_defaults()
self.skip_to_close_bracket = False self.skip_to_close_bracket = False
self.is_chorus = False self.is_chorus = False
self.italics = False self.italics = False
@ -221,17 +223,17 @@ class SofImport(OooImport):
Add a song number, store as alternate title. Also use the song Add a song number, store as alternate title. Also use the song
number to work out which songbook we're in number to work out which songbook we're in
""" """
self.song.song_number = song_no self.song_number = song_no
self.song.alternate_title = song_no + u'.' self.alternate_title = song_no + u'.'
self.song.song_book_pub = u'Kingsway Publications' self.song_book_pub = u'Kingsway Publications'
if int(song_no) <= 640: if int(song_no) <= 640:
self.song.song_book = u'Songs of Fellowship 1' self.song_book = u'Songs of Fellowship 1'
elif int(song_no) <= 1150: elif int(song_no) <= 1150:
self.song.song_book = u'Songs of Fellowship 2' self.song_book = u'Songs of Fellowship 2'
elif int(song_no) <= 1690: elif int(song_no) <= 1690:
self.song.song_book = u'Songs of Fellowship 3' self.song_book = u'Songs of Fellowship 3'
else: else:
self.song.song_book = u'Songs of Fellowship 4' self.song_book = u'Songs of Fellowship 4'
def add_title(self, text): def add_title(self, text):
""" """
@ -243,10 +245,10 @@ class SofImport(OooImport):
title = title[1:] title = title[1:]
if title.endswith(u','): if title.endswith(u','):
title = title[:-1] title = title[:-1]
self.song.title = title self.title = title
self.import_wizard.incrementProgressBar(u'Processing song ' + title, 0) self.import_wizard.incrementProgressBar(u'Processing song ' + title, 0)
def add_author(self, text): def add_sof_author(self, text):
""" """
Add the author. OpenLP stores them individually so split by 'and', '&' Add the author. OpenLP stores them individually so split by 'and', '&'
and comma. and comma.
@ -254,7 +256,7 @@ class SofImport(OooImport):
"Mr Smith" and "Mrs Smith". "Mr Smith" and "Mrs Smith".
""" """
text = text.replace(u' and ', u' & ') text = text.replace(u' and ', u' & ')
self.song.parse_author(text) self.parse_author(text)
def add_verse_line(self, text): def add_verse_line(self, text):
""" """
@ -262,7 +264,7 @@ class SofImport(OooImport):
we're beyond the second line of first verse, then this indicates we're beyond the second line of first verse, then this indicates
a change of verse. Italics are a chorus a change of verse. Italics are a chorus
""" """
if self.italics != self.is_chorus and ((len(self.song.verses) > 0) or if self.italics != self.is_chorus and ((len(self.verses) > 0) or
(self.currentverse.count(u'\n') > 1)): (self.currentverse.count(u'\n') > 1)):
self.finish_verse() self.finish_verse()
if self.italics: if self.italics:
@ -282,14 +284,14 @@ class SofImport(OooImport):
splitat = None splitat = None
else: else:
versetag = u'V' versetag = u'V'
splitat = self.verse_splits(self.song.song_number) splitat = self.verse_splits(self.song_number)
if splitat: if splitat:
ln = 0 ln = 0
verse = u'' verse = u''
for line in self.currentverse.split(u'\n'): for line in self.currentverse.split(u'\n'):
ln += 1 ln += 1
if line == u'' or ln > splitat: if line == u'' or ln > splitat:
self.song.add_verse(verse, versetag) self.add_sof_verse(verse, versetag)
ln = 0 ln = 0
if line: if line:
verse = line + u'\n' verse = line + u'\n'
@ -298,12 +300,18 @@ class SofImport(OooImport):
else: else:
verse += line + u'\n' verse += line + u'\n'
if verse: if verse:
self.song.add_verse(verse, versetag) self.add_sof_verse(verse, versetag)
else: else:
self.song.add_verse(self.currentverse, versetag) self.add_sof_verse(self.currentverse, versetag)
self.currentverse = u'' self.currentverse = u''
self.is_chorus = False self.is_chorus = False
def add_sof_verse(self, lyrics, tag):
self.add_verse(lyrics, tag)
if not self.is_chorus and u'C1' in self.verse_order_list_generated:
self.verse_order_list_generated.append(u'C1')
self.verse_order_list_generated_useful = True
def uncap_text(self, text): def uncap_text(self, text):
""" """
Words in the title are in all capitals, so we lowercase them. Words in the title are in all capitals, so we lowercase them.

View File

@ -103,23 +103,7 @@ class SongImport(QtCore.QObject):
def register(self, import_wizard): def register(self, import_wizard):
self.import_wizard = import_wizard self.import_wizard = import_wizard
@staticmethod def tidy_text(self, text):
def process_songs_text(manager, text):
songs = []
songtexts = SongImport.tidy_text(text).split(u'\f')
song = SongImport(manager)
for songtext in songtexts:
if songtext.strip():
song.process_song_text(songtext.strip())
if song.check_complete():
songs.append(song)
song = SongImport(manager)
if song.check_complete():
songs.append(song)
return songs
@staticmethod
def tidy_text(text):
""" """
Get rid of some dodgy unicode and formatting characters we're not Get rid of some dodgy unicode and formatting characters we're not
interested in. Some can be converted to ascii. interested in. Some can be converted to ascii.
@ -146,12 +130,12 @@ class SongImport(QtCore.QObject):
def process_verse_text(self, text): def process_verse_text(self, text):
lines = text.split(u'\n') lines = text.split(u'\n')
if text.lower().find(self.copyright_string) >= 0 \ if text.lower().find(self.copyright_string) >= 0 \
or text.find(SongStrings.CopyrightSymbol) >= 0: or text.find(unicode(SongStrings.CopyrightSymbol)) >= 0:
copyright_found = False copyright_found = False
for line in lines: for line in lines:
if (copyright_found or if (copyright_found or
line.lower().find(self.copyright_string) >= 0 or line.lower().find(self.copyright_string) >= 0 or
line.find(SongStrings.CopyrightSymbol) >= 0): line.find(unicode(SongStrings.CopyrightSymbol)) >= 0):
copyright_found = True copyright_found = True
self.add_copyright(line) self.add_copyright(line)
else: else:
@ -240,7 +224,7 @@ class SongImport(QtCore.QObject):
self.verse_counts[verse_def[0]] = int(verse_def[1:]) self.verse_counts[verse_def[0]] = int(verse_def[1:])
self.verses.append([verse_def, verse_text.rstrip(), lang]) self.verses.append([verse_def, verse_text.rstrip(), lang])
self.verse_order_list_generated.append(verse_def) self.verse_order_list_generated.append(verse_def)
def repeat_verse(self): def repeat_verse(self):
""" """
Repeat the previous verse in the verse order Repeat the previous verse in the verse order