Mercurial > libervia-backend
annotate sat_frontends/primitivus/contact_list.py @ 3865:59fbb66b2923
component AP gateway: handle XMPP attachments -> AP likes conversion:
convert `noticed` attachments coming from XMPP to suitable `Like` activities. Virtual node
is created in cache when necessary, and virtual items published to virtual JID mapping AP
accounts are cached too.
rel 370
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Jul 2022 17:53:12 +0200 |
parents | be6d91572633 |
children | 524856bd7b19 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
4 # Primitivus: a SAT frontend |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
10 # (at your option) any later version. |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
15 # GNU Affero General Public License for more details. |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 import urwid |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
22 from urwid_satext import sat_widgets |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
23 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList |
737
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
736
diff
changeset
|
24 from sat_frontends.primitivus.status import StatusBar |
1229
03661d1b216a
primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents:
1183
diff
changeset
|
25 from sat_frontends.primitivus.constants import Const as C |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
26 from sat_frontends.primitivus.keys import action_key_map as a_key |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
27 from sat_frontends.primitivus.widget import PrimitivusWidget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
28 from sat_frontends.tools import jid |
1183
f36d7068a44b
Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents:
1158
diff
changeset
|
29 from sat.core import log as logging |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
30 |
1183
f36d7068a44b
Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents:
1158
diff
changeset
|
31 log = logging.getLogger(__name__) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
32 from sat_frontends.quick_frontend import quick_widgets |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
33 |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
35 class ContactList(PrimitivusWidget, QuickContactList): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
36 PROFILES_MULTIPLE = False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
37 PROFILES_ALLOW_NONE = False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
38 signals = ["click", "change"] |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
39 # FIXME: Only single profile is managed so far |
116
7c482ecac0ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
41 def __init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
42 self, host, target, on_click=None, on_change=None, user_data=None, profiles=None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
43 ): |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
44 QuickContactList.__init__(self, host, profiles) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
45 self.contact_list = self.host.contact_lists[self.profile] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
46 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
47 # we now build the widget |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
48 self.status_bar = StatusBar(host) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
49 self.frame = sat_widgets.FocusFrame(self._buildList(), None, self.status_bar) |
3028 | 50 PrimitivusWidget.__init__(self, self.frame, _("Contacts")) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
116
diff
changeset
|
51 if on_click: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
52 urwid.connect_signal(self, "click", on_click, user_data) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
116
diff
changeset
|
53 if on_change: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
54 urwid.connect_signal(self, "change", on_change, user_data) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
55 self.host.addListener("notification", self.onNotification, [self.profile]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
56 self.host.addListener("notificationsClear", self.onNotification, [self.profile]) |
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
|
57 self.postInit() |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
116
diff
changeset
|
58 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
59 def update(self, entities=None, type_=None, profile=None): |
500
00d3679976ab
primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents:
499
diff
changeset
|
60 """Update display, keep focus""" |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
61 # FIXME: full update is done each time, must handle entities, type_ and profile |
500
00d3679976ab
primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents:
499
diff
changeset
|
62 widget, position = self.frame.body.get_focus() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
63 self.frame.body = self._buildList() |
500
00d3679976ab
primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents:
499
diff
changeset
|
64 if position: |
646
f7804c52c754
primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
65 try: |
911
b12706d164d7
primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents:
812
diff
changeset
|
66 self.frame.body.focus_position = position |
646
f7804c52c754
primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
67 except IndexError: |
f7804c52c754
primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
68 pass |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
69 self._invalidate() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
70 self.host.redraw() # FIXME: check if can be avoided |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
71 |
497
50dd2a0196c0
primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
72 def keypress(self, size, key): |
1183
f36d7068a44b
Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents:
1158
diff
changeset
|
73 # FIXME: we have a temporary behaviour here: FOCUS_SWITCH change focus globally in the parent, |
f36d7068a44b
Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents:
1158
diff
changeset
|
74 # and FOCUS_UP/DOWN is transwmitter to parent if we are respectively on the first or last element |
f36d7068a44b
Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents:
1158
diff
changeset
|
75 if key in sat_widgets.FOCUS_KEYS: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
76 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
77 key == a_key["FOCUS_SWITCH"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
78 or (key == a_key["FOCUS_UP"] and self.frame.focus_position == "body") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
79 or (key == a_key["FOCUS_DOWN"] and self.frame.focus_position == "footer") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
80 ): |
1183
f36d7068a44b
Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents:
1158
diff
changeset
|
81 return key |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
82 if key == a_key["STATUS_HIDE"]: # user wants to (un)hide contacts' statuses |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
83 self.contact_list.show_status = not self.contact_list.show_status |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
84 self.update() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
85 elif ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
86 key == a_key["DISCONNECTED_HIDE"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
87 ): # user wants to (un)hide disconnected contacts |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
88 self.host.bridge.setParam( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
89 C.SHOW_OFFLINE_CONTACTS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
90 C.boolConst(not self.contact_list.show_disconnected), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
91 "General", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
92 profile_key=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
93 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
94 elif key == a_key["RESOURCES_HIDE"]: # user wants to (un)hide contacts resources |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
95 self.contact_list.showResources(not self.contact_list.show_resources) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
96 self.update() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
97 return super(ContactList, self).keypress(size, key) |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
98 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
99 # QuickWidget methods |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
100 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
101 @staticmethod |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
102 def getWidgetHash(target, profiles): |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
103 profiles = sorted(profiles) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
104 return tuple(profiles) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
105 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
106 # modify the contact list |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
107 |
685
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
108 def setFocus(self, text, select=False): |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
109 """give focus to the first element that matches the given text. You can also |
1139
75025461141f
move sat.tools.jid to sat_frontends.tools.jid
souliane <souliane@mailoo.org>
parents:
1058
diff
changeset
|
110 pass in text a sat_frontends.tools.jid.JID (it's a subclass of unicode). |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
111 |
685
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
112 @param text: contact group name, contact or muc userhost, muc private dialog jid |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
113 @param select: if True, the element is also clicked |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
114 """ |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
115 idx = 0 |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
116 for widget in self.frame.body.body: |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
117 try: |
685
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
118 if isinstance(widget, sat_widgets.ClickableText): |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
119 # contact group |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
120 value = widget.getValue() |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
121 elif isinstance(widget, sat_widgets.SelectableText): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
122 # contact or muc |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
123 value = widget.data |
685
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
124 else: |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
125 # Divider instance |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
126 continue |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
127 # there's sometimes a leading space |
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
128 if text.strip() == value.strip(): |
911
b12706d164d7
primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents:
812
diff
changeset
|
129 self.frame.body.focus_position = idx |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
130 if select: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
131 self._contactClicked(False, widget, True) |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
132 return |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
133 except AttributeError: |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
134 pass |
685
0b9bd47dffcd
primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents:
646
diff
changeset
|
135 idx += 1 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
136 |
3028 | 137 log.debug("Not element found for {} in setFocus".format(text)) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
138 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
139 # events |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
140 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
141 def _groupClicked(self, group_wid): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
142 group = group_wid.getValue() |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
143 data = self.contact_list.getGroupData(group) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
144 data[C.GROUP_DATA_FOLDED] = not data.setdefault(C.GROUP_DATA_FOLDED, False) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
145 self.setFocus(group) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
146 self.update() |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
147 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
148 def _contactClicked(self, use_bare_jid, contact_wid, selected): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
149 """Method called when a contact is clicked |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
150 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
151 @param use_bare_jid: True if use_bare_jid is set in self._buildEntityWidget. |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
152 @param contact_wid: widget of the contact, must have the entity set in data attribute |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
153 @param selected: boolean returned by the widget, telling if it is selected |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
154 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
155 entity = contact_wid.data |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
156 self.host.modeHint(C.MODE_INSERTION) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
157 self._emit("click", entity) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
158 |
2009
90134b2e3dc4
primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
159 def onNotification(self, entity, notif, profile): |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2015
diff
changeset
|
160 notifs = list(self.host.getNotifs(C.ENTITY_ALL, profile=self.profile)) |
2009
90134b2e3dc4
primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
161 if notifs: |
3028 | 162 self.title_dynamic = "({})".format(len(notifs)) |
2009
90134b2e3dc4
primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
163 else: |
90134b2e3dc4
primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
164 self.title_dynamic = None |
90134b2e3dc4
primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
165 self.host.redraw() # FIXME: should not be necessary |
90134b2e3dc4
primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
166 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
167 # Methods to build the widget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
168 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
169 def _buildEntityWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
170 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
171 entity, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
172 keys=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
173 use_bare_jid=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
174 with_notifs=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
175 with_show_attr=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
176 markup_prepend=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
177 markup_append=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
178 special=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
179 ): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
180 """Build one contact markup data |
124 | 181 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
182 @param entity (jid.JID): entity to build |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
183 @param keys (iterable): value to markup, in preferred order. |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
184 The first available key will be used. |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
185 If key starts with "cache_", it will be checked in cache, |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
186 else, getattr will be done on entity with the key (e.g. getattr(entity, 'node')). |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
187 If nothing full or keys is None, full entity is used. |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
188 @param use_bare_jid (bool): if True, use bare jid for selected comparisons |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
189 @param with_notifs (bool): if True, show notification count |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
190 @param with_show_attr (bool): if True, show color corresponding to presence status |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
191 @param markup_prepend (list): markup to prepend to the generated one before building the widget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
192 @param markup_append (list): markup to append to the generated one before building the widget |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
193 @param special (bool): True if entity is a special one |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
194 @return (list): markup data are expected by Urwid text widgets |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
195 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
196 markup = [] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
197 if use_bare_jid: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
198 selected = {entity.bare for entity in self.contact_list._selected} |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
199 else: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
200 selected = self.contact_list._selected |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
201 if keys is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
202 entity_txt = entity |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
203 else: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
204 cache = self.contact_list.getCache(entity) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
205 for key in keys: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
206 if key.startswith("cache_"): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
207 entity_txt = cache.get(key[6:]) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
208 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
209 entity_txt = getattr(entity, key) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
210 if entity_txt: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
211 break |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
212 if not entity_txt: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
213 entity_txt = entity |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
116
diff
changeset
|
214 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
215 if with_show_attr: |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
216 show = self.contact_list.getCache(entity, C.PRESENCE_SHOW, default=None) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
217 if show is None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
218 show = C.PRESENCE_UNAVAILABLE |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
219 show_icon, entity_attr = C.PRESENCE.get(show, ("", "default")) |
3028 | 220 markup.insert(0, "{} ".format(show_icon)) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
221 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
222 entity_attr = "default" |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
223 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
224 notifs = list( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
225 self.host.getNotifs(entity, exact_jid=special, profile=self.profile) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
226 ) |
2993
d58dccd9e4b4
primitivus (contact list): fixed notifications counter for mentions:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
227 mentions = list( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
228 self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile) |
2993
d58dccd9e4b4
primitivus (contact list): fixed notifications counter for mentions:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
229 ) |
d58dccd9e4b4
primitivus (contact list): fixed notifications counter for mentions:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
230 if notifs or mentions: |
d58dccd9e4b4
primitivus (contact list): fixed notifications counter for mentions:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
231 attr = 'cl_mention' if mentions else 'cl_notifs' |
3028 | 232 header = [(attr, "({})".format(len(notifs) + len(mentions))), " "] |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
233 else: |
3028 | 234 header = "" |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
235 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
236 markup.append((entity_attr, entity_txt)) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
237 if markup_prepend: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
238 markup.insert(0, markup_prepend) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
239 if markup_append: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
240 markup.extend(markup_append) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
241 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
242 widget = sat_widgets.SelectableText( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
243 markup, selected=entity in selected, header=header |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
244 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
245 widget.data = entity |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
246 widget.comp = entity_txt.lower() # value to use for sorting |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
247 urwid.connect_signal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
248 widget, "change", self._contactClicked, user_args=[use_bare_jid] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
249 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
250 return widget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
251 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
252 def _buildEntities(self, content, entities): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
253 """Add entity representation in widget list |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
254 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
255 @param content: widget list, e.g. SimpleListWalker |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
256 @param entities (iterable): iterable of JID to display |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
257 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
258 if not entities: |
1230
3abc6563a0d2
primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1229
diff
changeset
|
259 return |
3abc6563a0d2
primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1229
diff
changeset
|
260 widgets = [] # list of built widgets |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
261 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
262 for entity in entities: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
263 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
264 entity in self.contact_list._specials |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
265 or not self.contact_list.entityVisible(entity) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
266 ): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
267 continue |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
268 markup_extra = [] |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
269 if self.contact_list.show_resources: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
270 for resource in self.contact_list.getCache(entity, C.CONTACT_RESOURCES): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
271 resource_disp = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
272 "resource_main" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
273 if resource |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
274 == self.contact_list.getCache(entity, C.CONTACT_MAIN_RESOURCE) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
275 else "resource", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
276 "\n " + resource, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
277 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
278 markup_extra.append(resource_disp) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
279 if self.contact_list.show_status: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
280 status = self.contact_list.getCache( |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
281 jid.JID("%s/%s" % (entity, resource)), "status", default=None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
282 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
283 status_disp = ("status", "\n " + status) if status else "" |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
284 markup_extra.append(status_disp) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
285 |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
507
diff
changeset
|
286 else: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
287 if self.contact_list.show_status: |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
288 status = self.contact_list.getCache(entity, "status", default=None) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
289 status_disp = ("status", "\n " + status) if status else "" |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
290 markup_extra.append(status_disp) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
291 widget = self._buildEntityWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
292 entity, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
293 ("cache_nick", "cache_name", "node"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
294 use_bare_jid=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
295 markup_append=markup_extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
296 ) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
297 widgets.append(widget) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
298 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
299 widgets.sort(key=lambda widget: widget.comp) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
300 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
301 for widget in widgets: |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
302 content.append(widget) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
303 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
304 def _buildSpecials(self, content): |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
305 """Build the special entities""" |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
306 specials = sorted(self.contact_list.getSpecials()) |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
307 current = None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
308 for entity in specials: |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
309 if current is not None and current.bare == entity.bare: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
310 # nested entity (e.g. MUC private conversations) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
311 widget = self._buildEntityWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
312 entity, ("resource",), markup_prepend=" ", special=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
313 ) |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
314 else: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
315 # the special widgets |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
316 if entity.resource: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
317 widget = self._buildEntityWidget(entity, ("resource",), special=True) |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
318 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
319 widget = self._buildEntityWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
320 entity, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
321 ("cache_nick", "cache_name", "node"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
322 with_show_attr=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
323 special=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
324 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
325 content.append(widget) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
326 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
327 def _buildList(self): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
328 """Build the main contact list widget""" |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
329 content = urwid.SimpleListWalker([]) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
330 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
331 self._buildSpecials(content) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
332 if self.contact_list._specials: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
333 content.append(urwid.Divider("=")) |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
334 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
335 groups = list(self.contact_list._groups) |
3028 | 336 groups.sort(key=lambda x: x.lower() if x else '') |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
337 for group in groups: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
338 data = self.contact_list.getGroupData(group) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
339 folded = data.get(C.GROUP_DATA_FOLDED, False) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
340 jids = list(data["jids"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
341 if group is not None and ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
342 self.contact_list.anyEntityVisible(jids) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
343 or self.contact_list.show_empty_groups |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
344 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
345 header = "[-]" if not folded else "[+]" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
346 widget = sat_widgets.ClickableText(group, header=header + " ") |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
347 content.append(widget) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
348 urwid.connect_signal(widget, "click", self._groupClicked) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
349 if not folded: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
350 self._buildEntities(content, jids) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
351 not_in_roster = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
352 set(self.contact_list._cache) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
353 .difference(self.contact_list._roster) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
354 .difference(self.contact_list._specials) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
355 .difference((self.contact_list.whoami.bare,)) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
356 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
357 if not_in_roster: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
358 content.append(urwid.Divider("-")) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
359 self._buildEntities(content, not_in_roster) |
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:
1000
diff
changeset
|
360 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
361 return urwid.ListBox(content) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
362 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2617
diff
changeset
|
363 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
364 quick_widgets.register(QuickContactList, ContactList) |