Fix #1918 : Drag'n'Drop not working in Windows

This commit is contained in:
Calum Lind 2011-11-22 03:23:22 +00:00
parent d98231a713
commit 3c3f93db3e
2 changed files with 15 additions and 10 deletions

View File

@ -38,6 +38,8 @@ import sys
import os import os
import base64 import base64
import logging import logging
from urllib import url2pathname
from urlparse import urlparse
try: try:
import rencode import rencode
@ -190,29 +192,34 @@ def process_args(args):
component.get("QueuedTorrents").add_to_queue(args) component.get("QueuedTorrents").add_to_queue(args)
return return
config = ConfigManager("gtkui.conf") config = ConfigManager("gtkui.conf")
for arg in args: for arg in args:
if not arg.strip(): 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):
log.debug("Attempting to add %s from external source..", log.debug("Attempting to add url (%s) from external source...", arg)
arg)
if config["interactive_add"]: if config["interactive_add"]:
component.get("AddTorrentDialog").add_from_url(arg) component.get("AddTorrentDialog").add_from_url(arg)
component.get("AddTorrentDialog").show(config["focus_add_dialog"]) component.get("AddTorrentDialog").show(config["focus_add_dialog"])
else: else:
client.core.add_torrent_url(arg, None) client.core.add_torrent_url(arg, None)
elif deluge.common.is_magnet(arg): elif deluge.common.is_magnet(arg):
log.debug("Attempting to add %s from external source..", arg) log.debug("Attempting to add magnet (%s) from external source...", arg)
if config["interactive_add"]: if config["interactive_add"]:
component.get("AddTorrentDialog").add_from_magnets([arg]) component.get("AddTorrentDialog").add_from_magnets([arg])
component.get("AddTorrentDialog").show(config["focus_add_dialog"]) component.get("AddTorrentDialog").show(config["focus_add_dialog"])
else: else:
client.core.add_torrent_magnet(arg, {}) client.core.add_torrent_magnet(arg, {})
else: else:
# Just a file log.debug("Attempting to add file (%s) from external source...", arg)
path = os.path.abspath(arg.replace('file://', '', 1)) if urlparse(arg).scheme == "file":
log.debug("Attempting to add %s from external source..", path) arg = url2pathname(urlparse(arg).path)
path = os.path.abspath(arg)
if not os.path.exists(path): if not os.path.exists(path):
log.error("No such file: %s", path) log.error("No such file: %s", path)
continue continue

View File

@ -284,10 +284,8 @@ class MainWindow(component.Component):
self.config["window_pane_position"] = self.vpaned.get_position() self.config["window_pane_position"] = self.vpaned.get_position()
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 = [] log.debug("Selection(s) dropped on main window %s", selection_data.get_uris())
for uri in selection_data.data.split(): process_args(selection_data.get_uris())
args.append(urllib.unquote(uri))
process_args(args)
drag_context.finish(True, True) drag_context.finish(True, True)
def on_expose_event(self, widget, event): def on_expose_event(self, widget, event):