Clicking Save in the settings dialog saves settings

This commit is contained in:
Micah Lee 2016-12-28 20:03:32 -08:00
parent c9607cf986
commit 9462b7d05f
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
3 changed files with 32 additions and 5 deletions

View File

@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import platform, os, json import platform, os, json
from . import helpers from . import strings, helpers
class Settings(object): class Settings(object):
""" """
@ -77,8 +77,12 @@ class Settings(object):
""" """
Save settings to file. 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)) open(self.filename, 'w').write(json.dumps(self._settings))
print(strings._('settings_saved').format(self.filename))
def get(self, key): def get(self, key):
return self._settings[key] return self._settings[key]

View File

@ -151,7 +151,7 @@ class SettingsDialog(QtWidgets.QDialog):
if connection_type == 'automatic': if connection_type == 'automatic':
self.connection_type_automatic_radio.setChecked(True) self.connection_type_automatic_radio.setChecked(True)
elif connection_type == 'control_port': 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': elif connection_type == 'socket_file':
self.connection_type_socket_file_radio.setChecked(True) self.connection_type_socket_file_radio.setChecked(True)
self.connection_type_control_port_extras_address.setText(self.settings.get('control_port_address')) 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. 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): def cancel_clicked(self):
""" """

View File

@ -77,5 +77,6 @@
"gui_settings_cookie_label": "Cookie path", "gui_settings_cookie_label": "Cookie path",
"gui_settings_button_test": "Test Settings", "gui_settings_button_test": "Test Settings",
"gui_settings_button_save": "Save", "gui_settings_button_save": "Save",
"gui_settings_button_cancel": "Cancel" "gui_settings_button_cancel": "Cancel",
"settings_saved": "Settings saved to {}"
} }