comparison frontends/quick_frontend/quick_contact_management.py @ 51:8c67ea98ab91

frontend improved to take into account new SàT features - quick_frontend: better use of contact management, it now manages nicks, avatars, and connected status - quick_frontend: disconnect and remove are now 2 separate methods for contact list - wix: new contact list using HTML items, and showing avatars. Groups are not showed for now - wix: contact status now use tuples, to keep order, human readable status and color of contact - wix: contact list is updated when avatar or nick is found - wix: fixed 'question' dialog, which is renamed in 'yes/no' - wix: action result are now ignored for unkwnown id - sortilege refactored to work again
author Goffi <goffi@goffi.org>
date Thu, 07 Jan 2010 00:17:27 +1100
parents c4bc297b82f0
children 6455fb62ff83
comparison
equal deleted inserted replaced
50:daa1f01a5332 51:8c67ea98ab91
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU 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, info, warning, error
23 from tools.jid import JID 23 from tools.jid import JID
24 import pdb 24 import pdb
25 25
26 26
27 class QuickContactManagement(): 27 class QuickContactManagement():
28 """This helper class manage the contacts and ease the use of nicknames and shortcuts""" 28 """This helper class manage the contacts and ease the use of nicknames and shortcuts"""
29 ### FIXME: is SàT a better place for all this stuff ??? ###
29 30
30 def __init__(self): 31 def __init__(self):
31 self.__contactlist = {} 32 self.__contactlist = {}
32 33
33 def add(self, jid_param): 34 def add(self, entity):
34 jid=JID(jid_param) 35 """Add contact to the list, update resources"""
35 self.__contactlist[jid.short] = {'name':jid, 'last_resource':jid.resource} 36 if not self.__contactlist.has_key(entity.short):
37 self.__contactlist[entity.short] = {'resources':[]}
38 if entity.resource in self.__contactlist[entity.short]['resources']:
39 self.__contactlist[entity.short]['resources'].remove(entity.resource)
40 self.__contactlist[entity.short]['resources'].append(entity.resource)
36 41
37 def remove(self, jid_param): 42 def getAttr(self, entity, name):
38 jid=JID(jid_param) 43 """Return a specific attribute of contact, or all attributes
44 @param entity: jid of the contact
45 @param name: name of the attribute
46 @return: asked attribute"""
47 if self.__contactlist.has_key(entity.short):
48 if name == 'status': #FIXME: for the moment, we only use the first status
49 if self.__contactlist[entity.short]['statuses']:
50 return self.__contactlist[entity.short]['statuses'].values()[0]
51 if self.__contactlist[entity.short].has_key(name):
52 return self.__contactlist[entity.short][name]
53 else:
54 debug('Trying to get attribute for an unknown contact')
55 return None
56
57 def isConnected(self, entity):
58 """Tell if the contact is online"""
59 print "is connected (%s): %s" %(entity, str(self.__contactlist.has_key(entity.short))) #gof
60 return self.__contactlist.has_key(entity.short)
61
62 def remove(self, entity):
63 """remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
39 try: 64 try:
40 del self.__contactlist[jid.short] 65 if entity.resource:
66 self.__contactlist[entity.short]['resources'].remove(entity.resource)
67 if not entity.resource or not self.__contactlist[entity.short]['resources']:
68 #no more resource available: the contact seems really disconnected
69 del self.__contactlist[entity.short]
41 except KeyError: 70 except KeyError:
42 pass 71 pass
43 72
44 def get_full(self, jid_param): 73 def update(self, entity, key, value):
45 jid=JID(jid_param) 74 """Update attribute of contact
46 return jid.short+'/'+self.__contactlist[jid.short]['last_resource'] 75 @param entity: jid of the contact
76 @param key: name of the attribute
77 @param value: value of the attribute
78 """
79 if self.__contactlist.has_key(entity.short):
80 self.__contactlist[entity.short][key] = value
81 else:
82 debug ('Trying to update an uknown contact: %s', entity.short)
83
84 def get_full(self, entity):
85 return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1]
47 86