Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_contact_list.py @ 1967:de6faf9be715 refacoring_messages
primitivus (chat): fixed filters clearing when changing filter while one already exists
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 20 Jun 2016 23:07:53 +0200 |
parents | 633b5c21aefd |
children | 02d21a589be2 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
0 | 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 |
1766 | 5 # Copyright (C) 2009-2016 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 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
20 """Contact List handling multi profiles at once, should replace quick_contact_list module in the future""" |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
21 |
771 | 22 from sat.core.i18n import _ |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
1000
diff
changeset
|
23 from sat.core.log import getLogger |
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
1000
diff
changeset
|
24 log = getLogger(__name__) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
25 from sat.core import exceptions |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
26 from sat_frontends.quick_frontend.quick_widgets import QuickWidget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
27 from sat_frontends.quick_frontend.constants import Const as C |
1334
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
28 from sat_frontends.tools import jid |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
29 from collections import OrderedDict |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
30 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
31 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
32 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
33 # FIXME: to be removed when an acceptable solution is here |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
34 unicode('') # XXX: unicode doesn't exist in pyjamas |
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
35 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
36 # XXX: pyjamas' max doesn't support key argument, so we implement it ourself |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
37 pyjamas_max = max |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
38 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
39 def max(iterable, key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
40 iter_cpy = list(iterable) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
41 iter_cpy.sort(key=key) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
42 return pyjamas_max(iter_cpy) |
0 | 43 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
44 handler = None |
0 | 45 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
46 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
47 class ProfileContactList(object): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
48 """Contact list data for a single profile""" |
0 | 49 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
50 def __init__(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
51 self.host = handler.host |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
52 self.profile = profile |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
53 # contain all jids in roster or not, |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
54 # bare jids as keys, resources are used in data |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
55 # XXX: we don't mutualise cache, as values may differ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
56 # for different profiles (e.g. directed presence) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
57 self._cache = {} |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
58 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
59 # special entities (groupchat, gateways, etc), bare jids |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
60 self._specials = set() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
61 # extras are specials with full jids (e.g.: private MUC conversation) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
62 self._special_extras = set() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
63 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
64 # group data contain jids in groups and misc frontend data |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
65 # None key is used for jids with not group |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
66 self._groups = {} # groups to group data map |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
67 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
68 # contacts in roster (bare jids) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
69 self._roster = set() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
70 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
71 # alerts per entity (key: full jid, value: list of alerts) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
72 self._alerts = {} |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
73 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
74 # selected entities, full jid |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
75 self._selected = set() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
76 |
1343
ec9e58357a07
quick frontends (contact list): added self.whoami
Goffi <goffi@goffi.org>
parents:
1342
diff
changeset
|
77 # we keep our own jid |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
78 self.whoami = self.host.profiles[profile].whoami |
1343
ec9e58357a07
quick frontends (contact list): added self.whoami
Goffi <goffi@goffi.org>
parents:
1342
diff
changeset
|
79 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
80 # options |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
81 self.show_disconnected = False |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
82 self.show_empty_groups = True |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
83 self.show_resources = False |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
84 self.show_status = False |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
85 |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
86 self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self._showEmptyGroups) |
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
87 self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self._showOfflineContacts) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
88 |
1332
0f92b6a150ff
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents:
1328
diff
changeset
|
89 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) |
1339
18cd46a264e9
quick frontends, primitivus: fixed listener calls (kwargs where forgotten) + fixed presence listener + renamed updatePresence to onPresenceUpdate for consistency with oter listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
90 self.presenceListener = self.onPresenceUpdate |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
91 self.host.addListener('presence', self.presenceListener, [self.profile]) |
1342
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
92 self.nickListener = self.onNickUpdate |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
93 self.host.addListener('nick', self.nickListener, [self.profile]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
94 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
95 def _showEmptyGroups(self, show_str): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
96 # Called only by __init__ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
97 # self.update is not wanted here, as it is done by |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
98 # handler when all profiles are ready |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
99 self.showEmptyGroups(C.bool(show_str)) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
100 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
101 def _showOfflineContacts(self, show_str): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
102 # same comments as for _showEmptyGroups |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
103 self.showOfflineContacts(C.bool(show_str)) |
1332
0f92b6a150ff
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents:
1328
diff
changeset
|
104 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
105 def __contains__(self, entity): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
106 """Check if entity is in contact list |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
107 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
108 An entity can be in contact list even if not in roster |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
109 @param entity (jid.JID): jid of the entity (resource is not ignored, use bare jid if needed) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
110 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
111 if entity.resource: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
112 try: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
113 return entity.resource in self.getCache(entity.bare, C.CONTACT_RESOURCES) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
114 except KeyError: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
115 return False |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
116 return entity in self._cache |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
117 |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
118 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
119 def roster(self): |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
120 """Return all the bare JIDs of the roster entities. |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
121 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
122 @return (set[jid.JID]) |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
123 """ |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
124 return self._roster |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
125 |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
126 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
127 def roster_connected(self): |
1328
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
128 """Return all the bare JIDs of the roster entities that are connected. |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
129 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
130 @return (set[jid.JID]) |
1328
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
131 """ |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
132 return set([entity for entity in self._roster if self.getCache(entity, C.PRESENCE_SHOW) is not None]) |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
133 |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
134 @property |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
135 def roster_entities_by_group(self): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
136 """Return a dictionary binding the roster groups to their entities bare JIDs. |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
137 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
138 This also includes the empty group (None key). |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
139 @return (dict[unicode,set(jid.JID)]) |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
140 """ |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
141 return {group: self._groups[group]['jids'] for group in self._groups} |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
142 |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
143 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
144 def roster_groups_by_entities(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
145 """Return a dictionary binding the entities bare JIDs to their roster groups |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
146 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
147 @return (dict[jid.JID, set(unicode)]) |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
148 """ |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
149 result = {} |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
150 for group, data in self._groups.iteritems(): |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
151 for entity in data['jids']: |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
152 result.setdefault(entity, set()).add(group) |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
153 return result |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
154 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
155 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
156 def selected(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
157 """Return contacts currently selected |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
158 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
159 @return (set): set of selected entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
160 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
161 return self._selected |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
162 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
163 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
164 def items(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
165 """Return item representation for all visible entities in cache |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
166 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
167 entities are not sorted |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
168 key: bare jid, value: data |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
169 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
170 return {jid_:cache for jid_, cache in self._cache.iteritems() if self.entityToShow(jid_)} |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
171 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
172 def getItem(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
173 """Return item representation of requested entity |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
174 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
175 @param entity(jid.JID): bare jid of entity |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
176 @raise (KeyError): entity is unknown |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
177 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
178 return self._cache[entity] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
179 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
180 def getSpecialExtras(self, special_type=None): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
181 """Return special extras with given type |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
182 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
183 If special_type is None, return all special extras. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
184 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
185 @param special_type(unicode, None): one of special type (e.g. C.CONTACT_SPECIAL_GROUP) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
186 None to return all special extras. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
187 @return (set[jid.JID]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
188 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
189 if special_type is None: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
190 return self._special_extras |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
191 specials = self.getSpecials(special_type) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
192 return {extra for extra in self._special_extras if extra.bare in specials} |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
193 |
1462 | 194 def _gotContacts(self, contacts): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
195 """Called during filling, add contacts and notice parent that contacts are filled""" |
1462 | 196 for contact in contacts: |
197 self.host.newContactHandler(*contact, profile=self.profile) | |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
198 handler._contactsFilled(self.profile) |
1462 | 199 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
200 def _fill(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
201 """Get all contacts from backend |
1429
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1428
diff
changeset
|
202 |
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1428
diff
changeset
|
203 Contacts will be cleared before refilling them |
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1428
diff
changeset
|
204 """ |
1430
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
205 self.clearContacts(keep_cache=True) |
1462 | 206 self.host.bridge.getContacts(self.profile, callback=self._gotContacts) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
207 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
208 def fill(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
209 handler.fill(self.profile) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
210 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
211 def getCache(self, entity, name=None): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
212 """Return a cache value for a contact |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
213 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
214 @param entity(entity.entity): entity of the contact from who we want data (resource is used if given) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
215 if a resource specific information is requested: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
216 - if no resource is given (bare jid), the main resource is used, according to priority |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
217 - if resource is given, it is used |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
218 @param name(unicode): name the data to get, or None to get everything |
1334
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
219 @return: full cache if no name is given, or value of "name", or None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
220 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
221 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
222 cache = self._cache[entity.bare] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
223 except KeyError: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
224 self.setContact(entity) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
225 cache = self._cache[entity.bare] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
226 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
227 if name is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
228 return cache |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
229 try: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
230 if name in ('status', C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
231 # these data are related to the resource |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
232 if not entity.resource: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
233 main_resource = cache[C.CONTACT_MAIN_RESOURCE] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
234 cache = cache[C.CONTACT_RESOURCES][main_resource] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
235 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
236 cache = cache[C.CONTACT_RESOURCES][entity.resource] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
237 |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
238 if name == 'status': # XXX: we get the first status for 'status' key |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
239 # TODO: manage main language for statuses |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1410
diff
changeset
|
240 return cache[C.PRESENCE_STATUSES].get(C.PRESENCE_STATUSES_DEFAULT, '') |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
241 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
242 return cache[name] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
243 except KeyError: |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
244 return None |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
245 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
246 def setCache(self, entity, name, value): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
247 """Set or update value for one data in cache |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
248 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
249 @param entity(JID): entity to update |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
250 @param name(unicode): value to set or update |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
251 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
252 self.setContact(entity, attributes={name: value}) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
253 |
1334
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
254 def getFullJid(self, entity): |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
255 """Get full jid from a bare jid |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
256 |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
257 @param entity(jid.JID): must be a bare jid |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
258 @return (jid.JID): bare jid + main resource |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
259 @raise ValueError: the entity is not bare |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
260 """ |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
261 if entity.resource: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
262 raise ValueError(u"getFullJid must be used with a bare jid") |
1334
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
263 main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE) |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
264 return jid.JID(u"{}/{}".format(entity, main_resource)) |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
265 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
266 def setGroupData(self, group, name, value): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
267 """Register a data for a group |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
268 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
269 @param group: a valid (existing) group name |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
270 @param name: name of the data (can't be "jids") |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
271 @param value: value to set |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
272 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
273 assert name is not 'jids' |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
274 self._groups[group][name] = value |
124 | 275 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
276 def getGroupData(self, group, name=None): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
277 """Return value associated to group data |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
278 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
279 @param group: a valid (existing) group name |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
280 @param name: name of the data or None to get the whole dict |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
281 @return: registered value |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
282 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
283 if name is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
284 return self._groups[group] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
285 return self._groups[group][name] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
286 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
287 def setSpecial(self, entity, special_type): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
288 """Set special flag on an entity |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
289 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
290 @param entity(jid.JID): jid of the special entity |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
291 @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) or None to remove special flag |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
292 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
293 assert special_type in C.CONTACT_SPECIAL_ALLOWED + (None,) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
294 self.setCache(entity, C.CONTACT_SPECIAL, special_type) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
295 |
1328
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
296 def getSpecials(self, special_type=None): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
297 """Return all the bare JIDs of the special roster entities of with given type. |
1328
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
298 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
299 If special_type is None, return all specials. |
1328
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
300 @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) or None to return all specials. |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
301 @return: set(jid.JID) |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
302 """ |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
303 if special_type is None: |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
304 return self._specials |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
305 return set([entity for entity in self._specials if self.getCache(entity, C.CONTACT_SPECIAL) == special_type]) |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
306 |
1428
0e518415d03a
display the resource in the chat dialog when printing a private MUC message
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
307 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
308 def disconnect(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
309 # for now we just clear contacts on disconnect |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
310 self.clearContacts() |
1428
0e518415d03a
display the resource in the chat dialog when printing a private MUC message
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
311 |
1430
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
312 def clearContacts(self, keep_cache=False): |
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
313 """Clear all the contact list |
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
314 |
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
315 @param keep_cache: if True, don't reset the cache |
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
316 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
317 self.select(None) |
1430
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
318 if not keep_cache: |
ba09cd879343
quick frontends (contact list): cache is not cleared anymore on QuickContactList.fill, avoiding the accidental removal of cached values like avatars
Goffi <goffi@goffi.org>
parents:
1429
diff
changeset
|
319 self._cache.clear() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
320 self._groups.clear() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
321 self._specials.clear() |
1410
e2e75c3c7c7b
quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
322 self._special_extras.clear() |
e2e75c3c7c7b
quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
323 self._roster.clear() |
e2e75c3c7c7b
quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
324 self._alerts.clear() |
1442
6ce18c4e5708
quick_frontend: display over whole alerts counter
souliane <souliane@mailoo.org>
parents:
1430
diff
changeset
|
325 self.host.updateAlertsCounter() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
326 self.update() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
327 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
328 def setContact(self, entity, groups=None, attributes=None, in_roster=False): |
1000
6f1e03068b5f
primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
329 """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
|
330 |
1058
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
1009
diff
changeset
|
331 This method can be called with groups=None for the purpose of updating |
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
1009
diff
changeset
|
332 the contact's attributes (e.g. nickname). In that case, the groups |
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
1009
diff
changeset
|
333 attribute must not be set to the default group but ignored. If not, |
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
1009
diff
changeset
|
334 you may move your contact from its actual group(s) to the default one. |
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
1009
diff
changeset
|
335 |
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
1009
diff
changeset
|
336 None value for 'groups' has a different meaning than [None] which is for the default group. |
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
1009
diff
changeset
|
337 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
338 @param entity (jid.JID): entity to add or replace |
1000
6f1e03068b5f
primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
339 @param groups (list): list of groups or None to ignore the groups membership. |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
340 @param attributes (dict): attibutes of the added jid or to update |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
341 @param in_roster (bool): True if contact is from roster |
1000
6f1e03068b5f
primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
342 """ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
343 if attributes is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
344 attributes = {} |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
345 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
346 entity_bare = entity.bare |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
347 update_type = C.UPDATE_MODIFY if entity_bare in self._cache else C.UPDATE_ADD |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
348 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
349 if in_roster: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
350 self._roster.add(entity_bare) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
351 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
352 cache = self._cache.setdefault(entity_bare, {C.CONTACT_RESOURCES: {}, |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
353 C.CONTACT_SELECTED: set()}) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
354 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
355 assert not C.CONTACT_DATA_FORBIDDEN.intersection(attributes) # we don't want forbidden data in attributes |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
356 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
357 # we set groups and fill self._groups accordingly |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
358 if groups is not None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
359 if not groups: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
360 groups = [None] # [None] is the default group |
1306
789e86a8919d
quick_frontend: remove the contact from the groups it has been removed from
souliane <souliane@mailoo.org>
parents:
1305
diff
changeset
|
361 if C.CONTACT_GROUPS in cache: |
789e86a8919d
quick_frontend: remove the contact from the groups it has been removed from
souliane <souliane@mailoo.org>
parents:
1305
diff
changeset
|
362 # XXX: don't use set(cache[C.CONTACT_GROUPS]).difference(groups) because it won't work in Pyjamas if None is in cache[C.CONTACT_GROUPS] |
789e86a8919d
quick_frontend: remove the contact from the groups it has been removed from
souliane <souliane@mailoo.org>
parents:
1305
diff
changeset
|
363 for group in [group for group in cache[C.CONTACT_GROUPS] if group not in groups]: |
789e86a8919d
quick_frontend: remove the contact from the groups it has been removed from
souliane <souliane@mailoo.org>
parents:
1305
diff
changeset
|
364 self._groups[group]['jids'].remove(entity_bare) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
365 cache[C.CONTACT_GROUPS] = groups |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
366 for group in groups: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
367 self._groups.setdefault(group, {}).setdefault('jids', set()).add(entity_bare) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
368 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
369 # special entities management |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
370 if C.CONTACT_SPECIAL in attributes: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
371 if attributes[C.CONTACT_SPECIAL] is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
372 del attributes[C.CONTACT_SPECIAL] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
373 self._specials.remove(entity_bare) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
374 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
375 self._specials.add(entity_bare) |
1393
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
376 cache[C.CONTACT_MAIN_RESOURCE] = None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
377 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
378 # now the attributes we keep in cache |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
379 for attribute, value in attributes.iteritems(): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
380 cache[attribute] = value |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
381 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
382 # we can update the display |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
383 self.update([entity], update_type, self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
384 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
385 def entityToShow(self, entity, check_resource=False): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
386 """Tell if the contact should be showed or hidden. |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
387 |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
388 @param entity (jid.JID): jid of the contact |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
389 @param check_resource (bool): True if resource must be significant |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
390 @return (bool): True if that contact should be showed in the list |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
391 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
392 show = self.getCache(entity, C.PRESENCE_SHOW) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
393 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
394 if check_resource: |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
395 alerts = self._alerts.keys() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
396 selected = self._selected |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
397 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
398 alerts = {alert.bare for alert in self._alerts} |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
399 selected = {selected.bare for selected in self._selected} |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1410
diff
changeset
|
400 return ((show is not None and show != C.PRESENCE_UNAVAILABLE) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
401 or self.show_disconnected |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
402 or entity in alerts |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
403 or entity in selected) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
404 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
405 def anyEntityToShow(self, entities, check_resources=False): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
406 """Tell if in a list of entities, at least one should be shown |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
407 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
408 @param entities (list[jid.JID]): list of jids |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
409 @param check_resources (bool): True if resources must be significant |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
410 @return (bool): True if a least one entity need to be shown |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
411 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
412 # FIXME: looks inefficient, really needed? |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
413 for entity in entities: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
414 if self.entityToShow(entity, check_resources): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
415 return True |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
416 return False |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
417 |
1302
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
418 def isEntityInGroup(self, entity, group): |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
419 """Tell if an entity is in a roster group |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
420 |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
421 @param entity(jid.JID): jid of the entity |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
422 @param group(unicode): group to check |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
423 @return (bool): True if the entity is in the group |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
424 """ |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
425 return entity in self.getGroupData(group, "jids") |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
426 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
427 def removeContact(self, entity): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
428 """remove a contact from the list |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
429 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
430 @param entity(jid.JID): jid of the entity to remove (bare jid is used) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
431 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
432 entity_bare = entity.bare |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
433 try: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
434 groups = self._cache[entity_bare].get(C.CONTACT_GROUPS, set()) |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
435 except KeyError: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
436 log.error(_(u"Trying to delete an unknow entity [{}]").format(entity)) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
437 try: |
1738
baac0fc5e3ad
reverted patch 58ecc0e2e6fc as it may hide an other issue
Goffi <goffi@goffi.org>
parents:
1731
diff
changeset
|
438 self._roster.remove(entity_bare) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
439 except KeyError: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
440 pass |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
441 del self._cache[entity_bare] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
442 for group in groups: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
443 self._groups[group]['jids'].remove(entity_bare) |
1399
5c3d1d970b94
quick_frontend: keep the contact list groups synchronised on contact deletion
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
444 if not self._groups[group]['jids']: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
445 self._groups.pop(group) # FIXME: we use pop because of pyjamas: http://wiki.goffi.org/wiki/Issues_with_Pyjamas/en |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
446 for iterable in (self._selected, self._alerts, self._specials, self._special_extras): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
447 to_remove = set() |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
448 for set_entity in iterable: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
449 if set_entity.bare == entity.bare: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
450 to_remove.add(set_entity) |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
451 if isinstance(iterable, set): |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
452 iterable.difference_update(to_remove) |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
453 else: # XXX: self._alerts is a dict |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
454 for item in to_remove: |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
455 del iterable[item] |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
456 self.update([entity], C.UPDATE_DELETE, self.profile) |
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
|
457 |
1339
18cd46a264e9
quick frontends, primitivus: fixed listener calls (kwargs where forgotten) + fixed presence listener + renamed updatePresence to onPresenceUpdate for consistency with oter listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
458 def onPresenceUpdate(self, entity, show, priority, statuses, profile): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
459 """Update entity's presence status |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
460 |
1339
18cd46a264e9
quick frontends, primitivus: fixed listener calls (kwargs where forgotten) + fixed presence listener + renamed updatePresence to onPresenceUpdate for consistency with oter listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
461 @param entity(jid.JID): entity updated |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
462 @param show: availability |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
463 @parap priority: resource's priority |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
464 @param statuses: dict of statuses |
1339
18cd46a264e9
quick frontends, primitivus: fixed listener calls (kwargs where forgotten) + fixed presence listener + renamed updatePresence to onPresenceUpdate for consistency with oter listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
465 @param profile: %(doc_profile)s |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
466 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
467 cache = self.getCache(entity) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
468 if show == C.PRESENCE_UNAVAILABLE: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
469 if not entity.resource: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
470 cache[C.CONTACT_RESOURCES].clear() |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
471 cache[C.CONTACT_MAIN_RESOURCE] = None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
472 else: |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
473 try: |
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
474 del cache[C.CONTACT_RESOURCES][entity.resource] |
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
475 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1408
diff
changeset
|
476 log.error(u"Presence unavailable received for an unknown resource [{}]".format(entity)) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
477 if not cache[C.CONTACT_RESOURCES]: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
478 cache[C.CONTACT_MAIN_RESOURCE] = None |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
479 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
480 assert entity.resource |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
481 resources_data = cache[C.CONTACT_RESOURCES] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
482 resource_data = resources_data.setdefault(entity.resource, {}) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
483 resource_data[C.PRESENCE_SHOW] = show |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
484 resource_data[C.PRESENCE_PRIORITY] = int(priority) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
485 resource_data[C.PRESENCE_STATUSES] = statuses |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
486 |
1393
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
487 if entity.bare not in self._specials: |
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
488 priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY]) |
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
489 cache[C.CONTACT_MAIN_RESOURCE] = priority_resource |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
490 self.update([entity], C.UPDATE_MODIFY, self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
491 |
1342
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
492 def onNickUpdate(self, entity, new_nick, profile): |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
493 """Update entity's nick |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
494 |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
495 @param entity(jid.JID): entity updated |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
496 @param new_nick(unicode): new nick of the entity |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
497 @param profile: %(doc_profile)s |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
498 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
499 assert profile == self.profile |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
500 self.setCache(entity, 'nick', new_nick) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
501 self.update([entity], C.UPDATE_MODIFY, profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
502 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
503 def unselect(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
504 """Unselect an entity |
1342
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
505 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
506 @param entity(jid.JID): entity to unselect |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
507 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
508 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
509 cache = self._cache[entity.bare] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
510 except: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
511 log.error(u"Try to unselect an entity not in cache") |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
512 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
513 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
514 cache[C.CONTACT_SELECTED].remove(entity.resource) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
515 except KeyError: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
516 log.error(u"Try to unselect a not selected entity") |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
517 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
518 self._selected.remove(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
519 self.update([entity], C.UPDATE_SELECTION) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
520 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
521 def select(self, entity): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
522 """Select an entity |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
523 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
524 @param entity(jid.JID, None): entity to select (resource is significant) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
525 None to unselect all entities |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
526 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
527 if entity is None: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
528 self._selected.clear() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
529 for cache in self._cache.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
530 cache[C.CONTACT_SELECTED].clear() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
531 self.update(type_=C.UPDATE_SELECTION, profile=self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
532 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
533 log.debug(u"select %s" % entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
534 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
535 cache = self._cache[entity.bare] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
536 except: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
537 log.error(u"Try to select an entity not in cache") |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
538 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
539 cache[C.CONTACT_SELECTED].add(entity.resource) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
540 self._selected.add(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
541 self.update([entity], C.UPDATE_SELECTION, profile=self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
542 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
543 def getAlerts(self, entity, use_bare_jid=False, filter_=None): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
544 """Return alerts set to this entity. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
545 |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
546 @param entity (jid.JID): entity |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
547 @param use_bare_jid (bool): if True, cumulate the alerts of all the resources sharing the same bare JID |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
548 @param filter_(iterable, None): alert to take into account, |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
549 None to count all of them |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
550 @return (list[unicode,None]): list of C.ALERT_* or None for undefined ones |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
551 """ |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1943
diff
changeset
|
552 return [] # FIXME: temporarily disabled |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
553 if not use_bare_jid: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
554 alerts = self._alerts.get(entity, []) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
555 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
556 alerts = [] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
557 for contact, contact_alerts in self._alerts: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
558 if contact.bare == entity: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
559 alerts.extend(contact_alerts) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
560 if filter_ is None: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
561 return alerts |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
562 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
563 return [alert for alert in alerts if alert in filter_] |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
564 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
565 def addAlert(self, entity, type_=None): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
566 """Add an alert for this enity |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
567 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
568 @param entity(jid.JID): entity who received an alert (resource is significant) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
569 @param type_(unicode, None): type of alert (C.ALERT_*) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
570 None for generic alert |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
571 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
572 self._alerts.setdefault(entity, []) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
573 self._alerts[entity].append(type_) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
574 self.update([entity], C.UPDATE_MODIFY, self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
575 self.host.updateAlertsCounter() # FIXME: ? |
1229
03661d1b216a
primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents:
1058
diff
changeset
|
576 |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
577 def removeAlerts(self, entity, use_bare_jid=True): |
1408
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
578 """Eventually remove an alert on the entity (usually for a waiting message). |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
579 |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
580 @param entity(jid.JID): entity (resource is significant) |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
581 @param use_bare_jid (bool): if True, ignore the resource |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
582 """ |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
583 if use_bare_jid: |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
584 to_remove = set() |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
585 for alert_entity in self._alerts: |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
586 if alert_entity.bare == entity.bare: |
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
587 to_remove.add(alert_entity) |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
588 if not to_remove: |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
589 return # nothing changed |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
590 for entity in to_remove: |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
591 del self._alerts[entity] |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
592 self.update([to_remove], C.UPDATE_MODIFY, self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
593 self.host.updateAlertsCounter() # FIXME: ? |
1408
8a7145138330
quick_frontend, primitivus: move code to remove a new message alert from primitivus to quick_frontend
souliane <souliane@mailoo.org>
parents:
1399
diff
changeset
|
594 else: |
1658
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
595 try: |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
596 del self._alerts[entity] |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
597 except KeyError: |
683b76c1145d
quick_frontend, primitivus: display the number of alerts for each contact and not only a symbol (*)
souliane <souliane@mailoo.org>
parents:
1572
diff
changeset
|
598 return # nothing changed |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
599 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
600 self.update([entity], C.UPDATE_MODIFY, self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
601 self.host.updateAlertsCounter() # FIXME: ? |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
602 |
1229
03661d1b216a
primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents:
1058
diff
changeset
|
603 def showOfflineContacts(self, show): |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
604 """Tell if offline contacts should shown |
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
605 |
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
606 @param show(bool): True if offline contacts should be shown |
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
607 """ |
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
608 assert isinstance(show, bool) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
609 if self.show_disconnected == show: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
610 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
611 self.show_disconnected = show |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
612 self.update(type_=C.UPDATE_STRUCTURE, profile=self.profile) |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
613 |
1230
3abc6563a0d2
primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1229
diff
changeset
|
614 def showEmptyGroups(self, show): |
1333
7c2289090b9b
quick_frontends (contact list): use of intermediate method for showEmptyGroups and showOfflineMessages to convert bridge values to actual booleans
Goffi <goffi@goffi.org>
parents:
1306
diff
changeset
|
615 assert isinstance(show, bool) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
616 if self.show_empty_groups == show: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
617 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
618 self.show_empty_groups = show |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
619 self.update(type_=C.UPDATE_STRUCTURE, profile=self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
620 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
621 def showResources(self, show): |
1572
6a6fe840c3a6
quick frontend: fixed resources display in quickContactList
Goffi <goffi@goffi.org>
parents:
1462
diff
changeset
|
622 assert isinstance(show, bool) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
623 if self.show_resources == show: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
624 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
625 self.show_resources = show |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
626 self.update(profile=self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
627 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
628 def plug(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
629 handler.addProfile(self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
630 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
631 def unplug(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
632 handler.removeProfile(self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
633 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
634 def update(self, entities=None, type_=None, profile=None): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
635 handler.update(entities, type_, profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
636 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
637 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
638 class QuickContactListHandler(object): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
639 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
640 def __init__(self, host): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
641 super(QuickContactListHandler, self).__init__() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
642 self.host = host |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
643 global handler |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
644 if handler is not None: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
645 raise exceptions.InternalError(u"QuickContactListHandler must be instanciated only once") |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
646 handler = self |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
647 self._clist = {} # key: profile, value: ProfileContactList |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
648 self._widgets = set() |
1939
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
649 self._update_locked = False # se to True to ignore updates |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
650 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
651 def __getitem__(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
652 """Return ProfileContactList instance for the requested profile""" |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
653 return self._clist[profile] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
654 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
655 def __contains__(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
656 """Check if entity is in contact list |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
657 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
658 @param entity (jid.JID): jid of the entity (resource is not ignored, use bare jid if needed) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
659 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
660 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
661 if entity in contact_list: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
662 return True |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
663 return False |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
664 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
665 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
666 def roster_entities(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
667 """Return all the bare JIDs of the roster entities. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
668 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
669 @return (set[jid.JID]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
670 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
671 entities = set() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
672 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
673 entities.update(contact_list.roster_entities) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
674 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
675 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
676 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
677 def roster_entities_connected(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
678 """Return all the bare JIDs of the roster entities that are connected. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
679 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
680 @return (set[jid.JID]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
681 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
682 entities = set() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
683 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
684 entities.update(contact_list.roster_entities_connected) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
685 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
686 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
687 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
688 def roster_entities_by_group(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
689 """Return a dictionary binding the roster groups to their entities bare |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
690 JIDs. This also includes the empty group (None key). |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
691 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
692 @return (dict[unicode,set(jid.JID)]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
693 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
694 groups = {} |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
695 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
696 groups.update(contact_list.roster_entities_by_group) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
697 return groups |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
698 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
699 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
700 def roster_groups_by_entities(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
701 """Return a dictionary binding the entities bare JIDs to their roster |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
702 groups. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
703 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
704 @return (dict[jid.JID, set(unicode)]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
705 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
706 entities = {} |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
707 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
708 entities.update(contact_list.roster_groups_by_entities) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
709 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
710 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
711 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
712 def selected(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
713 """Return contacts currently selected |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
714 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
715 @return (set): set of selected entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
716 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
717 entities = set() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
718 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
719 entities.update(contact_list.selected) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
720 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
721 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
722 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
723 def items(self): |
1943 | 724 """Return item representation for visible entities in cache |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
725 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
726 items are unordered |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
727 key: bare jid, value: data |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
728 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
729 items = {} |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
730 for profile, contact_list in self._clist.iteritems(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
731 for bare_jid, cache in contact_list.items.iteritems(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
732 data = cache.copy() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
733 items[bare_jid] = data |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
734 data[C.CONTACT_PROFILE] = profile |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
735 items.update(contact_list.items) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
736 return items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
737 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
738 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
739 def items_sorted(self): |
1943 | 740 """Return item representation for visible entities in cache |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
741 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
742 items are ordered using self.items_sort |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
743 key: bare jid, value: data |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
744 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
745 return self.items_sort(self.items) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
746 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
747 def items_sort(self, items): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
748 """sort items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
749 |
1943 | 750 @param items(dict): items to sort (will be emptied !) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
751 @return (OrderedDict): sorted items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
752 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
753 ordered_items = OrderedDict() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
754 bare_jids = sorted(items.keys()) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
755 for jid_ in bare_jids: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
756 ordered_items[jid_] = items.pop(jid_) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
757 return ordered_items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
758 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
759 def register(self, widget): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
760 """Register a QuickContactList widget |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
761 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
762 This method should only be used in QuickContactList |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
763 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
764 self._widgets.add(widget) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
765 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
766 def unregister(self, widget): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
767 """Unregister a QuickContactList widget |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
768 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
769 This method should only be used in QuickContactList |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
770 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
771 self._widgets.remove(widget) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
772 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
773 def addProfiles(self, profiles): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
774 """Add a contact list for plugged profiles |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
775 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
776 @param profile(iterable[unicode]): plugged profiles |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
777 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
778 for profile in profiles: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
779 if profile not in self._clist: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
780 self._clist[profile] = ProfileContactList(profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
781 return [self._clist[profile] for profile in profiles] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
782 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
783 def addProfile(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
784 return self.addProfiles([profile])[0] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
785 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
786 def removeProfiles(self, profiles): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
787 """Remove given unplugged profiles from contact list |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
788 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
789 @param profile(iterable[unicode]): unplugged profiles |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
790 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
791 for profile in profiles: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
792 del self._clist[profile] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
793 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
794 def removeProfile(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
795 self.removeProfiles([profile]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
796 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
797 def getSpecialExtras(self, special_type=None): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
798 """Return special extras with given type |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
799 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
800 If special_type is None, return all special extras. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
801 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
802 @param special_type(unicode, None): one of special type (e.g. C.CONTACT_SPECIAL_GROUP) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
803 None to return all special extras. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
804 @return (set[jid.JID]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
805 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
806 entities = set() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
807 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
808 entities.update(contact_list.getSpecialExtras(special_type)) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
809 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
810 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
811 def _contactsFilled(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
812 self._to_fill.remove(profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
813 if not self._to_fill: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
814 del self._to_fill |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
815 self.update() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
816 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
817 def fill(self, profile=None): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
818 """Get all contacts from backend, and fill the widget |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
819 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
820 Contacts will be cleared before refilling them |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
821 @param profile(unicode, None): profile to fill |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
822 None to fill all profiles |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
823 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
824 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
825 to_fill = self._to_fill |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
826 except AttributeError: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
827 to_fill = self._to_fill = set() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
828 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
829 # if check if profiles have already been filled |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
830 # to void filling them several times |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
831 filled = to_fill.copy() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
832 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
833 if profile is not None: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
834 assert profile in self._clist |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
835 to_fill.add(profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
836 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
837 to_fill.update(self._clist.items()) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
838 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
839 remaining = to_fill.difference(filled) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
840 if remaining != to_fill: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
841 log.debug(u"Not re-filling already filled contact list(s) for {}".format(u', '.join(to_fill.intersection(filled)))) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
842 for profile in remaining: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
843 self._clist[profile]._fill() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
844 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
845 def clearContacts(self, keep_cache=False): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
846 """Clear all the contact list |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
847 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
848 @param keep_cache: if True, don't reset the cache |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
849 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
850 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
851 contact_list.clearContacts(keep_cache) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
852 self.update() |
1332
0f92b6a150ff
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents:
1328
diff
changeset
|
853 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
854 def select(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
855 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
856 contact_list.select(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
857 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
858 def unselect(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
859 for contact_list in self._clist.itervalues(): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
860 contact_list.select(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
861 |
1939
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
862 def lockUpdate(self, locked=True, do_update=True): |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
863 """Forbid contact list updates |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
864 |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
865 Used mainly while profiles are plugged, as many updates can occurs, causing |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
866 an impact on performances |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
867 @param locked(bool): updates are forbidden if True |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
868 @param do_update(bool): if True, a full update is done after unlocking |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
869 if set to False, widget state can be inconsistent, be sure to know |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
870 what youa re doing! |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
871 """ |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
872 log.debug(u"Contact lists updates are now {}".format(u"LOCKED" if locked else u"UNLOCKED")) |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
873 self._update_locked = locked |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
874 if not locked and do_update: |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
875 self.update() |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
876 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
877 def update(self, entities=None, type_=None, profile=None): |
1939
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
878 if not self._update_locked: |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
879 for widget in self._widgets: |
e68483c5a999
quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
880 widget.update(entities, type_, profile) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
881 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
882 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
883 class QuickContactList(QuickWidget): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
884 """This class manage the visual representation of contacts""" |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
885 SINGLE=False |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
886 PROFILES_MULTIPLE=True |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
887 PROFILES_ALLOW_NONE=True # Can be linked to no profile (e.g. at the early forntend start) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
888 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
889 def __init__(self, host, profiles): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
890 super(QuickContactList, self).__init__(host, None, profiles) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
891 handler.register(self) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
892 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
893 # options |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
894 # for next values, None means use indivual value per profile |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
895 # True or False mean override these values for all profiles |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
896 self.show_disconnected = None # TODO |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
897 self.show_empty_groups = None # TODO |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
898 self.show_resources = None # TODO |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
899 self.show_status = None # TODO |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
900 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
901 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
902 def items(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
903 return handler.items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
904 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
905 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
906 def items_sorted(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
907 return handler.items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
908 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
909 def update(self, entities=None, type_=None, profile=None): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
910 """Update the display when something changed |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
911 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
912 @param entities(iterable[jid.JID], None): updated entities, |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
913 None to update the whole contact list |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
914 @param type_(unicode, None): update type, may be: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
915 - C.UPDATE_DELETE: entity deleted |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
916 - C.UPDATE_MODIFY: entity updated |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
917 - C.UPDATE_ADD: entity added |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
918 - C.UPDATE_SELECTION: selection modified |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
919 or None for undefined update |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
920 @param profile(unicode, None): profile concerned with the update |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
921 None if unknown |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
922 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
923 raise NotImplementedError |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
924 |
1332
0f92b6a150ff
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents:
1328
diff
changeset
|
925 def onDelete(self): |
0f92b6a150ff
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents:
1328
diff
changeset
|
926 QuickWidget.onDelete(self) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
927 handler.unregister(self) |