comparison cagou/plugins/plugin_wid_contact_list.py @ 322:e2b51663d8b8

core, android: new share widget + added Cagou to "share" menu: - new intent filter to add Cagou to share menu for all media types - minimum Kivy version is now 1.11.0 - new "Share" widget to display data to share via SàT and select the target - new core.platform_ module (the suffix "_" avoid trouble with standard "platform" module), for platform specific code. - Android intent are now checked on startup and "on_new_intent" events - if a android.intent.action.SEND action is received (i.e. some data is shared), the "Share" widget is shown - new Cagou.share method to share data using "Share" widget - new Cagou.getAncestorWidget method to easily retrieve an instance of a specific class in a widget's ancestors - ContactList's Avatar and ContactItem widgets have been moved to core.common
author Goffi <goffi@goffi.org>
date Fri, 06 Dec 2019 13:23:03 +0100
parents 772c170b47a9
children 9c6fe392d623
comparison
equal deleted inserted replaced
321:a6eb154ba266 322:e2b51663d8b8
19 19
20 20
21 from sat.core import log as logging 21 from sat.core import log as logging
22 log = logging.getLogger(__name__) 22 log = logging.getLogger(__name__)
23 from cagou.core.constants import Const as C 23 from cagou.core.constants import Const as C
24 from ..core.common import ContactItem
24 from sat.core.i18n import _ 25 from sat.core.i18n import _
25 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList 26 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
26 from sat_frontends.tools import jid 27 from sat_frontends.tools import jid
27 from kivy.uix.boxlayout import BoxLayout
28 from cagou.core.utils import FilterBehavior 28 from cagou.core.utils import FilterBehavior
29 from cagou.core.menu import SideMenu, TouchMenuBehaviour, TouchMenuItemBehaviour 29 from cagou.core.menu import SideMenu, TouchMenuBehaviour, TouchMenuItemBehaviour
30 from kivy.metrics import dp
31 from kivy import properties 30 from kivy import properties
32 from cagou.core import cagou_widget 31 from cagou.core import cagou_widget
33 from cagou.core import image
34 from cagou import G 32 from cagou import G
35 from functools import partial 33 from functools import partial
36 import bisect 34 import bisect
37 import re 35 import re
38 36
97 errback=partial(G.host.errback, 95 errback=partial(G.host.errback,
98 title=_("can't remove contact"), 96 title=_("can't remove contact"),
99 message=_("error while trying to remove contact: {msg}"))) 97 message=_("error while trying to remove contact: {msg}")))
100 98
101 99
102 100 class CLContactItem(TouchMenuItemBehaviour, ContactItem):
103 class Avatar(image.Image):
104 pass
105
106
107 class ContactItem(TouchMenuItemBehaviour, BoxLayout):
108 base_width = dp(150)
109 profile = properties.StringProperty()
110 data = properties.DictProperty()
111 jid = properties.StringProperty('')
112
113 def __init__(self, **kwargs):
114 super(ContactItem, self).__init__(**kwargs)
115 101
116 def do_item_action(self, touch): 102 def do_item_action(self, touch):
117 assert self.profile 103 assert self.profile
118 # XXX: for now clicking on an item launch the corresponding Chat widget 104 # XXX: for now clicking on an item launch the corresponding Chat widget
119 # behaviour should change in the future 105 # behaviour should change in the future
160 width_cb=lambda c: c.base_width, 146 width_cb=lambda c: c.base_width,
161 height_cb=lambda c: c.minimum_height, 147 height_cb=lambda c: c.minimum_height,
162 ) 148 )
163 149
164 def _addContactItem(self, bare_jid, profile): 150 def _addContactItem(self, bare_jid, profile):
165 """Create a new ContactItem instance, and add it 151 """Create a new CLContactItem instance, and add it
166 152
167 item will be added in a sorted position 153 item will be added in a sorted position
168 @param bare_jid(jid.JID): entity bare JID 154 @param bare_jid(jid.JID): entity bare JID
169 @param profile(unicode): profile where the contact is 155 @param profile(unicode): profile where the contact is
170 """ 156 """
171 data = G.host.contact_lists[profile].getItem(bare_jid) 157 data = G.host.contact_lists[profile].getItem(bare_jid)
172 wid = ContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self) 158 wid = CLContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self)
173 child_jids = [c.jid for c in reversed(self.layout.children)] 159 child_jids = [c.jid for c in reversed(self.layout.children)]
174 idx = bisect.bisect_right(child_jids, bare_jid) 160 idx = bisect.bisect_right(child_jids, bare_jid)
175 self.layout.add_widget(wid, -idx) 161 self.layout.add_widget(wid, -idx)
176 self._wid_map[(profile, bare_jid)] = wid 162 self._wid_map[(profile, bare_jid)] = wid
177 163
179 log.debug("update: %s %s %s" % (entities, type_, profile)) 165 log.debug("update: %s %s %s" % (entities, type_, profile))
180 if type_ == None or type_ == C.UPDATE_STRUCTURE: 166 if type_ == None or type_ == C.UPDATE_STRUCTURE:
181 log.debug("full contact list update") 167 log.debug("full contact list update")
182 self.layout.clear_widgets() 168 self.layout.clear_widgets()
183 for bare_jid, data in self.items_sorted.items(): 169 for bare_jid, data in self.items_sorted.items():
184 wid = ContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self) 170 wid = CLContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self)
185 self.layout.add_widget(wid) 171 self.layout.add_widget(wid)
186 self._wid_map[(profile, bare_jid)] = wid 172 self._wid_map[(profile, bare_jid)] = wid
187 elif type_ == C.UPDATE_MODIFY: 173 elif type_ == C.UPDATE_MODIFY:
188 for entity in entities: 174 for entity in entities:
189 entity_bare = entity.bare 175 entity_bare = entity.bare