changeset 53:6dfe5bb10008

Wix: groups in contact list, first draft
author Goffi <goffi@goffi.org>
date Sun, 10 Jan 2010 16:42:09 +1100
parents 6455fb62ff83
children 2ce9e350cdf9
files frontends/quick_frontend/quick_app.py frontends/wix/main_window.py
diffstat 2 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_app.py	Thu Jan 07 01:55:30 2010 +1100
+++ b/frontends/quick_frontend/quick_app.py	Sun Jan 10 16:42:09 2010 +1100
@@ -117,12 +117,11 @@
 
         if show != 'unavailable':
             name=""
-            group=""
+            groups = []
             if self.rosterList.has_key(from_jid.short):
                 if self.rosterList[from_jid.short][0].has_key("name"):
                     name=self.rosterList[from_jid.short][0]["name"]
-                if len(self.rosterList[from_jid.short][1]):
-                    group=self.rosterList[from_jid.short][1][0]
+                groups=self.rosterList[from_jid.short][1]
 
             #FIXME: must be moved in a plugin
             if from_jid.short in self.watched and not from_jid.short in self.onlineContact:
@@ -133,7 +132,7 @@
             self.CM.update(from_jid, 'name', name)
             self.CM.update(from_jid, 'show', show)
             self.CM.update(from_jid, 'statuses', statuses)
-            self.CM.update(from_jid, 'group', group)
+            self.CM.update(from_jid, 'groups', groups)
             cache = self.bridge.getProfileCache(from_jid)
             if cache.has_key('nick'): 
                 self.CM.update(from_jid, 'nick', cache['nick'])
@@ -188,8 +187,6 @@
             pass
 
     def updatedValue(self, name, data):
-        print "toto"
-        print "updatedValue", name, data
         if name == "profile_nick":
             target = JID(data['jid'])
             self.CM.update(target, 'nick', data['nick'])
--- a/frontends/wix/main_window.py	Thu Jan 07 01:55:30 2010 +1100
+++ b/frontends/wix/main_window.py	Sun Jan 10 16:42:09 2010 +1100
@@ -74,14 +74,17 @@
         wx.SimpleHtmlListBox.__init__(self, parent, -1)
         QuickContactList.__init__(self, CM)
         self.host = parent
+        self.groups = {}  #list contacts in each groups, key = group
+        self.Bind(wx.EVT_LISTBOX, self.onSelected)
         self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated)
 
-    def __find_idx(self, jid, reverse=False):
+    def __find_idx(self, entity, reverse=False):
         """Find indexes of given jid in contact list
         @return: list of indexes"""
         result=[]
         for i in range(self.GetCount()):
-            if self.GetClientData(i).short == jid.short:
+            if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).short == entity.short) or\
+                self.GetClientData(i) == entity:
                 result.append(i)
         return result
 
@@ -96,6 +99,12 @@
     def disconnect(self, jid):
         self.remove(jid) #for now, we only show online contacts
 
+    def __presentGroup(self, group):
+        """Make a nice presentation for the contact groups"""
+        html = """[%s]""" % group
+
+        return html
+
     def __presentItem(self, jid):
         """Make a nice presentation of the contact in the list."""
         name = self.CM.getAttr(jid,'name')
@@ -133,9 +142,21 @@
     def add(self, jid):
         """add a contact to the list"""
         debug ("adding %s",jid)
-        idx = self.Append(self.__presentItem(jid))
+        groups = self.CM.getAttr(jid, 'groups')
+        if not groups:
+            idx = self.Append(self.__presentItem(jid), jid)
+        else:
+            for group in groups:
+                indexes = self.__find_idx(group)
+                gp_idx = 0
+                if not indexes:  #this is a new group, we have to create it
+                    gp_idx = self.Append(self.__presentGroup(group), group)
+                else:
+                    gp_idx = indexes[0]
 
-        self.SetClientData(idx, jid)
+                self.Insert(self.__presentItem(jid), gp_idx+1, jid)
+
+
 
     def remove(self, jid):
         """remove a contact from the list"""
@@ -145,6 +166,16 @@
         for i in list_idx:
             self.Delete(i)
 
+    def onSelected(self, event):
+        """Called when a contact is selected."""
+        data = self.getSelection()
+        if type(data) == JID:
+            event.Skip()
+        else:
+            #We don't want to select groups
+            self.SetSelection(wx.NOT_FOUND)
+            event.Skip(False)
+    
     def onActivated(self, event):
         """Called when a contact is clicked or activated with keyboard."""
         data = self.getSelection()