diff --git a/deluge/core/core.py b/deluge/core/core.py
index b8e51a3fe..f16cc91e1 100644
--- a/deluge/core/core.py
+++ b/deluge/core/core.py
@@ -143,7 +143,21 @@ class Core(dbus.service.Object):
self.torrent_added(torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
- in_signature="s", out_signature="(six)")
+ in_signature="s", out_signature="")
+ def remove_torrent(self, torrent_id):
+ log.debug("Removing torrent %s from the core.", torrent_id)
+ try:
+ # Remove from libtorrent session
+ self.session.remove_torrent(self.torrents[torrent_id].handle)
+ # Remove from TorrentManager
+ self.torrents.remove(torrent_id)
+ # Emit the torrent_removed signal
+ self.torrent_removed(torrent_id)
+ except RuntimeError, KeyError:
+ log.warning("Error removing torrent")
+
+ @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
+ in_signature="s", out_signature="(sxi)")
def get_torrent_info(self, torrent_id):
# Get the info tuple from the torrent and return it
return self.torrents[torrent_id].get_info()
@@ -154,6 +168,20 @@ class Core(dbus.service.Object):
def get_torrent_status(self, torrent_id):
# Get the status tuple from the torrent and return it
return self.torrents[torrent_id].get_status()
+
+ @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
+ in_signature="",
+ out_signature="as")
+ def get_torrent_status_template(self):
+ # A list of strings the correspond to the status tuple
+ return self.torrents.get_status_template()
+
+ @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
+ in_signature="",
+ out_signature="as")
+ def get_torrent_info_template(self):
+ # A list of strings the correspond to the info tuple
+ return self.torrents.get_info_template()
## Queueing functions ######
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
@@ -162,8 +190,6 @@ class Core(dbus.service.Object):
# If the queue method returns True, then we should emit a signal
if self.queue.top(torrent_id):
self.torrent_queue_top()
- # Store the new torrent position in the torrent object
-# self.torrents[torrent_id].set_position(self.queue[torrent_id])
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
in_signature="s", out_signature="")
@@ -199,6 +225,12 @@ class Core(dbus.service.Object):
"""Emitted when a new torrent fails addition to the session"""
log.debug("torrent_add_failed signal emitted")
+ @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
+ signature="s")
+ def torrent_removed(self, torrent_id):
+ """Emitted when a torrent has been removed from the core"""
+ log.debug("torrent_remove signal emitted")
+
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
signature="s")
def torrent_queue_top(self, torrent_id):
diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py
index 8b59dac59..54d695e88 100644
--- a/deluge/core/torrent.py
+++ b/deluge/core/torrent.py
@@ -31,8 +31,13 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
+import logging
+
import deluge.libtorrent as lt
+# Get the logger
+log = logging.getLogger("deluge")
+
class Torrent:
def __init__(self, handle, queue):
# Set the libtorrent handle
@@ -42,17 +47,20 @@ class Torrent:
# Set the torrent_id for this torrent
self.torrent_id = str(handle.info_hash())
+ def __del__(self):
+ self.queue.remove(self.torrent_id)
+
def get_eta(self):
"""Returns the ETA in seconds for this torrent"""
left = self.handle.status().total_wanted \
- self.handle.status().total_done
- # The torrent file is done
- if left == 0:
- return 0
-
- # Calculate the ETA in seconds and return it
- return (left / self.handle.status().download_payload_rate)
+ try:
+ eta = left / self.handle.status().download_payload_rate
+ except ZeroDivisionError:
+ eta = 0
+
+ return eta
def get_info(self):
"""Returns the torrents info.. stuff that remains constant, such as
@@ -83,3 +91,4 @@ class Torrent:
self.get_eta(),
self.queue[self.torrent_id]
)
+
diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py
index bb71fec54..af715935e 100644
--- a/deluge/core/torrentmanager.py
+++ b/deluge/core/torrentmanager.py
@@ -59,3 +59,37 @@ class TorrentManager:
# Add the torrent to the queue
self.queue.append(torrent.torrent_id)
return torrent.torrent_id
+
+ def remove(self, torrent_id):
+ """Remove a torrent from the manager"""
+ try:
+ del self.torrents[torrent_id]
+ except KeyError, ValueError:
+ return False
+ return True
+
+ def get_info_template(self):
+ """Returns a list of strings that correspond to the info tuple"""
+ return [
+ "name",
+ "total_size",
+ "num_pieces"
+ ]
+
+ def get_status_template(self):
+ """Returns a list of strings that correspond to the status tuple"""
+ return [
+ "state",
+ "paused",
+ "progress",
+ "next_announce",
+ "total_payload_download",
+ "total_payload_upload",
+ "download_payload_rate",
+ "upload_payload_rate",
+ "num_peers",
+ "num_seeds",
+ "total_wanted",
+ "eta",
+ "position"
+ ]
diff --git a/deluge/core/torrentqueue.py b/deluge/core/torrentqueue.py
index 3e09cadcb..5694f592e 100644
--- a/deluge/core/torrentqueue.py
+++ b/deluge/core/torrentqueue.py
@@ -54,7 +54,11 @@ class TorrentQueue:
"""Prepend torrent_id to the top of the queue"""
log.debug("Prepend torrent %s to queue..", torrent_id)
self.queue.insert(0, torrent_id)
-
+
+ def remove(self, torrent_id):
+ """Removes torrent_id from the list"""
+ self.queue.remove(torrent_id)
+
def up(self, torrent_id):
"""Move torrent_id up one in the queue"""
if torrent_id not in self.queue:
diff --git a/deluge/ui/gtkui/columns.py b/deluge/ui/gtkui/columns.py
index 23ceeda12..d47cd3c5a 100644
--- a/deluge/ui/gtkui/columns.py
+++ b/deluge/ui/gtkui/columns.py
@@ -62,7 +62,7 @@ def cell_data_time(column, cell, model, iter, data):
time_str = _("Infinity")
else:
time_str = deluge.common.ftime(time)
- cell.set_property('text', time_str)
+ cell.set_property('text', time_str)
def cell_data_ratio(column, cell, model, iter, data):
ratio = float(model.get_value(iter, data))
diff --git a/deluge/ui/gtkui/functions.py b/deluge/ui/gtkui/functions.py
index f06e8f332..5e6fb7226 100644
--- a/deluge/ui/gtkui/functions.py
+++ b/deluge/ui/gtkui/functions.py
@@ -85,3 +85,28 @@ def add_torrent_file():
(path, filename) = os.path.split(torrent_file)
core.add_torrent_file(filename, f.read())
f.close()
+
+def remove_torrent(torrent_ids):
+ """Removes torrent_ids from the core.. Expects a list of torrent_ids"""
+ log.debug("Attempting to removing torrents: %s", torrent_ids)
+ core = get_core()
+ for torrent_id in torrent_ids:
+ core.remove_torrent(torrent_id)
+
+def get_torrent_status_dict(core, torrent_id):
+ """Builds and returns a status dictionary using the status template"""
+ status = core.get_torrent_status(torrent_id)
+ template = core.get_torrent_status_template()
+ status_dict = {}
+ for string in template:
+ status_dict[string] = status[template.index(string)]
+ return status_dict
+
+def get_torrent_info_dict(core, torrent_id):
+ """Builds and returns an info dictionary using the info template"""
+ info = core.get_torrent_info(torrent_id)
+ template = core.get_torrent_info_template()
+ info_dict = {}
+ for string in template:
+ info_dict[string] = info[template.index(string)]
+ return info_dict
diff --git a/deluge/ui/gtkui/glade/torrent_menu.glade b/deluge/ui/gtkui/glade/torrent_menu.glade
index 21b1a7f12..dc1c89d74 100644
--- a/deluge/ui/gtkui/glade/torrent_menu.glade
+++ b/deluge/ui/gtkui/glade/torrent_menu.glade
@@ -58,7 +58,7 @@
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
_Remove Torrent
True
-
+