diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index e521536b9..16db36b20 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -21,12 +21,15 @@ def strip_rtf(blob): if control: # for delimiters, set control to False if c == '{': - depth += 1 + if len(control_word) > 0: + depth += 1 control = False elif c == '}': - depth -= 1 + if len(control_word) > 0: + depth -= 1 control = False elif c == '\\': + new_control = (len(control_word) > 0) control = False elif c.isspace(): control = False @@ -34,31 +37,32 @@ def strip_rtf(blob): control_word.append(c) if len(control_word) == 3 and control_word[0] == '\'': control = False - if not control: - control_word_str = ''.join(control_word) - if control_word_str == 'par': - clear_text.append(u'\n') - # Really should take RTF character set into account - # but for now assume ANSI (Windows-1252) and call it good - if control_word_str[0] == '\'': - s = chr(int(control_word_str[1:3], 16)) - clear_text.append(s.decode(u'windows-1252')) - del control_word[:] - - if c == '\\': + if len(control_word) == 0: + if c == '{' or c == '}' or c == '\\': + clear_text.append(c) + else: + control_str = ''.join(control_word) + if control_str == 'par' or control_str == 'line': + clear_text.append(u'\n') + elif control_str == 'tab': + clear_text.append(u'\n') + elif control_str[0] == '\'': + # Really should take RTF character set into account but + # for now assume ANSI (Windows-1252) and call it good + s = chr(int(control_str[1:3], 16)) + clear_text.append(s.decode(u'windows-1252')) + del control_word[:] + if c == '\\' and new_control: control = True - elif c == '{': depth += 1 elif c == '}': depth -= 1 elif depth > 2: continue - elif c == '\n' or c == '\r': continue - elif c == '\\': control = True else: @@ -92,20 +96,17 @@ class EasyWorshipSongImport(SongImport): return False db_file = open(self.import_source, 'rb') self.memo_file = open(import_source_mb, 'rb') - # Don't accept files that are clearly not paradox files - record_size, header_size, block_size, next_block, num_fields \ - = struct.unpack(' 4: db_file.close() self.memo_file.close() return False - # There does not appear to be a _reliable_ way of getting the number # of songs/records, so let's use file blocks for measuring progress. total_blocks = (db_size - header_size) / (block_size * 1024) self.import_wizard.importProgressBar.setMaximum(total_blocks) - # Read the field description information db_file.seek(120) field_info = db_file.read(num_fields * 2) @@ -119,7 +120,6 @@ class EasyWorshipSongImport(SongImport): field_descs.append(FieldDescEntry(field_name, field_type, field_size)) self.set_record_struct(field_descs) - # Pick out the field description indexes we will need success = True try: @@ -132,18 +132,19 @@ class EasyWorshipSongImport(SongImport): except IndexError: # This is the wrong table success = False - - while next_block != 0 and success: - db_file.seek(header_size + ((next_block - 1) * 1024 * block_size)) - next_block, rec_count = struct.unpack(''] for field_desc in field_descs: - if field_desc.type == 1: # string + if field_desc.type == 1: + # string fsl.append('%ds' % field_desc.size) - elif field_desc.type == 3: # 16-bit int + elif field_desc.type == 3: + # 16-bit int fsl.append('H') - elif field_desc.type == 4: # 32-bit int + elif field_desc.type == 4: + # 32-bit int fsl.append('I') - elif field_desc.type == 9: # Logical + elif field_desc.type == 9: + # Logical fsl.append('B') - elif field_desc.type == 0x0c: # Memo + elif field_desc.type == 0x0c: + # Memo fsl.append('%ds' % field_desc.size) - elif field_desc.type == 0x0d: # Blob + elif field_desc.type == 0x0d: + # Blob fsl.append('%ds' % field_desc.size) - elif field_desc.type == 0x15: # Timestamp + elif field_desc.type == 0x15: + # Timestamp fsl.append('Q') else: fsl.append('%ds' % field_desc.size) @@ -211,23 +214,27 @@ class EasyWorshipSongImport(SongImport): def get_field(self, field_desc_index): field = self.fields[field_desc_index] field_desc = self.field_descs[field_desc_index] - # Check for 'blank' entries if isinstance(field, str): if len(field.rstrip('\0')) == 0: return u'' elif field == 0: return 0 - - if field_desc.type == 1: # string + # Format the field depending on the field type + if field_desc.type == 1: + # string return field.rstrip('\0').decode(u'windows-1252') - elif field_desc.type == 3: # 16-bit int + elif field_desc.type == 3: + # 16-bit int return field ^ 0x8000 - elif field_desc.type == 4: # 32-bit int + elif field_desc.type == 4: + # 32-bit int return field ^ 0x80000000 - elif field_desc.type == 9: # Logical + elif field_desc.type == 9: + # Logical return (field ^ 0x80 == 1) elif field_desc.type == 0x0c or field_desc.type == 0x0d: + # Memo or Blob sub_block, block_start, blob_size = \ struct.unpack_from('