From c8f701b551c8648e627c96dc8a945ee6519f4662 Mon Sep 17 00:00:00 2001 From: Zach Tibbitts Date: Mon, 12 Feb 2007 20:41:06 +0000 Subject: [PATCH] partial fix for peer_view bug --- src/delugegtk.py | 66 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/delugegtk.py b/src/delugegtk.py index 7e78e685b..9b633955f 100755 --- a/src/delugegtk.py +++ b/src/delugegtk.py @@ -379,6 +379,9 @@ class DelugeGTK(dbus.service.Object): self.store.remove(itr) if not self.store.iter_is_valid(itr): itr = None + + self.saved_peer_info = None + if tab == 0: #Details Pane try: state = self.manager.get_torrent_state(self.get_selected_torrent()) @@ -404,13 +407,62 @@ class DelugeGTK(dbus.service.Object): #self.text_summary_compact_allocation.set_text(str(state[""])) self.text_summary_eta.set_text(dcommon.estimate_eta(state)) elif tab == 1: #Peers List - uid = self.get_selected_torrent() - self.peer_store.clear() - peer_data = self.manager.get_torrent_peer_info(uid) - for peer in peer_data: - # ip client percent dl ul - self.peer_store.append([peer["ip"], unicode(peer["client"], 'Latin-1'), peer["peer_has"], - peer["download_speed"], peer["upload_speed"]]) + unique_id = self.get_selected_torrent() + + if self.saved_peer_info is None: + self.saved_peer_info = self.manager.get_torrent_peer_info(unique_id) + + + new_peer_info = self.saved_peer_info + + new_ips = {} + + for index in range(len(new_peer_info)): + if not new_peer_info[index]['client'] == "": + assert(new_peer_info[index]['ip'] not in new_ips.keys()) + new_ips[new_peer_info[index]['ip']] = index + + def biographer(model, path, iter, dictionary): + assert(model.get_value(iter, 0) not in dictionary.keys()) + dictionary[model.get_value(iter, 0)] = model.get_string_from_iter(iter) + + class remover_data: + def __init__(self, new_ips): + self.new_ips = new_ips + self.removed = False + + def remover(model, path, iter, data): + if model.get_value(iter, 0) not in data.new_ips: + model.remove(iter) + data.removed = True + return True + else: + return False + + while True: + data = remover_data(new_ips.keys()) + self.peer_store.foreach(remover, data) + if not data.removed: + break + + curr_ips = {} + + self.peer_store.foreach(biographer, curr_ips) + + assert(self.peer_store.iter_n_children(None) == len(curr_ips.keys())) + + for peer in new_peer_info: + if peer['ip'] in curr_ips.keys(): + self.peer_store.set(self.peer_store.get_iter_from_string(curr_ips[peer['ip']]), + 1, unicode(peer['client'], 'Latin-1'), + 2, peer['peer_has'], + 3, peer['download_speed'], + 4, peer['upload_speed']) + for peer in new_peer_info: + if peer['ip'] not in curr_ips.keys() and peer['client'] is not "": + self.peer_store.append([peer["ip"], unicode(peer["client"], 'Latin-1'), peer["peer_has"], + peer["download_speed"], peer["upload_speed"]]) + elif tab == 2: #File List pass else: