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
|
return ret
|
||||||
|
|
||||||
def get_tracker_host(self):
|
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:
|
if not self.status:
|
||||||
self.status = self.handle.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:
|
if tracker:
|
||||||
url = urlparse(self.status.current_tracker)
|
url = urlparse(tracker)
|
||||||
if hasattr(url, "hostname"):
|
if hasattr(url, "hostname"):
|
||||||
host = (url.hostname or 'unknown?')
|
host = (url.hostname or 'unknown?')
|
||||||
parts = host.split(".")
|
parts = host.split(".")
|
||||||
|
|
|
@ -71,7 +71,6 @@ class Core(CorePluginBase):
|
||||||
def enable(self):
|
def enable(self):
|
||||||
log.info("*** Start Label plugin ***")
|
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)
|
self.plugin.register_status_field("label", self._status_get_label)
|
||||||
|
|
||||||
#__init__
|
#__init__
|
||||||
|
@ -111,31 +110,12 @@ class Core(CorePluginBase):
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
# De-register the label field
|
# 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")
|
self.plugin.deregister_status_field("label")
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
pass
|
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 ##
|
## Filters ##
|
||||||
def filter_state(self, torrents, value):
|
def filter_state(self, torrents, value):
|
||||||
|
@ -147,7 +127,7 @@ class Core(CorePluginBase):
|
||||||
|
|
||||||
def filter_tracker(self, torrents, value):
|
def filter_tracker(self, torrents, value):
|
||||||
"in/out: a list of torrent objects."
|
"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):
|
def filter_label(self, torrents, value):
|
||||||
"in/out: a list of torrent objects."
|
"in/out: a list of torrent objects."
|
||||||
|
@ -191,7 +171,7 @@ class Core(CorePluginBase):
|
||||||
#trackers:
|
#trackers:
|
||||||
trackers = {}
|
trackers = {}
|
||||||
for t in self.torrents.values():
|
for t in self.torrents.values():
|
||||||
tracker = self.get_tracker(t)
|
tracker = t.get_tracker_host()
|
||||||
if not tracker in trackers:
|
if not tracker in trackers:
|
||||||
trackers[tracker] = 0
|
trackers[tracker] = 0
|
||||||
trackers[tracker] +=1
|
trackers[tracker] +=1
|
||||||
|
@ -373,10 +353,6 @@ class Core(CorePluginBase):
|
||||||
self.config.save()
|
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):
|
def _status_get_label(self, torrent_id):
|
||||||
return self.torrent_labels.get(torrent_id) or ""
|
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):
|
def cell_data_label(column, cell, model, row, data):
|
||||||
cell.set_property('text', str(model.get_value(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):
|
class GtkUI(ui.UI):
|
||||||
def __init__(self, plugin_api, plugin_name):
|
def __init__(self, plugin_api, plugin_name):
|
||||||
log.debug("Calling UI init")
|
log.debug("Calling UI init")
|
||||||
|
@ -71,8 +68,6 @@ class GtkUI(ui.UI):
|
||||||
try:
|
try:
|
||||||
component.get("TorrentView").remove_column(_("Label"))
|
component.get("TorrentView").remove_column(_("Label"))
|
||||||
log.debug(1.1)
|
log.debug(1.1)
|
||||||
component.get("TorrentView").remove_column(_("Tracker"))
|
|
||||||
log.debug(1.2)
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug(e) #fix this!
|
log.debug(e) #fix this!
|
||||||
log.debug(1.2)
|
log.debug(1.2)
|
||||||
|
@ -120,11 +115,6 @@ class GtkUI(ui.UI):
|
||||||
[str],
|
[str],
|
||||||
status_field=["label"])
|
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.
|
component.get("TorrentView").create_model_filter() #todo:improve.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue