diff frontends/wix/main_window.py @ 54:2ce9e350cdf9

Wix: clicking on group in contact_list now (un)hide it. Quick App: added a method to get all contacts in a group in contact_management
author Goffi <goffi@goffi.org>
date Sun, 10 Jan 2010 17:25:43 +1100
parents 6dfe5bb10008
children 20e54702fc0b
line wrap: on
line diff
--- a/frontends/wix/main_window.py	Sun Jan 10 16:42:09 2010 +1100
+++ b/frontends/wix/main_window.py	Sun Jan 10 17:25:43 2010 +1100
@@ -79,7 +79,7 @@
         self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated)
 
     def __find_idx(self, entity, reverse=False):
-        """Find indexes of given jid in contact list
+        """Find indexes of given jid (or groups) in contact list
         @return: list of indexes"""
         result=[]
         for i in range(self.GetCount()):
@@ -98,10 +98,23 @@
 
     def disconnect(self, jid):
         self.remove(jid) #for now, we only show online contacts
+    
+    def __eraseGroup(self, group):
+        """Erase all contacts in group
+        @param group: group to erase
+        @return: True if something as been erased"""
+        erased = False
+        indexes = self.__find_idx(group)
+        for idx in indexes:
+            while idx<self.GetCount()-1 and type(self.GetClientData(idx+1)) == JID:
+                erased = True
+                self.Delete(idx+1)
+        return erased
+
 
     def __presentGroup(self, group):
         """Make a nice presentation for the contact groups"""
-        html = """[%s]""" % group
+        html = """-- [%s] --""" % group
 
         return html
 
@@ -172,7 +185,14 @@
         if type(data) == JID:
             event.Skip()
         else:
-            #We don't want to select groups
+            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.sort()
+                id_insert = self.GetSelection()+1
+                for contact in contacts:
+                    self.Insert(self.__presentItem(contact), id_insert, contact)
             self.SetSelection(wx.NOT_FOUND)
             event.Skip(False)
     
@@ -185,8 +205,10 @@
     def getSelection(self):
         """Return the selected contact, or an empty string if there is not"""
         if self.GetSelection() == wx.NOT_FOUND:
-            return ""  #FIXME: gof: à améliorer
+            return None
         data = self.GetClientData(self.GetSelection())
+        if type(data) != JID:
+            return None
         return data
 
     def registerActivatedCB(self, cb):