comparison cagou/core/menu.py @ 400:71f51198478c

android: handle runtime permissions: - some mandatory permissions are requested on Cagou start, Cagou won't start at all and display a warning message if they are not granted (we request 5 times before showing the warning) - transfer plugin can now use "android_permissions" in plugin_info, to indicate what is necessary. The permissions will then be requested, and the plugin widget won't be shown if they are not granted (and a warning not will then be displayed)
author Goffi <goffi@goffi.org>
date Sun, 09 Feb 2020 23:47:29 +0100
parents 1da3c379205b
children f7476818f9fb
comparison
equal deleted inserted replaced
399:672880661797 400:71f51198478c
225 item = TransferItem( 225 item = TransferItem(
226 plug_info = plug_info 226 plug_info = plug_info
227 ) 227 )
228 self.items_layout.add_widget(item) 228 self.items_layout.add_widget(item)
229 229
230 def _onTransferCb(self, file_path, external, wid_cont, cleaning_cb=None):
231 if not external:
232 wid = wid_cont[0]
233 self._closeUI(wid)
234 self.callback(
235 file_path,
236 transfer_type = (C.TRANSFER_UPLOAD
237 if self.ids['upload_btn'].state == "down" else C.TRANSFER_SEND),
238 cleaning_cb=cleaning_cb,
239 )
240
241 def _check_plugin_permissions_cb(self, plug_info):
242 external = plug_info.get('external', False)
243 wid_cont = []
244 wid_cont.append(plug_info['factory'](
245 plug_info,
246 partial(self._onTransferCb, external=external, wid_cont=wid_cont),
247 self.cancel_cb,
248 self.profiles))
249 if not external:
250 G.host.showExtraUI(wid_cont[0])
251
230 def do_callback(self, plug_info): 252 def do_callback(self, plug_info):
231 self.parent.remove_widget(self) 253 self.parent.remove_widget(self)
232 if self.callback is None: 254 if self.callback is None:
233 log.warning("TransferMenu callback is not set") 255 log.warning("TransferMenu callback is not set")
234 else: 256 else:
235 wid = None 257 G.local_platform.check_plugin_permissions(
236 external = plug_info.get('external', False) 258 plug_info,
237 def onTransferCb(file_path, cleaning_cb=None): 259 callback=partial(self._check_plugin_permissions_cb, plug_info),
238 if not external: 260 errback=lambda: G.host.addNote(
239 self._closeUI(wid) 261 _("permission refused"),
240 self.callback( 262 _("this transfer menu can't be used if you refuse the requested "
241 file_path, 263 "permission"),
242 transfer_type = (C.TRANSFER_UPLOAD 264 C.XMLUI_DATA_LVL_WARNING)
243 if self.ids['upload_btn'].state == "down" else C.TRANSFER_SEND), 265 )
244 cleaning_cb=cleaning_cb,
245 )
246 wid = plug_info['factory'](plug_info,
247 onTransferCb,
248 self.cancel_cb,
249 self.profiles)
250 if not external:
251 G.host.showExtraUI(wid)
252 266
253 267
254 class EntitiesSelectorMenu(SideMenu, FilterBehavior): 268 class EntitiesSelectorMenu(SideMenu, FilterBehavior):
255 """allow to select entities from roster""" 269 """allow to select entities from roster"""
256 profiles = properties.ObjectProperty() 270 profiles = properties.ObjectProperty()