diff cagou/core/platform_/android.py @ 491:203755bbe0fe

massive refactoring from camelCase -> snake_case. See backend commit log for more details
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:44:32 +0200
parents 83c67b093350
children
line wrap: on
line diff
--- a/cagou/core/platform_/android.py	Sat Apr 08 13:34:55 2023 +0200
+++ b/cagou/core/platform_/android.py	Sat Apr 08 13:44:32 2023 +0200
@@ -93,9 +93,9 @@
         self.cache.append((self.on_new_intent, mActivity.getIntent()))
         self.last_selected_wid = None
         self.restore_selected_wid = True
-        host.addListener('profilePlugged', self.onProfilePlugged)
-        host.addListener('selected', self.onSelectedWidget)
-        local_dir = Path(host.getConfig('', 'local_dir')).resolve()
+        host.addListener('profile_plugged', self.on_profile_plugged)
+        host.addListener('selected', self.on_selected_widget)
+        local_dir = Path(host.config_get('', 'local_dir')).resolve()
         self.tmp_dir = local_dir / 'tmp'
         # we assert to avoid disaster if `/ 'tmp'` is removed by mistake on the line
         # above
@@ -105,7 +105,7 @@
             shutil.rmtree(self.tmp_dir)
         self.tmp_dir.mkdir(0o700, parents=True)
 
-    def on_initFrontendState(self):
+    def on_init_frontend_state(self):
         # XXX: we use a separated socket instead of bridge because if we
         #      try to call a bridge method in on_pause method, the call data
         #      is not written before the actual pause
@@ -114,14 +114,14 @@
         s.connect(os.path.join(SOCKET_DIR, SOCKET_FILE))
         s.sendall(STATE_RUNNING)
 
-    def profileAutoconnectGetCb(self, profile=None):
+    def profile_autoconnect_get_cb(self, profile=None):
         if profile is not None:
             G.host.options.profile = profile
-        G.host.postInit()
+        G.host.post_init()
 
-    def profileAutoconnectGetEb(self, failure_):
+    def profile_autoconnect_get_eb(self, failure_):
         log.error(f"Error while getting profile to autoconnect: {failure_}")
-        G.host.postInit()
+        G.host.post_init()
 
     def _show_perm_warning(self, permissions):
         root_wid = G.host.app.root
@@ -166,16 +166,16 @@
             request_permissions(PERMISSION_MANDATORY, callback=self.permission_cb)
             return
 
