# HG changeset patch # User Goffi # Date 1580156229 -3600 # Node ID b2a87239af257d656f54cc81efa7a6d605f5aab3 # Parent 9ef01266e3feb194fa9dd8adab7b3745db69e5ba android: platform specific menu to disconnect profile: This menu is platform specific because it also unset the autostart parameter (which is handler in a specific way on Android). diff -r 9ef01266e3fe -r b2a87239af25 cagou/core/cagou_main.py --- a/cagou/core/cagou_main.py Mon Jan 27 21:17:09 2020 +0100 +++ b/cagou/core/cagou_main.py Mon Jan 27 21:17:09 2020 +0100 @@ -307,7 +307,7 @@ local_platform.on_app_build(wid) return wid - def showWidget(self): + def showProfileManager(self): self._profile_manager = ProfileManager() self.root.changeWidget(self._profile_manager) @@ -498,7 +498,7 @@ def onBackendReady(self): super().onBackendReady() - self.app.showWidget() + self.app.showProfileManager() self.bridge.getVersion(callback=self._getVersionCb) self.app.initFrontendState() if local_platform.do_postInit(): diff -r 9ef01266e3fe -r b2a87239af25 cagou/core/platform_/android.py --- a/cagou/core/platform_/android.py Mon Jan 27 21:17:09 2020 +0100 +++ b/cagou/core/platform_/android.py Mon Jan 27 21:17:09 2020 +0100 @@ -19,11 +19,14 @@ import sys import os import socket +from functools import partial from jnius import autoclass, cast from android import activity +from sat.core.i18n import _ from sat.core import log as logging from urllib.parse import urlparse from cagou.core.constants import Const as C +from cagou.core import dialog from cagou import G from kivy.clock import Clock from .base import Platform as BasePlatform @@ -101,8 +104,8 @@ log.debug("ANDROID profilePlugged") G.host.bridge.setParam( "autoconnect_backend", C.BOOL_TRUE, "Connection", -1, profile, - callback=lambda: log.info(f"profile {profile} autonnection set"), - errback=lambda: log.error(f"can't set {profile} autonnection")) + callback=lambda: log.info(f"profile {profile} autoconnection set"), + errback=lambda: log.error(f"can't set {profile} autoconnection")) for method, *args in self.cache: method(*args) del self.cache @@ -130,6 +133,32 @@ PythonActivity.moveTaskToBack(True) return True + def _disconnect(self, profile): + G.host.bridge.setParam( + "autoconnect_backend", C.BOOL_FALSE, "Connection", -1, profile, + callback=lambda: log.info(f"profile {profile} autoconnection unset"), + errback=lambda: log.error(f"can't unset {profile} autoconnection")) + G.host.profiles.unplug(profile) + G.host.bridge.disconnect(profile) + G.host.app.showProfileManager() + G.host.closeUI() + + def _on_disconnect(self): + current_profile = next(iter(G.host.profiles)) + wid = dialog.ConfirmDialog( + title=_("Are you sure to disconnect?"), + message=_( + "If you disconnect the current user ({profile}), you won't receive " + "any notification until you connect it again, is this really what you " + "want?").format(profile=current_profile), + yes_cb=partial(self._disconnect, profile=current_profile), + no_cb=G.host.closeUI, + ) + G.host.showExtraUI(wid) + + def on_extra_menu_init(self, extra_menu): + extra_menu.addItem(_('disconnect'), self._on_disconnect) + def updateParamsExtra(self, extra): # on Android, we handle autoconnection automatically, # user must not modify those parameters