Fix v1 theme importing

This commit is contained in:
Jon Tibble 2011-12-11 14:53:44 +00:00
parent c975a4b309
commit 26df14e43c
2 changed files with 28 additions and 6 deletions

View File

@ -44,7 +44,7 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
from openlp.core.theme import Theme from openlp.core.theme import Theme
from openlp.core.ui import FileRenameForm, ThemeForm from openlp.core.ui import FileRenameForm, ThemeForm
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \
get_filesystem_encoding file_is_mbcs, get_filesystem_encoding
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -528,11 +528,13 @@ class ThemeManager(QtGui.QWidget):
for file in zip.namelist(): for file in zip.namelist():
ucsfile = file_is_unicode(file) ucsfile = file_is_unicode(file)
if not ucsfile: if not ucsfile:
critical_error_message_box( ucsfile = file_is_mbcs(file)
message=translate('OpenLP.ThemeManager', if not ucsfile:
'File is not a valid theme.\n' critical_error_message_box(
'The content encoding is not UTF-8.')) message=translate('OpenLP.ThemeManager',
continue 'File is not a valid theme.\n'
'The content encoding is not UTF-8.'))
continue
osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile))
theme_dir = None theme_dir = None
if osfile.endswith(os.path.sep): if osfile.endswith(os.path.sep):

View File

@ -475,6 +475,26 @@ def file_is_unicode(filename):
return None return None
return ucsfile return ucsfile
def file_is_mbcs(filename):
"""
Checks if a file is valid Windows file system encoded unicode and returns
the unicode decoded file or None.
``filename``
File to check is valid Windows file system encoded.
"""
if not filename:
return None
ucsfile = None
try:
ucsfile = filename.decode(u'mbcs')
except UnicodeDecodeError:
log.exception(u'Filename "%s" is not valid Windows encoded file' %
filename.decode(u'mbcs', u'replace'))
if not ucsfile:
return None
return ucsfile
def get_uno_command(): def get_uno_command():
""" """
Returns the UNO command to launch an openoffice.org instance. Returns the UNO command to launch an openoffice.org instance.