annotate libervia/tui/contact_list.py @ 4326:5fd6a4dc2122

cli (output/std): use `rich` to output JSON.
author Goffi <goffi@goffi.org>
date Wed, 20 Nov 2024 11:38:44 +0100
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia TUI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3254
diff changeset
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
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.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
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
23 from libervia.frontends.quick_frontend.quick_contact_list import QuickContactList
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
24 from libervia.tui.status import StatusBar
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
25 from libervia.tui.constants import Const as C
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
26 from libervia.tui.keys import action_key_map as a_key
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
27 from libervia.tui.widget import LiberviaTUIWidget
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
28 from libervia.frontends.tools import jid
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
29 from libervia.backend.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__)
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
32 from libervia.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
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
35 class ContactList(LiberviaTUIWidget, 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)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
49 self.frame = sat_widgets.FocusFrame(self._build_list(), None, self.status_bar)
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
50 LiberviaTUIWidget.__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)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
55 self.host.addListener("notification", self.on_notification, [self.profile])
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
56 self.host.addListener("notificationsClear", self.on_notification, [self.profile])
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
57 self.post_init()
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()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
63 self.frame.body = self._build_list()
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
88 self.host.bridge.param_set(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
89 C.SHOW_OFFLINE_CONTACTS,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
90 C.bool_const(not self.contact_list.show_disconnected),
2624
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
4170
b47f21f2b8fa quick_frontend, tui: fix name conflict with `show_resources`
Goffi <goffi@goffi.org>
parents: 4076
diff changeset
95 self.contact_list.show_resources = 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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
102 def get_widget_hash(target, profiles):
1938
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
108 def set_focus(self, text, select=False):
685
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
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
110 pass in text a libervia.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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
120 value = widget.get_value()
685
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:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
131 self._contact_clicked(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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
137 log.debug("Not element found for {} in set_focus".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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
141 def _group_clicked(self, group_wid):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
142 group = group_wid.get_value()
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
143 data = self.contact_list.get_group_data(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)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
145 self.set_focus(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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
148 def _contact_clicked(self, use_bare_jid, contact_wid, selected):
1265
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
151 @param use_bare_jid: True if use_bare_jid is set in self._build_entity_widget.
1265
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
156 self.host.mode_hint(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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
159 def on_notification(self, entity, notif, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
160 notifs = list(self.host.get_notifs(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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2993
diff changeset
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
169 def _build_entity_widget(
2624
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
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2993
diff changeset
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(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
225 self.host.get_notifs(entity, exact_jid=special, profile=self.profile)
2624
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(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
228 self.host.get_notifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
229 )
2993
d58dccd9e4b4 primitivus (contact list): fixed notifications counter for mentions:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
230 if notifs or mentions:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
231 attr = "cl_mention" if mentions else "cl_notifs"
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2993
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2993
diff changeset
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(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
248 widget, "change", self._contact_clicked, user_args=[use_bare_jid]
2624
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
252 def _build_entities(self, content, entities):
1265
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
265 or not self.contact_list.entity_visible(entity)
2624
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 = (
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
272 (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
273 "resource_main"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
274 if resource
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
275 == self.contact_list.getCache(entity, C.CONTACT_MAIN_RESOURCE)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
276 else "resource"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
277 ),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
278 "\n " + resource,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
279 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
280 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
281 if self.contact_list.show_status:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
282 status = self.contact_list.getCache(
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
283 jid.JID("%s/%s" % (entity, resource)), "status", default=None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
284 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
285 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
286 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
287
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
288 else:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
289 if self.contact_list.show_status:
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
290 status = self.contact_list.getCache(entity, "status", default=None)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
291 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
292 markup_extra.append(status_disp)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
293 widget = self._build_entity_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
294 entity,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
295 ("cache_nick", "cache_name", "node"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
296 use_bare_jid=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
297 markup_append=markup_extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
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.append(widget)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
300
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
301 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
302
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
303 for widget in widgets:
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
304 content.append(widget)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
305
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
306 def _build_specials(self, content):
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
307 """Build the special entities"""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
308 specials = sorted(self.contact_list.get_specials())
2015
20fb71b656e3 quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
309 current = None
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
310 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
311 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
312 # nested entity (e.g. MUC private conversations)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
313 widget = self._build_entity_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
314 entity, ("resource",), markup_prepend=" ", special=True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
315 )
2015
20fb71b656e3 quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
316 else:
20fb71b656e3 quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
317 # the special widgets
20fb71b656e3 quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
318 if entity.resource:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
319 widget = self._build_entity_widget(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
320 entity, ("resource",), special=True
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
321 )
2015
20fb71b656e3 quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
322 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
323 widget = self._build_entity_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
324 entity,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
325 ("cache_nick", "cache_name", "node"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
326 with_show_attr=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
327 special=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
328 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
329 content.append(widget)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
330
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
331 def _build_list(self):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
332 """Build the main contact list widget"""
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
333 content = urwid.SimpleListWalker([])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
334
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
335 self._build_specials(content)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
336 if self.contact_list._specials:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
337 content.append(urwid.Divider("="))
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
338
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
339 groups = list(self.contact_list._groups)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4170
diff changeset
340 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
341 for group in groups:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
342 data = self.contact_list.get_group_data(group)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
343 folded = data.get(C.GROUP_DATA_FOLDED, False)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
344 jids = list(data["jids"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
345 if group is not None and (
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
346 self.contact_list.any_entity_visible(jids)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
347 or self.contact_list.show_empty_groups
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
348 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
349 header = "[-]" if not folded else "[+]"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
350 widget = sat_widgets.ClickableText(group, header=header + " ")
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
351 content.append(widget)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
352 urwid.connect_signal(widget, "click", self._group_clicked)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
353 if not folded:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
354 self._build_entities(content, jids)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
355 not_in_roster = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
356 set(self.contact_list._cache)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
357 .difference(self.contact_list._roster)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
358 .difference(self.contact_list._specials)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
359 .difference((self.contact_list.whoami.bare,))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
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 if not_in_roster:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
362 content.append(urwid.Divider("-"))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
363 self._build_entities(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
364
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
365 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
366
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2617
diff changeset
367
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
368 quick_widgets.register(QuickContactList, ContactList)