Mercurial > libervia-desktop-kivy
comparison cagou/core/common.py @ 458:1dd6db69406a
core: update avatar handling following backend changes:
new avatar data format is handled. When ContactItem is created, avatar and nicknames are
requested to backend if they are not already in cache.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 14 Apr 2020 21:14:44 +0200 |
parents | efee0e0afb78 |
children | 72290ebfaa8b |
comparison
equal
deleted
inserted
replaced
457:ec11a35dcf14 | 458:1dd6db69406a |
---|---|
18 | 18 |
19 """common simple widgets""" | 19 """common simple widgets""" |
20 | 20 |
21 import json | 21 import json |
22 from functools import partial, total_ordering | 22 from functools import partial, total_ordering |
23 from sat.core.i18n import _ | |
24 from sat.core import log as logging | |
25 from kivy.uix.widget import Widget | 23 from kivy.uix.widget import Widget |
26 from kivy.uix.image import Image, AsyncImage | 24 from kivy.uix.image import Image, AsyncImage |
27 from kivy.uix.label import Label | 25 from kivy.uix.label import Label |
28 from kivy.uix.behaviors import ButtonBehavior | 26 from kivy.uix.behaviors import ButtonBehavior |
29 from kivy.uix.behaviors import ToggleButtonBehavior | 27 from kivy.uix.behaviors import ToggleButtonBehavior |
31 from kivy.uix.boxlayout import BoxLayout | 29 from kivy.uix.boxlayout import BoxLayout |
32 from kivy.uix.scrollview import ScrollView | 30 from kivy.uix.scrollview import ScrollView |
33 from kivy.event import EventDispatcher | 31 from kivy.event import EventDispatcher |
34 from kivy.metrics import dp | 32 from kivy.metrics import dp |
35 from kivy import properties | 33 from kivy import properties |
34 from sat.core.i18n import _ | |
35 from sat.core import log as logging | |
36 from sat.tools.common import data_format | |
36 from sat_frontends.quick_frontend import quick_chat | 37 from sat_frontends.quick_frontend import quick_chat |
37 from .constants import Const as C | 38 from .constants import Const as C |
38 from .common_widgets import CategorySeparator | 39 from .common_widgets import CategorySeparator |
39 from cagou import G | 40 from cagou import G |
40 | 41 |
57 @total_ordering | 58 @total_ordering |
58 class ContactItem(BoxLayout): | 59 class ContactItem(BoxLayout): |
59 """An item from ContactList | 60 """An item from ContactList |
60 | 61 |
61 The item will drawn as an icon (JID avatar) with its jid below. | 62 The item will drawn as an icon (JID avatar) with its jid below. |
62 If "notifs" are present in data, a notification counter will be drawn above the | 63 If "badge_text" is set, a label with the text will be drawn above the avatar. |
63 avatar. | |
64 """ | 64 """ |
65 base_width = dp(150) | 65 base_width = dp(150) |
66 avatar_layout = properties.ObjectProperty() | 66 avatar_layout = properties.ObjectProperty() |
67 avatar = properties.ObjectProperty() | 67 avatar = properties.ObjectProperty() |
68 badge = properties.ObjectProperty(allownone=True) | 68 badge = properties.ObjectProperty(allownone=True) |
69 badge_text = properties.StringProperty('') | 69 badge_text = properties.StringProperty('') |
70 profile = properties.StringProperty() | 70 profile = properties.StringProperty() |
71 data = properties.DictProperty() | 71 data = properties.DictProperty() |
72 jid = properties.StringProperty('') | 72 jid = properties.StringProperty('') |
73 | |
74 def on_kv_post(self, __): | |
75 if ((self.profile and self.jid and self.data is not None | |
76 and ('avatar' not in self.data or 'nicknames' not in self.data))): | |
77 G.host.bridge.identityGet( | |
78 self.jid, ['avatar', 'nicknames'], True, self.profile, | |
79 callback=self._identityGetCb, | |
80 errback=partial( | |
81 G.host.errback, | |
82 message=_("Can't retrieve identity for {jid}: {{msg}}").format( | |
83 jid=self.jid) | |
84 ) | |
85 ) | |
86 | |
87 def _identityGetCb(self, identity_raw): | |
88 identity_data = data_format.deserialise(identity_raw) | |
89 self.data.update(identity_data) | |
73 | 90 |
74 def on_badge_text(self, wid, text): | 91 def on_badge_text(self, wid, text): |
75 if text: | 92 if text: |
76 if self.badge is not None: | 93 if self.badge is not None: |
77 self.badge.text = text | 94 self.badge.text = text |