comparison 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
comparison
equal deleted inserted replaced
500:00d3679976ab 501:e9634d2e7b38
42 @param host: wix main app class 42 @param host: wix main app class
43 @param type: type of contact list: "JID" for the usual big jid contact list 43 @param type: type of contact list: "JID" for the usual big jid contact list
44 "CUSTOM" for a customized contact list (self.__presentItem must then be overrided) 44 "CUSTOM" for a customized contact list (self.__presentItem must then be overrided)
45 """ 45 """
46 wx.SimpleHtmlListBox.__init__(self, parent, -1) 46 wx.SimpleHtmlListBox.__init__(self, parent, -1)
47 QuickContactList.__init__(self, host.CM) 47 QuickContactList.__init__(self)
48 self.host = host 48 self.host = host
49 self.type = type 49 self.type = type
50 self.__typeSwitch() 50 self.__typeSwitch()
51 self.groups = {} #list contacts in each groups, key = group 51 self.groups = {} #list contacts in each groups, key = group
52 self.empty_avatar = join(host.media_dir, 'misc/empty_avatar') 52 self.empty_avatar = join(host.media_dir, 'misc/empty_avatar')
70 if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).short == entity.short) or\ 70 if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).short == entity.short) or\
71 self.GetClientData(i) == entity: 71 self.GetClientData(i) == entity:
72 result.append(i) 72 result.append(i)
73 return result 73 return result
74 74
75 def replace(self, contact, groups=None): 75 def update_jid(self, jid):
76 self.replace(jid)
77
78 def replace(self, contact, groups=None, attributes=None):
76 debug(_("update %s") % contact) 79 debug(_("update %s") % contact)
77 if not self.__find_idx(contact): 80 if not self.__find_idx(contact):
78 self.add(contact, groups) 81 self.add(contact, groups)
79 else: 82 else:
80 for i in self.__find_idx(contact): 83 for i in self.__find_idx(contact):
81 self.SetString(i, self.__presentItem(contact)) 84 _present = self.__presentItem(contact)
82 85 if _present != None:
83 def disconnect(self, contact): 86 self.SetString(i, _present)
84 self.remove(contact) #for now, we only show online contacts 87
85
86 def __eraseGroup(self, group): 88 def __eraseGroup(self, group):
87 """Erase all contacts in group 89 """Erase all contacts in group
88 @param group: group to erase 90 @param group: group to erase
89 @return: True if something as been erased""" 91 @return: True if something as been erased"""
90 erased = False 92 erased = False
106 """Make a basic presentation of string contacts in the list.""" 108 """Make a basic presentation of string contacts in the list."""
107 return contact 109 return contact
108 110
109 def __presentItemJID(self, jid): 111 def __presentItemJID(self, jid):
110 """Make a nice presentation of the contact in the list for JID contacts.""" 112 """Make a nice presentation of the contact in the list for JID contacts."""
111 name = self.CM.getAttr(jid,'name') 113 name = self.getCache(jid,'name')
112 nick = self.CM.getAttr(jid,'nick') 114 nick = self.getCache(jid,'nick')
113 show = filter(lambda x:x[0]==self.CM.getAttr(jid,'show'), const_STATUS)[0] 115 _show = self.getCache(jid,'show')
116 if _show == None or _show == 'unavailable':
117 return None
118 show = filter(lambda x : x[0] == _show, const_STATUS)[0]
119
114 #show[0]==shortcut 120 #show[0]==shortcut
115 #show[1]==human readable 121 #show[1]==human readable
116 #show[2]==color (or None) 122 #show[2]==color (or None)
117 show_html = "<font color='%s'>[%s]</font>" % (show[2], show[1]) if show[2] else "" 123 show_html = "<font color='%s'>[%s]</font>" % (show[2], show[1]) if show[2] else ""
118 status = self.CM.getAttr(jid,'status') or '' 124 status = self.getCache(jid,'status') or ''
119 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), 125 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),
120 #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 126 #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
121 #to WxPython dev. Anyway, the program crash with a segfault, not a python exception, so there is definitely something wrong with WxPython. 127 #to WxPython dev. Anyway, the program crash with a segfault, not a python exception, so there is definitely something wrong with WxPython.
122 #The case seems to happen when SimpleHtmlListBox parse the HTML with the <img> tag 128 #The case seems to happen when SimpleHtmlListBox parse the HTML with the <img> tag
123 129
124 html = """ 130 html = """
136 show_html, 142 show_html,
137 escape(status)) 143 escape(status))
138 144
139 return html 145 return html
140 146
141 def clear_contacts(self): 147 def clearContacts(self):
142 """Clear all the contact list""" 148 """Clear all the contact list"""
143 self.Clear() 149 self.Clear()
144 150
145 def add(self, contact, groups = None): 151 def add(self, contact, groups = None):
146 """add a contact to the list""" 152 """add a contact to the list"""
147 debug (_("adding %s"),contact) 153 debug (_("adding %s"),contact)
148 if not groups: 154 if not groups:
149 idx = self.Insert(self.__presentItem(contact), 0, contact) 155 _present = self.__presentItem(contact)
156 if _present:
157 idx = self.Insert(_present, 0, contact)
150 else: 158 else:
151 for group in groups: 159 for group in groups:
152 indexes = self.__find_idx(group) 160 indexes = self.__find_idx(group)
153 gp_idx = 0 161 gp_idx = 0
154 if not indexes: #this is a new group, we have to create it 162 if not indexes: #this is a new group, we have to create it
155 gp_idx = self.Append(self.__presentGroup(group), Group(group)) 163 gp_idx = self.Append(self.__presentGroup(group), Group(group))
156 else: 164 else:
157 gp_idx = indexes[0] 165 gp_idx = indexes[0]
158 166
159 self.Insert(self.__presentItem(contact), gp_idx+1, contact) 167 _present = self.__presentItem(contact)
168 if _present:
169 self.Insert(_present, gp_idx+1, contact)
160 170
161 171
162 172
163 def remove(self, contact): 173 def remove(self, contact):
164 """remove a contact from the list""" 174 """remove a contact from the list"""
174 if data == None: #we have a group 184 if data == None: #we have a group
175 first_visible = self.GetVisibleBegin() 185 first_visible = self.GetVisibleBegin()
176 group = self.GetClientData(self.GetSelection()) 186 group = self.GetClientData(self.GetSelection())
177 erased = self.__eraseGroup(group) 187 erased = self.__eraseGroup(group)
178 if not erased: #the group was already erased, we can add again the contacts 188 if not erased: #the group was already erased, we can add again the contacts
179 contacts = self.CM.getContFromGroup(group) 189 contacts = [JID(contact) for contact in self.host.bridge.getContactsFromGroup(group, self.host.profile)]
180 contacts.sort() 190 contacts.sort()
181 id_insert = self.GetSelection()+1 191 id_insert = self.GetSelection()+1
182 for contact in contacts: 192 for contact in contacts:
183 self.Insert(self.__presentItem(contact), id_insert, contact) 193 _present = self.__presentItem(contact)
194 if _present:
195 self.Insert(_present, id_insert, contact)
184 self.SetSelection(wx.NOT_FOUND) 196 self.SetSelection(wx.NOT_FOUND)
185 self.ScrollToLine(first_visible) 197 self.ScrollToLine(first_visible)
186 event.Skip(False) 198 event.Skip(False)
187 else: 199 else:
188 event.Skip() 200 event.Skip()