From 2984577f28e90ec7780a94f80f2b6f7c3398611a Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 2 Nov 2019 10:24:12 -0700 Subject: [PATCH] Get/set tab settings using a getter and setter function --- onionshare_gui/tab/mode/mode_settings.py | 28 +++++++++---------- .../tab/mode/receive_mode/__init__.py | 2 +- .../tab/mode/share_mode/__init__.py | 8 +++--- .../tab/mode/website_mode/__init__.py | 6 ++-- onionshare_gui/tab/tab.py | 26 ++++++++++------- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/onionshare_gui/tab/mode/mode_settings.py b/onionshare_gui/tab/mode/mode_settings.py index b36183d8..c5ca3a8e 100644 --- a/onionshare_gui/tab/mode/mode_settings.py +++ b/onionshare_gui/tab/mode/mode_settings.py @@ -137,34 +137,34 @@ class ModeSettings(QtWidgets.QWidget): self.client_auth_checkbox.hide() def persistent_checkbox_clicked(self): - self.tab.tab_settings["persistent"][ - "enabled" - ] = self.persistent_checkbox.isChecked() + self.tab.set_tab_setting( + "persistent", "enabled", self.persistent_checkbox.isChecked() + ) self.change_persistent.emit( self.tab.tab_id, self.persistent_checkbox.isChecked() ) def public_checkbox_clicked(self): - self.tab.tab_settings["general"]["public"] = self.public_checkbox.isChecked() + self.tab.set_tab_setting("general", "public", self.public_checkbox.isChecked()) def autostart_timer_checkbox_clicked(self): - self.tab.tab_settings["general"][ - "autostart_timer" - ] = self.autostart_timer_checkbox.isChecked() + self.tab.set_tab_setting( + "general", "autostart_timer", self.autostart_timer_checkbox.isChecked() + ) def autostop_timer_checkbox_clicked(self): - self.tab.tab_settings["general"][ - "autostop_timer" - ] = self.autostop_timer_checkbox.isChecked() + self.tab.set_tab_setting( + "general", "autostop_timer", self.autostop_timer_checkbox.isChecked() + ) def legacy_checkbox_clicked(self): - self.tab.tab_settings["general"]["legacy"] = self.legacy_checkbox.isChecked() + self.tab.set_tab_setting("general", "legacy", self.legacy_checkbox.isChecked()) def client_auth_checkbox_clicked(self): - self.tab.tab_settings["general"][ - "client_auth" - ] = self.client_auth_checkbox.isChecked() + self.tab.set_tab_setting( + "general", "client_auth", self.client_auth_checkbox.isChecked() + ) def toggle_advanced_clicked(self): if self.advanced_widget.isVisible(): diff --git a/onionshare_gui/tab/mode/receive_mode/__init__.py b/onionshare_gui/tab/mode/receive_mode/__init__.py index 97645e1e..f0a2c6e9 100644 --- a/onionshare_gui/tab/mode/receive_mode/__init__.py +++ b/onionshare_gui/tab/mode/receive_mode/__init__.py @@ -140,7 +140,7 @@ class ReceiveMode(Mode): f"selected dir: {selected_dir}", ) self.data_dir_lineedit.setText(selected_dir) - self.tab.tab_settings["receive"]["data_dir"] = data_dir + self.tab.set_tab_setting("receive", "data_dir", data_dir) def get_stop_server_autostop_timer_text(self): """ diff --git a/onionshare_gui/tab/mode/share_mode/__init__.py b/onionshare_gui/tab/mode/share_mode/__init__.py index 3ba9afdc..8d595e7f 100644 --- a/onionshare_gui/tab/mode/share_mode/__init__.py +++ b/onionshare_gui/tab/mode/share_mode/__init__.py @@ -157,9 +157,9 @@ class ShareMode(Mode): """ Save autostop sharing setting to the tab settings """ - self.tab.tab_settings["share"][ - "autostop_sharing" - ] = self.autostop_sharing_checkbox.isChecked() + self.tab.set_tab_setting( + "share", "autostop_sharing", self.autostop_sharing_checkbox.isChecked() + ) def get_stop_server_autostop_timer_text(self): """ @@ -309,7 +309,7 @@ class ShareMode(Mode): self.history.update_in_progress() # Close on finish? - if self.common.settings.get("close_after_first_download"): + if self.tab.tab_settings["share"]["autostop_sharing"]: self.server_status.stop_server() self.status_bar.clearMessage() self.server_status_label.setText(strings._("closing_automatically")) diff --git a/onionshare_gui/tab/mode/website_mode/__init__.py b/onionshare_gui/tab/mode/website_mode/__init__.py index 8e163cec..1ba969cc 100644 --- a/onionshare_gui/tab/mode/website_mode/__init__.py +++ b/onionshare_gui/tab/mode/website_mode/__init__.py @@ -155,9 +155,9 @@ class WebsiteMode(Mode): """ Save disable CSP setting to the tab settings """ - self.tab.tab_settings["website"][ - "disable_csp" - ] = self.disable_csp_checkbox.isChecked() + self.tab.set_tab_setting( + "website", "disable_csp", self.disable_csp_checkbox.isChecked() + ) def get_stop_server_autostop_timer_text(self): """ diff --git a/onionshare_gui/tab/tab.py b/onionshare_gui/tab/tab.py index 62ff2d26..d121c9b5 100644 --- a/onionshare_gui/tab/tab.py +++ b/onionshare_gui/tab/tab.py @@ -118,6 +118,17 @@ class Tab(QtWidgets.QWidget): self.timer = QtCore.QTimer() self.timer.timeout.connect(self.timer_callback) + # Persistent image + self.persistent_image_label = QtWidgets.QLabel() + self.persistent_image_label.setPixmap( + QtGui.QPixmap.fromImage( + QtGui.QImage( + self.common.get_resource_path("images/persistent_enabled.png") + ) + ) + ) + self.persistent_image_label.setFixedSize(30, 30) + # Settings for this tab self.tab_settings = { "persistent": { @@ -138,16 +149,11 @@ class Tab(QtWidgets.QWidget): "website": {"disable_csp": False}, } - # Persistent image - self.persistent_image_label = QtWidgets.QLabel() - self.persistent_image_label.setPixmap( - QtGui.QPixmap.fromImage( - QtGui.QImage( - self.common.get_resource_path("images/persistent_enabled.png") - ) - ) - ) - self.persistent_image_label.setFixedSize(30, 30) + def get_tab_setting(self, group, key): + return self.tab_settings[group][key] + + def set_tab_setting(self, group, key, val): + self.tab_settings[group][key] = val def share_mode_clicked(self): self.common.log("Tab", "share_mode_clicked")