use a list in the OLP1 import to get sorted entries in the encoding comboBox

This commit is contained in:
M2j 2010-11-12 14:20:45 +01:00
parent ef91b24d8a
commit 682fcc2405

View File

@ -67,7 +67,7 @@ class OpenLP1SongImport(SongImport):
encoding = self.get_encoding() encoding = self.get_encoding()
if not encoding: if not encoding:
return False return False
connection = sqlite.connect(self.import_source, mode=0555, connection = sqlite.connect(self.import_source, mode=0444,
encoding=(encoding, 'replace')) encoding=(encoding, 'replace'))
cursor = connection.cursor() cursor = connection.cursor()
# Determine if we're using a new or an old DB # Determine if we're using a new or an old DB
@ -151,7 +151,7 @@ class OpenLP1SongImport(SongImport):
Detect character encoding of an openlp.org 1.x song database. Detect character encoding of an openlp.org 1.x song database.
""" """
# Connect to the database # Connect to the database
connection = sqlite.connect(self.import_source) connection = sqlite.connect(self.import_source, mode=0444)
cursor = connection.cursor() cursor = connection.cursor()
detector = UniversalDetector() detector = UniversalDetector()
@ -200,42 +200,43 @@ class OpenLP1SongImport(SongImport):
else: else:
guess = u'cp1252' guess = u'cp1252'
encodings = {u'cp874': translate('SongsPlugin.OpenLP1SongImport', # Show dialog for encoding selection
'CP-874 (Thai)'), encodings = [[u'cp874', u'cp932', u'cp936', u'cp949', u'cp950',
u'cp932': translate('SongsPlugin.OpenLP1SongImport', u'cp1250', u'cp1251', u'cp1252', u'cp1253', u'cp1254',
'CP-932 (Japanese)'), u'cp1255', u'cp1256', u'cp1257', u'cp1258'],
u'cp936': translate('SongsPlugin.OpenLP1SongImport', [translate('SongsPlugin.OpenLP1SongImport',
'CP-936 (Simplified Chinese)'), 'CP-874 (Thai)'),
u'cp949': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-949 (Korean)'), 'CP-932 (Japanese)'),
u'cp950': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-950 (Traditional Chinese)'), 'CP-936 (Simplified Chinese)'),
u'cp1250': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1250 (Central European)'), 'CP-949 (Korean)'),
u'cp1251': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1251 (Cyrillic)'), 'CP-950 (Traditional Chinese)'),
u'cp1252': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1252 (Western European)'), 'CP-1250 (Central European)'),
u'cp1253': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1253 (Greek)'), 'CP-1251 (Cyrillic)'),
u'cp1254': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1254 (Turkish)'), 'CP-1252 (Western European)'),
u'cp1255': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1255 (Hebrew)'), 'CP-1253 (Greek)'),
u'cp1256': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1256 (Arabic)'), 'CP-1254 (Turkish)'),
u'cp1257': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1257 (Baltic)'), 'CP-1255 (Hebrew)'),
u'cp1258': translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'CP-1258 (Vietnam)')} 'CP-1256 (Arabic)'),
encoding_list = encodings.keys() translate('SongsPlugin.OpenLP1SongImport',
'CP-1257 (Baltic)'),
translate('SongsPlugin.OpenLP1SongImport',
'CP-1258 (Vietnam)')]]
encoding_index = 0 encoding_index = 0
for encoding in encoding_list: for index in range(len(encodings[0])):
if encoding == guess: if guess == encodings[0][index]:
encoding_index = index
break break
else:
encoding_index = encoding_index + 1
ok_applied = False
chosen_encoding = QtGui.QInputDialog.getItem(None, chosen_encoding = QtGui.QInputDialog.getItem(None,
translate('SongsPlugin.OpenLP1SongImport', translate('SongsPlugin.OpenLP1SongImport',
'Database Character Encoding'), 'Database Character Encoding'),
@ -243,9 +244,9 @@ class OpenLP1SongImport(SongImport):
'The codepage setting is responsible\n' 'The codepage setting is responsible\n'
'for the correct character representation.\n' 'for the correct character representation.\n'
'Usually you are fine with the preselected choise.'), 'Usually you are fine with the preselected choise.'),
encodings.values(), encoding_index, False) encodings[1], encoding_index, False)
if not chosen_encoding[1]: if not chosen_encoding[1]:
return None return None
for encoding in encodings.items(): for index in range(len(encodings[1])):
if encoding[1] == unicode(chosen_encoding[0]): if unicode(chosen_encoding[0]) == encodings[1][index]:
return encoding[0] return encodings[0][index]