Trying to fix unicode filename handling on Windows. Patch ported from 2.2.

svn: r9354
This commit is contained in:
Martin Hawlisch 2007-11-16 16:45:45 +00:00
parent 5cf5857bed
commit 802f0eb33f
6 changed files with 35 additions and 18 deletions

View File

@ -1,3 +1,11 @@
2007-11-16 Martin Hawlisch <Martin.Hawlisch@gmx.de>
Trying to fix unicode filename handling on Windows. Patch ported from 2.2.
* src/Utils.py: add get_unicode_path()
* src/ArgHandler.py: use Utils.get_unicode_path()
* src/AddMedia.py: use Utils.get_unicode_path()
* src/DbLoader.py: use Utils.get_unicode_path()
* src/Editors/_EditMedia.py: use Utils.get_unicode_path()
2007-11-16 Jerome Rapinat <romjerome@yahoo.fr>
* src/glade/gramps.glade: correct mnemonic_widget
* src/glade/edit_person.glade: correct mnemonic_widget

View File

@ -151,9 +151,8 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
msgstr2 = _("The filename supplied could not be found.")
ErrorDialog(msgstr, msgstr2)
return
filename = unicode(self.file_text.get_filename(),
sys.getfilesystemencoding())
filename = Utils.get_unicode_path(self.file_text.get_filename())
full_file = filename
if self.relpath.get_active():
@ -197,7 +196,7 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
fname = self.file_text.get_filename()
if not fname:
return
filename = unicode(fname, sys.getfilesystemencoding())
filename = Utils.get_unicode_path(fname)
basename = os.path.basename(filename)
(root, ext) = os.path.splitext(basename)
old_title = unicode(self.description.get_text())

View File

@ -770,8 +770,7 @@ class NewNativeDbPrompter:
while (True):
response = choose.run()
if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(),
sys.getfilesystemencoding())
filename = Utils.get_unicode_path(choose.get_filename())
if filename == None:
continue
if os.path.splitext(filename)[1] != ".grdb":

View File

@ -110,8 +110,7 @@ class DbLoader:
choose.set_current_folder(get_default_dir())
response = choose.run()
if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(),
sys.getfilesystemencoding())
filename = Utils.get_unicode_path(choose.get_filename())
if self.check_errors(filename):
return ('','')
@ -170,8 +169,7 @@ class DbLoader:
response = choose.run()
if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(),
sys.getfilesystemencoding())
filename = Utils.get_unicode_path(choose.get_filename())
if self.check_errors(filename):
return ('','')
@ -262,8 +260,7 @@ class DbLoader:
choose.set_current_folder(default_dir)
response = choose.run()
if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(),
sys.getfilesystemencoding())
filename = Utils.get_unicode_path(choose.get_filename())
if self.check_errors(filename):
return False

View File

@ -46,6 +46,7 @@ import Config
import gen.lib
import Mime
import ThumbNails
import Utils
from _EditPrimary import EditPrimary
from GrampsWidgets import *
@ -126,7 +127,7 @@ class EditMedia(EditPrimary):
mtype = self.obj.get_mime_type()
if mtype:
pb = ThumbNails.get_thumbnail_image(self.obj.get_path(),mtype)
pb = ThumbNails.get_thumbnail_image(Utils.find_file(self.obj.get_path()),mtype)
pixmap.set_from_pixbuf(pb)
ebox.connect('button-press-event', self.button_press_event)
descr = Mime.get_description(mtype)
@ -214,8 +215,7 @@ class EditMedia(EditPrimary):
status = f.run()
if status == gtk.RESPONSE_OK:
self.file_path.set_text(unicode(f.get_filename(),
sys.getfilesystemencoding()))
self.file_path.set_text(Utils.get_unicode_path(f.get_filename()))
f.destroy()
def setup_filepath(self):
@ -223,7 +223,7 @@ class EditMedia(EditPrimary):
self.file_path = self.glade.get_widget("path")
if self.obj.get_mime_type():
fname = self.obj.get_path()
fname = Utils.get_unicode_path(self.obj.get_path())
self.file_path.set_text(fname)
self.select.connect('clicked', self.select_file)
else:
@ -235,11 +235,11 @@ class EditMedia(EditPrimary):
path = self.glade.get_widget('path').get_text()
if path != self.obj.get_path():
mime = Mime.get_type(os.path.abspath(path))
mime = Mime.get_type(Utils.find_file(os.path.abspath(path)))
self.obj.set_mime_type(mime)
if self.obj.get_mime_type():
self.obj.set_path(path)
self.obj.set_path(Utils.get_unicode_path(path))
trans = self.db.transaction_begin()
self.db.commit_media_object(self.obj,trans)

View File

@ -327,6 +327,20 @@ def find_folder( filename):
# not found
return ''
def get_unicode_path(path):
"""
Return the Unicode version of a path string.
@type path: str
@param path: The path to be converted to Unicode
@rtype: unicode
@return: The Unicode version of path.
"""
if os.sys.platform == "win32":
return unicode(path)
else:
return unicode(path,sys.getfilesystemencoding())
#-------------------------------------------------------------------------
#
#