comparison frontends/src/quick_frontend/quick_contact_management.py @ 688:f7878ad3c846

tools: renamed tools.jid.JID attribute "short" to "bare"
author souliane <souliane@mailoo.org>
date Tue, 29 Oct 2013 16:26:55 +0100
parents 84a6e83157c2
children bfabeedbf32e
comparison
equal deleted inserted replaced
687:af0d08a84cc6 688:f7878ad3c846
28 28
29 def __init__(self): 29 def __init__(self):
30 self.__contactlist = {} 30 self.__contactlist = {}
31 31
32 def __contains__(self, entity): 32 def __contains__(self, entity):
33 return entity.short in self.__contactlist 33 return entity.bare in self.__contactlist
34 34
35 def clear(self): 35 def clear(self):
36 """Clear all the contact list""" 36 """Clear all the contact list"""
37 self.__contactlist.clear() 37 self.__contactlist.clear()
38 38
39 def add(self, entity): 39 def add(self, entity):
40 """Add contact to the list, update resources""" 40 """Add contact to the list, update resources"""
41 if not self.__contactlist.has_key(entity.short): 41 if not self.__contactlist.has_key(entity.bare):
42 self.__contactlist[entity.short] = {'resources':[]} 42 self.__contactlist[entity.bare] = {'resources':[]}
43 if not entity.resource: 43 if not entity.resource:
44 return 44 return
45 if entity.resource in self.__contactlist[entity.short]['resources']: 45 if entity.resource in self.__contactlist[entity.bare]['resources']:
46 self.__contactlist[entity.short]['resources'].remove(entity.resource) 46 self.__contactlist[entity.bare]['resources'].remove(entity.resource)
47 self.__contactlist[entity.short]['resources'].append(entity.resource) 47 self.__contactlist[entity.bare]['resources'].append(entity.resource)
48 48
49 def getContFromGroup(self, group): 49 def getContFromGroup(self, group):
50 """Return all contacts which are in given group""" 50 """Return all contacts which are in given group"""
51 result = [] 51 result = []
52 for contact in self.__contactlist: 52 for contact in self.__contactlist:
58 def getAttr(self, entity, name): 58 def getAttr(self, entity, name):
59 """Return a specific attribute of contact, or all attributes 59 """Return a specific attribute of contact, or all attributes
60 @param entity: jid of the contact 60 @param entity: jid of the contact
61 @param name: name of the attribute 61 @param name: name of the attribute
62 @return: asked attribute""" 62 @return: asked attribute"""
63 if self.__contactlist.has_key(entity.short): 63 if self.__contactlist.has_key(entity.bare):
64 if name == 'status': #FIXME: for the moment, we only use the first status 64 if name == 'status': #FIXME: for the moment, we only use the first status
65 if self.__contactlist[entity.short]['statuses']: 65 if self.__contactlist[entity.bare]['statuses']:
66 return self.__contactlist[entity.short]['statuses'].values()[0] 66 return self.__contactlist[entity.bare]['statuses'].values()[0]
67 if self.__contactlist[entity.short].has_key(name): 67 if self.__contactlist[entity.bare].has_key(name):
68 return self.__contactlist[entity.short][name] 68 return self.__contactlist[entity.bare][name]
69 else: 69 else:
70 debug(_('Trying to get attribute for an unknown contact')) 70 debug(_('Trying to get attribute for an unknown contact'))
71 return None 71 return None
72 72
73 def isConnected(self, entity): 73 def isConnected(self, entity):
74 """Tell if the contact is online""" 74 """Tell if the contact is online"""
75 return self.__contactlist.has_key(entity.short) 75 return self.__contactlist.has_key(entity.bare)
76 76
77 def remove(self, entity): 77 def remove(self, entity):
78 """remove resource. If no more resource is online or is no resource is specified, contact is deleted""" 78 """remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
79 try: 79 try:
80 if entity.resource: 80 if entity.resource:
81 self.__contactlist[entity.short]['resources'].remove(entity.resource) 81 self.__contactlist[entity.bare]['resources'].remove(entity.resource)
82 if not entity.resource or not self.__contactlist[entity.short]['resources']: 82 if not entity.resource or not self.__contactlist[entity.bare]['resources']:
83 #no more resource available: the contact seems really disconnected 83 #no more resource available: the contact seems really disconnected
84 del self.__contactlist[entity.short] 84 del self.__contactlist[entity.bare]
85 except KeyError: 85 except KeyError:
86 error(_('INTERNAL ERROR: Key error')) 86 error(_('INTERNAL ERROR: Key error'))
87 raise 87 raise
88 88
89 def update(self, entity, key, value): 89 def update(self, entity, key, value):
90 """Update attribute of contact 90 """Update attribute of contact
91 @param entity: jid of the contact 91 @param entity: jid of the contact
92 @param key: name of the attribute 92 @param key: name of the attribute
93 @param value: value of the attribute 93 @param value: value of the attribute
94 """ 94 """
95 if self.__contactlist.has_key(entity.short): 95 if self.__contactlist.has_key(entity.bare):
96 self.__contactlist[entity.short][key] = value 96 self.__contactlist[entity.bare][key] = value
97 else: 97 else:
98 debug (_('Trying to update an unknown contact: %s'), entity.short) 98 debug (_('Trying to update an unknown contact: %s'), entity.bare)
99 99
100 def get_full(self, entity): 100 def get_full(self, entity):
101 return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1] 101 return entity.bare+'/'+self.__contactlist[entity.bare]['resources'][-1]
102 102