diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 5093d6180..0ef2200ea 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -24,6 +24,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +from PyQt4 import QtGui from openlp.core.lib import translate class VerseType(object): @@ -123,6 +124,57 @@ class VerseType(object): unicode(VerseType.to_string(VerseType.Other)).lower(): return VerseType.Other + +def retrieve_windows_encoding(recommendation=None): + # map chardet result to compatible windows standard code page + codepage_mapping = {'IBM866': u'cp866', 'TIS-620': u'cp874', + 'SHIFT_JIS': u'cp932', 'GB2312': u'cp936', 'HZ-GB-2312': u'cp936', + 'EUC-KR': u'cp949', 'Big5': u'cp950', 'ISO-8859-2': u'cp1250', + 'windows-1250': u'cp1250', 'windows-1251': u'cp1251', + 'windows-1252': u'cp1252', 'ISO-8859-7': u'cp1253', + 'windows-1253': u'cp1253', 'ISO-8859-8': u'cp1255', + 'windows-1255': u'cp1255'} + if recommendation in codepage_mapping: + recommendation = codepage_mapping[recommendation] + + # Show dialog for encoding selection + encodings = [(u'cp1256', translate('SongsPlugin', 'Arabic (CP-1256)')), + (u'cp1257', translate('SongsPlugin', 'Baltic (CP-1257)')), + (u'cp1250', translate('SongsPlugin', 'Central European (CP-1250)')), + (u'cp1251', translate('SongsPlugin', 'Cyrillic (CP-1251)')), + (u'cp1253', translate('SongsPlugin', 'Greek (CP-1253)')), + (u'cp1255', translate('SongsPlugin', 'Hebrew (CP-1255)')), + (u'cp932', translate('SongsPlugin', 'Japanese (CP-932)')), + (u'cp949', translate('SongsPlugin', 'Korean (CP-949)')), + (u'cp936', translate('SongsPlugin', 'Simplified Chinese (CP-936)')), + (u'cp874', translate('SongsPlugin', 'Thai (CP-874)')), + (u'cp950', translate('SongsPlugin', 'Traditional Chinese (CP-950)')), + (u'cp1254', translate('SongsPlugin', 'Turkish (CP-1254)')), + (u'cp1258', translate('SongsPlugin', 'Vietnam (CP-1258)')), + (u'cp1252', translate('SongsPlugin', 'Western European (CP-1252)'))] + recommended_index = -1 + if recommendation: + for index in range(len(encodings)): + if recommendation == encodings[index][0]: + recommended_index = index + break + if recommended_index > 0: + choice = QtGui.QInputDialog.getItem(None, + translate('SongsPlugin', 'Character Encoding'), + translate('SongsPlugin', 'The codepage setting is responsible\n' + 'for the correct character representation.\n' + 'Usually you are fine with the preselected choise.'), + [pair[1] for pair in encodings], recommended_index, False) + else: + choice = QtGui.QInputDialog.getItem(None, + translate('SongsPlugin', 'Character Encoding'), + translate('SongsPlugin', 'Please choose the character encoding.\n' + 'The encoding is responsible for the correct character ' + 'representation.'), [pair[1] for pair in encodings], 0, False) + if not choice[1]: + return None + return filter(lambda item: item[1] == choice[0], encodings)[0][0] + from xml import LyricsXML, SongXMLBuilder, SongXMLParser, OpenLyricsParser from songstab import SongsTab -from mediaitem import SongMediaItem \ No newline at end of file +from mediaitem import SongMediaItem diff --git a/openlp/plugins/songs/lib/ewimport.py b/openlp/plugins/songs/lib/ewimport.py index cb46eb798..d74cd284f 100644 --- a/openlp/plugins/songs/lib/ewimport.py +++ b/openlp/plugins/songs/lib/ewimport.py @@ -32,6 +32,7 @@ import os import struct from openlp.core.lib import translate +from openlp.plugins.songs.lib import retrieve_windows_encoding from songimport import SongImport def strip_rtf(blob, encoding): @@ -163,22 +164,25 @@ class EasyWorshipSongImport(SongImport): self.encoding = u'cp1250' # The following codepage to actual encoding mappings have not been # observed, but merely guessed. Actual example files are needed. - #if code_page == 737: - # self.encoding = u'cp1253' - #if code_page == 775: - # self.encoding = u'cp1257' - #if code_page == 855: - # self.encoding = u'cp1251' - #if code_page == 857: - # self.encoding = u'cp1254' - #if code_page == 866: - # self.encoding = u'cp1251' - #if code_page == 869: - # self.encoding = u'cp1253' - #if code_page == 862: - # self.encoding = u'cp1255' - #if code_page == 874: - # self.encoding = u'cp874' + elif code_page == 737: + self.encoding = u'cp1253' + elif code_page == 775: + self.encoding = u'cp1257' + elif code_page == 855: + self.encoding = u'cp1251' + elif code_page == 857: + self.encoding = u'cp1254' + elif code_page == 866: + self.encoding = u'cp1251' + elif code_page == 869: + self.encoding = u'cp1253' + elif code_page == 862: + self.encoding = u'cp1255' + elif code_page == 874: + self.encoding = u'cp874' + self.encoding = retrieve_windows_encoding(self.encoding) + if not self.encoding: + 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) @@ -347,4 +351,4 @@ class EasyWorshipSongImport(SongImport): return u'' return self.memo_file.read(blob_size) else: - return 0 \ No newline at end of file + return 0 diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index cd305877c..1be86e47c 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -151,11 +151,14 @@ class SongMediaItem(MediaManagerItem): def initialise(self): self.SearchTextEdit.setSearchTypes([ - (1, u':/songs/song_search_all.png', translate('SongsPlugin.MediaItem', 'Entire Song')), - (2, u':/songs/song_search_title.png', translate('SongsPlugin.MediaItem', 'Titles')), - (3, u':/songs/song_search_lyrics.png', translate('SongsPlugin.MediaItem', 'Lyrics')), - (4, u':/songs/song_search_author.png', translate('SongsPlugin.MediaItem', 'Authors')) - ]) + (1, u':/songs/song_search_all.png', + translate('SongsPlugin.MediaItem', 'Entire Song')), + (2, u':/songs/song_search_title.png', + translate('SongsPlugin.MediaItem', 'Titles')), + (3, u':/songs/song_search_lyrics.png', + translate('SongsPlugin.MediaItem', 'Lyrics')), + (4, u':/songs/song_search_author.png', + translate('SongsPlugin.MediaItem', 'Authors'))]) self.configUpdated() def onSearchTextButtonClick(self): diff --git a/openlp/plugins/songs/lib/olp1import.py b/openlp/plugins/songs/lib/olp1import.py index 69714e773..ceaee3302 100644 --- a/openlp/plugins/songs/lib/olp1import.py +++ b/openlp/plugins/songs/lib/olp1import.py @@ -28,13 +28,12 @@ The :mod:`olp1import` module provides the functionality for importing openlp.org 1.x song databases into the current installation database. """ -from PyQt4 import QtGui - import logging from chardet.universaldetector import UniversalDetector import sqlite from openlp.core.lib import translate +from openlp.plugins.songs.lib import retrieve_windows_encoding from songimport import SongImport log = logging.getLogger(__name__) @@ -185,64 +184,4 @@ class OpenLP1SongImport(SongImport): detector.close() return detector.result[u'encoding'] detector.close() - guess = detector.result[u'encoding'] - - # map chardet result to compatible windows standard code page - codepage_mapping = {'IBM866': u'cp866', 'TIS-620': u'cp874', - 'SHIFT_JIS': u'cp932', 'GB2312': u'cp936', 'HZ-GB-2312': u'cp936', - 'EUC-KR': u'cp949', 'Big5': u'cp950', 'ISO-8859-2': u'cp1250', - 'windows-1250': u'cp1250', 'windows-1251': u'cp1251', - 'windows-1252': u'cp1252', 'ISO-8859-7': u'cp1253', - 'windows-1253': u'cp1253', 'ISO-8859-8': u'cp1255', - 'windows-1255': u'cp1255'} - if guess in codepage_mapping: - guess = codepage_mapping[guess] - else: - guess = u'cp1252' - - # Show dialog for encoding selection - encodings = [(u'cp1256', translate('SongsPlugin.OpenLP1SongImport', - 'Arabic (CP-1256)')), - (u'cp1257', translate('SongsPlugin.OpenLP1SongImport', - 'Baltic (CP-1257)')), - (u'cp1250', translate('SongsPlugin.OpenLP1SongImport', - 'Central European (CP-1250)')), - (u'cp1251', translate('SongsPlugin.OpenLP1SongImport', - 'Cyrillic (CP-1251)')), - (u'cp1253', translate('SongsPlugin.OpenLP1SongImport', - 'Greek (CP-1253)')), - (u'cp1255', translate('SongsPlugin.OpenLP1SongImport', - 'Hebrew (CP-1255)')), - (u'cp932', translate('SongsPlugin.OpenLP1SongImport', - 'Japanese (CP-932)')), - (u'cp949', translate('SongsPlugin.OpenLP1SongImport', - 'Korean (CP-949)')), - (u'cp936', translate('SongsPlugin.OpenLP1SongImport', - 'Simplified Chinese (CP-936)')), - (u'cp874', translate('SongsPlugin.OpenLP1SongImport', - 'Thai (CP-874)')), - (u'cp950', translate('SongsPlugin.OpenLP1SongImport', - 'Traditional Chinese (CP-950)')), - (u'cp1254', translate('SongsPlugin.OpenLP1SongImport', - 'Turkish (CP-1254)')), - (u'cp1258', translate('SongsPlugin.OpenLP1SongImport', - 'Vietnam (CP-1258)')), - (u'cp1252', translate('SongsPlugin.OpenLP1SongImport', - 'Western European (CP-1252)'))] - encoding_index = 0 - for index in range(len(encodings)): - if guess == encodings[index][0]: - encoding_index = index - break - chosen_encoding = QtGui.QInputDialog.getItem(None, - translate('SongsPlugin.OpenLP1SongImport', - 'Database Character Encoding'), - translate('SongsPlugin.OpenLP1SongImport', - 'The codepage setting is responsible\n' - 'for the correct character representation.\n' - 'Usually you are fine with the preselected choise.'), - [pair[1] for pair in encodings], encoding_index, False) - if not chosen_encoding[1]: - return None - return filter(lambda item: item[1] == chosen_encoding[0], - encodings)[0][0] \ No newline at end of file + return retrieve_windows_encoding(detector.result[u'encoding'])