From f995b3268eae0a8feb4d589a0850b109c69a65cb Mon Sep 17 00:00:00 2001 From: James Newton <redshodan@gmail.com> Date: Mon, 19 Nov 2007 15:53:16 +0000 Subject: [PATCH] native gtk on osx seems to like to send file uri's like 'file://localhost/usr/bin/foo'. rip out the host and check the uri's for valid before asking the user to send the files. --- src/common/helpers.py | 6 +++++- src/roster_window.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/helpers.py b/src/common/helpers.py index 23096817c3..aed9e52800 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -506,7 +506,11 @@ def get_file_path_from_dnd_dropped_uri(uri): if path.startswith('file:\\\\\\'): # windows path = path[8:] # 8 is len('file:///') elif path.startswith('file://'): # nautilus, rox - path = path[7:] # 7 is len('file://') + if sys.platform == 'darwin': + # OS/X includes hostname in file:// URI + path = re.sub('file://[^/]*', '', path) + else: + path = path[7:] # 7 is len('file://') elif path.startswith('file:'): # xffm path = path[5:] # 5 is len('file:') return path diff --git a/src/roster_window.py b/src/roster_window.py index 7a3458ddad..18ff203eef 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -5018,6 +5018,15 @@ class RosterWindow: uri = data.strip() uri_splitted = uri.split() # we may have more than one file dropped nb_uri = len(uri_splitted) + # Check the URIs + bad_uris = [] + for a_uri in uri_splitted: + path = helpers.get_file_path_from_dnd_dropped_uri(a_uri) + if not os.path.isfile(path): + bad_uris.append(a_uri) + if len(bad_uris): + dialogs.ErrorDialog(_('Invalid file URI:'), '\n'.join(bad_uris)) + return def _on_send_files(account, jid, uris): c = gajim.contacts.get_contact_with_highest_priority(account, jid) for uri in uris: @@ -5027,7 +5036,7 @@ class RosterWindow: account, c, path) # Popup dialog to confirm sending prim_text = 'Send file?' - sec_text = i18n.ngettext('Do you want to send that file to %s:', + sec_text = i18n.ngettext('Do you want to send this file to %s:', 'Do you want to send those files to %s:', nb_uri) %\ c_dest.get_shown_name() for uri in uri_splitted: -- GitLab