Fix uri handling when dragged to gtk window

This commit is contained in:
Calum Lind 2011-06-17 19:42:08 +01:00
parent d2e1d66f43
commit 00900fef1c
3 changed files with 9 additions and 19 deletions

View File

@ -85,15 +85,6 @@ class IPCInterface(component.Component):
if not os.path.exists(deluge.configmanager.get_config_dir("ipc")): if not os.path.exists(deluge.configmanager.get_config_dir("ipc")):
os.makedirs(deluge.configmanager.get_config_dir("ipc")) os.makedirs(deluge.configmanager.get_config_dir("ipc"))
# Make the args absolute paths
_args = []
for arg in args:
if arg.strip():
if not deluge.common.is_magnet(arg) and not deluge.common.is_url(arg):
arg = os.path.abspath(arg.replace('file://', '', 1))
_args.append(arg)
args = _args
socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk") socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk")
if deluge.common.windows_check(): if deluge.common.windows_check():
@ -198,7 +189,7 @@ def process_args(args):
return return
config = ConfigManager("gtkui.conf") config = ConfigManager("gtkui.conf")
for arg in args: for arg in args:
if not arg: if not arg.strip():
continue continue
log.debug("arg: %s", arg) log.debug("arg: %s", arg)
if deluge.common.is_url(arg): if deluge.common.is_url(arg):
@ -218,13 +209,14 @@ def process_args(args):
client.core.add_torrent_magnet(arg, {}) client.core.add_torrent_magnet(arg, {})
else: else:
# Just a file # Just a file
log.debug("Attempting to add %s from external source..", arg) path = os.path.abspath(arg.replace('file://', '', 1))
if not os.path.exists(arg): log.debug("Attempting to add %s from external source..", path)
log.error("No such file: %s", arg) if not os.path.exists(path):
log.error("No such file: %s", path)
continue continue
if config["interactive_add"]: if config["interactive_add"]:
component.get("AddTorrentDialog").add_from_files([arg]) component.get("AddTorrentDialog").add_from_files([path])
component.get("AddTorrentDialog").show(config["focus_add_dialog"]) component.get("AddTorrentDialog").show(config["focus_add_dialog"])
else: else:
client.core.add_torrent_file(os.path.split(arg)[-1], base64.encodestring(open(arg, "rb").read()), None) client.core.add_torrent_file(os.path.split(path)[-1], base64.encodestring(open(path, "rb").read()), None)

View File

@ -217,10 +217,7 @@ class MainWindow(component.Component):
def on_drag_data_received_event(self, widget, drag_context, x, y, selection_data, info, timestamp): def on_drag_data_received_event(self, widget, drag_context, x, y, selection_data, info, timestamp):
args = [] args = []
for uri in selection_data.data.split(): for uri in selection_data.data.split():
if deluge.common.windows_check(): args.append(urllib.unquote(uri))
args.append(urllib.url2pathname(uri[7:]))
else:
args.append(urllib.unquote(urlparse(uri).path))
process_args(args) process_args(args)
drag_context.finish(True, True) drag_context.finish(True, True)

View File

@ -190,6 +190,7 @@ class QueuedTorrents(component.Component):
else: else:
client.core.add_magnet_uris([torrent_path], []) client.core.add_magnet_uris([torrent_path], [])
else: else:
torrent_path = os.path.abspath(torrent_path.replace('file://', '', 1))
if not os.path.exists(torrent_path): if not os.path.exists(torrent_path):
log.error("No such file: %s", torrent_path) log.error("No such file: %s", torrent_path)
return return