When any setting is changed, update the tab settings dict

This commit is contained in:
Micah Lee 2019-11-02 10:15:18 -07:00
parent 555ae9114f
commit f2d4bddc23
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
5 changed files with 57 additions and 3 deletions

View file

@ -24,7 +24,7 @@ from onionshare import strings
class ModeSettings(QtWidgets.QWidget):
"""
A settings widget
All of the common settings for each mode are in this widget
"""
change_persistent = QtCore.pyqtSignal(int, bool)
@ -45,11 +45,15 @@ class ModeSettings(QtWidgets.QWidget):
# Public
self.public_checkbox = QtWidgets.QCheckBox()
self.public_checkbox.clicked.connect(self.public_checkbox_clicked)
self.public_checkbox.setCheckState(QtCore.Qt.Unchecked)
self.public_checkbox.setText(strings._("mode_settings_public_checkbox"))
# Whether or not to use an auto-start timer
self.autostart_timer_checkbox = QtWidgets.QCheckBox()
self.autostart_timer_checkbox.clicked.connect(
self.autostart_timer_checkbox_clicked
)
self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
self.autostart_timer_checkbox.setText(
strings._("mode_settings_autostart_timer_checkbox")
@ -57,6 +61,9 @@ class ModeSettings(QtWidgets.QWidget):
# Whether or not to use an auto-stop timer
self.autostop_timer_checkbox = QtWidgets.QCheckBox()
self.autostop_timer_checkbox.clicked.connect(
self.autostop_timer_checkbox_clicked
)
self.autostop_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
self.autostop_timer_checkbox.setText(
strings._("mode_settings_autostop_timer_checkbox")
@ -64,12 +71,14 @@ class ModeSettings(QtWidgets.QWidget):
# Legacy address
self.legacy_checkbox = QtWidgets.QCheckBox()
self.legacy_checkbox.clicked.connect(self.legacy_checkbox_clicked)
self.legacy_checkbox.clicked.connect(self.update_ui)
self.legacy_checkbox.setCheckState(QtCore.Qt.Unchecked)
self.legacy_checkbox.setText(strings._("mode_settings_legacy_checkbox"))
# Client auth
self.client_auth_checkbox = QtWidgets.QCheckBox()
self.client_auth_checkbox.clicked.connect(self.client_auth_checkbox_clicked)
self.client_auth_checkbox.clicked.connect(self.update_ui)
self.client_auth_checkbox.setCheckState(QtCore.Qt.Unchecked)
self.client_auth_checkbox.setText(
@ -136,6 +145,27 @@ class ModeSettings(QtWidgets.QWidget):
self.tab.tab_id, self.persistent_checkbox.isChecked()
)
def public_checkbox_clicked(self):
self.tab.tab_settings["general"]["public"] = self.public_checkbox.isChecked()
def autostart_timer_checkbox_clicked(self):
self.tab.tab_settings["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()
def legacy_checkbox_clicked(self):
self.tab.tab_settings["general"]["legacy"] = self.legacy_checkbox.isChecked()
def client_auth_checkbox_clicked(self):
self.tab.tab_settings["general"][
"client_auth"
] = self.client_auth_checkbox.isChecked()
def toggle_advanced_clicked(self):
if self.advanced_widget.isVisible():
self.advanced_widget.hide()

View file

@ -41,6 +41,7 @@ class ReceiveMode(Mode):
# Header
self.header_label.setText(strings._("gui_new_tab_receive_button"))
# Settings
data_dir_label = QtWidgets.QLabel(
strings._("mode_settings_receive_data_dir_label")
)
@ -125,7 +126,7 @@ class ReceiveMode(Mode):
def data_dir_button_clicked(self):
"""
Browse for a new OnionShare data directory
Browse for a new OnionShare data directory, and save to tab settings
"""
data_dir = self.data_dir_lineedit.text()
selected_dir = QtWidgets.QFileDialog.getExistingDirectory(
@ -139,6 +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
def get_stop_server_autostop_timer_text(self):
"""

View file

@ -50,7 +50,11 @@ class ShareMode(Mode):
# Header
self.header_label.setText(strings._("gui_new_tab_share_button"))
# Settings
self.autostop_sharing_checkbox = QtWidgets.QCheckBox()
self.autostop_sharing_checkbox.clicked.connect(
self.autostop_sharing_checkbox_clicked
)
self.autostop_sharing_checkbox.setCheckState(QtCore.Qt.Checked)
self.autostop_sharing_checkbox.setText(
strings._("mode_settings_share_autostop_sharing_checkbox")
@ -149,6 +153,14 @@ class ShareMode(Mode):
# Always start with focus on file selection
self.file_selection.setFocus()
def autostop_sharing_checkbox_clicked(self):
"""
Save autostop sharing setting to the tab settings
"""
self.tab.tab_settings["share"][
"autostop_sharing"
] = self.autostop_sharing_checkbox.isChecked()
def get_stop_server_autostop_timer_text(self):
"""
Return the string to put on the stop server button, if there's an auto-stop timer

View file

@ -52,7 +52,9 @@ class WebsiteMode(Mode):
# Header
self.header_label.setText(strings._("gui_new_tab_website_button"))
# Settings
self.disable_csp_checkbox = QtWidgets.QCheckBox()
self.disable_csp_checkbox.clicked.connect(self.disable_csp_checkbox_clicked)
self.disable_csp_checkbox.setCheckState(QtCore.Qt.Unchecked)
self.disable_csp_checkbox.setText(
strings._("mode_settings_website_disable_csp_checkbox")
@ -149,6 +151,14 @@ class WebsiteMode(Mode):
# Always start with focus on file selection
self.file_selection.setFocus()
def disable_csp_checkbox_clicked(self):
"""
Save disable CSP setting to the tab settings
"""
self.tab.tab_settings["website"][
"disable_csp"
] = self.disable_csp_checkbox.isChecked()
def get_stop_server_autostop_timer_text(self):
"""
Return the string to put on the stop server button, if there's an auto-stop timer

View file

@ -130,7 +130,7 @@ class Tab(QtWidgets.QWidget):
"public": False,
"autostart_timer": False,
"autostop_timer": False,
"legacy_addresses": False,
"legacy": False,
"client_auth": False,
},
"share": {"autostop_sharing": True},