comparison cagou/core/platform_/android.py @ 377:b2a87239af25

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).
author Goffi <goffi@goffi.org>
date Mon, 27 Jan 2020 21:17:09 +0100
parents 5d994be1161b
children 4d660b252487
comparison
equal deleted inserted replaced
376:9ef01266e3fe 377:b2a87239af25
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 import sys 19 import sys
20 import os 20 import os
21 import socket 21 import socket
22 from functools import partial
22 from jnius import autoclass, cast 23 from jnius import autoclass, cast
23 from android import activity 24 from android import activity
25 from sat.core.i18n import _
24 from sat.core import log as logging 26 from sat.core import log as logging
25 from urllib.parse import urlparse 27 from urllib.parse import urlparse
26 from cagou.core.constants import Const as C 28 from cagou.core.constants import Const as C
29 from cagou.core import dialog
27 from cagou import G 30 from cagou import G
28 from kivy.clock import Clock 31 from kivy.clock import Clock
29 from .base import Platform as BasePlatform 32 from .base import Platform as BasePlatform
30 33
31 34
99 102
100 def onProfilePlugged(self, profile): 103 def onProfilePlugged(self, profile):
101 log.debug("ANDROID profilePlugged") 104 log.debug("ANDROID profilePlugged")
102 G.host.bridge.setParam( 105 G.host.bridge.setParam(
103 "autoconnect_backend", C.BOOL_TRUE, "Connection", -1, profile, 106 "autoconnect_backend", C.BOOL_TRUE, "Connection", -1, profile,
104 callback=lambda: log.info(f"profile {profile} autonnection set"), 107 callback=lambda: log.info(f"profile {profile} autoconnection set"),
105 errback=lambda: log.error(f"can't set {profile} autonnection")) 108 errback=lambda: log.error(f"can't set {profile} autoconnection"))
106 for method, *args in self.cache: 109 for method, *args in self.cache:
107 method(*args) 110 method(*args)
108 del self.cache 111 del self.cache
109 G.host.removeListener("profilePlugged", self.onProfilePlugged) 112 G.host.removeListener("profilePlugged", self.onProfilePlugged)
110 113
127 130
128 def on_key_back_share(self, share_widget): 131 def on_key_back_share(self, share_widget):
129 share_widget.close() 132 share_widget.close()
130 PythonActivity.moveTaskToBack(True) 133 PythonActivity.moveTaskToBack(True)
131 return True 134 return True
135
136 def _disconnect(self, profile):
137 G.host.bridge.setParam(
138 "autoconnect_backend", C.BOOL_FALSE, "Connection", -1, profile,
139 callback=lambda: log.info(f"profile {profile} autoconnection unset"),
140 errback=lambda: log.error(f"can't unset {profile} autoconnection"))
141 G.host.profiles.unplug(profile)
142 G.host.bridge.disconnect(profile)
143 G.host.app.showProfileManager()
144 G.host.closeUI()
145
146 def _on_disconnect(self):
147 current_profile = next(iter(G.host.profiles))
148 wid = dialog.ConfirmDialog(
149 title=_("Are you sure to disconnect?"),
150 message=_(
151 "If you disconnect the current user ({profile}), you won't receive "
152 "any notification until you connect it again, is this really what you "
153 "want?").format(profile=current_profile),
154 yes_cb=partial(self._disconnect, profile=current_profile),
155 no_cb=G.host.closeUI,
156 )
157 G.host.showExtraUI(wid)
158
159 def on_extra_menu_init(self, extra_menu):
160 extra_menu.addItem(_('disconnect'), self._on_disconnect)
132 161
133 def updateParamsExtra(self, extra): 162 def updateParamsExtra(self, extra):
134 # on Android, we handle autoconnection automatically, 163 # on Android, we handle autoconnection automatically,
135 # user must not modify those parameters 164 # user must not modify those parameters
136 extra.update( 165 extra.update(