-        Clock.schedule_once(lambda *args: G.host.bridge.profileAutoconnectGet(
-            callback=self.profileAutoconnectGetCb,
-            errback=self.profileAutoconnectGetEb),
+        Clock.schedule_once(lambda *args: G.host.bridge.profile_autoconnect_get(
+            callback=self.profile_autoconnect_get_cb,
+            errback=self.profile_autoconnect_get_eb),
             0)
 
-    def do_postInit(self):
+    def do_post_init(self):
         request_permissions(PERMISSION_MANDATORY, callback=self.permission_cb)
         return False
 
-    def privateDataGetCb(self, data_s, profile):
+    def private_data_get_cb(self, data_s, profile):
         data = data_format.deserialise(data_s, type_check=None)
         if data is not None and self.restore_selected_wid:
             log.debug(f"restoring previous widget {data}")
@@ -187,38 +187,38 @@
                 return
             if target:
                 target = jid.JID(data['target'])
-            plugin_info = G.host.getPluginInfo(name=name)
+            plugin_info = G.host.get_plugin_info(name=name)
             if plugin_info is None:
                 log.warning("Can't restore unknown plugin: {name}")
                 return
             factory = plugin_info['factory']
-            G.host.switchWidget(
+            G.host.switch_widget(
                 None,
                 factory(plugin_info, target=target, profiles=[profile])
             )
 
-    def onProfilePlugged(self, profile):
-        log.debug("ANDROID profilePlugged")
-        G.host.bridge.setParam(
+    def on_profile_plugged(self, profile):
+        log.debug("ANDROID profile_plugged")
+        G.host.bridge.param_set(
             "autoconnect_backend", C.BOOL_TRUE, "Connection", -1, profile,
             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
-        G.host.removeListener("profilePlugged", self.onProfilePlugged)
+        G.host.removeListener("profile_plugged", self.on_profile_plugged)
         # we restore the stored widget if any
         # user will then go back to where they was when the frontend was closed
-        G.host.bridge.privateDataGet(
+        G.host.bridge.private_data_get(
             "cagou", "selected_widget", profile,
-            callback=partial(self.privateDataGetCb, profile=profile),
+            callback=partial(self.private_data_get_cb, profile=profile),
             errback=partial(
                 G.host.errback,
                 title=_("can't get selected widget"),
                 message=_("error while retrieving selected widget: {msg}"))
         )
 
-    def onSelectedWidget(self, wid):
+    def on_selected_widget(self, wid):
         """Store selected widget in backend, to restore it on next startup"""
         if self.last_selected_wid == None:
             self.last_selected_wid = wid
@@ -254,7 +254,7 @@
             "target": target,
         }
 
-        G.host.bridge.privateDataSet(
+        G.host.bridge.private_data_set(
             "cagou", "selected_widget", data_format.serialise(data), profile,
             errback=partial(
                 G.host.errback,
@@ -285,14 +285,14 @@
         return True
 
     def _disconnect(self, profile):
-        G.host.bridge.setParam(
+        G.host.bridge.param_set(
             "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()
+        G.host.app.show_profile_manager()
+        G.host.close_ui()
 
     def _on_disconnect(self):
         current_profile = next(iter(G.host.profiles))
@@ -303,14 +303,14 @@
                 "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,
+            no_cb=G.host.close_ui,
         )
-        G.host.showExtraUI(wid)
+        G.host.show_extra_ui(wid)
 
     def on_extra_menu_init(self, extra_menu):
-        extra_menu.addItem(_('disconnect'), self._on_disconnect)
+        extra_menu.add_item(_('disconnect'), self._on_disconnect)
 
-    def updateParamsExtra(self, extra):
+    def update_params_extra(self, extra):
         # on Android, we handle autoconnection automatically,
         # user must not modify those parameters
         extra.update(
@@ -323,7 +323,7 @@
             }
         )
 
-    def getColDataFromUri(self, uri, col_name):
+    def get_col_data_from_uri(self, uri, col_name):
         cursor = mActivity.getContentResolver().query(uri, None, None, None, None)
         if cursor is None:
             return None
@@ -336,8 +336,8 @@
         finally:
             cursor.close()
 
-    def getFilenameFromUri(self, uri, media_type):
-        filename = self.getColDataFromUri(uri, DISPLAY_NAME)
+    def get_filename_from_uri(self, uri, media_type):
+        filename = self.get_col_data_from_uri(uri, DISPLAY_NAME)
         if filename is None:
             uri_p = Path(uri.toString())
             filename = uri_p.name or "unnamed"
@@ -347,11 +347,11 @@
                     filename = filename + suffix
         return filename
 
-    def getPathFromUri(self, uri):
+    def get_path_from_uri(self, uri):
         # FIXME: using DATA is not recommended (and DATA is deprecated)
         # we should read directly the file with
         # ContentResolver#openFileDescriptor(Uri, String)
-        path = self.getColDataFromUri(uri, DATA)
+        path = self.get_col_data_from_uri(uri, DATA)
         return uri.getPath() if path is None else path
 
     def on_new_intent(self, intent):
@@ -378,7 +378,7 @@
                         # and now we open the widget linked to the intent
                         current_profile = next(iter(G.host.profiles))
                         Clock.schedule_once(
-                            lambda *args: G.host.doAction(
+                            lambda *args: G.host.do_action(
                                 widget, jid.JID(target), [current_profile]),
                             0)
                 else:
@@ -400,7 +400,7 @@
                 uri = cast('android.net.Uri', item)
                 if uri.getScheme() == 'content':
                     # Android content, we'll dump it to a temporary file
-                    filename = self.getFilenameFromUri(uri, intent_type)
+                    filename = self.get_filename_from_uri(uri, intent_type)
                     filepath = self.tmp_dir / filename
                     input_stream = mActivity.getContentResolver().openInputStream(uri)
                     buff = bytearray(4096)
@@ -415,7 +415,7 @@
                     data['path'] = path = str(filepath)
                 else:
                     data['uri'] = uri.toString()
-                    path = self.getPathFromUri(uri)
+                    path = self.get_path_from_uri(uri)
                     if path is not None and path not in data:
                         data['path'] = path
             else: