From 060aa01857ed129af25620a7abafb06bd49d2636 Mon Sep 17 00:00:00 2001 From: Nathalie Rud Date: Wed, 27 Apr 2016 02:44:13 +0300 Subject: [PATCH] Fix file chooser dialog on Windows Dropped decode_filechooser_file_paths() as with Python 3 it raised AttributeError: 'str' object has no attribute 'decode' on Windows, and silently handled exceptions effectively doing nothing on *nix systems. --- src/dialogs.py | 9 --------- src/filetransfers_window.py | 4 ---- src/gtkgui_helpers.py | 25 ------------------------- 3 files changed, 38 deletions(-) diff --git a/src/dialogs.py b/src/dialogs.py index 3574af2d2..cce4d5a98 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -4712,9 +4712,6 @@ class ClientCertChooserDialog(FileChooserDialog): check if file exists and call callback ''' path_to_clientcert_file = self.get_filename() - path_to_clientcert_file = \ - gtkgui_helpers.decode_filechooser_file_paths( - (path_to_clientcert_file,))[0] if os.path.exists(path_to_clientcert_file): callback(widget, path_to_clientcert_file) @@ -4757,8 +4754,6 @@ class SoundChooserDialog(FileChooserDialog): Check if file exists and call callback """ path_to_snd_file = self.get_filename() - path_to_snd_file = gtkgui_helpers.decode_filechooser_file_paths( - (path_to_snd_file,))[0] if os.path.exists(path_to_snd_file): callback(widget, path_to_snd_file) @@ -4799,8 +4794,6 @@ class ImageChooserDialog(FileChooserDialog): path_to_file = self.get_filename() if not path_to_file: return - path_to_file = gtkgui_helpers.decode_filechooser_file_paths( - (path_to_file,))[0] if os.path.exists(path_to_file): if isinstance(callback, tuple): callback[0](widget, path_to_file, *callback[1:]) @@ -4892,8 +4885,6 @@ class ArchiveChooserDialog(FileChooserDialog): path_to_file = self.get_filename() if not path_to_file: return - path_to_file = gtkgui_helpers.decode_filechooser_file_paths( - (path_to_file,))[0] if os.path.exists(path_to_file): if isinstance(callback, tuple): callback[0](path_to_file, *callback[1:]) diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py index f8eb150b9..9537fff6b 100644 --- a/src/filetransfers_window.py +++ b/src/filetransfers_window.py @@ -297,8 +297,6 @@ class FileTransfersWindow: def on_ok(widget): file_dir = None files_path_list = dialog.get_filenames() - files_path_list = gtkgui_helpers.decode_filechooser_file_paths( - files_path_list) text_buffer = desc_entry.get_buffer() desc = text_buffer.get_text(text_buffer.get_start_iter(), text_buffer.get_end_iter(), True) @@ -379,8 +377,6 @@ class FileTransfersWindow: def on_file_request_accepted(self, account, contact, file_props): def on_ok(widget, account, contact, file_props): file_path = dialog2.get_filename() - file_path = gtkgui_helpers.decode_filechooser_file_paths( - (file_path,))[0] if os.path.exists(file_path): # check if we have write permissions if not os.access(file_path, os.W_OK): diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index a060a01fc..0a85dc9c8 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -679,30 +679,6 @@ def make_pixbuf_grayscale(pixbuf): 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: - try: - file_path = file_path.decode(sys.getfilesystemencoding()) - except Exception: - try: - file_path = file_path - except Exception: - pass - file_paths_list.append(file_path) - - return file_paths_list - def escape_underscore(s): """ Escape underlines to prevent them from being interpreted as keyboard @@ -771,7 +747,6 @@ def on_avatar_save_as_menuitem_activate(widget, jid, default_name=''): def on_ok(widget): file_path = dialog.get_filename() - file_path = decode_filechooser_file_paths((file_path,))[0] if os.path.exists(file_path): # check if we have write permissions if not os.access(file_path, os.W_OK):