Mercurial > libervia-desktop-kivy
annotate libervia/desktop_kivy/core/common.py @ 514:d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
- Add a new "file" icon in call UI to send a file via WebRTC.
- Handle new preflight mechanism, and WebRTC file transfer.
- Native file chooser handling has been moved to new `core.file_chooser` module, and now
supports "save" and "dir" modes (based on `plyer`).
rel 442
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 06 Apr 2024 13:37:27 +0200 |
parents | d1a023280733 |
children | 196483685a63 |
rev | line source |
---|---|
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
1 #!/usr/bin/env python3 |
26
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
3 #Libervia Desktop-Kivy |
461 | 4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) |
26
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
237
059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
220
diff
changeset
|
19 """common simple widgets""" |
26
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
21 import json |
405
84ff5c917064
widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents:
404
diff
changeset
|
22 from functools import partial, total_ordering |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
23 from kivy.uix.widget import Widget |
134 | 24 from kivy.uix.label import Label |
26
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from kivy.uix.behaviors import ButtonBehavior |
193
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
26 from kivy.uix.behaviors import ToggleButtonBehavior |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
27 from kivy.uix.stacklayout import StackLayout |
107 | 28 from kivy.uix.boxlayout import BoxLayout |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
29 from kivy.uix.scrollview import ScrollView |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
30 from kivy.event import EventDispatcher |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
31 from kivy.metrics import dp |
134 | 32 from kivy import properties |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
33 from libervia.backend.core.i18n import _ |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
34 from libervia.backend.core import log as logging |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
35 from libervia.backend.tools.common import data_format |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
36 from libervia.frontends.quick_frontend import quick_chat |
503
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
37 from libervia.frontends.tools import aio |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
38 from .constants import Const as C |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
39 from .common_widgets import CategorySeparator |
459
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
40 from .image import Image, AsyncImage |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
41 from libervia.desktop_kivy import G |
134 | 42 |
43 log = logging.getLogger(__name__) | |
44 | |
312 | 45 UNKNOWN_SYMBOL = 'Unknown symbol name' |
26
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 class IconButton(ButtonBehavior, Image): |
3efca1b10b2f
common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 pass |
107 | 50 |
51 | |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
52 class Avatar(Image): |
459
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
53 data = properties.DictProperty(allownone=True) |
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
54 |
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
55 def on_kv_post(self, __): |
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
56 if not self.source: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
57 self.source = G.host.get_default_avatar() |
459
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
58 |
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
59 def on_data(self, __, data): |
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
60 if data is None: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
61 self.source = G.host.get_default_avatar() |
459
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
62 else: |
72290ebfaa8b
core (common), contact_list: new `data` property:
Goffi <goffi@goffi.org>
parents:
458
diff
changeset
|
63 self.source = data['path'] |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
64 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
65 |
397
54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents:
389
diff
changeset
|
66 class NotifLabel(Label): |
54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents:
389
diff
changeset
|
67 pass |
54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents:
389
diff
changeset
|
68 |
405
84ff5c917064
widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents:
404
diff
changeset
|
69 @total_ordering |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
70 class ContactItem(BoxLayout): |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
71 """An item from ContactList |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
72 |
397
54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents:
389
diff
changeset
|
73 The item will drawn as an icon (JID avatar) with its jid below. |
458
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
74 If "badge_text" is set, a label with the text will be drawn above the avatar. |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
75 """ |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
76 base_width = dp(150) |
397
54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents:
389
diff
changeset
|
77 avatar_layout = properties.ObjectProperty() |
54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents:
389
diff
changeset
|
78 avatar = properties.ObjectProperty() |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
79 badge = properties.ObjectProperty(allownone=True) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
80 badge_text = properties.StringProperty('') |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
81 profile = properties.StringProperty() |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
82 data = properties.DictProperty() |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
83 jid = properties.StringProperty('') |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
84 |
458
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
85 def on_kv_post(self, __): |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
86 if ((self.profile and self.jid and self.data is not None |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
87 and ('avatar' not in self.data or 'nicknames' not in self.data))): |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
88 G.host.bridge.identity_get( |
458
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
89 self.jid, ['avatar', 'nicknames'], True, self.profile, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
90 callback=self._identity_get_cb, |
458
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
91 errback=partial( |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
92 G.host.errback, |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
93 message=_("Can't retrieve identity for {jid}: {{msg}}").format( |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
94 jid=self.jid) |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
95 ) |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
96 ) |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
97 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
98 def _identity_get_cb(self, identity_raw): |
458
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
99 identity_data = data_format.deserialise(identity_raw) |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
100 self.data.update(identity_data) |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
101 |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
102 def on_badge_text(self, wid, text): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
103 if text: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
104 if self.badge is not None: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
105 self.badge.text = text |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
106 else: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
107 self.badge = NotifLabel( |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
108 pos_hint={"right": 0.8, "y": 0}, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
109 text=text, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
110 ) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
111 self.avatar_layout.add_widget(self.badge) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
112 else: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
113 if self.badge is not None: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
114 self.avatar_layout.remove_widget(self.badge) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
115 self.badge = None |
397
54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents:
389
diff
changeset
|
116 |
405
84ff5c917064
widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents:
404
diff
changeset
|
117 def __lt__(self, other): |
84ff5c917064
widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents:
404
diff
changeset
|
118 return self.jid < other.jid |
84ff5c917064
widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents:
404
diff
changeset
|
119 |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
120 |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
121 class ContactButton(ButtonBehavior, ContactItem): |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
122 pass |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
123 |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
124 |
193
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
125 class JidItem(BoxLayout): |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
126 bg_color = properties.ListProperty([0.2, 0.2, 0.2, 1]) |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
127 color = properties.ListProperty([1, 1, 1, 1]) |
256
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
128 jid = properties.StringProperty() |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
129 profile = properties.StringProperty() |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
130 nick = properties.StringProperty() |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
131 avatar = properties.ObjectProperty() |
107 | 132 |
256
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
133 def on_avatar(self, wid, jid_): |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
134 if self.jid and self.profile: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
135 self.get_image() |
107 | 136 |
256
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
137 def on_jid(self, wid, jid_): |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
138 if self.profile and self.avatar: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
139 self.get_image() |
256
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
140 |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
141 def on_profile(self, wid, profile): |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
142 if self.jid and self.avatar: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
143 self.get_image() |
256
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
144 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
145 def get_image(self): |
107 | 146 host = G.host |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
147 if host.contact_lists[self.profile].is_room(self.jid.bare): |
256
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
148 self.avatar.opacity = 0 |
ba7b8cb7ddcd
common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
149 self.avatar.source = "" |
107 | 150 else: |
503
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
151 if not self.avatar.source: |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
152 aio.run_async(self._get_avatar()) |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
153 |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
154 async def _get_avatar(self) -> None: |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
155 avatar_data = data_format.deserialise( |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
156 await G.host.a_bridge.avatar_get(self.jid, True, self.profile) |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
157 ) |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
158 self.avatar.source = ( |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
159 avatar_data.get("path") |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
160 or G.host.get_default_avatar(self.jid) |
d1a023280733
core (common): fix avatar retrieval in `JidItem`
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
161 ) |
134 | 162 |
163 | |
193
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
164 class JidButton(ButtonBehavior, JidItem): |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
165 pass |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
166 |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
167 |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
168 class JidToggle(ToggleButtonBehavior, JidItem): |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
169 selected_color = properties.ListProperty(C.COLOR_SEC_DARK) |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
170 |
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
171 |
134 | 172 class Symbol(Label): |
173 symbol_map = None | |
174 symbol = properties.StringProperty() | |
175 | |
176 def __init__(self, **kwargs): | |
177 if self.symbol_map is None: | |
178 with open(G.host.app.expand('{media}/fonts/fontello/config.json')) as f: | |
179 fontello_conf = json.load(f) | |
180 Symbol.symbol_map = {g['css']:g['code'] for g in fontello_conf['glyphs']} | |
181 | |
182 super(Symbol, self).__init__(**kwargs) | |
183 | |
184 def on_symbol(self, instance, symbol): | |
185 try: | |
186 code = self.symbol_map[symbol] | |
187 except KeyError: | |
312 | 188 log.warning(_("Invalid symbol {symbol}").format(symbol=symbol)) |
134 | 189 else: |
312 | 190 self.text = chr(code) |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
134
diff
changeset
|
191 |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
134
diff
changeset
|
192 |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
134
diff
changeset
|
193 class SymbolButton(ButtonBehavior, Symbol): |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
134
diff
changeset
|
194 pass |
178
11ff8cd93659
common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
195 |
11ff8cd93659
common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
196 |
416
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
197 class SymbolLabel(BoxLayout): |
218
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
198 symbol = properties.StringProperty("") |
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
199 text = properties.StringProperty("") |
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
200 color = properties.ListProperty(C.COLOR_SEC) |
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
201 bold = properties.BooleanProperty(True) |
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
202 symbol_wid = properties.ObjectProperty() |
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
203 label = properties.ObjectProperty() |
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
204 |
30be583dbabc
core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
205 |
416
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
206 class SymbolButtonLabel(ButtonBehavior, SymbolLabel): |
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
207 pass |
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
208 |
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
209 |
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
210 class SymbolToggleLabel(ToggleButtonBehavior, SymbolLabel): |
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
211 pass |
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
212 |
3e2333a11f61
common: implemented SymbolToggleLabel:
Goffi <goffi@goffi.org>
parents:
407
diff
changeset
|
213 |
178
11ff8cd93659
common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
214 class ActionSymbol(Symbol): |
11ff8cd93659
common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
215 pass |
179
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
216 |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
217 |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
218 class ActionIcon(BoxLayout): |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
219 plugin_info = properties.DictProperty() |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
220 |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
221 def on_plugin_info(self, instance, plugin_info): |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
222 self.clear_widgets() |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
223 try: |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
224 symbol = plugin_info['icon_symbol'] |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
225 except KeyError: |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
226 icon_src = plugin_info['icon_medium'] |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
227 icon_wid = Image(source=icon_src, allow_stretch=True) |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
228 self.add_widget(icon_wid) |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
229 else: |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
230 icon_wid = ActionSymbol(symbol=symbol) |
7177fe2d9725
common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
231 self.add_widget(icon_wid) |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
232 |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
233 |
422
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
234 class SizedImage(AsyncImage): |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
235 """AsyncImage sized according to C.IMG_MAX_WIDTH and C.IMG_MAX_HEIGHT""" |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
236 # following properties are desired height/width |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
237 # i.e. the ones specified in height/width attributes of <img> |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
238 # (or wanted for whatever reason) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
239 # set to None to ignore them |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
240 target_height = properties.NumericProperty(allownone=True) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
241 target_width = properties.NumericProperty(allownone=True) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
242 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
243 def __init__(self, **kwargs): |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
244 # best calculated size |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
245 self._best_width = self._best_height = 100 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
246 super().__init__(**kwargs) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
247 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
248 def on_texture(self, instance, texture): |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
249 """Adapt the size according to max size and target_*""" |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
250 if texture is None: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
251 return |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
252 max_width, max_height = dp(C.IMG_MAX_WIDTH), dp(C.IMG_MAX_HEIGHT) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
253 width, height = texture.size |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
254 if self.target_width: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
255 width = min(width, self.target_width) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
256 if width > max_width: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
257 width = C.IMG_MAX_WIDTH |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
258 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
259 height = width / self.image_ratio |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
260 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
261 if self.target_height: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
262 height = min(height, self.target_height) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
263 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
264 if height > max_height: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
265 height = max_height |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
266 width = height * self.image_ratio |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
267 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
268 self.width, self.height = self._best_width, self._best_height = width, height |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
269 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
270 def on_parent(self, instance, parent): |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
271 if parent is not None: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
272 parent.bind(width=self.on_parent_width) |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
273 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
274 def on_parent_width(self, instance, width): |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
275 if self._best_width > width: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
276 self.width = width |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
277 self.height = width / self.image_ratio |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
278 else: |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
279 self.width, self.height = self._best_width, self._best_height |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
280 |
efee0e0afb78
core (common): moved simple_xhtml's image code to a generic "SizedImage" widget
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
281 |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
282 class JidSelectorCategoryLayout(StackLayout): |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
283 pass |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
284 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
285 |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
286 class JidSelector(ScrollView, EventDispatcher): |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
287 layout = properties.ObjectProperty(None) |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
288 # if item_class is changed, the properties must be the same as for ContactButton |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
289 # and ordering must be supported |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
290 item_class = properties.ObjectProperty(ContactButton) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
291 add_separators = properties.ObjectProperty(True) |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
292 # list of item to show, can be: |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
293 # - a well-known string which can be: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
294 # * "roster": all roster jids |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
295 # * "opened_chats": all opened chat widgets |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
296 # * "bookmarks": MUC bookmarks |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
297 # A layout will be created each time and stored in the attribute of the same |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
298 # name. |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
299 # If add_separators is True, a CategorySeparator will be added on top of each |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
300 # layout. |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
301 # - a kivy Widget, which will be added to the layout (notable useful with |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
302 # common_widgets.CategorySeparator) |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
303 # - a callable, which must return an iterable of kwargs for ContactButton |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
304 to_show = properties.ListProperty(['roster']) |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
305 |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
306 # TODO: roster and bookmarks must be updated in real time, like for opened_chats |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
307 |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
308 |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
309 def __init__(self, **kwargs): |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
310 self.register_event_type('on_select') |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
311 # list of layouts containing items |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
312 self.items_layouts = [] |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
313 # jid to list of ContactButton instances map |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
314 self.items_map = {} |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
315 super().__init__(**kwargs) |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
316 |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
317 def on_kv_post(self, wid): |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
318 self.update() |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
319 |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
320 def on_select(self, wid): |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
321 pass |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
322 |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
323 def on_parent(self, wid, parent): |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
324 if parent is None: |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
325 log.debug("removing listeners") |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
326 G.host.removeListener("contactsFilled", self.on_contacts_filled) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
327 G.host.removeListener("notification", self.on_notification) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
328 G.host.removeListener("notificationsClear", self.on_notifications_clear) |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
329 G.host.removeListener( |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
330 "widgetNew", self.on_widget_new, ignore_missing=True) |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
331 G.host.removeListener( |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
332 "widgetDeleted", self.on_widget_deleted, ignore_missing=True) |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
333 else: |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
334 log.debug("adding listeners") |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
335 G.host.addListener("contactsFilled", self.on_contacts_filled) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
336 G.host.addListener("notification", self.on_notification) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
337 G.host.addListener("notificationsClear", self.on_notifications_clear) |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
338 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
339 def on_contacts_filled(self, profile): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
340 log.debug("on_contacts_filled event received") |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
341 self.update() |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
342 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
343 def on_notification(self, entity, notification_data, profile): |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
344 for item in self.items_map.get(entity.bare, []): |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
345 notifs = list(G.host.get_notifs(entity.bare, profile=profile)) |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
346 item.badge_text = str(len(notifs)) |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
347 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
348 def on_notifications_clear(self, entity, type_, profile): |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
349 for item in self.items_map.get(entity.bare, []): |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
350 item.badge_text = '' |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
351 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
352 def on_widget_new(self, wid): |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
353 if not isinstance(wid, quick_chat.QuickChat): |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
354 return |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
355 item = self.get_item_from_wid(wid) |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
356 if item is None: |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
357 return |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
358 idx = 0 |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
359 for child in self.opened_chats.children: |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
360 if isinstance(child, self.item_class) and child < item: |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
361 break |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
362 idx+=1 |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
363 self.opened_chats.add_widget(item, index=idx) |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
364 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
365 def on_widget_deleted(self, wid): |
406
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
366 if not isinstance(wid, quick_chat.QuickChat): |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
367 return |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
368 |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
369 for child in self.opened_chats.children: |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
370 if not isinstance(child, self.item_class): |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
371 continue |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
372 if child.jid.bare == wid.target.bare: |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
373 self.opened_chats.remove_widget(child) |
03554ad70846
common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents:
405
diff
changeset
|
374 break |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
375 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
376 def _create_item(self, **kwargs): |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
377 item = self.item_class(**kwargs) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
378 jid = kwargs['jid'] |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
379 self.items_map.setdefault(jid, []).append(item) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
380 return item |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
381 |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
382 def update(self): |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
383 log.debug("starting update") |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
384 self.layout.clear_widgets() |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
385 for item in self.to_show: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
386 if isinstance(item, str): |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
387 if item == 'roster': |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
388 self.add_roster_items() |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
389 elif item == 'bookmarks': |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
390 self.add_bookmarks_items() |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
391 elif item == 'opened_chats': |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
392 self.add_opened_chats_items() |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
393 else: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
394 log.error(f'unknown "to_show" magic string {item!r}') |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
395 elif isinstance(item, Widget): |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
396 self.layout.add_widget(item) |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
397 elif callable(item): |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
398 items_kwargs = item() |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
399 for item_kwargs in items_kwargs: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
400 item = self._create_item(**items_kwargs) |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
401 item.bind(on_press=partial(self.dispatch, 'on_select')) |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
402 self.layout.add_widget(item) |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
403 else: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
404 log.error(f"unmanaged to_show item type: {item!r}") |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
405 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
406 def add_category_layout(self, label=None): |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
407 category_layout = JidSelectorCategoryLayout() |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
408 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
409 if label and self.add_separators: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
410 category_layout.add_widget(CategorySeparator(text=label)) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
411 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
412 self.layout.add_widget(category_layout) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
413 self.items_layouts.append(category_layout) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
414 return category_layout |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
415 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
416 def get_item_from_wid(self, wid): |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
417 """create JidSelector item from QuickChat widget""" |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
418 contact_list = G.host.contact_lists[wid.profile] |
407
364d2c8eb476
core (common): Don't crash JidSelector when data for entity is missing from cache
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
419 try: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
420 data=contact_list.get_item(wid.target) |
407
364d2c8eb476
core (common): Don't crash JidSelector when data for entity is missing from cache
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
421 except KeyError: |
364d2c8eb476
core (common): Don't crash JidSelector when data for entity is missing from cache
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
422 log.warning(f"Can't find item data for {wid.target}") |
364d2c8eb476
core (common): Don't crash JidSelector when data for entity is missing from cache
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
423 data={} |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
424 try: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
425 item = self._create_item( |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
426 jid=wid.target, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
427 data=data, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
428 profile=wid.profile, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
429 ) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
430 except Exception as e: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
431 log.warning(f"Can't add contact {wid.target}: {e}") |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
432 return |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
433 notifs = list(G.host.get_notifs(wid.target, profile=wid.profile)) |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
434 if notifs: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
435 item.badge_text = str(len(notifs)) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
436 item.bind(on_press=partial(self.dispatch, 'on_select')) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
437 return item |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
438 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
439 def add_opened_chats_items(self): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
440 G.host.addListener("widgetNew", self.on_widget_new) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
441 G.host.addListener("widgetDeleted", self.on_widget_deleted) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
442 self.opened_chats = category_layout = self.add_category_layout(_("Opened chats")) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
443 widgets = sorted(G.host.widgets.get_widgets( |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
444 quick_chat.QuickChat, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
445 profiles = G.host.profiles, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
446 with_duplicates=False)) |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
447 |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
448 for wid in widgets: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
449 item = self.get_item_from_wid(wid) |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
450 if item is None: |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
451 continue |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
452 category_layout.add_widget(item) |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
453 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
454 def add_roster_items(self): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
455 self.roster = category_layout = self.add_category_layout(_("Your contacts")) |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
456 for profile in G.host.profiles: |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
457 contact_list = G.host.contact_lists[profile] |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
458 for entity_jid in sorted(contact_list.roster): |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
459 item = self._create_item( |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
460 jid=entity_jid, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
461 data=contact_list.get_item(entity_jid), |
348
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
462 profile=profile, |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
463 ) |
38fd457b2158
core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
464 item.bind(on_press=partial(self.dispatch, 'on_select')) |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
465 category_layout.add_widget(item) |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
466 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
467 def add_bookmarks_items(self): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
468 self.bookmarks = category_layout = self.add_category_layout(_("Your chat rooms")) |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
469 for profile in G.host.profiles: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
470 profile_manager = G.host.profiles[profile] |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
471 try: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
472 bookmarks = profile_manager._bookmarks |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
473 except AttributeError: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
474 log.warning(f"no bookmark in cache for profile {profile}") |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
475 continue |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
476 |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
477 contact_list = G.host.contact_lists[profile] |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
478 for entity_jid in bookmarks: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
479 try: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
480 cache = contact_list.get_item(entity_jid) |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
481 except KeyError: |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
482 cache = {} |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
483 item = self._create_item( |
389
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
484 jid=entity_jid, |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
485 data=cache, |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
486 profile=profile, |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
487 ) |
442756495a96
core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents:
378
diff
changeset
|
488 item.bind(on_press=partial(self.dispatch, 'on_select')) |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
489 category_layout.add_widget(item) |