annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 helper class for making a SAT frontend
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
22 from logging import debug, info, warning, error
0
goffi@necton2
parents:
diff changeset
23 from tools.jid import JID
goffi@necton2
parents:
diff changeset
24 import pdb
goffi@necton2
parents:
diff changeset
25
goffi@necton2
parents:
diff changeset
26
goffi@necton2
parents:
diff changeset
27 class QuickContactManagement():
goffi@necton2
parents:
diff changeset
28 """This helper class manage the contacts and ease the use of nicknames and shortcuts"""
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
29 ### FIXME: is SàT a better place for all this stuff ??? ###
0
goffi@necton2
parents:
diff changeset
30
goffi@necton2
parents:
diff changeset
31 def __init__(self):
goffi@necton2
parents:
diff changeset
32 self.__contactlist = {}
goffi@necton2
parents:
diff changeset
33
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
34 def add(self, entity):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
35 """Add contact to the list, update resources"""
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
36 if not self.__contactlist.has_key(entity.short):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
37 self.__contactlist[entity.short] = {'resources':[]}
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
38 if entity.resource in self.__contactlist[entity.short]['resources']:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
39 self.__contactlist[entity.short]['resources'].remove(entity.resource)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
40 self.__contactlist[entity.short]['resources'].append(entity.resource)
0
goffi@necton2
parents:
diff changeset
41
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
42 def getAttr(self, entity, name):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
43 """Return a specific attribute of contact, or all attributes
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
44 @param entity: jid of the contact
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
45 @param name: name of the attribute
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
46 @return: asked attribute"""
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
47 if self.__contactlist.has_key(entity.short):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
48 if name == 'status': #FIXME: for the moment, we only use the first status
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
49 if self.__contactlist[entity.short]['statuses']:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
50 return self.__contactlist[entity.short]['statuses'].values()[0]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
51 if self.__contactlist[entity.short].has_key(name):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
52 return self.__contactlist[entity.short][name]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
53 else:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
54 debug('Trying to get attribute for an unknown contact')
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
55 return None
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
56
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
57 def isConnected(self, entity):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
58 """Tell if the contact is online"""
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
59 print "is connected (%s): %s" %(entity, str(self.__contactlist.has_key(entity.short))) #gof
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
60 return self.__contactlist.has_key(entity.short)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
61
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
62 def remove(self, entity):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
63 """remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
0
goffi@necton2
parents:
diff changeset
64 try:
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
65 if entity.resource:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
66 self.__contactlist[entity.short]['resources'].remove(entity.resource)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
67 if not entity.resource or not self.__contactlist[entity.short]['resources']:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
68 #no more resource available: the contact seems really disconnected
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
69 del self.__contactlist[entity.short]
0
goffi@necton2
parents:
diff changeset
70 except KeyError:
goffi@necton2
parents:
diff changeset
71 pass
goffi@necton2
parents:
diff changeset
72
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
73 def update(self, entity, key, value):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
74 """Update attribute of contact
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
75 @param entity: jid of the contact
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
76 @param key: name of the attribute
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
77 @param value: value of the attribute
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
78 """
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
79 if self.__contactlist.has_key(entity.short):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
80 self.__contactlist[entity.short][key] = value
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
81 else:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
82 debug ('Trying to update an uknown contact: %s', entity.short)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
83
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
84 def get_full(self, entity):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 0
diff changeset
85 return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1]
0
goffi@necton2
parents:
diff changeset
86