From 9a00d4db3984056f234503ac389851490d13071c Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Wed, 30 Jul 2008 14:15:00 +0000 Subject: [PATCH] Add progress to the peers tab --- ChangeLog | 3 ++ deluge/core/torrent.py | 3 +- deluge/plugins/label/label/core.py | 2 +- deluge/ui/gtkui/peers_tab.py | 31 ++++++++++++++++---- libtorrent/bindings/python/src/peer_info.cpp | 6 ++++ 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b98112bb6..5ee24f192 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,3 +2,6 @@ Deluge 1.1.0 - "" (In Development) Core: * Implement #79 ability to change outgoing port range * Implement #296 ability to change peer TOS byte + + GtkUI: + * Add peer progress to the peers tab diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 4bb953c46..02ffe2602 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -367,7 +367,8 @@ class Torrent: "down_speed": peer.down_speed, "country": country, "client": client, - "seed": peer.flags & peer.seed + "seed": peer.flags & peer.seed, + "progress": peer.progress }) return ret diff --git a/deluge/plugins/label/label/core.py b/deluge/plugins/label/label/core.py index 229a44477..4eca73f21 100644 --- a/deluge/plugins/label/label/core.py +++ b/deluge/plugins/label/label/core.py @@ -154,7 +154,7 @@ class Core(CorePluginBase): #specialized-state: #todo: traffic. - log.debug("hide-z:%s" % self.config["hide_zero_hits"]) + #log.debug("hide-z:%s" % self.config["hide_zero_hits"]) if self.config["hide_zero_hits"]: for state in set(KNOWN_STATES): log.debug(states.keys()) diff --git a/deluge/ui/gtkui/peers_tab.py b/deluge/ui/gtkui/peers_tab.py index 703fa9169..838a4cecc 100644 --- a/deluge/ui/gtkui/peers_tab.py +++ b/deluge/ui/gtkui/peers_tab.py @@ -46,6 +46,11 @@ from deluge.ui.gtkui.listview import cell_data_speed as cell_data_speed from deluge.ui.gtkui.torrentdetails import Tab from deluge.log import LOG as log +def cell_data_progress(column, cell, model, row, data): + value = model.get_value(row, data) + cell.set_property("value", value * 100) + cell.set_property("text", "%.2f%%" % (value * 100)) + class ColumnState: def __init__(self, name, position, width, sort, sort_order): self.name = name @@ -66,8 +71,8 @@ class PeersTab(Tab): self._child_widget.connect("button-press-event", self.on_button_press_event) self.listview = glade.get_widget("peers_listview") - # country pixbuf, ip, client, downspeed, upspeed, country code, int_ip, seed/peer icon - self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, str, int, int, str, gobject.TYPE_UINT, gtk.gdk.Pixbuf) + # country pixbuf, ip, client, downspeed, upspeed, country code, int_ip, seed/peer icon, progress + self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, str, int, int, str, gobject.TYPE_UINT, gtk.gdk.Pixbuf, float) self.cached_flag_pixbufs = {} self.seed_pixbuf = gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap("seeding16.png")) @@ -118,6 +123,19 @@ class PeersTab(Tab): column.set_reorderable(True) self.listview.append_column(column) + # Progress column + column = gtk.TreeViewColumn(_("Progress")) + render = gtk.CellRendererProgress() + column.pack_start(render, True) + column.set_cell_data_func(render, cell_data_progress, 8) + column.set_sort_column_id(8) + column.set_clickable(True) + column.set_resizable(True) + column.set_expand(False) + column.set_min_width(10) + column.set_reorderable(True) + self.listview.append_column(column) + # Down Speed column column = gtk.TreeViewColumn(_("Down Speed")) render = gtk.CellRendererText() @@ -258,7 +276,7 @@ class PeersTab(Tab): # This iter is invalid, delete it and continue to next iteration del self.peers[peer["ip"]] continue - values = self.liststore.get(row, 3, 4, 5, 7) + values = self.liststore.get(row, 3, 4, 5, 7, 8) if peer["down_speed"] != values[0]: self.liststore.set_value(row, 3, peer["down_speed"]) if peer["up_speed"] != values[1]: @@ -273,7 +291,9 @@ class PeersTab(Tab): if icon != values[3]: self.liststore.set_value(row, 7, icon) - + + if peer["progress"] != values[4]: + self.liststore.set_value(row, 8, peer["progress"]) else: # Peer is not in list so we need to add it @@ -294,7 +314,8 @@ class PeersTab(Tab): peer["up_speed"], peer["country"], ip_int, - icon]) + icon, + peer["progress"]]) self.peers[peer["ip"]] = row diff --git a/libtorrent/bindings/python/src/peer_info.cpp b/libtorrent/bindings/python/src/peer_info.cpp index 9ceeead7a..3d410fb63 100755 --- a/libtorrent/bindings/python/src/peer_info.cpp +++ b/libtorrent/bindings/python/src/peer_info.cpp @@ -44,6 +44,11 @@ list get_pieces(peer_info const& pi) return ret; } +float get_progress(peer_info const& pi) +{ + return (float)pi.pieces.count() / (float)pi.pieces.size(); +} + void bind_peer_info() { scope pi = class_("peer_info") @@ -89,6 +94,7 @@ void bind_peer_info() .def_readonly("send_quota", &peer_info::send_quota) .def_readonly("receive_quota", &peer_info::receive_quota) .def_readonly("rtt", &peer_info::rtt) + .add_property("progress", get_progress) ; // flags