Mercurial > libervia-backend
annotate sat_frontends/quick_frontend/quick_contact_list.py @ 3114:060ac43627fc
quick frontend (widgets): fixed widget creation in getOrCreateWidget:
when a new widget was created, it was overwritting the exiting instances list. This patch
fixes it.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jan 2020 17:55:57 +0100 |
parents | b067736d5099 |
children | 9d0df638c8b4 |
rev | line source |
---|---|
3113
b067736d5099
quick frontend (app): removed workaround for pyjamas
Goffi <goffi@goffi.org>
parents:
3065
diff
changeset
|
1 #!/usr/bin/env python3 |
0 | 2 |
3113
b067736d5099
quick frontend (app): removed workaround for pyjamas
Goffi <goffi@goffi.org>
parents:
3065
diff
changeset
|
3 # helper class for making a SàT frontend contact lists |
2771 | 4 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
0 | 5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
6 # 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
|
7 # 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
|
8 # 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
|
9 # (at your option) any later version. |
0 | 10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
11 # 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
|
12 # 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
|
13 # 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
|
14 # GNU Affero General Public License for more details. |
0 | 15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
16 # 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
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
19 """Contact List handling multi profiles at once, |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
20 should replace quick_contact_list module in the future""" |
1938
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 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 |
2978
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
30 log = getLogger(__name__) |
1290
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 |
3028 | 34 str("") # XXX: unicode doesn't exist in pyjamas |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
35 except (TypeError, AttributeError): # Error raised is not the same depending on |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
36 # pyjsbuild options |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
37 # 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
|
38 pyjamas_max = max |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
39 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
40 def max(iterable, key): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
41 iter_cpy = list(iterable) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
42 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
|
43 return pyjamas_max(iter_cpy) |
0 | 44 |
2032
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
45 # next doesn't exist in pyjamas |
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
46 def next(iterable, *args): |
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
47 try: |
3028 | 48 return iterable.__next__() |
2032
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
49 except StopIteration as e: |
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
50 if args: |
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
51 return args[0] |
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
52 raise e |
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
53 |
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
54 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
55 handler = None |
0 | 56 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
57 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
58 class ProfileContactList(object): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
59 """Contact list data for a single profile""" |
0 | 60 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
61 def __init__(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
62 self.host = handler.host |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
63 self.profile = profile |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
64 # 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
|
65 # 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
|
66 # 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
|
67 # 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
|
68 self._cache = {} |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
69 |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
70 # special entities (groupchat, gateways, etc) |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
71 # may be bare or full jid |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
72 self._specials = set() |
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 # group data contain jids in groups and misc frontend data |
2582
2e6864b1d577
quick frontend (contact list): don't store "nick" for group contacts:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 # None key is used for jids with no group |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
76 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
|
77 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
78 # 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
|
79 self._roster = set() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
80 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
81 # 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
|
82 self._selected = set() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
83 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
84 # options |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 self.show_status = False |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
89 # do we show entities with notifications? |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
90 # if True, entities will be show even if they normally would not |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
91 # (e.g. not in contact list) if they have notifications attached |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
92 self.show_entities_with_notifs = True |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
93 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
94 self.host.bridge.asyncGetParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
95 C.SHOW_EMPTY_GROUPS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
96 "General", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
97 profile_key=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
98 callback=self._showEmptyGroups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
99 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
100 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
101 self.host.bridge.asyncGetParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
102 C.SHOW_OFFLINE_CONTACTS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
103 "General", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
104 profile_key=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
105 callback=self._showOfflineContacts, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
106 ) |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
107 |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
108 # FIXME: workaround for a pyjamas issue: calling hash on a class method always |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
109 # return a different value if that method is defined directly within the |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
110 # 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
|
111 self.presenceListener = self.onPresenceUpdate |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
112 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
|
113 self.nickListener = self.onNickUpdate |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
114 self.host.addListener("nick", self.nickListener, [self.profile]) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
115 self.notifListener = self.onNotification |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
116 self.host.addListener("notification", self.notifListener, [self.profile]) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
117 # notifListener only update the entity, so we can re-use it |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
118 self.host.addListener("notificationsClear", self.notifListener, [self.profile]) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
119 |
2686
ce1e15d59496
quick frontend (contact list): use property to retrieve "whoami" in ProfileContactList:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
120 @property |
ce1e15d59496
quick frontend (contact list): use property to retrieve "whoami" in ProfileContactList:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
121 def whoami(self): |
ce1e15d59496
quick frontend (contact list): use property to retrieve "whoami" in ProfileContactList:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
122 return self.host.profiles[self.profile].whoami |
ce1e15d59496
quick frontend (contact list): use property to retrieve "whoami" in ProfileContactList:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
123 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
124 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
|
125 # Called only by __init__ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
126 # 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
|
127 # 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
|
128 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
|
129 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
130 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
|
131 # 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
|
132 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
|
133 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
134 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
|
135 """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
|
136 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
137 An entity can be in contact list even if not in roster |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
138 @param entity (jid.JID): jid of the entity (resource is not ignored, |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
139 use bare jid if needed) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
140 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
141 if entity.resource: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
142 try: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
143 return entity.resource in self.getCache(entity.bare, C.CONTACT_RESOURCES) |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
144 except exceptions.NotFound: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
145 return False |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
146 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
|
147 |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
148 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
149 def roster(self): |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
150 """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
|
151 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
152 @return (set[jid.JID]) |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
153 """ |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
154 return self._roster |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
155 |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
156 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
157 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
|
158 """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
|
159 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
160 @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
|
161 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
162 return set( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
163 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
164 entity |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
165 for entity in self._roster |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
166 if self.getCache(entity, C.PRESENCE_SHOW) is not None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
167 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
168 ) |
1328
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
169 |
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
170 @property |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
171 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
|
172 """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
|
173 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
174 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
|
175 @return (dict[unicode,set(jid.JID)]) |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
176 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
177 return {group: self._groups[group]["jids"] for group in self._groups} |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
178 |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
179 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
180 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
|
181 """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
|
182 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
183 @return (dict[jid.JID, set(unicode)]) |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
184 """ |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
185 result = {} |
3028 | 186 for group, data in self._groups.items(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
187 for entity in data["jids"]: |
1297
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
188 result.setdefault(entity, set()).add(group) |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
189 return result |
ef7e8e23b353
quick_frontend: add some properties for QuickContactList
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
190 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
191 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
192 def selected(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
193 """Return contacts currently selected |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
194 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
195 @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
|
196 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
197 return self._selected |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
198 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
199 @property |
2124
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
200 def all_iter(self): |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
201 """return all know entities in cache as an iterator of tuples |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
202 |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
203 entities are not sorted |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
204 """ |
3028 | 205 return iter(self._cache.items()) |
2124
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
206 |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
207 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
208 def items(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
209 """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
|
210 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
211 entities are not sorted |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
212 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
|
213 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
214 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
215 jid_: cache |
3028 | 216 for jid_, cache in self._cache.items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
217 if self.entityVisible(jid_) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
218 } |
2124
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
219 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
220 def getItem(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
221 """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
|
222 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
223 @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
|
224 @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
|
225 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
226 return self._cache[entity] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
227 |
1462 | 228 def _gotContacts(self, contacts): |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
229 """Add contacts and notice parent that contacts are filled |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
230 |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
231 Called during initial contact list filling |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
232 @param contacts(tuple): all contacts |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
233 """ |
1462 | 234 for contact in contacts: |
2978
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
235 entity = jid.JID(contact[0]) |
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
236 if entity.resource: |
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
237 # we use entity's bare jid to cache data, so a resource here |
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
238 # will cause troubles |
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
239 log.warning( |
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
240 "Roster entities with resources are not managed, ignoring {entity}" |
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
241 .format(entity=entity)) |
bad0b4280b77
quick frontends (contact list): ignore roster entities with a resource:
Goffi <goffi@goffi.org>
parents:
2897
diff
changeset
|
242 continue |
1462 | 243 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
|
244 handler._contactsFilled(self.profile) |
1462 | 245 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
246 def _fill(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
247 """Get all contacts from backend |
1429
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1428
diff
changeset
|
248 |
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1428
diff
changeset
|
249 Contacts will be cleared before refilling them |
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1428
diff
changeset
|
250 """ |
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
|
251 self.clearContacts(keep_cache=True) |
1462 | 252 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
|
253 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
254 def fill(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
255 handler.fill(self.profile) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
256 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
257 def getCache(self, entity, name=None, bare_default=True, create_if_not_found=False): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
258 """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
|
259 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
260 @param entity(jid.JID): entity of the contact from who we want data |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
261 (resource is used if given) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
262 if a resource specific information is requested: |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
263 - if no resource is given (bare jid), the main resource is used, |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
264 according to priority |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
265 - 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
|
266 @param name(unicode): name the data to get, or None to get everything |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
267 @param bare_default(bool, None): if True and entity is a full jid, |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
268 the value of bare jid will be returned if not value is found for |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
269 the requested resource. |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
270 If False, None is returned if no value is found for the requested resource. |
2122
3970ebcf8830
quick frontend (contact list): bare_default in getCache now default to True, plus added None:
Goffi <goffi@goffi.org>
parents:
2121
diff
changeset
|
271 If None, bare_default will be set to False if entity is in a room, True else |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
272 @param create_if_not_found(bool): if True, create contact if it's not found |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
273 in cache |
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
|
274 @return: full cache if no name is given, or value of "name", or None |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
275 @raise NotFound: entity not found in cache |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
276 """ |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
277 # FIXME: resource handling need to be reworked |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
278 # FIXME: bare_default work for requesting full jid to get bare jid, |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
279 # but not the other way |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
280 # e.g.: if we have set an avatar for user@server.tld/resource |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
281 # and we request user@server.tld |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2122
diff
changeset
|
282 # we won't get the avatar set in the resource |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
283 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
284 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
|
285 except KeyError: |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
286 if create_if_not_found: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
287 self.setContact(entity) |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
288 cache = self._cache[entity.bare] |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
289 else: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
290 raise exceptions.NotFound |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
291 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
292 if name is None: |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
293 # full cache is requested |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
294 return cache |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
295 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
296 if name in ("status", C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW): |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
297 # these data are related to the resource |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
298 if not entity.resource: |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
299 main_resource = cache[C.CONTACT_MAIN_RESOURCE] |
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
300 if main_resource is None: |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
301 # we ignore presence info if we don't have any resource in cache |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
302 # FIXME: to be checked |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
303 return |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
304 cache = cache[C.CONTACT_RESOURCES].setdefault(main_resource, {}) |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
305 else: |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
306 cache = cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {}) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
307 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
308 if name == "status": # XXX: we get the first status for 'status' key |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
309 # TODO: manage main language for statuses |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
310 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
|
311 |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
312 elif entity.resource: |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
313 try: |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
314 return cache[C.CONTACT_RESOURCES][entity.resource][name] |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
315 except KeyError: |
2122
3970ebcf8830
quick frontend (contact list): bare_default in getCache now default to True, plus added None:
Goffi <goffi@goffi.org>
parents:
2121
diff
changeset
|
316 if bare_default is None: |
3970ebcf8830
quick frontend (contact list): bare_default in getCache now default to True, plus added None:
Goffi <goffi@goffi.org>
parents:
2121
diff
changeset
|
317 bare_default = not self.isRoom(entity.bare) |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
318 if not bare_default: |
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
319 return None |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
320 |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2032
diff
changeset
|
321 try: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
322 return cache[name] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
323 except KeyError: |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
324 return None |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
325 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
326 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
|
327 """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
|
328 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
329 @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
|
330 @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
|
331 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
332 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
|
333 |
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
|
334 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
|
335 """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
|
336 |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
337 @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
|
338 @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
|
339 @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
|
340 """ |
15e177584d82
quick frontends(contact list): added a getFullJid method to add resource to a bare jid
Goffi <goffi@goffi.org>
parents:
1333
diff
changeset
|
341 if entity.resource: |
3028 | 342 raise ValueError("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
|
343 main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE) |
3028 | 344 return jid.JID("{}/{}".format(entity, main_resource)) |
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
|
345 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
346 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
|
347 """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
|
348 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
349 @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
|
350 @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
|
351 @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
|
352 """ |
2828
08b54bf77c54
primitivus(contact list): fixed room not always appearing correctly in contact list
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
353 assert name != "jids" |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
354 self._groups[group][name] = value |
124 | 355 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
356 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
|
357 """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
|
358 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
359 @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
|
360 @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
|
361 @return: registered value |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
362 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 |
2121
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
367 def isRoom(self, entity): |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
368 """Helper method to know if entity is a MUC room |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
369 |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
370 @param entity(jid.JID): jid of the entity |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
371 hint: use bare jid here, as room can't be full jid with MUC |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
372 @return (bool): True if entity is a room |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
373 """ |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
374 assert entity.resource is None # FIXME: this may change when MIX will be handled |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
375 return self.isSpecial(entity, C.CONTACT_SPECIAL_GROUP) |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
376 |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
377 def isSpecial(self, entity, special_type): |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
378 """Tell if an entity is of a specialy _type |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
379 |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
380 @param entity(jid.JID): jid of the special entity |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
381 if the jid is full, will be added to special extras |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
382 @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
383 @return (bool): True if entity is from this special type |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
384 """ |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
385 return self.getCache(entity, C.CONTACT_SPECIAL) == special_type |
df5cb9e7d0b7
quick frontend (contact list): added isSpecial and isRoom to quickly now if an entity is specific
Goffi <goffi@goffi.org>
parents:
2120
diff
changeset
|
386 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
387 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
|
388 """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
|
389 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
390 @param entity(jid.JID): jid of the special entity |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
391 if the jid is full, will be added to special extras |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
392 @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
393 or None to remove special flag |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
394 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
395 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
|
396 self.setCache(entity, C.CONTACT_SPECIAL, special_type) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
397 |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
398 def getSpecials(self, special_type=None, bare=False): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
399 """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
|
400 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
401 @param special_type(unicode, None): if not None, filter by special type |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
402 (e.g. C.CONTACT_SPECIAL_GROUP) |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
403 @param bare(bool): return only bare jids if True |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
404 @return (iter[jid.JID]): found special entities |
1328
7a3a232d4938
quick_frontend (quick_contact_list): add property roster_entities_connected and method getSpecials
souliane <souliane@mailoo.org>
parents:
1306
diff
changeset
|
405 """ |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
406 for entity in self._specials: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
407 if bare and entity.resource: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
408 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
409 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
410 special_type is not None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
411 and self.getCache(entity, C.CONTACT_SPECIAL) != special_type |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
412 ): |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
413 continue |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
414 yield entity |
1428
0e518415d03a
display the resource in the chat dialog when printing a private MUC message
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
415 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
416 def disconnect(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
417 # 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
|
418 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
|
419 |
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
|
420 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
|
421 """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
|
422 |
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
|
423 @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
|
424 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 self._groups.clear() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
429 self._specials.clear() |
1410
e2e75c3c7c7b
quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
430 self._roster.clear() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
431 self.update() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
432 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
433 def setContact(self, entity, groups=None, attributes=None, in_roster=False): |
2828
08b54bf77c54
primitivus(contact list): fixed room not always appearing correctly in contact list
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
434 """Add a contact to the list if it doesn't exist, else update it. |
1000
6f1e03068b5f
primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
435 |
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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
441 None value for 'groups' has a different meaning than [None] |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
442 which is for the default group. |
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
|
443 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
444 @param entity (jid.JID): entity to add or replace |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
445 if entity is a full jid, attributes will be cached in for the full jid only |
1000
6f1e03068b5f
primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
446 @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
|
447 @param attributes (dict): attibutes of the added jid or to update |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
448 if attribute value is None, it will be removed |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
449 @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
|
450 """ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
451 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
|
452 attributes = {} |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
453 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
454 entity_bare = entity.bare |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
455 # we check if the entity is visible before changing anything |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
456 # this way we know if we need to do an UPDATE_ADD, UPDATE_MODIFY |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
457 # or an UPDATE_DELETE |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
458 was_visible = self.entityVisible(entity_bare) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
459 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
460 if in_roster: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
461 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
|
462 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
463 cache = self._cache.setdefault( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
464 entity_bare, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
465 { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
466 C.CONTACT_RESOURCES: {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
467 C.CONTACT_MAIN_RESOURCE: None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
468 C.CONTACT_SELECTED: set(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
469 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
470 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
471 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
472 # we don't want forbidden data in attributes |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
473 assert not C.CONTACT_DATA_FORBIDDEN.intersection(attributes) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
474 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
475 # 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
|
476 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
|
477 if not groups: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
478 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
|
479 if C.CONTACT_GROUPS in cache: |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
480 # XXX: don't use set(cache[C.CONTACT_GROUPS]).difference(groups) because |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
481 # it won't work in Pyjamas if None is in cache[C.CONTACT_GROUPS] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
482 for group in [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
483 group for group in cache[C.CONTACT_GROUPS] if group not in groups |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
484 ]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
485 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
|
486 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
|
487 for group in groups: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
488 self._groups.setdefault(group, {}).setdefault("jids", set()).add( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
489 entity_bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
490 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
491 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
492 # special entities management |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
493 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
|
494 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
|
495 del attributes[C.CONTACT_SPECIAL] |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
496 self._specials.remove(entity) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
497 else: |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
498 self._specials.add(entity) |
1393
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
499 cache[C.CONTACT_MAIN_RESOURCE] = None |
2987
8990ed9aad31
quick_frontend (contact list): fixed `nick` use for groupchat:
Goffi <goffi@goffi.org>
parents:
2978
diff
changeset
|
500 if 'nick' in cache: |
8990ed9aad31
quick_frontend (contact list): fixed `nick` use for groupchat:
Goffi <goffi@goffi.org>
parents:
2978
diff
changeset
|
501 del cache['nick'] |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
502 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
503 # now the attributes we keep in cache |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
504 # XXX: if entity is a full jid, we store the value for the resource only |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
505 cache_attr = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
506 cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {}) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
507 if entity.resource |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
508 else cache |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
509 ) |
3028 | 510 for attribute, value in attributes.items(): |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
511 if value is None: |
2120
4d9aeae5d9d0
quick frontend (contact list): fixed cached key removal
Goffi <goffi@goffi.org>
parents:
2082
diff
changeset
|
512 # XXX: pyjamas hack: we need to use pop instead of del |
4d9aeae5d9d0
quick frontend (contact list): fixed cached key removal
Goffi <goffi@goffi.org>
parents:
2082
diff
changeset
|
513 try: |
4d9aeae5d9d0
quick frontend (contact list): fixed cached key removal
Goffi <goffi@goffi.org>
parents:
2082
diff
changeset
|
514 cache_attr[attribute].pop(value) |
4d9aeae5d9d0
quick frontend (contact list): fixed cached key removal
Goffi <goffi@goffi.org>
parents:
2082
diff
changeset
|
515 except KeyError: |
4d9aeae5d9d0
quick frontend (contact list): fixed cached key removal
Goffi <goffi@goffi.org>
parents:
2082
diff
changeset
|
516 pass |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
517 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
518 if attribute == "nick" and self.isSpecial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
519 entity, C.CONTACT_SPECIAL_GROUP |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
520 ): |
2582
2e6864b1d577
quick frontend (contact list): don't store "nick" for group contacts:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
521 # we don't want to keep nick for MUC rooms |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
522 # FIXME: this is here as plugin XEP-0054 can link resource's nick |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
523 # with bare jid which in the case of MUC |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
524 # set the nick for the whole MUC |
2582
2e6864b1d577
quick frontend (contact list): don't store "nick" for group contacts:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
525 # resulting in bad name displayed in some frontends |
2e6864b1d577
quick frontend (contact list): don't store "nick" for group contacts:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
526 continue |
2065
f3167c873e7b
quick frontend (contact list): better handling of cache with full jid:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
527 cache_attr[attribute] = value |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
528 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
529 # we can update the display if needed |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
530 if self.entityVisible(entity_bare): |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
531 # if the contact was not visible, we need to add a widget |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
532 # else we just update id |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
533 update_type = C.UPDATE_MODIFY if was_visible else C.UPDATE_ADD |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
534 self.update([entity], update_type, self.profile) |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
535 elif was_visible: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
536 # the entity was visible and is not anymore, we remove it |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
537 self.update([entity], C.UPDATE_DELETE, self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
538 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
539 def entityVisible(self, entity, check_resource=False): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
540 """Tell if the contact should be showed or hidden. |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
541 |
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
|
542 @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
|
543 @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
|
544 @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
|
545 """ |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
546 try: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
547 show = self.getCache(entity, C.PRESENCE_SHOW) |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
548 except exceptions.NotFound: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
549 return False |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
550 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
551 if check_resource: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
552 selected = self._selected |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
553 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
554 selected = {selected.bare for selected in self._selected} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
555 return ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
556 (show is not None and show != C.PRESENCE_UNAVAILABLE) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
557 or self.show_disconnected |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
558 or entity in selected |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
559 or ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
560 self.show_entities_with_notifs |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
561 and next(self.host.getNotifs(entity.bare, profile=self.profile), None) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
562 ) |
2828
08b54bf77c54
primitivus(contact list): fixed room not always appearing correctly in contact list
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
563 or entity.resource is None and self.isRoom(entity.bare) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
564 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
565 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
566 def anyEntityVisible(self, entities, check_resources=False): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
567 """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
|
568 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
569 @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
|
570 @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
|
571 @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
|
572 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
573 # 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
|
574 for entity in entities: |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
575 if self.entityVisible(entity, check_resources): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
576 return True |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
577 return False |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
578 |
1302
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
579 def isEntityInGroup(self, entity, group): |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
580 """Tell if an entity is in a roster group |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
581 |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
582 @param entity(jid.JID): jid of the entity |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
583 @param group(unicode): group to check |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
584 @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
|
585 """ |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
586 return entity in self.getGroupData(group, "jids") |
447d28b1b4ec
quick frontends (QuickContactList): added isEntityInGroup method
Goffi <goffi@goffi.org>
parents:
1290
diff
changeset
|
587 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
588 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
|
589 """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
|
590 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
591 @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
|
592 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
593 entity_bare = entity.bare |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
594 was_visible = self.entityVisible(entity_bare) |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
595 try: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
596 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
|
597 except KeyError: |
3028 | 598 log.error(_("Trying to delete an unknow entity [{}]").format(entity)) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
599 try: |
1738
baac0fc5e3ad
reverted patch 58ecc0e2e6fc as it may hide an other issue
Goffi <goffi@goffi.org>
parents:
1731
diff
changeset
|
600 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
|
601 except KeyError: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
602 pass |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
603 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
|
604 for group in groups: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
605 self._groups[group]["jids"].remove(entity_bare) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
606 if not self._groups[group]["jids"]: |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
607 # FIXME: we use pop because of pyjamas: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
608 # http://wiki.goffi.org/wiki/Issues_with_Pyjamas/en |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
609 self._groups.pop(group) |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
1983
diff
changeset
|
610 for iterable in (self._selected, self._specials): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
611 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
|
612 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
|
613 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
|
614 to_remove.add(set_entity) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
615 iterable.difference_update(to_remove) |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
616 if was_visible: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
617 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
|
618 |
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
|
619 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
|
620 """Update entity's presence status |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
621 |
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
|
622 @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
|
623 @param show: availability |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
624 @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
|
625 @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
|
626 @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
|
627 """ |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
628 # FIXME: cache modification should be done with setContact |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
629 # the resources/presence handling logic should be moved there |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
630 was_visible = self.entityVisible(entity.bare) |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
631 cache = self.getCache(entity, create_if_not_found=True) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
632 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
|
633 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
|
634 cache[C.CONTACT_RESOURCES].clear() |
1391
1276e6a0716b
quick_frontend: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 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
|
639 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
640 log.error( |
3028 | 641 "Presence unavailable received " |
642 "for an unknown resource [{}]".format(entity) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
643 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
644 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
|
645 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
|
646 else: |
1983
8c4087fd034a
quick_frontend: allow presence of entities without resource
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
647 if not entity.resource: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
648 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
649 _( |
3028 | 650 "received presence from entity " |
651 "without resource: {}".format(entity) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
652 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
653 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 |
1393
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
660 if entity.bare not in self._specials: |
2082
e8cb9cc09485
quick frontend(contact_list): avoid crash when resource in cache has not priority
Goffi <goffi@goffi.org>
parents:
2065
diff
changeset
|
661 # we may have resources with no priority |
e8cb9cc09485
quick frontend(contact_list): avoid crash when resource in cache has not priority
Goffi <goffi@goffi.org>
parents:
2065
diff
changeset
|
662 # (when a cached value is added for a not connected resource) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
663 priority_resource = max( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
664 resources_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
665 key=lambda res: resources_data[res].get( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
666 C.PRESENCE_PRIORITY, -2 ** 32 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
667 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
668 ) |
1393
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
669 cache[C.CONTACT_MAIN_RESOURCE] = priority_resource |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
670 if self.entityVisible(entity.bare): |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
671 update_type = C.UPDATE_MODIFY if was_visible else C.UPDATE_ADD |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
672 self.update([entity], update_type, self.profile) |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
673 elif was_visible: |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
674 self.update([entity], C.UPDATE_DELETE, self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
675 |
1342
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
676 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
|
677 """Update entity's nick |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
678 |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
679 @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
|
680 @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
|
681 @param profile: %(doc_profile)s |
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
682 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
683 assert profile == self.profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
684 self.setCache(entity, "nick", new_nick) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
685 |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
686 def onNotification(self, entity, notif, profile): |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
687 """Update entity with notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
688 |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
689 @param entity(jid.JID): entity updated |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
690 @param notif(dict): notification data |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
691 @param profile: %(doc_profile)s |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
692 """ |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
693 assert profile == self.profile |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
694 if entity is not None and self.entityVisible(entity): |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
695 self.update([entity], C.UPDATE_MODIFY, profile) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
696 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
697 def unselect(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
698 """Unselect an entity |
1342
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
699 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
700 @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
|
701 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
702 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
703 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
|
704 except: |
3028 | 705 log.error("Try to unselect an entity not in cache") |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
706 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
707 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
708 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
|
709 except KeyError: |
3028 | 710 log.error("Try to unselect a not selected entity") |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
711 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
712 self._selected.remove(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
713 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
|
714 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
715 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
|
716 """Select an entity |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
717 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
718 @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
|
719 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
|
720 """ |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
721 if entity is None: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
722 self._selected.clear() |
3028 | 723 for cache in self._cache.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
724 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
|
725 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
|
726 else: |
3028 | 727 log.debug("select %s" % entity) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
728 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
729 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
|
730 except: |
3028 | 731 log.error("Try to select an entity not in cache") |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
732 else: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
733 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
|
734 self._selected.add(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
735 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
|
736 |
1229
03661d1b216a
primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents:
1058
diff
changeset
|
737 def showOfflineContacts(self, show): |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
738 """Tell if offline contacts should be shown |
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
|
739 |
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
|
740 @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
|
741 """ |
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
|
742 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
|
743 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
|
744 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
745 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
|
746 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
|
747 |
1230
3abc6563a0d2
primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1229
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
752 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
|
753 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
|
754 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
755 def showResources(self, show): |
1572
6a6fe840c3a6
quick frontend: fixed resources display in quickContactList
Goffi <goffi@goffi.org>
parents:
1462
diff
changeset
|
756 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
|
757 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
|
758 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
759 self.show_resources = show |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
760 self.update(type_=C.UPDATE_STRUCTURE, profile=self.profile) |
1938
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 def plug(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
763 handler.addProfile(self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
764 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
765 def unplug(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
766 handler.removeProfile(self.profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
767 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
768 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
|
769 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
|
770 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
771 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
772 class QuickContactListHandler(object): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
773 def __init__(self, host): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
774 super(QuickContactListHandler, self).__init__() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
775 self.host = host |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
776 global handler |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
777 if handler is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
778 raise exceptions.InternalError( |
3028 | 779 "QuickContactListHandler must be instanciated only once" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
780 ) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
781 handler = self |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
782 self._clist = {} # key: profile, value: ProfileContactList |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
783 self._widgets = set() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
784 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
|
785 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
786 def __getitem__(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
787 """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
|
788 return self._clist[profile] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
789 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
790 def __contains__(self, entity): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
791 """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
|
792 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
793 @param entity (jid.JID): jid of the entity (resource is not ignored, |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
794 use bare jid if needed) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
795 """ |
3028 | 796 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
797 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
|
798 return True |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
799 return False |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
800 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
801 @property |
2032
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
802 def roster(self): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
803 """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
|
804 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
805 @return (set[jid.JID]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
806 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
807 entities = set() |
3028 | 808 for contact_list in self._clist.values(): |
2032
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
809 entities.update(contact_list.roster) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
810 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
811 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
812 @property |
2032
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
813 def roster_connected(self): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
814 """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
|
815 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
816 @return (set[jid.JID]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
817 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
818 entities = set() |
3028 | 819 for contact_list in self._clist.values(): |
2032
d941fa9954f4
quick frontend (contact): fixed roster and roster_connected in handler + add a next function for pyjamas compatibility
Goffi <goffi@goffi.org>
parents:
2017
diff
changeset
|
820 entities.update(contact_list.roster_connected) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
821 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
822 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
823 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
824 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
|
825 """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
|
826 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
|
827 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
828 @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
|
829 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
830 groups = {} |
3028 | 831 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
832 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
|
833 return groups |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
834 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
835 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
836 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
|
837 """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
|
838 groups. |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
839 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
840 @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
|
841 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
842 entities = {} |
3028 | 843 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
844 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
|
845 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
846 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
847 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
848 def selected(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
849 """Return contacts currently selected |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
850 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
851 @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
|
852 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
853 entities = set() |
3028 | 854 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
855 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
|
856 return entities |
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 @property |
2124
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
859 def all_iter(self): |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
860 """Return item representation for all entities in cache |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
861 |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
862 items are unordered |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
863 """ |
3028 | 864 for profile, contact_list in self._clist.items(): |
2124
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
865 for bare_jid, cache in contact_list.all_iter: |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
866 data = cache.copy() |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
867 data[C.CONTACT_PROFILE] = profile |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
868 yield bare_jid, data |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
869 |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
870 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
871 def items(self): |
1943 | 872 """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
|
873 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
874 items are unordered |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
875 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
|
876 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
877 items = {} |
3028 | 878 for profile, contact_list in self._clist.items(): |
879 for bare_jid, cache in contact_list.items.items(): | |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
880 data = cache.copy() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
881 items[bare_jid] = data |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
882 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
|
883 return items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
884 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
885 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
886 def items_sorted(self): |
1943 | 887 """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
|
888 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
889 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
|
890 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
|
891 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
892 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
|
893 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
894 def items_sort(self, items): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
895 """sort items |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
896 |
1943 | 897 @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
|
898 @return (OrderedDict): sorted items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
899 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
900 ordered_items = OrderedDict() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
901 bare_jids = sorted(items.keys()) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
902 for jid_ in bare_jids: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
903 ordered_items[jid_] = items.pop(jid_) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
904 return ordered_items |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
905 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
906 def register(self, widget): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
907 """Register a QuickContactList widget |
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 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
|
910 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
911 self._widgets.add(widget) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
912 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
913 def unregister(self, widget): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
914 """Unregister a QuickContactList widget |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
915 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
916 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
|
917 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
918 self._widgets.remove(widget) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
919 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
920 def addProfiles(self, profiles): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
921 """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
|
922 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
923 @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
|
924 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
925 for profile in profiles: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
926 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
|
927 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
|
928 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
|
929 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
930 def addProfile(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
931 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
|
932 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
933 def removeProfiles(self, profiles): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
934 """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
|
935 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
936 @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
|
937 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
938 for profile in profiles: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
939 del self._clist[profile] |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
940 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
941 def removeProfile(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
942 self.removeProfiles([profile]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
943 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
944 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
|
945 """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
|
946 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
947 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
|
948 |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
949 @param special_type(unicode, None): one of special type |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
950 (e.g. C.CONTACT_SPECIAL_GROUP) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
951 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
|
952 @return (set[jid.JID]) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
953 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
954 entities = set() |
3028 | 955 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
956 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
|
957 return entities |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
958 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
959 def _contactsFilled(self, profile): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
960 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
|
961 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
|
962 del self._to_fill |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
963 # we need a full update when all contacts are filled |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
964 self.update() |
3065
f8e3789912d0
quick frontend (contact list): added "contactsFilled" event
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
965 self.host.callListeners("contactsFilled", profile=profile) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
966 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
967 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
|
968 """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
|
969 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
970 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
|
971 @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
|
972 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
|
973 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
974 try: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
975 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
|
976 except AttributeError: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
977 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
|
978 |
2897
82d8243e6ad1
quick frontend (contact list): fixed profile filtering in fill()
Goffi <goffi@goffi.org>
parents:
2828
diff
changeset
|
979 # we check if profiles have already been filled |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
980 # 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
|
981 filled = to_fill.copy() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
982 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
983 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
|
984 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
|
985 to_fill.add(profile) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
986 else: |
3028 | 987 to_fill.update(list(self._clist.keys())) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
988 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
989 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
|
990 if remaining != to_fill: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
991 log.debug( |
3028 | 992 "Not re-filling already filled contact list(s) for {}".format( |
993 ", ".join(to_fill.intersection(filled)) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
994 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
995 ) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
996 for profile in remaining: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
997 self._clist[profile]._fill() |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
998 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
999 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
|
1000 """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
|
1001 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1002 @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
|
1003 """ |
3028 | 1004 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1005 contact_list.clearContacts(keep_cache) |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
1006 # we need a full update |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1230
diff
changeset
|
1007 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
|
1008 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1009 def select(self, entity): |
3028 | 1010 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1011 contact_list.select(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1012 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1013 def unselect(self, entity): |
3028 | 1014 for contact_list in self._clist.values(): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1015 contact_list.select(entity) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1016 |
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
|
1017 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
|
1018 """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
|
1019 |
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
|
1020 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
|
1021 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
|
1022 @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
|
1023 @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
|
1024 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
|
1025 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
|
1026 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1027 log.debug( |
3028 | 1028 "Contact lists updates are now {}".format( |
1029 "LOCKED" if locked else "UNLOCKED" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1030 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1031 ) |
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
|
1032 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
|
1033 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
|
1034 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
|
1035 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1036 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
|
1037 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
|
1038 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
|
1039 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
|
1040 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1041 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1042 class QuickContactList(QuickWidget): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1043 """This class manage the visual representation of contacts""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1044 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1045 SINGLE = False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1046 PROFILES_MULTIPLE = True |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
1047 # Can be linked to no profile (e.g. at the early frontend start) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1048 PROFILES_ALLOW_NONE = True |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1049 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1050 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
|
1051 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
|
1052 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1053 # options |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1054 # 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
|
1055 # True or False mean override these values for all profiles |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1056 self.show_disconnected = None # TODO |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1057 self.show_empty_groups = None # TODO |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1058 self.show_resources = None # TODO |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
1059 self.show_status = None # TODO |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1060 |
2017
7aa58b7a47e2
quick_frontend, primitivus (contact_list): ContactList widget must now call postInit() when ready, to avoid being registered before being constructed
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
1061 def postInit(self): |
7aa58b7a47e2
quick_frontend, primitivus (contact_list): ContactList widget must now call postInit() when ready, to avoid being registered before being constructed
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
1062 """Method to be called by frontend after widget is initialised""" |
7aa58b7a47e2
quick_frontend, primitivus (contact_list): ContactList widget must now call postInit() when ready, to avoid being registered before being constructed
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
1063 handler.register(self) |
7aa58b7a47e2
quick_frontend, primitivus (contact_list): ContactList widget must now call postInit() when ready, to avoid being registered before being constructed
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
1064 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1065 @property |
2124
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
1066 def all_iter(self): |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
1067 return handler.all_iter |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
1068 |
cf63e4209643
quick frontend(contact list): added all_iter property to get all cached entities
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
1069 @property |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1070 def items(self): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1071 return handler.items |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1072 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1073 @property |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1074 def items_sorted(self): |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
1075 return handler.items_sorted |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1076 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1077 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
|
1078 """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
|
1079 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1080 @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
|
1081 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
|
1082 @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
|
1083 - 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
|
1084 - 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
|
1085 - 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
|
1086 - 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
|
1087 or None for undefined update |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
1088 Note that events correspond to addition, modification and deletion |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
1089 of items on the whole contact list. If the contact is visible or not |
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
1090 has no influence on the type_. |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1091 @param profile(unicode, None): profile concerned with the update |
2617
81b70eeb710f
quick_frontend(contact list): refactored update:
Goffi <goffi@goffi.org>
parents:
2582
diff
changeset
|
1092 None if all profiles need to be updated |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1093 """ |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1094 raise NotImplementedError |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1095 |
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
|
1096 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
|
1097 QuickWidget.onDelete(self) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1098 handler.unregister(self) |