diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 10dbabd05..44a287b68 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -240,13 +240,17 @@ class Torrent: # We do not want to report peers that are half-connected if peer.flags & peer.connecting: continue + try: + client = str(peer.client).decode("utf-8") + except UnicodeDecodeError: + client = str(peer.client).decode("latin-1") ret.append({ "ip": "%s:%s" % (peer.ip[0], peer.ip[1]), "up_speed": peer.up_speed, "down_speed": peer.down_speed, "country": deluge.xmlrpclib.Binary(peer.country), - "client": deluge.xmlrpclib.Binary(peer.client), + "client": client }) return ret diff --git a/deluge/ui/gtkui/peers_tab.py b/deluge/ui/gtkui/peers_tab.py index 6a18905b9..30822d1de 100644 --- a/deluge/ui/gtkui/peers_tab.py +++ b/deluge/ui/gtkui/peers_tab.py @@ -35,6 +35,7 @@ import gtk, gtk.glade import os.path import cPickle import pkg_resources +from itertools import izip from deluge.ui.client import aclient as client from deluge.configmanager import ConfigManager @@ -56,7 +57,7 @@ class PeersTab: glade = component.get("MainWindow").get_glade() self.listview = glade.get_widget("peers_listview") # country pixbuf, ip, client, progress, progress, downspeed, upspeed, country code - self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, str, int, int, str) + self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, str, int, int, str, int) self.cached_flag_pixbufs = {} # Country column @@ -77,7 +78,7 @@ class PeersTab: render = gtk.CellRendererText() column.pack_start(render, False) column.add_attribute(render, "text", 1) - column.set_sort_column_id(1) + column.set_sort_column_id(6) column.set_clickable(True) column.set_resizable(True) column.set_expand(False) @@ -222,16 +223,21 @@ class PeersTab: return None return self.cached_flag_pixbufs[country] + def _on_get_torrent_status(self, status): self.liststore.clear() for peer in status["peers"]: + # Create an int IP address for sorting purposes + ip_int = sum([int(byte) << shift + for byte, shift in izip(peer["ip"].split(":")[0].split("."), (24, 16, 8, 0))]) self.liststore.append([ self.get_flag_pixbuf(peer["country"]), peer["ip"], - peer["client"], + peer["client"], peer["down_speed"], peer["up_speed"], - peer["country"]]) + peer["country"], + ip_int]) def clear(self): self.liststore.clear()