Mercurial > libervia-backend
annotate frontends/quick_frontend/quick_contact_management.py @ 52:6455fb62ff83
Connection/disconnection signals
- wix, sortilege: management of this new signals
/!\ sortilege is bugged, the contact list window is not updated correctly
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 07 Jan 2010 01:55:30 +1100 |
parents | 8c67ea98ab91 |
children | 2ce9e350cdf9 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 helper class for making a SAT frontend | |
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
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/>. | |
20 """ | |
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 | 23 from tools.jid import JID |
24 import pdb | |
25 | |
26 | |
27 class QuickContactManagement(): | |
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 | 30 |
31 def __init__(self): | |
32 self.__contactlist = {} | |
33 | |
52 | 34 def clear(self): |
35 """Clear all the contact list""" | |
36 self.__contactlist.clear() | |
37 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
38 def add(self, entity): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
39 """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
|
40 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
|
41 self.__contactlist[entity.short] = {'resources':[]} |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
42 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
|
43 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
|
44 self.__contactlist[entity.short]['resources'].append(entity.resource) |
0 | 45 |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
46 def getAttr(self, entity, name): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
47 """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
|
48 @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
|
49 @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
|
50 @return: asked attribute""" |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 else: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
58 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
|
59 return None |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
60 |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
61 def isConnected(self, entity): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
62 """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
|
63 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
|
64 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
|
65 |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
66 def remove(self, entity): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
67 """remove resource. If no more resource is online or is no resource is specified, contact is deleted""" |
0 | 68 try: |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
69 if entity.resource: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
70 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
|
71 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
|
72 #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
|
73 del self.__contactlist[entity.short] |
0 | 74 except KeyError: |
75 pass | |
76 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
77 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
|
78 """Update attribute of contact |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
79 @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
|
80 @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
|
81 @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
|
82 """ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
83 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
|
84 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
|
85 else: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
86 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
|
87 |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
88 def get_full(self, entity): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
89 return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1] |
0 | 90 |