diff frontends/src/wix/contact_list.py @ 501:e9634d2e7b38

core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1: - QuickContactManagement is not used anymore and will be removed, ContactList + Core are used instead - disconnected contacts are now displayed in Primitivus (M-d to show/hide them) - avatars are temporary unavailable in wix - new bridge method: getContactsFromGroup
author Goffi <goffi@goffi.org>
date Tue, 25 Sep 2012 00:58:34 +0200
parents 2a072735e459
children debcf5dd404a
line wrap: on
line diff
--- a/frontends/src/wix/contact_list.py	Wed Sep 05 00:19:32 2012 +0200
+++ b/frontends/src/wix/contact_list.py	Tue Sep 25 00:58:34 2012 +0200
@@ -44,7 +44,7 @@
                                            "CUSTOM" for a customized contact list (self.__presentItem must then be overrided)
         """
         wx.SimpleHtmlListBox.__init__(self, parent, -1)
-        QuickContactList.__init__(self, host.CM)
+        QuickContactList.__init__(self)
         self.host = host
         self.type = type
         self.__typeSwitch()
@@ -72,17 +72,19 @@
                 result.append(i)
         return result
 
-    def replace(self, contact, groups=None):
+    def update_jid(self, jid):
+        self.replace(jid)
+
+    def replace(self, contact, groups=None, attributes=None):
         debug(_("update %s") % contact)
         if not self.__find_idx(contact):
             self.add(contact, groups)
         else:
             for i in self.__find_idx(contact):
-                self.SetString(i, self.__presentItem(contact))
+                _present = self.__presentItem(contact)
+                if _present != None:
+                    self.SetString(i, _present)
 
-    def disconnect(self, contact):
-        self.remove(contact) #for now, we only show online contacts
-    
     def __eraseGroup(self, group):
         """Erase all contacts in group
         @param group: group to erase
@@ -108,15 +110,19 @@
     
     def __presentItemJID(self, jid):
         """Make a nice presentation of the contact in the list for JID contacts."""
-        name = self.CM.getAttr(jid,'name')
-        nick = self.CM.getAttr(jid,'nick')
-        show =  filter(lambda x:x[0]==self.CM.getAttr(jid,'show'), const_STATUS)[0]
+        name = self.getCache(jid,'name')
+        nick = self.getCache(jid,'nick')
+        _show = self.getCache(jid,'show')
+        if _show == None or _show == 'unavailable':
+            return None
+        show =  filter(lambda x : x[0] == _show, const_STATUS)[0]
+            
         #show[0]==shortcut
         #show[1]==human readable
         #show[2]==color (or None)
         show_html = "<font color='%s'>[%s]</font>" % (show[2], show[1]) if show[2] else ""
-        status = self.CM.getAttr(jid,'status') or ''
-        avatar = self.CM.getAttr(jid,'avatar') or self.empty_avatar #XXX: there is a weird bug here: if the image has an extension (i.e. empty_avatar.png),
+        status = self.getCache(jid,'status') or ''
+        avatar = self.getCache(jid,'avatar') or self.empty_avatar #XXX: there is a weird bug here: if the image has an extension (i.e. empty_avatar.png),
         #WxPython segfault, and it doesn't without nothing. I couldn't reproduce the case with a basic test script, so it need further investigation before reporting it
         #to WxPython dev. Anyway, the program crash with a segfault, not a python exception, so there is definitely something wrong with WxPython.
         #The case seems to happen when SimpleHtmlListBox parse the HTML with the <img> tag
@@ -138,7 +144,7 @@
 
         return html
 
-    def clear_contacts(self):
+    def clearContacts(self):
         """Clear all the contact list"""
         self.Clear()
 
@@ -146,7 +152,9 @@
         """add a contact to the list"""
         debug (_("adding %s"),contact)
         if not groups:
-            idx = self.Insert(self.__presentItem(contact), 0, contact)
+            _present =  self.__presentItem(contact)
+            if _present:
+                idx = self.Insert(_present, 0, contact)
         else:
             for group in groups:
                 indexes = self.__find_idx(group)
@@ -156,7 +164,9 @@
                 else:
                     gp_idx = indexes[0]
                 
-                self.Insert(self.__presentItem(contact), gp_idx+1, contact)
+                _present = self.__presentItem(contact)
+                if _present:
+                    self.Insert(_present, gp_idx+1, contact)
 
 
 
@@ -176,11 +186,13 @@
             group = self.GetClientData(self.GetSelection())
             erased = self.__eraseGroup(group)
             if not erased: #the group was already erased, we can add again the contacts
-                contacts = self.CM.getContFromGroup(group)
+                contacts = [JID(contact) for contact in self.host.bridge.getContactsFromGroup(group, self.host.profile)]
                 contacts.sort()
                 id_insert = self.GetSelection()+1
                 for contact in contacts:
-                    self.Insert(self.__presentItem(contact), id_insert, contact)
+                    _present =  self.__presentItem(contact)
+                    if _present:
+                        self.Insert(_present, id_insert, contact)
             self.SetSelection(wx.NOT_FOUND)
             self.ScrollToLine(first_visible)
             event.Skip(False)