comparison src/browser/sat_browser/contact_panel.py @ 695:e86490a7c76e

browser_side: don't rebuild the whole list on contact list update
author souliane <souliane@mailoo.org>
date Sun, 19 Apr 2015 13:10:41 +0200
parents 7a9c7b9f6a28
children 102bab805ec1
comparison
equal deleted inserted replaced
694:82123705474b 695:e86490a7c76e
82 """set all contacts in the list in one shot. 82 """set all contacts in the list in one shot.
83 83
84 @param jids (list[jid.JID]): jids to display (the order is kept) 84 @param jids (list[jid.JID]): jids to display (the order is kept)
85 @param name (unicode): optional name of the contact 85 @param name (unicode): optional name of the contact
86 """ 86 """
87 # FIXME: we do a full clear and add boxes after, we should only remove recently hidden boxes and add new ones, and re-order 87 current_jids = [box.jid for box in self.children if isinstance(box, contact_widget.ContactBox)]
88 current = [box.jid for box in self.children if isinstance(box, contact_widget.ContactBox)] 88 if current_jids == jids:
89 if current == jids:
90 # the display doesn't change 89 # the display doesn't change
91 return 90 return
92 self.clear() 91 for contact_jid in set(current_jids).difference(jids):
92 self.removeContactBox(contact_jid)
93 current_index = 0
94 insert_count = 0
93 for contact_jid in jids: 95 for contact_jid in jids:
96 try:
97 if current_jids[current_index] == contact_jid:
98 current_index += 1
99 continue
100 except IndexError:
101 pass
94 assert isinstance(contact_jid, jid.JID) 102 assert isinstance(contact_jid, jid.JID)
95 self.updateContactBox(contact_jid) 103 self.updateContactBox(contact_jid, current_index + insert_count)
104 insert_count += 1
96 105
97 def getContactBox(self, contact_jid): 106 def getContactBox(self, contact_jid):
98 """Get the contact box for the given contact. 107 """Get the contact box for the given contact.
99 108
100 @param contact_jid (jid.JID): contact JID 109 @param contact_jid (jid.JID): contact JID
103 try: 112 try:
104 return self._contacts[self._key(contact_jid)] 113 return self._contacts[self._key(contact_jid)]
105 except KeyError: 114 except KeyError:
106 return None 115 return None
107 116
108 def updateContactBox(self, contact_jid): 117 def updateContactBox(self, contact_jid, index=None):
109 """Add a contact or update it if it already exists. 118 """Add a contact or update it if it already exists.
110 119
111 @param contact_jid (jid.JID): contact JID 120 @param contact_jid (jid.JID): contact JID
121 @param index (int): insertion index if the contact is added
112 @return: ContactBox 122 @return: ContactBox
113 """ 123 """
114 box = self.getContactBox(contact_jid) 124 box = self.getContactBox(contact_jid)
115 if box: 125 if box:
116 box.update() 126 box.update()
119 box = contact_widget.ContactBox(self.host, entity, 129 box = contact_widget.ContactBox(self.host, entity,
120 style_name=self.contacts_style, 130 style_name=self.contacts_style,
121 display=self.contacts_display, 131 display=self.contacts_display,
122 plugin_menu_context=self.contacts_menus) 132 plugin_menu_context=self.contacts_menus)
123 self._contacts[self._key(contact_jid)] = box 133 self._contacts[self._key(contact_jid)] = box
124 VerticalPanel.append(self, box) 134 if index:
135 VerticalPanel.insert(self, box, index)
136 else:
137 VerticalPanel.append(self, box)
125 return box 138 return box
126 139
127 def removeContactBox(self, contact_jid): 140 def removeContactBox(self, contact_jid):
128 """Remove a contact. 141 """Remove a contact.
129 142