Tidy song_import code and fix bug 634771

bzr-revno: 1024
This commit is contained in:
Jonathan Corwin 2010-09-10 19:29:54 +01:00
commit 0cddc0910d
2 changed files with 12 additions and 35 deletions

View File

@ -632,6 +632,8 @@ class ServiceManager(QtGui.QWidget):
def onLoadService(self, lastService=False): def onLoadService(self, lastService=False):
if lastService: if lastService:
if not self.parent.recentFiles:
return
filename = self.parent.recentFiles[0] filename = self.parent.recentFiles[0]
else: else:
filename = QtGui.QFileDialog.getOpenFileName( filename = QtGui.QFileDialog.getOpenFileName(

View File

@ -71,13 +71,7 @@ class SongImport(QtCore.QObject):
self.song_book_pub = u'' self.song_book_pub = u''
self.verse_order_list = [] self.verse_order_list = []
self.verses = [] self.verses = []
self.versecount = 0 self.versecounts = {}
self.choruscount = 0
self.bridgecount = 0
self.introcount = 0
self.prechoruscount = 0
self.endingcount = 0
self.othercount = 0
self.copyright_string = unicode(translate( self.copyright_string = unicode(translate(
'SongsPlugin.SongImport', 'copyright')) 'SongsPlugin.SongImport', 'copyright'))
self.copyright_symbol = unicode(translate( self.copyright_symbol = unicode(translate(
@ -198,7 +192,7 @@ class SongImport(QtCore.QObject):
return return
self.media_files.append(filename) self.media_files.append(filename)
def add_verse(self, verse, versetag=None): def add_verse(self, verse, versetag=u'V'):
""" """
Add a verse. This is the whole verse, lines split by \n Add a verse. This is the whole verse, lines split by \n
Verse tag can be V1/C1/B etc, or 'V' and 'C' (will count the verses/ Verse tag can be V1/C1/B etc, or 'V' and 'C' (will count the verses/
@ -210,33 +204,14 @@ class SongImport(QtCore.QObject):
if oldverse.strip() == verse.strip(): if oldverse.strip() == verse.strip():
self.verse_order_list.append(oldversetag) self.verse_order_list.append(oldversetag)
return return
if versetag == u'V' or not versetag: if versetag[0] in self.versecounts:
self.versecount += 1 self.versecounts[versetag[0]] += 1
versetag = u'V' + unicode(self.versecount) else:
if versetag.startswith(u'C'): self.versecounts[versetag[0]] = 1
self.choruscount += 1 if len(versetag) == 1:
if versetag == u'C': versetag += unicode(self.versecounts[versetag[0]])
versetag += unicode(self.choruscount) elif int(versetag[1:]) > self.versecounts[versetag[0]]:
if versetag.startswith(u'B'): self.versecounts[versetag[0]] = int(versetag[1:])
self.bridgecount += 1
if versetag == u'B':
versetag += unicode(self.bridgecount)
if versetag.startswith(u'I'):
self.introcount += 1
if versetag == u'I':
versetag += unicode(self.introcount)
if versetag.startswith(u'P'):
self.prechoruscount += 1
if versetag == u'P':
versetag += unicode(self.prechoruscount)
if versetag.startswith(u'E'):
self.endingcount += 1
if versetag == u'E':
versetag += unicode(self.endingcount)
if versetag.startswith(u'O'):
self.othercount += 1
if versetag == u'O':
versetag += unicode(self.othercount)
self.verses.append([versetag, verse.rstrip()]) self.verses.append([versetag, verse.rstrip()])
self.verse_order_list.append(versetag) self.verse_order_list.append(versetag)
if versetag.startswith(u'V') and self.contains_verse(u'C1'): if versetag.startswith(u'V') and self.contains_verse(u'C1'):