diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 52d7fb025..7f570e155 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -34,6 +34,7 @@ """Internal Torrent class""" import os +from urlparse import urlparse import deluge.libtorrent as lt import deluge.common @@ -377,7 +378,22 @@ class Torrent: ret.append(0.0) return ret - + + def get_tracker_host(self): + """Returns just the hostname of the currently connected tracker""" + if not self.status: + self.status = self.handle.status() + + if self.status.current_tracker: + url = urlparse(self.status.current_tracker) + if hasattr(url, "hostname"): + host = (url.hostname or 'unknown?') + parts = host.split(".") + if len(parts) > 2: + host = ".".join(parts[-2:]) + return host + return "" + def get_status(self, keys): """Returns the status of the torrent based on the keys provided""" # Create the full dictionary @@ -445,6 +461,7 @@ class Torrent: "queue": self.handle.queue_position, "is_seed": self.handle.is_seed, "peers": self.get_peers, + "tracker_host": self.get_tracker_host } self.status = None diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 2517c4050..b921aa38a 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -99,20 +99,6 @@ def cell_data_queue(column, cell, model, row, data): cell.set_property("text", "") else: cell.set_property("text", value + 1) - -def cell_data_tracker(column, cell, model, row, data): - value = model.get_value(row, data) - if value: - url = urlparse(value) - if hasattr(url, "hostname"): - host = (url.hostname or 'unknown?') - parts = host.split(".") - if len(parts) > 2: - host = ".".join(parts[-2:]) - cell.set_property("text", host) - return - - cell.set_property("text", "") class TorrentView(listview.ListView, component.Component): """TorrentView handles the listing of torrents.""" @@ -179,11 +165,8 @@ class TorrentView(listview.ListView, component.Component): listview.cell_data_ratio, [float], status_field=["distributed_copies"]) + self.add_text_column(_("Tracker"), status_field=["tracker_host"]) - self.add_func_column(_("Tracker"), - cell_data_tracker, - [str], - status_field=["tracker"]) # Set default sort column to # self.liststore.set_sort_column_id(self.get_column_index("#"), gtk.SORT_ASCENDING)