Ensure it is asked only once for encoding.

This commit is contained in:
Mattias Põldaru 2012-06-25 23:30:24 +03:00
parent 556f28db33
commit 4aa62141a0
1 changed files with 12 additions and 7 deletions

View File

@ -61,11 +61,11 @@ class SundayPlusImport(SongImport):
Initialise the class. Initialise the class.
""" """
SongImport.__init__(self, manager, **kwargs) SongImport.__init__(self, manager, **kwargs)
self.encoding = u'us-ascii'
self.rtf = StripRtf() self.rtf = StripRtf()
def doImport(self): def doImport(self):
self.importWizard.progressBar.setMaximum(len(self.importSource)) self.importWizard.progressBar.setMaximum(len(self.importSource))
self.encoding = 'us-ascii'
for filename in self.importSource: for filename in self.importSource:
if self.stopImportFlag: if self.stopImportFlag:
return return
@ -81,12 +81,12 @@ class SundayPlusImport(SongImport):
if not self.parse(file.read()): if not self.parse(file.read()):
self.logError(file.name) self.logError(file.name)
return return
if self.title == '': if not self.title:
self.title = self.titleFromFilename(file.name) self.title = self.titleFromFilename(file.name)
if not self.finish(): if not self.finish():
self.logError(file.name) self.logError(file.name)
def parse(self, data, cell = False): def parse(self, data, cell=False):
if len(data) == 0 or data[0:1] != '[' or data[-1] != ']': if len(data) == 0 or data[0:1] != '[' or data[-1] != ']':
self.logError(u'File is malformed') self.logError(u'File is malformed')
return False return False
@ -94,7 +94,7 @@ class SundayPlusImport(SongImport):
verse_type = VerseType.Tags[VerseType.Verse] verse_type = VerseType.Tags[VerseType.Verse]
while i < len(data): while i < len(data):
# Data is held as #name: value pairs inside groups marked as []. # Data is held as #name: value pairs inside groups marked as [].
# Now we are looking for name. # Now we are looking for the name.
if data[i:i+1] == '#': if data[i:i+1] == '#':
name_end = data.find(':', i+1) name_end = data.find(':', i+1)
name = data[i+1:name_end] name = data[i+1:name_end]
@ -179,7 +179,7 @@ class SundayPlusImport(SongImport):
if title.endswith(u'.ptf'): if title.endswith(u'.ptf'):
title = title[:-4] title = title[:-4]
# For some strange reason all example files names ended with 1-7. # For some strange reason all example files names ended with 1-7.
if title.endswith('1-7'): if title.endswith(u'1-7'):
title = title[:-3] title = title[:-3]
return title.replace(u'_', u' ') return title.replace(u'_', u' ')
@ -189,8 +189,13 @@ class SundayPlusImport(SongImport):
return unicode(blob, self.encoding) return unicode(blob, self.encoding)
except: except:
# This is asked again every time the previously chosen # This is asked again every time the previously chosen
# encoding does not work. # encoding does not work. Integrated with StripRtf encoding.
if len(self.rtf.user_encoding) and \
self.encoding != self.rtf.user_encoding[-1]:
self.encoding = self.rtf.user_encoding[-1]
else:
self.encoding = retrieve_windows_encoding() self.encoding = retrieve_windows_encoding()
self.rtf.user_encoding.append(self.encoding)
def unescape(self, text): def unescape(self, text):
text = text.replace('^^', '"') text = text.replace('^^', '"')