annotate cagou/core/common.py @ 406:03554ad70846

common (jidSelector): replace implitict_update mechanism by real-time update: instead of having the possibility to (de)activate implicit update, real time update of items is now done. For now only the notifications and opened chat items are updated in real time.
author Goffi <goffi@goffi.org>
date Wed, 12 Feb 2020 20:02:58 +0100
parents 84ff5c917064
children 364d2c8eb476
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
378
4d660b252487 dates update
Goffi <goffi@goffi.org>
parents: 348
diff changeset
4 # Copyright (C) 2016-2020 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
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
23 from sat.core.i18n import _
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
24 from sat.core import log as logging
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
25 from kivy.uix.widget import Widget
26
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy.uix.image import Image
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
27 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
28 from kivy.uix.behaviors import ButtonBehavior
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
29 from kivy.uix.behaviors import ToggleButtonBehavior
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
30 from kivy.uix.stacklayout import StackLayout
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
31 from kivy.uix.boxlayout import BoxLayout
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
32 from kivy.uix.scrollview import ScrollView
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
33 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
34 from kivy.metrics import dp
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
35 from kivy import properties
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
36 from sat_frontends.quick_frontend import quick_chat
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
37 from .constants import Const as C
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
38 from .common_widgets import CategorySeparator
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
39 from cagou import G
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
40
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
41 log = logging.getLogger(__name__)
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
42
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
43 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
44
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
45
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
46 class IconButton(ButtonBehavior, Image):
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
47 pass
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
48
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
49
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
50 class Avatar(Image):
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
51 pass
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
52
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
53
397
54f6a47cc60a core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents: 389
diff changeset
54 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
55 pass
54f6a47cc60a core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents: 389
diff changeset
56
405
84ff5c917064 widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
57 @total_ordering
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
58 class ContactItem(BoxLayout):
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
59 """An item from ContactList
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
60
397
54f6a47cc60a core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents: 389
diff changeset
61 The item will drawn as an icon (JID avatar) with its jid below.
54f6a47cc60a core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents: 389
diff changeset
62 If "notifs" are present in data, a notification counter will be drawn above the
54f6a47cc60a core (common): added a notifications counter on ContactButton and use it in JidSelector:
Goffi <goffi@goffi.org>
parents: 389
diff changeset
63 avatar.
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
64 """
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
65 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
66 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
67 avatar = properties.ObjectProperty()
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
68 badge = properties.ObjectProperty(allownone=True)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
69 badge_text = properties.StringProperty('')
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
70 profile = properties.StringProperty()
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
71 data = properties.DictProperty()
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
72 jid = properties.StringProperty('')
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
73
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
74 def on_badge_text(self, wid, text):
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
75 if text:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
76 if self.badge is not None:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
77 self.badge.text = text
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
78 else:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
79 self.badge = NotifLabel(
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
80 pos_hint={"right": 0.8, "y": 0},
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
81 text=text,
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
82 )
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
83 self.avatar_layout.add_widget(self.badge)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
84 else:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
85 if self.badge is not None:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
86 self.avatar_layout.remove_widget(self.badge)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
87 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
88
405
84ff5c917064 widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
89 def __lt__(self, other):
84ff5c917064 widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
90 return self.jid < other.jid
84ff5c917064 widgets: implemented ordering in ContactItem and CagouWidget:
Goffi <goffi@goffi.org>
parents: 404
diff changeset
91
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
92
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
93 class ContactButton(ButtonBehavior, ContactItem):
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
94 pass
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
95
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
96
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
97 class JidItem(BoxLayout):
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
98 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
99 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
100 jid = properties.StringProperty()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
101 profile = properties.StringProperty()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
102 nick = properties.StringProperty()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
103 avatar = properties.ObjectProperty()
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
104
256
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
105 def on_avatar(self, wid, jid_):
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
106 if self.jid and self.profile:
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
107 self.getImage()
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
108
256
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
109 def on_jid(self, wid, jid_):
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
110 if self.profile and self.avatar:
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
111 self.getImage()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
112
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
113 def on_profile(self, wid, profile):
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
114 if self.jid and self.avatar:
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
115 self.getImage()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
116
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
117 def getImage(self):
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
118 host = G.host
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
119 if host.contact_lists[self.profile].isRoom(self.jid.bare):
256
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
120 self.avatar.opacity = 0
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
121 self.avatar.source = ""
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
122 else:
273
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
123 self.avatar.source = (
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
124 host.getAvatar(self.jid, profile=self.profile)
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
125 or host.getDefaultAvatar(self.jid)
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
126 )
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
127
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
128
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
129 class JidButton(ButtonBehavior, JidItem):
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
130 pass
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
131
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
132
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
133 class JidToggle(ToggleButtonBehavior, JidItem):
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
134 selected_color = properties.ListProperty(C.COLOR_SEC_DARK)
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
135
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
136
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
137 class Symbol(Label):
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
138 symbol_map = None
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
139 symbol = properties.StringProperty()
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
140
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
141 def __init__(self, **kwargs):
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
142 if self.symbol_map is None:
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
143 with open(G.host.app.expand('{media}/fonts/fontello/config.json')) as f:
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
144 fontello_conf = json.load(f)
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
145 Symbol.symbol_map = {g['css']:g['code'] for g in fontello_conf['glyphs']}
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
146
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
147 super(Symbol, self).__init__(**kwargs)
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
148
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
149 def on_symbol(self, instance, symbol):
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
150 try:
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
151 code = self.symbol_map[symbol]
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
152 except KeyError:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
153 log.warning(_("Invalid symbol {symbol}").format(symbol=symbol))
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
154 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
155 self.text = chr(code)
135
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
156
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
157
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
158 class SymbolButton(ButtonBehavior, Symbol):
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
159 pass
178
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
160
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
161
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
162 class SymbolLabel(ButtonBehavior, BoxLayout):
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
163 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
164 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
165 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
166 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
167 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
168 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
169
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
170
178
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
171 class ActionSymbol(Symbol):
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
172 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
173
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
174
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
175 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
176 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
177
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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 self.add_widget(icon_wid)
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
189
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
190
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
191 class JidSelectorCategoryLayout(StackLayout):
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
192 pass
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
193
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
194
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
195 class JidSelector(ScrollView, EventDispatcher):
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
196 layout = properties.ObjectProperty(None)
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
197 # 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
198 # and ordering must be supported
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
199 item_class = properties.ObjectProperty(ContactButton)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
200 add_separators = properties.ObjectProperty(True)
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
201 # list of item to show, can be:
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
202 # - a well-known string which can be:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
203 # * "roster": all roster jids
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
204 # * "opened_chats": all opened chat widgets
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
205 # * "bookmarks": MUC bookmarks
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
206 # 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
207 # name.
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
208 # 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
209 # layout.
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
210 # - 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
211 # common_widgets.CategorySeparator)
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
212 # - 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
213 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
214
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
215 # 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
216
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
217
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
218 def __init__(self, **kwargs):
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
219 self.register_event_type('on_select')
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
220 # list of layouts containing items
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
221 self.items_layouts = []
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
222 # jid to list of ContactButton instances map
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
223 self.items_map = {}
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
224 super().__init__(**kwargs)
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
225
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
226 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
227 self.update()
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
228
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
229 def on_select(self, wid):
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
230 pass
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
231
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
232 def on_parent(self, wid, parent):
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
233 if parent is None:
406
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
234 log.debug("removing listeners")
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
235 G.host.removeListener("contactsFilled", self.onContactsFilled)
406
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
236 G.host.removeListener("notification", self.onNotification)
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
237 G.host.removeListener("notificationsClear", self.onNotificationsClear)
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
238 G.host.removeListener(
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
239 "widgetNew", self.onWidgetNew, ignore_missing=True)
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
240 G.host.removeListener(
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
241 "widgetDeleted", self.onWidgetDeleted, ignore_missing=True)
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
242 else:
406
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
243 log.debug("adding listeners")
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
244 G.host.addListener("contactsFilled", self.onContactsFilled)
406
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
245 G.host.addListener("notification", self.onNotification)
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
246 G.host.addListener("notificationsClear", self.onNotificationsClear)
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
247
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
248 def onContactsFilled(self, profile):
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
249 log.debug("onContactsFilled event received")
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
250 self.update()
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
251
406
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
252 def onNotification(self, entity, notification_data, profile):
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
253 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
254 notifs = list(G.host.getNotifs(entity.bare, profile=profile))
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
255 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
256
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
257 def onNotificationsClear(self, entity, type_, profile):
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
258 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
259 item.badge_text = ''
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
260
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
261 def onWidgetNew(self, wid):
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
262 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
263 return
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
264 item = self.getItemFromWid(wid)
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
265 if item is None:
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
266 return
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
267 idx = 0
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
268 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
269 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
270 break
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
271 idx+=1
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
272 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
273
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
274 def onWidgetDeleted(self, wid):
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
275 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
276 return
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
277
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
278 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
279 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
280 continue
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
281 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
282 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
283 break
404
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 def _createItem(self, **kwargs):
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
286 item = self.item_class(**kwargs)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
287 jid = kwargs['jid']
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
288 self.items_map.setdefault(jid, []).append(item)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
289 return item
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
290
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
291 def update(self):
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
292 log.debug("starting update")
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
293 self.layout.clear_widgets()
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
294 for item in self.to_show:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
295 if isinstance(item, str):
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
296 if item == 'roster':
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
297 self.addRosterItems()
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
298 elif item == 'bookmarks':
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
299 self.addBookmarksItems()
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
300 elif item == 'opened_chats':
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
301 self.addOpenedChatsItems()
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
302 else:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
303 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
304 elif isinstance(item, Widget):
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
305 self.layout.add_widget(item)
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
306 elif callable(item):
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
307 items_kwargs = item()
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
308 for item_kwargs in items_kwargs:
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
309 item = self._createItem(**items_kwargs)
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
310 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
311 self.layout.add_widget(item)
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
312 else:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
313 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
314
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
315 def addCategoryLayout(self, label=None):
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
316 category_layout = JidSelectorCategoryLayout()
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
317
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
318 if label and self.add_separators:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
319 category_layout.add_widget(CategorySeparator(text=label))
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
320
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
321 self.layout.add_widget(category_layout)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
322 self.items_layouts.append(category_layout)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
323 return category_layout
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
324
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
325 def getItemFromWid(self, wid):
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
326 """create JidSelector item from QuickChat widget"""
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
327 contact_list = G.host.contact_lists[wid.profile]
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
328 data=contact_list.getItem(wid.target)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
329 try:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
330 item = self._createItem(
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
331 jid=wid.target,
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
332 data=data,
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
333 profile=wid.profile,
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
334 )
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
335 except Exception as e:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
336 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
337 return
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
338 notifs = list(G.host.getNotifs(wid.target, profile=wid.profile))
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
339 if notifs:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
340 item.badge_text = str(len(notifs))
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
341 item.bind(on_press=partial(self.dispatch, 'on_select'))
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
342 return item
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
343
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
344 def addOpenedChatsItems(self):
406
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
345 G.host.addListener("widgetNew", self.onWidgetNew)
03554ad70846 common (jidSelector): replace implitict_update mechanism by real-time update:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
346 G.host.addListener("widgetDeleted", self.onWidgetDeleted)
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
347 self.opened_chats = category_layout = self.addCategoryLayout(_("Opened chats"))
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
348 widgets = sorted(G.host.widgets.getWidgets(
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
349 quick_chat.QuickChat,
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
350 profiles = G.host.profiles,
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
351 with_duplicates=False))
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
352
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
353 for wid in widgets:
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
354 item = self.getItemFromWid(wid)
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
355 if item is None:
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
356 continue
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
357 category_layout.add_widget(item)
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
358
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
359 def addRosterItems(self):
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
360 self.roster = category_layout = self.addCategoryLayout(_("Your contacts"))
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
361 for profile in G.host.profiles:
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
362 contact_list = G.host.contact_lists[profile]
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
363 for entity_jid in sorted(contact_list.roster):
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
364 item = self._createItem(
348
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
365 jid=entity_jid,
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
366 data=contact_list.getItem(entity_jid),
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
367 profile=profile,
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
368 )
38fd457b2158 core (common, share_widget): new JidSelector widget:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
369 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
370 category_layout.add_widget(item)
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
371
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
372 def addBookmarksItems(self):
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
373 self.bookmarks = category_layout = self.addCategoryLayout(_("Your chat rooms"))
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
374 for profile in G.host.profiles:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
375 profile_manager = G.host.profiles[profile]
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
376 try:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
377 bookmarks = profile_manager._bookmarks
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
378 except AttributeError:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
379 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
380 continue
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
381
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
382 contact_list = G.host.contact_lists[profile]
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
383 for entity_jid in bookmarks:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
384 try:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
385 cache = contact_list.getItem(entity_jid)
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
386 except KeyError:
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
387 cache = {}
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
388 item = self._createItem(
389
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
389 jid=entity_jid,
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
390 data=cache,
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
391 profile=profile,
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
392 )
442756495a96 core (common): improved flexibility of jid selector:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
393 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
394 category_layout.add_widget(item)