Wix: groups in contact list, first draft

This commit is contained in:
Goffi 2010-01-10 16:42:09 +11:00
commit 6a1039a083
2 changed files with 38 additions and 10 deletions

View file

@ -117,12 +117,11 @@ class QuickApp():
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 @@ class QuickApp():
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 @@ class QuickApp():
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'])

View file

@ -74,14 +74,17 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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.Insert(self.__presentItem(jid), gp_idx+1, jid)
self.SetClientData(idx, jid)
def remove(self, jid):
"""remove a contact from the list"""
@ -145,6 +166,16 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
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()