comparison src/browser/sat_browser/contact_list.py @ 600:32dbbc941123 frontends_multi_profiles

browser_side: fixes the contact group manager
author souliane <souliane@mailoo.org>
date Fri, 06 Feb 2015 17:53:01 +0100
parents a099990f77a6
children 49ccfc22116c 7af8f4ab3675
comparison
equal deleted inserted replaced
599:a6b9809b9a68 600:32dbbc941123
254 def getContactBox(self, contact_jid): 254 def getContactBox(self, contact_jid):
255 """get the widget of a contact 255 """get the widget of a contact
256 256
257 @param contact_jid (jid.JID): the contact 257 @param contact_jid (jid.JID): the contact
258 @return: ContactBox instance if present, else None""" 258 @return: ContactBox instance if present, else None"""
259 assert isinstance(contact_jid, jid.JID)
259 for wid in self: 260 for wid in self:
260 if isinstance(wid, ContactBox) and wid.jid == contact_jid: 261 if isinstance(wid, ContactBox) and wid.jid == contact_jid:
261 return wid 262 return wid
262 return None 263 return None
263 264
583 # log.warning('No box for group %s: this code line should not be reached' % group) 584 # log.warning('No box for group %s: this code line should not be reached' % group)
584 585
585 # def refresh(self): 586 # def refresh(self):
586 # """Show or hide disconnected contacts and empty groups""" 587 # """Show or hide disconnected contacts and empty groups"""
587 # self.updateVisibility(self._contacts_panel.contacts, self.groups.keys()) 588 # self.updateVisibility(self._contacts_panel.contacts, self.groups.keys())
589
590
591 def mayContainJID(iterable, item):
592 """Tells if the given item is in the iterable, works with JID.
593
594 @param iterable(object): list, set or another iterable object
595 @param item (object): element
596 @return: bool
597 """
598 # Pyjamas JID-friendly implementation of the "in" operator. Since our JID
599 # doesn't inherit from str, without this method the test would return True
600 # only when the objects references are the same.
601 if isinstance(item, jid.JID):
602 return hash(item) in [hash(other) for other in iterable if isinstance(other, jid.JID)]
603 return super(type(iterable), iterable).__contains__(self, item)
604
605
606 class JIDSet(set):
607 """JID set implementation for Pyjamas"""
608
609 def __contains__(self, item):
610 return mayContainJID(self, item)
611
612
613 class JIDList(list):
614 """JID list implementation for Pyjamas"""
615
616 def __contains__(self, item):
617 return mayContainJID(self, item)
618
619
620 class JIDDict(dict):
621 """JID dict implementation for Pyjamas (a dict with JID keys)"""
622
623 def __contains__(self, item):
624 return mayContainJID(self, item)
625
626 def keys(self):
627 return JIDSet(dict.keys(self))