Mercurial > libervia-desktop-kivy
comparison cagou/core/common.py @ 397:54f6a47cc60a
core (common): added a notifications counter on ContactButton and use it in JidSelector:
A notifications counter is drawned above avatar if `nofifs` key is present and not empty
in `data`.
This is used in JidSelector to show counter when necessary with opened chats.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 09 Feb 2020 23:47:29 +0100 |
parents | 442756495a96 |
children | f7476818f9fb |
comparison
equal
deleted
inserted
replaced
396:ae6f7fd1cb0e | 397:54f6a47cc60a |
---|---|
47 | 47 |
48 class Avatar(Image): | 48 class Avatar(Image): |
49 pass | 49 pass |
50 | 50 |
51 | 51 |
52 class NotifLabel(Label): | |
53 pass | |
54 | |
55 | |
52 class ContactItem(BoxLayout): | 56 class ContactItem(BoxLayout): |
53 """An item from ContactList | 57 """An item from ContactList |
54 | 58 |
55 The item will drawn as an icon (JID avatar) with its jid below | 59 The item will drawn as an icon (JID avatar) with its jid below. |
60 If "notifs" are present in data, a notification counter will be drawn above the | |
61 avatar. | |
56 """ | 62 """ |
57 base_width = dp(150) | 63 base_width = dp(150) |
64 avatar_layout = properties.ObjectProperty() | |
65 avatar = properties.ObjectProperty() | |
58 profile = properties.StringProperty() | 66 profile = properties.StringProperty() |
59 data = properties.DictProperty() | 67 data = properties.DictProperty() |
60 jid = properties.StringProperty('') | 68 jid = properties.StringProperty('') |
69 | |
70 def on_kv_post(self, __): | |
71 if self.data and self.data.get('notifs'): | |
72 notif = NotifLabel( | |
73 pos_hint={"right": 0.8, "y": 0}, | |
74 text=str(len(self.data['notifs'])) | |
75 ) | |
76 self.avatar_layout.add_widget(notif) | |
61 | 77 |
62 | 78 |
63 class ContactButton(ButtonBehavior, ContactItem): | 79 class ContactButton(ButtonBehavior, ContactItem): |
64 pass | 80 pass |
65 | 81 |
223 quick_chat.QuickChat, | 239 quick_chat.QuickChat, |
224 profiles = G.host.profiles) | 240 profiles = G.host.profiles) |
225 | 241 |
226 for wid in opened_chats: | 242 for wid in opened_chats: |
227 contact_list = G.host.contact_lists[wid.profile] | 243 contact_list = G.host.contact_lists[wid.profile] |
244 data=contact_list.getItem(wid.target) | |
245 notifs = list(G.host.getNotifs(wid.target, profile=wid.profile)) | |
246 if notifs: | |
247 # we shallow copy the dict to have the notification displayed only with | |
248 # opened chats (otherwise, the counter would appear on each other | |
249 # instance of ContactButton for this entity, i.e. in roster too). | |
250 data = data.copy() | |
251 data['notifs'] = notifs | |
228 try: | 252 try: |
229 item = ContactButton( | 253 item = ContactButton( |
230 jid=wid.target, | 254 jid=wid.target, |
231 data=contact_list.getItem(wid.target), | 255 data=data, |
232 profile=wid.profile, | 256 profile=wid.profile, |
233 ) | 257 ) |
234 except Exception as e: | 258 except Exception as e: |
235 log.warning(f"Can't add contact {wid.target}: {e}") | 259 log.warning(f"Can't add contact {wid.target}: {e}") |
236 continue | 260 continue |