Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_contact_list.py @ 756:efa0e0f57950
core (memory): new Sessions management class (similar to dict)
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Dec 2013 15:19:08 +0100 |
parents | f7878ad3c846 |
children | bfabeedbf32e |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
4 # helper class for making a SAT frontend |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
20 from logging import debug |
0 | 21 |
22 | |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
23 class QuickContactList(object): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
24 """This class manage the visual representation of contacts""" |
0 | 25 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
26 def __init__(self): |
70 | 27 debug(_("Contact List init")) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
28 self._cache = {} |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
29 self.specials={} |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
30 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
31 def update_jid(self, jid): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
32 """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
|
33 raise NotImplementedError |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
34 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
35 def getCache(self, jid, name): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
36 try: |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
37 jid_cache = self._cache[jid.bare] |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
38 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
|
39 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
|
40 return jid_cache[name] |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
41 except (KeyError, IndexError): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
42 return None |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
43 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
44 def setCache(self, jid, name, value): |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
45 jid_cache = self._cache.setdefault(jid.bare, {}) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
46 jid_cache[name] = value |
124 | 47 |
48 def __contains__(self, jid): | |
49 raise NotImplementedError | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
50 |
543
a7f53e778d8e
quick frontend: fixed clearContacts
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
51 def clearContacts(self): |
52 | 52 """Clear all the contact list""" |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
53 self.specials.clear() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
54 |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
55 def replace(self, jid, groups=None, attributes=None): |
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
56 """add a contact to the list if doesn't exist, else update it""" |
504
65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents:
502
diff
changeset
|
57 if attributes and 'name' in attributes: |
501
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']) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
59 |
0 | 60 def remove(self, jid): |
61 """remove a contact from the list""" | |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
62 try: |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
63 del self.specials[jid.bare] |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
64 except KeyError: |
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
65 pass |
504
65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents:
502
diff
changeset
|
66 |
72 | 67 def add(self, jid, param_groups=None): |
0 | 68 """add a contact to the list""" |
69 raise NotImplementedError | |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
70 |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
71 def getSpecial(self, jid): |
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
72 """Return special type of jid, or None if it's not special""" |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
73 return self.specials.get(jid.bare) |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
74 |
685
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
75 def setSpecial(self, jid, _type, show=False): |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
76 """Set entity as a special |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
77 @param jid: jid of the entity |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
78 @param _type: special type (e.g.: "MUC") |
685
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
79 @param show: True to display the dialog to chat with this entity |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
80 """ |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
81 self.specials[jid.bare] = _type |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
82 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
83 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
|
84 """Update entity's presence status |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
85 @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
|
86 @param show: availability |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
87 @parap priority: resource's priority |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
88 @param statuses: dict of statuses""" |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
89 self.setCache(jid, 'show', show) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
90 self.setCache(jid, 'prority', priority) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
91 self.setCache(jid, 'statuses', statuses) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
92 self.update_jid(jid) |