mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-26 12:45:31 +00:00
tracker-column:use connected or first
This commit is contained in:
parent
2f881fe734
commit
f79f5d9113
3 changed files with 11 additions and 40 deletions
|
@ -380,12 +380,17 @@ class Torrent:
|
|||
return ret
|
||||
|
||||
def get_tracker_host(self):
|
||||
"""Returns just the hostname of the currently connected tracker"""
|
||||
"""Returns just the hostname of the currently connected tracker
|
||||
if no tracker is connected, it uses the 1st tracker."""
|
||||
if not self.status:
|
||||
self.status = self.handle.status()
|
||||
|
||||
tracker = self.status.current_tracker
|
||||
if not tracker and self.trackers:
|
||||
tracker = self.trackers[0]["url"]
|
||||
|
||||
if self.status.current_tracker:
|
||||
url = urlparse(self.status.current_tracker)
|
||||
if tracker:
|
||||
url = urlparse(tracker)
|
||||
if hasattr(url, "hostname"):
|
||||
host = (url.hostname or 'unknown?')
|
||||
parts = host.split(".")
|
||||
|
|
|
@ -71,7 +71,6 @@ class Core(CorePluginBase):
|
|||
def enable(self):
|
||||
log.info("*** Start Label plugin ***")
|
||||
|
||||
#self.plugin.register_status_field("tracker_host", self._status_get_tracker)
|
||||
self.plugin.register_status_field("label", self._status_get_label)
|
||||
|
||||
#__init__
|
||||
|
@ -111,31 +110,12 @@ class Core(CorePluginBase):
|
|||
|
||||
def disable(self):
|
||||
# De-register the label field
|
||||
self.plugin.deregister_status_field("tracker_host")
|
||||
#self.plugin.deregister_status_field("tracker_host")
|
||||
self.plugin.deregister_status_field("label")
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
## Utils ##
|
||||
def get_tracker(self, torrent):
|
||||
"""
|
||||
returns 1st tracker hostname
|
||||
save space: reduced to *.com without any subdomain dots before
|
||||
TODO: CLEANUP
|
||||
"""
|
||||
log.debug(torrent)
|
||||
log.debug(torrent.trackers)
|
||||
if not torrent.trackers:
|
||||
return 'tracker-less'
|
||||
url = urlparse(torrent.trackers[0]['url'])
|
||||
if hasattr(url,'hostname'):
|
||||
host = (url.hostname or 'unknown?')
|
||||
parts = host.split(".")
|
||||
if len(parts) > 2:
|
||||
host = ".".join(parts[-2:])
|
||||
return host
|
||||
return 'No-tracker?'
|
||||
|
||||
## Filters ##
|
||||
def filter_state(self, torrents, value):
|
||||
|
@ -147,7 +127,7 @@ class Core(CorePluginBase):
|
|||
|
||||
def filter_tracker(self, torrents, value):
|
||||
"in/out: a list of torrent objects."
|
||||
return [t for t in torrents if self.get_tracker(t) == value]
|
||||
return [t for t in torrents if t.get_tracker_host() == value]
|
||||
|
||||
def filter_label(self, torrents, value):
|
||||
"in/out: a list of torrent objects."
|
||||
|
@ -191,7 +171,7 @@ class Core(CorePluginBase):
|
|||
#trackers:
|
||||
trackers = {}
|
||||
for t in self.torrents.values():
|
||||
tracker = self.get_tracker(t)
|
||||
tracker = t.get_tracker_host()
|
||||
if not tracker in trackers:
|
||||
trackers[tracker] = 0
|
||||
trackers[tracker] +=1
|
||||
|
@ -373,10 +353,6 @@ class Core(CorePluginBase):
|
|||
self.config.save()
|
||||
|
||||
|
||||
## Status fields ##
|
||||
def _status_get_tracker(self, torrent_id):
|
||||
return self.get_tracker(self.torrents[torrent_id])
|
||||
|
||||
def _status_get_label(self, torrent_id):
|
||||
return self.torrent_labels.get(torrent_id) or ""
|
||||
|
||||
|
|
|
@ -51,9 +51,6 @@ NO_LABEL = "No Label"
|
|||
def cell_data_label(column, cell, model, row, data):
|
||||
cell.set_property('text', str(model.get_value(row, data)))
|
||||
|
||||
def cell_data_tracker_host(column, cell, model, row, data):
|
||||
cell.set_property('text', str(model.get_value(row, data)))
|
||||
|
||||
class GtkUI(ui.UI):
|
||||
def __init__(self, plugin_api, plugin_name):
|
||||
log.debug("Calling UI init")
|
||||
|
@ -71,8 +68,6 @@ class GtkUI(ui.UI):
|
|||
try:
|
||||
component.get("TorrentView").remove_column(_("Label"))
|
||||
log.debug(1.1)
|
||||
component.get("TorrentView").remove_column(_("Tracker"))
|
||||
log.debug(1.2)
|
||||
except Exception, e:
|
||||
log.debug(e) #fix this!
|
||||
log.debug(1.2)
|
||||
|
@ -120,11 +115,6 @@ class GtkUI(ui.UI):
|
|||
[str],
|
||||
status_field=["label"])
|
||||
|
||||
component.get("TorrentView").add_func_column(_("Tracker"),
|
||||
cell_data_tracker_host,
|
||||
[str],
|
||||
status_field=["tracker_host"])
|
||||
|
||||
component.get("TorrentView").create_model_filter() #todo:improve.
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue