Commit 4b045684 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Save settings when modified, even if incomplete

Before this patch, settings would be permanently saved only if
the state at the end of the modification was enough for a sync
to start.

After this patch, users will be able to save partial settings,
even if there are essential omissions.
parent d764f5b1
......@@ -27,7 +27,7 @@ HANDLER = logging.FileHandler(LOGFILE)
FORMATTER = logging.Formatter("%(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.INFO)
LOGGER.setLevel(logging.DEBUG)
# # run GUI
from agkyra import gui
......
......@@ -110,6 +110,7 @@ var settings_menu = new gui.MenuItem({
log_debug('Settings windows is closed');
var new_settings = import_settings();
$.each(new_settings, function(key, setting) {
log_debug('Compare ' + old_settings[key] + ' with ' + setting);
if (old_settings[key] !== setting) {
log_debug('Settings have been modified - updating...');
put_settings(socket, new_settings);
......
......@@ -129,7 +129,7 @@ socket.onmessage = function(e) {
}
break;
default:
console.log('Incomprehensible response ' + r);
console.log('Incomprehensible response ' + JSON.stringify(r));
}
};
......
......@@ -36,8 +36,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var fs = require('fs');
var exclude = null;
$(document).ready(function() {
var url = get_setting('url').replace(/\/+$/, '');
if (url) $('#cloud-url').val(url);
var url = get_setting('url')
if (url) {
url = url.replace(/\/+$/, '');
$('#cloud-url').val(url);
}
settings['url'] = url;
var token = get_setting('token');
if (token) $('#token').val(token);
......
......@@ -235,35 +235,44 @@ class WebSocketProtocol(WebSocket):
def _dump_settings(self):
LOG.debug('Saving settings')
if not self.settings.get('url', None):
LOG.debug('No settings to save')
return
sync = self._get_default_sync()
cloud = self._get_sync_cloud(sync)
changes = False
try:
old_url = self.cnf.get_cloud(cloud, 'url') or ''
except KeyError:
old_url = self.settings['url']
if not self.settings.get('url', None):
LOG.debug('No cloud settings to save')
else:
LOG.debug('Save cloud settings')
cloud = self._get_sync_cloud(sync)
while old_url != self.settings['url']:
cloud = '%s_%s' % (cloud, sync)
try:
self.cnf.get_cloud(cloud, 'url')
old_url = self.cnf.get_cloud(cloud, 'url') or ''
except KeyError:
break
self.cnf.set_cloud(cloud, 'url', self.settings['url'])
self.cnf.set_cloud(cloud, 'token', self.settings['token'] or '')
self.cnf.set_sync(sync, 'cloud', cloud)
old_url = self.settings['url']
while old_url and old_url != self.settings['url']:
cloud = '%s_%s' % (cloud, sync)
try:
self.cnf.get_cloud(cloud, 'url')
except KeyError:
break
LOG.debug('Cloud name is %s' % cloud)
self.cnf.set_cloud(cloud, 'url', self.settings['url'])
self.cnf.set_cloud(cloud, 'token', self.settings['token'] or '')
self.cnf.set_sync(sync, 'cloud', cloud)
changes = True
LOG.debug('Save sync settings, name is %s' % sync)
# for option in ('directory', 'container', 'exclude'):
for option in ('directory', 'container'):
self.cnf.set_sync(sync, option, self.settings[option] or '')
changes = True
self.cnf.write()
LOG.debug('Settings saved')
if changes:
self.cnf.write()
LOG.debug('Settings saved')
else:
LOG.debug('No setting changes spotted')
def _essentials_changed(self, new_settings):
"""Check if essential settings have changed in new_settings"""
......@@ -340,6 +349,7 @@ class WebSocketProtocol(WebSocket):
return self.settings
def set_settings(self, new_settings):
"""Set the settings and dump them to permanent storage if needed"""
# Prepare setting save
could_sync = self.can_sync()
was_active = False
......@@ -349,7 +359,7 @@ class WebSocketProtocol(WebSocket):
must_reset_syncing = self._essentials_changed(new_settings)
# save settings
self.settings = new_settings
self.settings.update(new_settings)
self._dump_settings()
# Restart
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment