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
This commit is contained in:
Goffi 2010-01-10 17:25:43 +11:00
commit b243054e9b
2 changed files with 36 additions and 5 deletions

View file

@ -42,7 +42,16 @@ class QuickContactManagement():
if entity.resource in self.__contactlist[entity.short]['resources']:
self.__contactlist[entity.short]['resources'].remove(entity.resource)
self.__contactlist[entity.short]['resources'].append(entity.resource)
def getContFromGroup(self, group):
"""Return all contacts which are in given group"""
result = []
for contact in self.__contactlist:
if self.__contactlist[contact].has_key('groups'):
if group in self.__contactlist[contact]['groups']:
result.append(JID(contact))
return result
def getAttr(self, entity, name):
"""Return a specific attribute of contact, or all attributes
@param entity: jid of the contact

View file

@ -79,7 +79,7 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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):