make decode filenames work allover
This commit is contained in:
parent
7303dabb3a
commit
8c33fab699
3 changed files with 29 additions and 18 deletions
|
@ -265,12 +265,9 @@ _('Connection with peer cannot be established.'))
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
file_dir = None
|
file_dir = None
|
||||||
files_path_list = dialog.get_filenames()
|
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:
|
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:
|
if self.send_file(account, contact, file_path) and file_dir is None:
|
||||||
file_dir = os.path.dirname(file_path)
|
file_dir = os.path.dirname(file_path)
|
||||||
if file_dir:
|
if file_dir:
|
||||||
|
@ -306,7 +303,7 @@ _('Connection with peer cannot be established.'))
|
||||||
|
|
||||||
def confirm_overwrite_cb(self, dialog, file_props):
|
def confirm_overwrite_cb(self, dialog, file_props):
|
||||||
file_path = dialog.get_filename()
|
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):
|
if os.path.exists(file_path):
|
||||||
stat = os.stat(file_path)
|
stat = os.stat(file_path)
|
||||||
dl_size = stat.st_size
|
dl_size = stat.st_size
|
||||||
|
@ -360,7 +357,8 @@ _('Connection with peer cannot be established.'))
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
file_path = dialog.get_filename()
|
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):
|
if not gtk28 and os.path.exists(file_path):
|
||||||
primtext = _('This file already exists')
|
primtext = _('This file already exists')
|
||||||
sectext = _('Would you like to overwrite it?')
|
sectext = _('Would you like to overwrite it?')
|
||||||
|
|
|
@ -474,3 +474,20 @@ def make_pixbuf_grayscale(pixbuf):
|
||||||
pixbuf2 = pixbuf.copy()
|
pixbuf2 = pixbuf.copy()
|
||||||
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
|
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
|
||||||
return pixbuf2
|
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
|
||||||
|
|
18
src/vcard.py
18
src/vcard.py
|
@ -200,17 +200,13 @@ class VcardWindow:
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
f = dialog.get_filename()
|
f = dialog.get_filename()
|
||||||
try:
|
f = gtkgui_helpers.decode_filechooser_file_paths((f,))[0]
|
||||||
f = f.decode('utf-8')
|
filesize = os.path.getsize(f) # in bytes
|
||||||
except UnicodeError:
|
if filesize > 32768: # 32 kb
|
||||||
pass
|
dialogs.ErrorDialog(_('The filesize of image "%s" is too large')\
|
||||||
else:
|
% os.path.basename(f),
|
||||||
filesize = os.path.getsize(f) # in bytes
|
_('The file must not be more than 32 kilobytes.')).get_response()
|
||||||
if filesize > 32768: # 32 kb
|
continue
|
||||||
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):
|
if self.image_is_ok(f):
|
||||||
done = True
|
done = True
|
||||||
else: # Cancel or WM X button
|
else: # Cancel or WM X button
|
||||||
|
|
Loading…
Add table
Reference in a new issue