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':
self.start_ooo_process()
self.desktop = self.manager.createInstance(
self.desktop = self.ooo_manager.createInstance(
u'com.sun.star.frame.Desktop')
else:
context = uno.getComponentContext()
@ -118,9 +118,9 @@ class OooImport(SongImport):
def start_ooo_process(self):
try:
if os.name == u'nt':
self.manager = Dispatch(u'com.sun.star.ServiceManager')
self.manager._FlagAsMethod(u'Bridge_GetStruct')
self.manager._FlagAsMethod(u'Bridge_GetValueObject')
self.ooo_manager = Dispatch(u'com.sun.star.ServiceManager')
self.ooo_manager._FlagAsMethod(u'Bridge_GetStruct')
self.ooo_manager._FlagAsMethod(u'Bridge_GetValueObject')
else:
cmd = get_uno_command()
process = QtCore.QProcess()
@ -134,9 +134,11 @@ class OooImport(SongImport):
"""
Open the passed file in OpenOffice.org Impress
"""
self.filepath = filepath
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 = u'file:///' + url
else:
url = uno.systemPathToFileUrl(filepath)
properties = []
@ -190,10 +192,7 @@ class OooImport(SongImport):
if slidetext.strip() == u'':
slidetext = u'\f'
text += slidetext
song = SongImport(self.manager)
songs = SongImport.process_songs_text(self.manager, text)
for song in songs:
song.finish()
self.process_songs_text(text)
return
def process_doc(self):
@ -215,6 +214,16 @@ class OooImport(SongImport):
if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH):
paratext += u'\f'
text += paratext + u'\n'
songs = SongImport.process_songs_text(self.manager, text)
for song in songs:
song.finish()
self.process_songs_text(text)
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
"""
OooImport.__init__(self, manager, **kwargs)
self.song = False
def process_ooo_document(self):
"""
@ -94,8 +95,8 @@ class SofImport(OooImport):
if paragraph.supportsService("com.sun.star.text.Paragraph"):
self.process_paragraph(paragraph)
if self.song:
self.song.finish()
self.song = None
self.finish()
self.song = False
def process_paragraph(self, paragraph):
"""
@ -143,7 +144,7 @@ class SofImport(OooImport):
self.blanklines += 1
if self.blanklines > 1:
return
if self.song.title != u'':
if self.title != u'':
self.finish_verse()
return
self.blanklines = 0
@ -161,17 +162,17 @@ class SofImport(OooImport):
self.skip_to_close_bracket = True
return
if text.startswith(u'Copyright'):
self.song.add_copyright(text)
self.add_copyright(text)
return
if text == u'(Repeat)':
self.finish_verse()
self.song.repeat_verse()
self.repeat_verse()
return
if self.song.title == u'':
if self.song.copyright == u'':
self.add_author(text)
if self.title == u'':
if self.copyright == u'':
self.add_sof_author(text)
else:
self.song.add_copyright(text)
self.add_copyright(text)
return
self.add_verse_line(text)
@ -183,15 +184,15 @@ class SofImport(OooImport):
into line
"""
text = textportion.getString()
text = SongImport.tidy_text(text)
text = self.tidy_text(text)
if text.strip() == u'':
return text
if textportion.CharWeight == BOLD:
boldtext = text.strip()
if boldtext.isdigit() and self.song.song_number == '':
if boldtext.isdigit() and self.song_number == '':
self.add_songnumber(boldtext)
return u''
if self.song.title == u'':
if self.title == u'':
text = self.uncap_text(text)
self.add_title(text)
return text
@ -207,10 +208,11 @@ class SofImport(OooImport):
"""
if self.song:
self.finish_verse()
if not self.song.check_complete():
if not self.check_complete():
return
self.song.finish()
self.song = SongImport(self.manager)
self.finish()
self.song = True
self.set_defaults()
self.skip_to_close_bracket = False
self.is_chorus = False
self.italics = False
@ -221,17 +223,17 @@ class SofImport(OooImport):
Add a song number, store as alternate title. Also use the song
number to work out which songbook we're in
"""
self.song.song_number = song_no
self.song.alternate_title = song_no + u'.'
self.song.song_book_pub = u'Kingsway Publications'
self.song_number = song_no
self.alternate_title = song_no + u'.'
self.song_book_pub = u'Kingsway Publications'
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:
self.song.song_book = u'Songs of Fellowship 2'
self.song_book = u'Songs of Fellowship 2'
elif int(song_no) <= 1690:
self.song.song_book = u'Songs of Fellowship 3'
self.song_book = u'Songs of Fellowship 3'
else:
self.song.song_book = u'Songs of Fellowship 4'
self.song_book = u'Songs of Fellowship 4'
def add_title(self, text):
"""
@ -243,10 +245,10 @@ class SofImport(OooImport):
title = title[1:]
if title.endswith(u','):
title = title[:-1]
self.song.title = title
self.title = title
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', '&'
and comma.
@ -254,7 +256,7 @@ class SofImport(OooImport):
"Mr Smith" and "Mrs Smith".
"""
text = text.replace(u' and ', u' & ')
self.song.parse_author(text)
self.parse_author(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
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.finish_verse()
if self.italics:
@ -282,14 +284,14 @@ class SofImport(OooImport):
splitat = None
else:
versetag = u'V'
splitat = self.verse_splits(self.song.song_number)
splitat = self.verse_splits(self.song_number)
if splitat:
ln = 0
verse = u''
for line in self.currentverse.split(u'\n'):
ln += 1
if line == u'' or ln > splitat:
self.song.add_verse(verse, versetag)
self.add_sof_verse(verse, versetag)
ln = 0
if line:
verse = line + u'\n'
@ -298,12 +300,18 @@ class SofImport(OooImport):
else:
verse += line + u'\n'
if verse:
self.song.add_verse(verse, versetag)
self.add_sof_verse(verse, versetag)
else:
self.song.add_verse(self.currentverse, versetag)
self.add_sof_verse(self.currentverse, versetag)
self.currentverse = u''
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):
"""
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):
self.import_wizard = import_wizard
@staticmethod
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):
def tidy_text(self, text):
"""
Get rid of some dodgy unicode and formatting characters we're not
interested in. Some can be converted to ascii.
@ -146,12 +130,12 @@ class SongImport(QtCore.QObject):
def process_verse_text(self, text):
lines = text.split(u'\n')
if text.lower().find(self.copyright_string) >= 0 \
or text.find(SongStrings.CopyrightSymbol) >= 0:
or text.find(unicode(SongStrings.CopyrightSymbol)) >= 0:
copyright_found = False
for line in lines:
if (copyright_found or
line.lower().find(self.copyright_string) >= 0 or
line.find(SongStrings.CopyrightSymbol) >= 0):
line.find(unicode(SongStrings.CopyrightSymbol)) >= 0):
copyright_found = True
self.add_copyright(line)
else: