comparison src/browser/sat_browser/contact_panel.py @ 687:3845a086f0b3

browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend: - Chat uses presence and avatar listener, remove unecessary methods for MUC and contact states - contact list doesn't add unecessary ContactBox (e.g for MUC bare entities) - nick, message alerts are handled directly in ContactLabel
author souliane <souliane@mailoo.org>
date Mon, 23 Mar 2015 09:35:46 +0100
parents 9877607c719a
children 7a9c7b9f6a28
comparison
equal deleted inserted replaced
686:90a5a5af2550 687:3845a086f0b3
90 # the display doesn't change 90 # the display doesn't change
91 return 91 return
92 self.clear() 92 self.clear()
93 for contact_jid in jids: 93 for contact_jid in jids:
94 assert isinstance(contact_jid, jid.JID) 94 assert isinstance(contact_jid, jid.JID)
95 self.addContact(contact_jid) 95 self.updateContactBox(contact_jid)
96 96
97 def getContactBox(self, contact_jid): 97 def getContactBox(self, contact_jid):
98 """Get a contact box for a contact, add it if it doesn't exist yet. 98 """Get the contact box for the given contact.
99
100 @param contact_jid (jid.JID): contact JID
101 @return: ContactBox or None
102 """
103 try:
104 return self._contacts[self._key(contact_jid)]
105 except KeyError:
106 return None
107
108 def updateContactBox(self, contact_jid):
109 """Add a contact or update it if it already exists.
99 110
100 @param contact_jid (jid.JID): contact JID 111 @param contact_jid (jid.JID): contact JID
101 @return: ContactBox 112 @return: ContactBox
102 """ 113 """
103 try: 114 box = self.getContactBox(contact_jid)
104 return self._contacts[self._key(contact_jid)] 115 if box:
105 except KeyError: 116 box.update()
106 box = contact_widget.ContactBox(self.host, contact_jid, 117 else:
118 entity = contact_jid.bare if self.merge_resources else contact_jid
119 box = contact_widget.ContactBox(self.host, entity,
107 style_name=self.contacts_style, 120 style_name=self.contacts_style,
108 display=self.contacts_display, 121 display=self.contacts_display,
109 plugin_menu_context=self.contacts_menus) 122 plugin_menu_context=self.contacts_menus)
110 self._contacts[self._key(contact_jid)] = box 123 self._contacts[self._key(contact_jid)] = box
111 return box 124 VerticalPanel.append(self, box)
125 return box
112 126
113 def addContact(self, contact_jid): 127 def removeContactBox(self, contact_jid):
114 """Add a contact to the list. 128 """Remove a contact.
115 129
116 @param contact_jid (jid.JID): contact JID 130 @param contact_jid (jid.JID): contact JID
117 """ 131 """
118 box = self.getContactBox(contact_jid) 132 box = self._contacts.pop(self._key(contact_jid), None)
119 if box not in self.children: 133 if box:
120 VerticalPanel.append(self, box) 134 VerticalPanel.remove(self, box)
121
122 def removeContact(self, contact_jid):
123 """Remove a contact from the list.
124
125 @param contact_jid (jid.JID): contact JID
126 """
127 box = self._contacts.pop(self._key(contact_jid))
128 VerticalPanel.remove(self, box)
129
130 def updateAvatar(self, contact_jid, url):
131 """Update the avatar of the given contact
132
133 @param contact_jid (jid.JID): contact JID
134 @param url (unicode): image url
135 """
136 self.getContactBox(contact_jid).updateAvatar(url)
137
138 def updateNick(self, contact_jid, new_nick):
139 """Update the avatar of the given contact.
140
141 @param contact_jid (jid.JID): contact JID
142 @param new_nick (unicode): new nick of the contact
143 """
144 self.getContactBox(contact_jid).updateNick(new_nick)
145
146 def setPresence(self, entity, show):
147 """Update entity's presence.
148
149 @param entity(jid.JID): entity updated
150 @param show: availability
151 """
152 if self.merge_resources: # we use cache to have the show information of main resource only
153 clist = self.host.contact_list
154 show = clist.getCache(entity.bare, C.PRESENCE_SHOW)
155 if show is None:
156 show = C.PRESENCE_UNAVAILABLE
157 html_tools.setPresenceStyle(self.getContactBox(entity).label, show)