Remove code duplication in queuedtorrents.py, use ipcinterface process_args() instead

This commit is contained in:
Calum Lind 2011-11-22 03:21:33 +00:00
parent a50c83c284
commit d98231a713
1 changed files with 2 additions and 33 deletions

View File

@ -42,6 +42,7 @@ import gobject
import deluge.component as component import deluge.component as component
from deluge.ui.client import client from deluge.ui.client import client
from deluge.ui.gtkui.ipcinterface import process_args
import deluge.common import deluge.common
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
import common import common
@ -173,39 +174,7 @@ class QueuedTorrents(component.Component):
# Add all the torrents in the liststore # Add all the torrents in the liststore
def add_torrent(model, path, iter, data): def add_torrent(model, path, iter, data):
torrent_path = model.get_value(iter, 1) torrent_path = model.get_value(iter, 1)
if deluge.common.is_url(torrent_path): process_args([torrent_path])
if self.config["interactive_add"]:
def on_show(result):
component.get("AddTorrentDialog").add_from_url(torrent_path)
d = component.get("AddTorrentDialog").show(self.config["focus_add_dialog"])
d.addCallback(on_show)
else:
client.core.add_torrent_url(torrent_path, None)
elif deluge.common.is_magnet(torrent_path):
if self.config["interactive_add"]:
def on_show(result):
component.get("AddTorrentDialog").add_from_magnets([torrent_path])
d = component.get("AddTorrentDialog").show(self.config["focus_add_dialog"])
d.addCallback(on_show)
else:
client.core.add_magnet_uris([torrent_path], [])
else:
torrent_path = os.path.abspath(torrent_path.replace('file://', '', 1))
if not os.path.exists(torrent_path):
log.error("No such file: %s", torrent_path)
return
if self.config["interactive_add"]:
def on_show(result):
component.get("AddTorrentDialog").add_from_files([torrent_path])
d = component.get("AddTorrentDialog").show(self.config["focus_add_dialog"])
d.addCallback(on_show)
else:
client.core.add_torrent_file(
os.path.split(torrent_path)[-1],
base64.encodestring(open(torrent_path, "rb").read()),
None)
self.liststore.foreach(add_torrent, None) self.liststore.foreach(add_torrent, None)
del self.queue[:] del self.queue[:]