comparison frontends/src/quick_frontend/quick_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
17 17
18 You should have received a copy of the GNU Affero General Public License 18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from logging import debug, info, error 22 from logging import debug
23 from sat.tools.jid import JID
24 23
25 24
26 class QuickContactList(): 25 class QuickContactList():
27 """This class manage the visual representation of contacts""" 26 """This class manage the visual representation of contacts"""
28 27
29 def __init__(self, CM): 28 def __init__(self):
30 """
31 @param CM: instance of QuickContactManagement
32 """
33 debug(_("Contact List init")) 29 debug(_("Contact List init"))
34 self.CM = CM 30 self._cache = {}
31
32 def update_jid(self, jid):
33 """Update the jid in the list when something changed"""
34 raise NotImplementedError
35
36 def getCache(self, jid, name):
37 try:
38 jid_cache = self._cache[jid.short]
39 if name == 'status': #XXX: we get the first status for 'status' key
40 return jid_cache['statuses'].get('default','')
41 return jid_cache[name]
42 except (KeyError, IndexError):
43 return None
44
45 def setCache(self, jid, name, value):
46 jid_cache = self._cache.setdefault(jid.short, {})
47 jid_cache[name] = value
35 48
36 def __contains__(self, jid): 49 def __contains__(self, jid):
37 raise NotImplementedError 50 raise NotImplementedError
38 51
39 def clear_contacts(self, jid): 52 def clearContacts(self, jid):
40 """Clear all the contact list""" 53 """Clear all the contact list"""
41 raise NotImplementedError 54 raise NotImplementedError
42 55
43 def replace(self, jid, groups=None): 56 def _replace(self, jid, groups=None, attributes=None):
57 if 'name' in attributes:
58 self.setCache(jid, 'name', attributes['name'])
59 self.replace(jid, groups, attributes)
60
61 def replace(self, jid, groups, attributes):
44 """add a contact to the list if doesn't exist, else update it""" 62 """add a contact to the list if doesn't exist, else update it"""
45 raise NotImplementedError
46
47 def disconnect(self, jid):
48 """mark a contact disconnected"""
49 raise NotImplementedError 63 raise NotImplementedError
50 64
51 def remove(self, jid): 65 def remove(self, jid):
52 """remove a contact from the list""" 66 """remove a contact from the list"""
53 raise NotImplementedError 67 raise NotImplementedError
54 68
55 def add(self, jid, param_groups=None): 69 def add(self, jid, param_groups=None):
56 """add a contact to the list""" 70 """add a contact to the list"""
57 raise NotImplementedError 71 raise NotImplementedError
72
73 def updatePresence(self, jid, show, priority, statuses):
74 """Update entity's presence status
75 @param jid: entity to update's jid
76 @param show: availability
77 @parap priority: resource's priority
78 @param statuses: dict of statuses"""
79 self.setCache(jid, 'show', show)
80 self.setCache(jid, 'prority', priority)
81 self.setCache(jid, 'statuses', statuses)
82 self.update_jid(jid)