From 9462b7d05f3f0a2f1e1da9b5d7ba6f626fad0c26 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 28 Dec 2016 20:03:32 -0800 Subject: [PATCH] Clicking Save in the settings dialog saves settings --- onionshare/settings.py | 8 ++++++-- onionshare_gui/settings_dialog.py | 26 ++++++++++++++++++++++++-- resources/locale/en.json | 3 ++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/onionshare/settings.py b/onionshare/settings.py index d36bb18c..6ba2779d 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -20,7 +20,7 @@ along with this program. If not, see . import platform, os, json -from . import helpers +from . import strings, helpers class Settings(object): """ @@ -77,8 +77,12 @@ class Settings(object): """ Save settings to file. """ - os.mkdirs(os.path.dirname(self.filename)) + try: + os.makedirs(os.path.dirname(self.filename)) + except: + pass open(self.filename, 'w').write(json.dumps(self._settings)) + print(strings._('settings_saved').format(self.filename)) def get(self, key): return self._settings[key] diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 55a76d0b..1f1120e3 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -151,7 +151,7 @@ class SettingsDialog(QtWidgets.QDialog): if connection_type == 'automatic': self.connection_type_automatic_radio.setChecked(True) elif connection_type == 'control_port': - self.connect_type_control_port_radio.setChecked(True) + self.connection_type_control_port_radio.setChecked(True) elif connection_type == 'socket_file': self.connection_type_socket_file_radio.setChecked(True) self.connection_type_control_port_extras_address.setText(self.settings.get('control_port_address')) @@ -238,7 +238,29 @@ class SettingsDialog(QtWidgets.QDialog): """ Save button clicked. Save current settings to disk. """ - pass + if self.connection_type_automatic_radio.isChecked(): + self.settings.set('connection_type', 'automatic') + if self.connection_type_control_port_radio.isChecked(): + self.settings.set('connection_type', 'control_port') + if self.connection_type_socket_file_radio.isChecked(): + self.settings.set('connection_type', 'socket_file') + + self.settings.set('control_port_address', self.connection_type_control_port_extras_address.text()) + self.settings.set('control_port_port', self.connection_type_control_port_extras_port.text()) + self.settings.set('socket_file_path', self.connection_type_socket_file_extras_path.text()) + + if self.authenticate_no_auth_radio.isChecked(): + self.settings.set('auth_type', 'no_auth') + if self.authenticate_password_radio.isChecked(): + self.settings.set('auth_type', 'password') + if self.authenticate_cookie_radio.isChecked(): + self.settings.set('auth_type', 'cookie') + + self.settings.set('auth_password', self.authenticate_password_extras_password.text()) + self.settings.set('auth_cookie_path', self.authenticate_cookie_extras_cookie_path.text()) + + self.settings.save() + self.close() def cancel_clicked(self): """ diff --git a/resources/locale/en.json b/resources/locale/en.json index 66494a5f..90e7d3ca 100644 --- a/resources/locale/en.json +++ b/resources/locale/en.json @@ -77,5 +77,6 @@ "gui_settings_cookie_label": "Cookie path", "gui_settings_button_test": "Test Settings", "gui_settings_button_save": "Save", - "gui_settings_button_cancel": "Cancel" + "gui_settings_button_cancel": "Cancel", + "settings_saved": "Settings saved to {}" }