From 1aa2131d17e73b4025d9bac7fe3095ebd3bd9bbc Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 23 Oct 2023 01:26:44 +0200 Subject: [PATCH] Trusted-only display mode, object view skeleton --- sbapp/main.py | 53 ++++++++++++++++++++++++++++++++++++--- sbapp/mapview/view.py | 1 + sbapp/sideband/core.py | 2 ++ sbapp/ui/layouts.py | 32 +++++++++++++++++++++-- sbapp/ui/objectdetails.py | 49 +++++++++++++++++++++++++++++++++--- 5 files changed, 128 insertions(+), 9 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 3446fa1..5c6353e 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -53,6 +53,7 @@ if RNS.vendor.platformutils.get_platform() == "android": from ui.layouts import * from ui.conversations import Conversations, MsgSync, NewConv + from ui.objectdetails import ObjectDetails from ui.announces import Announces from ui.messages import Messages, ts_format, messages_screen_kv from ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem @@ -71,6 +72,7 @@ else: from .ui.layouts import * from .ui.conversations import Conversations, MsgSync, NewConv from .ui.announces import Announces + from .ui.objectdetails import ObjectDetails from .ui.messages import Messages, ts_format, messages_screen_kv from .ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem @@ -119,6 +121,7 @@ class SidebandApp(MDApp): self.conversations_view = None self.messages_view = None self.map_screen = None + self.object_details_screen = None self.sync_dialog = None self.settings_ready = False self.telemetry_ready = False @@ -1398,7 +1401,8 @@ class SidebandApp(MDApp): self.settings_screen.ids.settings_display_name.bind(focus=save_disp_name) if RNS.vendor.platformutils.is_android(): - self.widget_hide(self.settings_screen.ids.settings_print_command, True) + pass + # self.widget_hide(self.settings_screen.ids.settings_print_command, True) else: self.settings_screen.ids.settings_print_command.text = self.sideband.config["print_command"] self.settings_screen.ids.settings_print_command.bind(focus=save_print_command) @@ -2922,6 +2926,9 @@ class SidebandApp(MDApp): self.telemetry_screen.ids.telemetry_send_to_trusted.active = self.sideband.config["telemetry_send_to_trusted"] self.telemetry_screen.ids.telemetry_send_to_trusted.bind(active=self.telemetry_save) + self.telemetry_screen.ids.telemetry_display_trusted_only.active = self.sideband.config["telemetry_display_trusted_only"] + self.telemetry_screen.ids.telemetry_display_trusted_only.bind(active=self.telemetry_save) + self.telemetry_screen.ids.telemetry_send_appearance.active = self.sideband.config["telemetry_send_appearance"] self.telemetry_screen.ids.telemetry_send_appearance.bind(active=self.telemetry_save) @@ -3001,6 +3008,7 @@ class SidebandApp(MDApp): self.sideband.config["telemetry_enabled"] = self.telemetry_screen.ids.telemetry_enabled.active self.sideband.config["telemetry_send_to_collector"] = self.telemetry_screen.ids.telemetry_send_to_collector.active self.sideband.config["telemetry_send_to_trusted"] = self.telemetry_screen.ids.telemetry_send_to_trusted.active + self.sideband.config["telemetry_display_trusted_only"] = self.telemetry_screen.ids.telemetry_display_trusted_only.active self.sideband.config["telemetry_send_appearance"] = self.telemetry_screen.ids.telemetry_send_appearance.active self.sideband.config["telemetry_s_location"] = self.telemetry_screen.ids.telemetry_s_location.active @@ -3016,6 +3024,7 @@ class SidebandApp(MDApp): self.sideband.config["telemetry_s_proximity"] = self.telemetry_screen.ids.telemetry_s_proximity.active self.sideband.save_configuration() + self.sideband.setstate("app.flags.last_telemetry", time.time()) def telemetry_action(self, sender=None, direction="left"): self.telemetry_init() @@ -3041,7 +3050,11 @@ class SidebandApp(MDApp): def telemetry_send_update(self, sender=None): # TODO: Implement - Clipboard.copy(str(self.sideband.get_packed_telemetry())) + pass + + def telemetry_request_action(self, sender=None): + # TODO: Implement + pass def telemetry_fg_color(self, sender=None): color_picker = MDColorPicker(size_hint=(0.85, 0.85)) @@ -3138,7 +3151,7 @@ class SidebandApp(MDApp): ### Map Screen ###################################### - def map_action(self, sender=None): + def map_action(self, sender=None, direction="left"): if not self.root.ids.screen_manager.has_screen("map_screen"): self.map_screen = Builder.load_string(layout_map_screen) self.map_screen.app = self @@ -3151,7 +3164,7 @@ class SidebandApp(MDApp): self.map_screen.ids.map_layout.map = mapview self.map_screen.ids.map_layout.add_widget(self.map_screen.ids.map_layout.map) - self.root.ids.screen_manager.transition.direction = "left" + self.root.ids.screen_manager.transition.direction = direction self.root.ids.screen_manager.current = "map_screen" self.root.ids.nav_drawer.set_state("closed") self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current) @@ -3192,6 +3205,23 @@ class SidebandApp(MDApp): self.map_action() self.map_show(location) + def map_display_telemetry(self, sender): + RNS.log("Display telemetry from "+str(sender), RNS.LOG_WARNING) + self.object_details_action() + + def close_sub_map_action(self, sender=None): + self.map_action(direction="right") + + def object_details_action(self, sender=None): + self.root.ids.screen_manager.transition.direction = "left" + self.root.ids.nav_drawer.set_state("closed") + + if self.object_details_screen == None: + self.object_details_screen = ObjectDetails(self) + + self.root.ids.screen_manager.current = "object_details_screen" + self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current) + def map_create_marker(self, source, telemetry, appearance): try: l = telemetry["location"] @@ -3204,6 +3234,7 @@ class SidebandApp(MDApp): icon=a_icon, icon_color=a_fg, md_bg_color=a_bg, theme_icon_color="Custom", icon_size=dp(32), + on_release=self.map_display_telemetry, ) marker.icon._default_icon_pad = dp(16) marker.add_widget(marker.icon) @@ -3240,6 +3271,20 @@ class SidebandApp(MDApp): self.sideband.config["telemetry_bg"] ] + skip_entries = [] + if self.sideband.config["telemetry_display_trusted_only"]: + for telemetry_source in telemetry_entries: + try: + if not self.sideband.is_trusted(telemetry_source): + skip_entries.append(telemetry_source) + except: + pass + for skip_entry in skip_entries: + try: + telemetry_entries.pop(skip_entry) + except: + pass + try: if own_telemetry != None and "location" in own_telemetry and own_telemetry["location"] != None and own_telemetry["location"]["latitude"] != None and own_telemetry["location"]["longtitude"] != None: retain_own = True diff --git a/sbapp/mapview/view.py b/sbapp/mapview/view.py index 83fc5b4..5926ab6 100644 --- a/sbapp/mapview/view.py +++ b/sbapp/mapview/view.py @@ -51,6 +51,7 @@ Builder.load_string( source: root.source size: list(map(dp, self.texture_size)) allow_stretch: True + on_release: root.app.map_display_telemetry() : canvas.before: diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 0d4c8c6..770a167 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -495,6 +495,8 @@ class SidebandCore(): self.config["telemetry_s_acceleration"] = False if not "telemetry_s_proximity" in self.config: self.config["telemetry_s_proximity"] = False + if not "telemetry_display_trusted_only" in self.config: + self.config["telemetry_display_trusted_only"] = False if not "map_history_limit" in self.config: self.config["map_history_limit"] = 7*24*60*60 diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index 57997bd..94ea8e3 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -866,6 +866,8 @@ MDScreen: [['menu', lambda x: root.app.nav_drawer.set_state("open")]] right_action_items: [ + ['arrow-down-bold-hexagon-outline', lambda x: root.app.telemetry_request_action(self)], + ['upload-lock', lambda x: root.app.telemetry_send_update(self)], ['close', lambda x: root.app.close_any_action(self)], ] @@ -924,11 +926,11 @@ MDScreen: spacing: dp(24) size_hint_y: None padding: [dp(0),dp(24),dp(0),dp(0)] - height: dp(74) + height: dp(160) MDRectangleFlatIconButton: id: telemetry_icons_button - icon: "update" + icon: "upload-lock" text: "Send Telemetry Update Now" padding: [dp(0), dp(14), dp(0), dp(14)] icon_size: dp(24) @@ -937,6 +939,17 @@ MDScreen: on_release: root.app.telemetry_send_update(self) disabled: False + MDRectangleFlatIconButton: + id: telemetry_icons_button + icon: "arrow-down-bold-hexagon-outline" + text: "Request Telemetry From Collector" + padding: [dp(0), dp(14), dp(0), dp(14)] + icon_size: dp(24) + font_size: dp(16) + size_hint: [1.0, None] + on_release: root.app.telemetry_request_action(self) + disabled: False + MDRectangleFlatIconButton: id: telemetry_icons_button icon: "content-copy" @@ -993,6 +1006,21 @@ MDScreen: pos_hint: {"center_y": 0.3} active: False + MDBoxLayout: + orientation: "horizontal" + size_hint_y: None + padding: [0,0,dp(24),dp(0)] + height: dp(48) + + MDLabel: + text: "Only display from trusted" + font_style: "H6" + + MDSwitch: + id: telemetry_display_trusted_only + pos_hint: {"center_y": 0.3} + active: False + MDBoxLayout: orientation: "horizontal" size_hint_y: None diff --git a/sbapp/ui/objectdetails.py b/sbapp/ui/objectdetails.py index 54daac9..449cf87 100644 --- a/sbapp/ui/objectdetails.py +++ b/sbapp/ui/objectdetails.py @@ -2,7 +2,6 @@ import time import RNS from kivy.metrics import dp,sp -from kivy.uix.label import MDLabel from kivy.lang.builder import Builder if RNS.vendor.platformutils.get_platform() == "android": @@ -16,6 +15,12 @@ class ObjectDetails(): self.widget = None self.object_hash = object_hash + if not self.app.root.ids.screen_manager.has_screen("object_details_screen"): + self.screen = Builder.load_string(layou_object_details) + self.screen.app = self.app + self.ids = self.screen.ids + self.app.root.ids.screen_manager.add_widget(self.screen) + def reload(self): self.clear_widget() self.update() @@ -35,6 +40,44 @@ class ObjectDetails(): def get_widget(self): return self.widget -Builder.load_string(""" +layou_object_details = """ +MDScreen: + name: "object_details_screen" + + BoxLayout: + orientation: "vertical" -""") \ No newline at end of file + MDTopAppBar: + title: "Details" + anchor_title: "left" + elevation: 0 + left_action_items: + [['menu', lambda x: root.app.nav_drawer.set_state("open")]] + right_action_items: + [ + ['close', lambda x: root.app.close_sub_map_action(self)], + ] + + ScrollView: + id: object_details_scrollview + + MDBoxLayout: + orientation: "vertical" + spacing: dp(48) + size_hint_y: None + height: self.minimum_height + padding: [dp(28), dp(48), dp(28), dp(16)] + + MDLabel: + id: name_label + markup: True + text: "Object Name" + font_style: "H6" + + MDLabel: + id: test_label + markup: True + text: "Test" + font_style: "H6" + +""" \ No newline at end of file