annotate frontends/src/quick_frontend/quick_contact_list.py @ 1045:65fffdcb97f1

memory: auto-update configuration file with libervia's passphrase when migrating the database
author souliane <souliane@mailoo.org>
date Fri, 23 May 2014 09:59:15 +0200
parents d1084f7e56a5
children 0a9986452bba
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
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
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 688
diff changeset
20 from sat.core.i18n import _
1009
d1084f7e56a5 quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
21 from sat.core.log import getLogger
d1084f7e56a5 quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
22 log = getLogger(__name__)
0
goffi@necton2
parents:
diff changeset
23
goffi@necton2
parents:
diff changeset
24
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
25 class QuickContactList(object):
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
goffi@necton2
parents:
diff changeset
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):
1009
d1084f7e56a5 quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents: 1000
diff changeset
29 log.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 = {}
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
31 self.specials={}
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
32
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
33 def update_jid(self, jid):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
34 """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
35 raise NotImplementedError
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
36
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
37 def getCache(self, jid, name):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
38 try:
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
39 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
40 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
41 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
42 return jid_cache[name]
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
43 except (KeyError, IndexError):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
44 return None
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
45
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
46 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
47 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
48 jid_cache[name] = value
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 111
diff changeset
49
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 111
diff changeset
50 def __contains__(self, jid):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 111
diff changeset
51 raise NotImplementedError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
52
543
a7f53e778d8e quick frontend: fixed clearContacts
Goffi <goffi@goffi.org>
parents: 510
diff changeset
53 def clearContacts(self):
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
54 """Clear all the contact list"""
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
55 self.specials.clear()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
56
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
57 def replace(self, jid, groups=None, attributes=None):
1000
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
58 """Add a contact to the list if doesn't exist, else update it.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
59
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
60 @param jid (JID)
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
61 @param groups (list): list of groups or None to ignore the groups membership.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
62 @param attributes (dict)
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
63
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
64 XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
65 """
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 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
67 self.setCache(jid, 'name', attributes['name'])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
68
0
goffi@necton2
parents:
diff changeset
69 def remove(self, jid):
goffi@necton2
parents:
diff changeset
70 """remove a contact from the list"""
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
71 try:
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
72 del self.specials[jid.bare]
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
73 except KeyError:
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
74 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
75
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
76 def add(self, jid, param_groups=None):
0
goffi@necton2
parents:
diff changeset
77 """add a contact to the list"""
goffi@necton2
parents:
diff changeset
78 raise NotImplementedError
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
79
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
80 def getSpecial(self, jid):
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
81 """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
82 return self.specials.get(jid.bare)
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 504
diff changeset
83
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
84 def setSpecial(self, jid, _type, show=False):
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
85 """Set entity as a special
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
86 @param jid: jid of the entity
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
87 @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
88 @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
89 """
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
90 self.specials[jid.bare] = _type
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
91
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
92 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
93 """Update entity's presence status
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
94 @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
95 @param show: availability
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
96 @parap priority: resource's priority
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
97 @param statuses: dict of statuses"""
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
98 self.setCache(jid, 'show', show)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
99 self.setCache(jid, 'prority', priority)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
100 self.setCache(jid, 'statuses', statuses)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
101 self.update_jid(jid)