make decode filenames work allover

This commit is contained in:
Nikos Kouremenos 2006-01-18 19:50:16 +00:00
parent 7303dabb3a
commit 8c33fab699
3 changed files with 29 additions and 18 deletions

View File

@ -265,12 +265,9 @@ _('Connection with peer cannot be established.'))
if response == gtk.RESPONSE_OK:
file_dir = None
files_path_list = dialog.get_filenames()
files_path_list = gtkgui_helpers.decode_filechooser_file_paths(
files_path_list)
for file_path in files_path_list:
# decode as UTF-8 under win
if os.name == 'nt':
file_path = file_path.decode('utf8')
else:
file_path = file_path.decode(sys.getfilesystemencoding())
if self.send_file(account, contact, file_path) and file_dir is None:
file_dir = os.path.dirname(file_path)
if file_dir:
@ -306,7 +303,7 @@ _('Connection with peer cannot be established.'))
def confirm_overwrite_cb(self, dialog, file_props):
file_path = dialog.get_filename()
file_path = file_path.decode('utf-8')
file_path = gtkgui_helpers.decode_filechooser_file_paths((file_path,))[0]
if os.path.exists(file_path):
stat = os.stat(file_path)
dl_size = stat.st_size
@ -360,7 +357,8 @@ _('Connection with peer cannot be established.'))
response = dialog.run()
if response == gtk.RESPONSE_OK:
file_path = dialog.get_filename()
file_path = file_path.decode('utf-8')
file_path = gtkgui_helpers.decode_filechooser_file_paths(
(file_path,))[0]
if not gtk28 and os.path.exists(file_path):
primtext = _('This file already exists')
sectext = _('Would you like to overwrite it?')

View File

@ -474,3 +474,20 @@ def make_pixbuf_grayscale(pixbuf):
pixbuf2 = pixbuf.copy()
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
return pixbuf2
def decode_filechooser_file_paths(file_paths):
'''decode as UTF-8 under Windows and
ask sys.getfilesystemencoding() in POSIX
file_paths MUST be LIST'''
file_paths_list = list()
if os.name == 'nt': # decode as UTF-8 under Windows
for file_path in file_paths:
file_path = file_path.decode('utf8')
file_paths_list.append(file_path)
else:
for file_path in file_paths:
file_path = file_path.decode(sys.getfilesystemencoding())
file_paths_list.append(file_path)
return file_paths_list

View File

@ -200,17 +200,13 @@ class VcardWindow:
response = dialog.run()
if response == gtk.RESPONSE_OK:
f = dialog.get_filename()
try:
f = f.decode('utf-8')
except UnicodeError:
pass
else:
filesize = os.path.getsize(f) # in bytes
if filesize > 32768: # 32 kb
dialogs.ErrorDialog(_('The filesize of image "%s" is too large')\
% os.path.basename(f),
_('The file must not be more than 32 kilobytes.')).get_response()
continue
f = gtkgui_helpers.decode_filechooser_file_paths((f,))[0]
filesize = os.path.getsize(f) # in bytes
if filesize > 32768: # 32 kb
dialogs.ErrorDialog(_('The filesize of image "%s" is too large')\
% os.path.basename(f),
_('The file must not be more than 32 kilobytes.')).get_response()
continue
if self.image_is_ok(f):
done = True
else: # Cancel or WM X button