From a1aa0544b318e0014eec39ceab9451f5239a4dd7 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 26 Oct 2023 20:38:19 +0200 Subject: [PATCH] Added map cache control --- sbapp/main.py | 41 ++++++++++++++++++++++++++++++++++++++++- sbapp/sideband/core.py | 13 +++++++++++++ sbapp/ui/layouts.py | 14 +++++++++++++- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 47154c8..19fbecd 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -783,7 +783,10 @@ class SidebandApp(MDApp): self.map_action(self) if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "p"): - self.settings_action(self) + if self.root.ids.screen_manager.current == "map_screen": + self.map_settings_action() + else: + self.settings_action(self) if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "t"): if self.root.ids.screen_manager.current == "messages_screen": @@ -3517,6 +3520,42 @@ class SidebandApp(MDApp): self.root.ids.nav_drawer.set_state("closed") self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current) + def update_cache_size(dt): + size = self.sideband.get_map_cache_size() + size_str = RNS.prettysize(size) + self.map_settings_screen.ids.map_cache_button.text = f"Clear {size_str} map cache" + if size > 0.0: + self.map_settings_screen.ids.map_cache_button.disabled = False + else: + self.map_settings_screen.ids.map_cache_button.disabled = True + self.map_settings_screen.ids.map_cache_button.text = f"No data in map cache" + + Clock.schedule_once(update_cache_size, 0.35) + + def map_clear_cache(self, sender=None): + yes_button = MDRectangleFlatButton(text="Yes",font_size=dp(18), theme_text_color="Custom", line_color=self.color_reject, text_color=self.color_reject) + no_button = MDRectangleFlatButton(text="No",font_size=dp(18)) + dialog = MDDialog( + title="Clear map cache?", + buttons=[ yes_button, no_button ], + # elevation=0, + ) + def dl_yes(s): + dialog.dismiss() + self.sideband.clear_map_cache() + + def cb(dt): + self.map_settings_action() + self.map_settings_screen.ids.map_cache_button.disabled = True + Clock.schedule_once(cb, 1.2) + + def dl_no(s): + dialog.dismiss() + + yes_button.bind(on_release=dl_yes) + no_button.bind(on_release=dl_no) + dialog.open() + def close_location_error_dialog(self, sender=None): if hasattr(self, "location_error_dialog") and self.location_error_dialog != None: self.location_error_dialog.dismiss() diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 67a4a8f..2e2f5e8 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -348,6 +348,19 @@ class SidebandCore(): self.__save_config() + def clear_map_cache(self): + for entry in os.scandir(self.map_cache): + os.unlink(entry.path) + + def get_map_cache_size(self): + total = 0 + for entry in os.scandir(self.map_cache): + if entry.is_dir(follow_symlinks=False): + pass + else: + total += entry.stat(follow_symlinks=False).st_size + return total + def should_persist_data(self): if self.reticulum != None: self.reticulum._should_persist_data() diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index eac34eb..9f83b90 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -946,11 +946,12 @@ MDScreen: MDBoxLayout: orientation: "vertical" size_hint_y: None + spacing: dp(24) height: self.minimum_height padding: [0, dp(24), 0, 0] MDRectangleFlatIconButton: - id: telemetry_icons_button + id: map_select_button icon: "list-box-outline" text: "Select MBTiles Map" padding: [dp(0), dp(14), dp(0), dp(14)] @@ -959,6 +960,17 @@ MDScreen: size_hint: [1.0, None] on_release: root.app.map_select_file_action(self) disabled: False + + MDRectangleFlatIconButton: + id: map_cache_button + icon: "map-clock-outline" + text: "Clear map cache" + 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.map_clear_cache(self) + disabled: False """