From 459328658916b1ef8cdd2a13e29ab7386433da5b Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 18 Oct 2022 15:06:25 +0200 Subject: [PATCH] Added interface mode settings when transport is active --- sbapp/buildozer.spec | 2 +- sbapp/main.py | 92 +++++++++++++++++++++++++++++++----------- sbapp/sideband/core.py | 24 +++++++++++ sbapp/ui/layouts.py | 79 +++++++++++++++++++++++++++++++++++- 4 files changed, 172 insertions(+), 25 deletions(-) diff --git a/sbapp/buildozer.spec b/sbapp/buildozer.spec index e01c55e..d142fb2 100644 --- a/sbapp/buildozer.spec +++ b/sbapp/buildozer.spec @@ -10,7 +10,7 @@ source.exclude_patterns = app_storage/*,venv/*,Makefile,./Makefil*,requirements, version.regex = __version__ = ['"](.*)['"] version.filename = %(source.dir)s/main.py -android.numeric_version = 20221016 +android.numeric_version = 20221018 requirements = python3==3.9.5,hostpython3==3.9.5,cryptography,cffi,pycparser,kivy==2.1.0,pygments,sdl2,sdl2_ttf==2.0.15,pillow,lxmf==0.1.9,netifaces,libbz2,pydenticon,usb4a,usbserial4a p4a.local_recipes = ../Others/python-for-android/pythonforandroid/recipes diff --git a/sbapp/main.py b/sbapp/main.py index fdc19fa..f940f2b 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -1,6 +1,6 @@ __debug_build__ = False __disable_shaders__ = True -__version__ = "0.2.4" +__version__ = "0.2.5" __variant__ = "beta" import sys @@ -1044,6 +1044,9 @@ class SidebandApp(MDApp): def con_collapse_serial(collapse=True): self.widget_hide(self.root.ids.connectivity_serial_fields, collapse) + def con_collapse_transport(collapse=True): + self.widget_hide(self.root.ids.connectivity_transport_fields, collapse) + def save_connectivity(sender=None, event=None): self.sideband.config["connect_transport"] = self.root.ids.connectivity_enable_transport.active self.sideband.config["connect_local"] = self.root.ids.connectivity_use_local.active @@ -1071,6 +1074,13 @@ class SidebandApp(MDApp): self.sideband.config["connect_modem_ifac_netname"] = self.root.ids.connectivity_modem_ifac_netname.text self.sideband.config["connect_modem_ifac_passphrase"] = self.root.ids.connectivity_modem_ifac_passphrase.text + self.sideband.config["connect_ifmode_local"] = self.root.ids.connectivity_local_ifmode.text.lower() + self.sideband.config["connect_ifmode_tcp"] = self.root.ids.connectivity_tcp_ifmode.text.lower() + self.sideband.config["connect_ifmode_i2p"] = self.root.ids.connectivity_i2p_ifmode.text.lower() + self.sideband.config["connect_ifmode_rnode"] = self.root.ids.connectivity_rnode_ifmode.text.lower() + self.sideband.config["connect_ifmode_modem"] = self.root.ids.connectivity_modem_ifmode.text.lower() + self.sideband.config["connect_ifmode_serial"] = self.root.ids.connectivity_serial_ifmode.text.lower() + con_collapse_local(collapse=not self.root.ids.connectivity_use_local.active) con_collapse_tcp(collapse=not self.root.ids.connectivity_use_tcp.active) con_collapse_i2p(collapse=not self.root.ids.connectivity_use_i2p.active) @@ -1078,6 +1088,7 @@ class SidebandApp(MDApp): con_collapse_bluetooth(collapse=not self.root.ids.connectivity_use_bluetooth.active) con_collapse_modem(collapse=not self.root.ids.connectivity_use_modem.active) con_collapse_serial(collapse=not self.root.ids.connectivity_use_serial.active) + con_collapse_transport(collapse=not self.sideband.config["connect_transport"]) self.sideband.save_configuration() @@ -1115,6 +1126,37 @@ class SidebandApp(MDApp): if not sender.focus: save_connectivity(sender, event) + def ifmode_validate(sender=None, event=None): + if not sender.focus: + all_valid = True + iftypes = ["local", "tcp", "i2p", "rnode", "modem", "serial"] + for iftype in iftypes: + element = self.root.ids["connectivity_"+iftype+"_ifmode"] + modes = ["full", "gateway", "access point", "roaming", "boundary"] + value = element.text.lower() + if value in ["", "f"] or value.startswith("fu"): + value = "full" + elif value in ["g", "gw"] or value.startswith("ga"): + value = "gateway" + elif value in ["a", "ap", "a p", "accesspoint", "access point", "ac", "acc", "acce", "acces"] or value.startswith("access"): + value = "access point" + elif value in ["r"] or value.startswith("ro"): + value = "roaming" + elif value in ["b", "edge"] or value.startswith("bo"): + value = "boundary" + else: + value = "full" + + if value in modes: + element.text = value.capitalize() + element.error = False + else: + element.error = True + all_valid = False + + if all_valid: + save_connectivity(sender, event) + if RNS.vendor.platformutils.get_platform() == "android": if not self.sideband.getpersistent("service.is_controlling_connectivity"): info = "Sideband is connected via a shared Reticulum instance running on this system.\n\n" @@ -1128,7 +1170,6 @@ class SidebandApp(MDApp): info += "For changes to connectivity to take effect, you must shut down and restart Sideband.\n" self.root.ids.connectivity_info.text = info - self.root.ids.connectivity_enable_transport.active = self.sideband.config["connect_transport"] self.root.ids.connectivity_use_local.active = self.sideband.config["connect_local"] con_collapse_local(collapse=not self.root.ids.connectivity_use_local.active) self.root.ids.connectivity_local_groupid.text = self.sideband.config["connect_local_groupid"] @@ -1156,7 +1197,6 @@ class SidebandApp(MDApp): self.root.ids.connectivity_use_bluetooth.active = False con_collapse_bluetooth(collapse=not self.root.ids.connectivity_use_bluetooth.active) - self.root.ids.connectivity_use_modem.active = self.sideband.config["connect_modem"] con_collapse_modem(collapse=not self.root.ids.connectivity_use_modem.active) self.root.ids.connectivity_modem_ifac_netname.text = self.sideband.config["connect_modem_ifac_netname"] @@ -1167,47 +1207,53 @@ class SidebandApp(MDApp): self.root.ids.connectivity_serial_ifac_netname.text = self.sideband.config["connect_serial_ifac_netname"] self.root.ids.connectivity_serial_ifac_passphrase.text = self.sideband.config["connect_serial_ifac_passphrase"] + self.root.ids.connectivity_enable_transport.active = self.sideband.config["connect_transport"] + con_collapse_transport(collapse=not self.sideband.config["connect_transport"]) self.root.ids.connectivity_enable_transport.bind(active=save_connectivity) + self.root.ids.connectivity_local_ifmode.text = self.sideband.config["connect_ifmode_local"].capitalize() + self.root.ids.connectivity_tcp_ifmode.text = self.sideband.config["connect_ifmode_tcp"].capitalize() + self.root.ids.connectivity_i2p_ifmode.text = self.sideband.config["connect_ifmode_i2p"].capitalize() + self.root.ids.connectivity_rnode_ifmode.text = self.sideband.config["connect_ifmode_rnode"].capitalize() + self.root.ids.connectivity_modem_ifmode.text = self.sideband.config["connect_ifmode_modem"].capitalize() + self.root.ids.connectivity_serial_ifmode.text = self.sideband.config["connect_ifmode_serial"].capitalize() + self.root.ids.connectivity_use_local.bind(active=save_connectivity) - self.root.ids.connectivity_local_groupid.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_local_ifac_netname.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_local_ifac_passphrase.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_use_tcp.bind(active=save_connectivity) - self.root.ids.connectivity_tcp_host.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_tcp_port.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_tcp_ifac_netname.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_tcp_ifac_passphrase.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_use_i2p.bind(active=save_connectivity) - self.root.ids.connectivity_i2p_b32.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_i2p_ifac_netname.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_i2p_ifac_passphrase.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_rnode_ifac_netname.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_rnode_ifac_passphrase.bind(on_text_validate=save_connectivity) - self.root.ids.connectivity_use_bluetooth.bind(active=save_connectivity) - - self.root.ids.connectivity_use_rnode.bind(active=serial_connectivity_save) - self.root.ids.connectivity_use_modem.bind(active=serial_connectivity_save) - self.root.ids.connectivity_use_serial.bind(active=serial_connectivity_save) - self.root.ids.connectivity_local_groupid.bind(focus=focus_save) self.root.ids.connectivity_local_ifac_netname.bind(focus=focus_save) self.root.ids.connectivity_local_ifac_passphrase.bind(focus=focus_save) + + self.root.ids.connectivity_use_tcp.bind(active=save_connectivity) self.root.ids.connectivity_tcp_host.bind(focus=focus_save) self.root.ids.connectivity_tcp_port.bind(focus=focus_save) self.root.ids.connectivity_tcp_ifac_netname.bind(focus=focus_save) self.root.ids.connectivity_tcp_ifac_passphrase.bind(focus=focus_save) + + self.root.ids.connectivity_use_i2p.bind(active=save_connectivity) self.root.ids.connectivity_i2p_b32.bind(focus=focus_save) self.root.ids.connectivity_i2p_ifac_netname.bind(focus=focus_save) self.root.ids.connectivity_i2p_ifac_passphrase.bind(focus=focus_save) + + self.root.ids.connectivity_use_rnode.bind(active=serial_connectivity_save) self.root.ids.connectivity_rnode_ifac_netname.bind(focus=focus_save) self.root.ids.connectivity_rnode_ifac_passphrase.bind(focus=focus_save) + self.root.ids.connectivity_use_modem.bind(active=serial_connectivity_save) self.root.ids.connectivity_modem_ifac_netname.bind(focus=focus_save) self.root.ids.connectivity_modem_ifac_passphrase.bind(focus=focus_save) + self.root.ids.connectivity_use_serial.bind(active=serial_connectivity_save) self.root.ids.connectivity_serial_ifac_netname.bind(focus=focus_save) self.root.ids.connectivity_serial_ifac_passphrase.bind(focus=focus_save) + self.root.ids.connectivity_local_ifmode.bind(focus=ifmode_validate) + self.root.ids.connectivity_tcp_ifmode.bind(focus=ifmode_validate) + self.root.ids.connectivity_i2p_ifmode.bind(focus=ifmode_validate) + self.root.ids.connectivity_rnode_ifmode.bind(focus=ifmode_validate) + self.root.ids.connectivity_modem_ifmode.bind(focus=ifmode_validate) + self.root.ids.connectivity_serial_ifmode.bind(focus=ifmode_validate) + + self.root.ids.connectivity_use_bluetooth.bind(active=save_connectivity) + else: info = "" diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 577bceb..16d45c6 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -208,6 +208,13 @@ class SidebandCore(): self.config["connect_modem"] = False self.config["connect_modem_ifac_netname"] = "" self.config["connect_modem_ifac_passphrase"] = "" + self.config["connect_ifmode_local"] = "full" + self.config["connect_ifmode_tcp"] = "full" + self.config["connect_ifmode_i2p"] = "full" + self.config["connect_ifmode_rnode"] = "full" + self.config["connect_ifmode_modem"] = "full" + self.config["connect_ifmode_serial"] = "full" + self.config["connect_ifmode_bluetooth"] = "full" # Hardware self.config["hw_rnode_frequency"] = None self.config["hw_rnode_modulation"] = "LoRa" @@ -264,6 +271,7 @@ class SidebandCore(): self.config["lxmf_sync_interval"] = 43200 if not "notifications_on" in self.config: self.config["notifications_on"] = True + if not "connect_transport" in self.config: self.config["connect_transport"] = False if not "connect_rnode" in self.config: @@ -284,6 +292,22 @@ class SidebandCore(): self.config["connect_modem_ifac_netname"] = "" if not "connect_modem_ifac_passphrase" in self.config: self.config["connect_modem_ifac_passphrase"] = "" + + if not "connect_ifmode_local" in self.config: + self.config["connect_ifmode_local"] = "full" + if not "connect_ifmode_tcp" in self.config: + self.config["connect_ifmode_tcp"] = "full" + if not "connect_ifmode_i2p" in self.config: + self.config["connect_ifmode_i2p"] = "full" + if not "connect_ifmode_rnode" in self.config: + self.config["connect_ifmode_rnode"] = "full" + if not "connect_ifmode_modem" in self.config: + self.config["connect_ifmode_modem"] = "full" + if not "connect_ifmode_serial" in self.config: + self.config["connect_ifmode_serial"] = "full" + if not "connect_ifmode_bluetooth" in self.config: + self.config["connect_ifmode_bluetooth"] = "full" + if not "hw_rnode_frequency" in self.config: self.config["hw_rnode_frequency"] = None if not "hw_rnode_modulation" in self.config: diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index 2e3cb96..427b80c 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -520,7 +520,6 @@ MDNavigationLayout: font_size: dp(24) # disabled: True - MDBoxLayout: orientation: "horizontal" padding: [0,0,dp(24),0] @@ -539,6 +538,84 @@ MDNavigationLayout: pos_hint: {"center_y": 0.3} # disabled: True + MDBoxLayout: + id: connectivity_transport_fields + orientation: "vertical" + size_hint_y: None + height: self.minimum_height + padding: [0, 0, 0, dp(32)] + + # MDLabel: + # id: connectivity_modes_info + # markup: True + # text: "With Transport enabled, you can configure the interface modes for any enabled interfaces. Changing interface modes affects how Reticulum processes traffic and announces. For more information, refer to the Reticulum Manual." + # size_hint_y: None + # text_size: self.width, None + # height: self.texture_size[1] + + MDBoxLayout: + orientation: "horizontal" + spacing: "24dp" + size_hint_y: None + height: self.minimum_height + padding: [dp(0), dp(12), dp(0), dp(12)] + + MDTextField: + id: connectivity_local_ifmode + hint_text: "Local Interface Mode" + text: "" + font_size: dp(24) + + MDTextField: + id: connectivity_tcp_ifmode + hint_text: "TCP Interface Mode" + text: "" + font_size: dp(24) + + MDBoxLayout: + orientation: "horizontal" + spacing: "24dp" + size_hint_y: None + height: self.minimum_height + padding: [dp(0), dp(12), dp(0), dp(12)] + + MDTextField: + id: connectivity_i2p_ifmode + hint_text: "I2P Mode" + text: "" + font_size: dp(24) + + MDTextField: + id: connectivity_rnode_ifmode + hint_text: "RNode Mode" + text: "" + font_size: dp(24) + + MDBoxLayout: + orientation: "horizontal" + spacing: "24dp" + size_hint_y: None + height: self.minimum_height + padding: [dp(0), dp(12), dp(0), dp(12)] + + MDTextField: + id: connectivity_modem_ifmode + hint_text: "Modem Mode" + text: "" + font_size: dp(24) + + MDTextField: + id: connectivity_serial_ifmode + hint_text: "Serial Mode" + text: "" + font_size: dp(24) + + # MDTextField: + # id: connectivity_bluetooth_ifmode + # hint_text: "Bluetooth Mode" + # text: "" + # font_size: dp(24) + MDScreen: name: "guide_screen"