Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_contact_list.py @ 502:debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
- MUC rooms are special entities
- Primitivus: special entities are shown at the top of the contacts list above a divider,
presence updates are temporary ignored for them
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Sep 2012 23:10:22 +0200 |
parents | e9634d2e7b38 |
children | 65ecbb473cbb |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 helper class for making a SAT frontend | |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0 | 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 | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
0 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
22 from logging import debug |
0 | 23 |
24 | |
25 class QuickContactList(): | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
26 """This class manage the visual representation of contacts""" |
0 | 27 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
28 def __init__(self): |
70 | 29 debug(_("Contact List init")) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
30 self._cache = {} |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
31 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
32 def update_jid(self, jid): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
33 """Update the jid in the list when something changed""" |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
34 raise NotImplementedError |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
35 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
36 def getCache(self, jid, name): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
37 try: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
38 jid_cache = self._cache[jid.short] |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
39 if name == 'status': #XXX: we get the first status for 'status' key |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
40 return jid_cache['statuses'].get('default','') |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
41 return jid_cache[name] |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
42 except (KeyError, IndexError): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
43 return None |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
44 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
45 def setCache(self, jid, name, value): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
46 jid_cache = self._cache.setdefault(jid.short, {}) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
47 jid_cache[name] = value |
124 | 48 |
49 def __contains__(self, jid): | |
50 raise NotImplementedError | |
0 | 51 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
52 def clearContacts(self, jid): |
52 | 53 """Clear all the contact list""" |
54 raise NotImplementedError | |
55 | |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
56 def _replace(self, jid, groups=None, attributes=None): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
57 if 'name' in attributes: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
58 self.setCache(jid, 'name', attributes['name']) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
59 self.replace(jid, groups, attributes) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
60 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
61 def replace(self, jid, groups, attributes): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
62 """add a contact to the list if doesn't exist, else update it""" |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
63 raise NotImplementedError |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
64 |
0 | 65 def remove(self, jid): |
66 """remove a contact from the list""" | |
67 raise NotImplementedError | |
68 | |
72 | 69 def add(self, jid, param_groups=None): |
0 | 70 """add a contact to the list""" |
71 raise NotImplementedError | |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
72 |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
73 def setSpecial(self, jid, _type): |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
74 """Set entity as a special |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
75 @param jid: jid of the entity |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
76 @param _type: special type (e.g.: "MUC") |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
77 """ |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
78 raise NotImplementedError |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
79 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
80 def updatePresence(self, jid, show, priority, statuses): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
81 """Update entity's presence status |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
82 @param jid: entity to update's jid |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
83 @param show: availability |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
84 @parap priority: resource's priority |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
85 @param statuses: dict of statuses""" |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
86 self.setCache(jid, 'show', show) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
87 self.setCache(jid, 'prority', priority) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
88 self.setCache(jid, 'statuses', statuses) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
89 self.update_jid(jid) |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
90 |