diff --git a/agkyra/config.py b/agkyra/config.py index 9f35d25cceee1ccfd8ddb71909c2577769a0daa9..d1de9233303b16d471db58602f146601815da472 100644 --- a/agkyra/config.py +++ b/agkyra/config.py @@ -59,6 +59,8 @@ SYNC_PREFIX = 'sync' config.DEFAULTS = { 'global': { 'agkyra_dir': AGKYRA_DIR, + 'sync_on_start': 'on', + 'language': 'en' }, CLOUD_PREFIX: { # <cloud>: { diff --git a/agkyra/nwgui/menu.html b/agkyra/nwgui/menu.html index eed7d935241fcee209de5e0aaa74bd8721ce676d..50bb6e161abe6698435d56c4bc83b3c5d78356a0 100644 --- a/agkyra/nwgui/menu.html +++ b/agkyra/nwgui/menu.html @@ -117,10 +117,10 @@ var settings_menu = new gui.MenuItem({ $.each(globals.settings, function(key, val) {old_settings[key]=val;}); windows['settings'] = gui.Window.open("settings.html", { toolbar: false, focus: true, - width: 860, height: 620 + width: 860, height: 860 }); windows['settings'].on('closed', function() { - log_debug('Settings windows is closed'); + log_debug('Settings windows is closed'); globals.settings_are_open = false; var new_settings = import_settings(); $.each(new_settings, function(key, setting) { diff --git a/agkyra/nwgui/protocol.js b/agkyra/nwgui/protocol.js index 9e9b4b990871fd9c00749320822fa185ac4dec5c..a75b7171a8daed67dd26e10ac9053cc24f19ed1b 100644 --- a/agkyra/nwgui/protocol.js +++ b/agkyra/nwgui/protocol.js @@ -37,7 +37,9 @@ var globals = { url: null, container: null, directory: null, - exclude: null + exclude: null, + language: 'en', + sync_on_start: true }, status: {synced: 0, unsynced: 0, failed: 0, code: STATUS['UNINITIALIZED']}, authenticated: false, diff --git a/agkyra/nwgui/settings.html b/agkyra/nwgui/settings.html index 7622a04be562881b7fe3ef4344e0e709ac475dda..c8b35de669e812a2e1a34b4ad9653ad576c42497 100644 --- a/agkyra/nwgui/settings.html +++ b/agkyra/nwgui/settings.html @@ -24,9 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. <script type="text/javascript"> var path = require('path'); var fs = require('fs'); - var COMMON = JSON.parse( - fs.readFileSync(path.join('..', 'ui_data/common_en.json'))); - var SETTINGS = COMMON.SETTINGS; + var LANG = JSON.parse(fs.readFileSync(path.join('..', 'ui_data/languages.json'))); var errors = { cloud_url_empty: 'Provide a Cloud Authentication URL', @@ -41,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. var fs = require('fs'); var exclude = null; + var cur_lang = 'en'; $(document).ready(function() { var url = get_setting('url') if (url) { @@ -62,7 +61,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. $('#exclude').val( fs.readFileSync(exclude, encoding='utf-8')); } catch (err) {console.log(err);} + if (!get_setting('language')) set_setting('language', cur_lang); + if (get_setting('sync_on_start')) $('#start_sync_box').click(); + }); + cur_lang = get_setting('language'); + function update_exclude(new_content) { if (exclude) fs.writeFile(exclude, new_content); } @@ -192,6 +196,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. return cloud && token && container && directory; } + function check_start_sync() { + settings['sync_on_start'] = $('#start_sync_box').is(':checked'); + } + + function localize() { + settings['language'] = cur_lang; + var COMMON = JSON.parse( + fs.readFileSync(path.join('..', 'ui_data/common_' + cur_lang + '.json'))); + var SETTINGS = COMMON.SETTINGS; + document.getElementById('title').innerHTML = SETTINGS.TITLE; + document.getElementById('appearance_label').innerHTML = SETTINGS.APPEARANCE; + document.getElementById('language_label').innerHTML = SETTINGS.LANGUAGE; + document.getElementById('cloud_label').innerHTML = SETTINGS.CLOUD; + document.getElementById('url_label').innerHTML = SETTINGS.URL; + document.getElementById('token_label').innerHTML = SETTINGS.TOKEN; + document.getElementById('get_creds').innerHTML = SETTINGS.RETRIEVE; + document.getElementById('sync_label').innerHTML = SETTINGS.SYNC; + document.getElementById('container_label').innerHTML = SETTINGS.CONTAINER; + document.getElementById('directory_label').innerHTML = SETTINGS.DIRECTORY; + document.getElementById('dirdialogue_label').innerHTML = SETTINGS.DIRDIALOGUE; + document.getElementById('sync_button').innerHTML = SETTINGS.SAVE; + + var lang_code = ''; + for (key in LANG) { + var lang = LANG[key]; + var checked = '' + if (key === cur_lang) checked = 'checked' + lang_code += '<div class="small-1 columns">' + + '<input type="radio" name="language" value="' + key + '" ' + + checked + + ' onclick="cur_lang=\'' + key + '\'; localize();">' + + lang.name + '<img src="' + lang.icon + '"/></input></div>'; + } + document.getElementById('language_space').innerHTML = lang_code; + } + window.setInterval(function() { // Refresh get_creds visibility, until refresh_endpoints // changes are in effect @@ -209,12 +249,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. <h2><img src="static/images/about.png"/> <span id="title">User Settings</span></h2> </header> <form> + <fieldset> + <legend id="appearance_label">Appearance</legend> + <div class="clearfix"> + <div class="small-3 columns"> + <label id="language_label" for="language_space" class="right inline">Language</label> + </div> + <div class="small-9 columns" id="language_space"> + <!-- This will be filled by scripts --> + </div> + </div> + <div class="clearfix"> + <div class="small-3 columns"> + <label id="start_sync_label" for="start_sync" class="right inline">Sync on start up</label> + </div> + <div class="small-9 columns" id="start_sync"> + <input type="checkbox" name="start_sync_box" id="start_sync_box" onchange="check_start_sync();"/> + </div> + </div> + </fieldset> <fieldset> <legend id="cloud_label">Cloud</legend> <div class="clearfix"> <div class="small-3 columns"> <label id="url_label" for="cloud-url" class="right inline">Cloud URL</label> - </div> <div class="small-9 columns" id="cloud-error"> <input type="text" id="cloud-url" placeholder="Authentication URL" @@ -294,16 +352,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. </form> </div> <script type="text/javascript"> - document.getElementById('title').innerHTML = SETTINGS.TITLE; - document.getElementById('cloud_label').innerHTML = SETTINGS.CLOUD; - document.getElementById('url_label').innerHTML = SETTINGS.URL; - document.getElementById('token_label').innerHTML = SETTINGS.TOKEN; - document.getElementById('get_creds').innerHTML = SETTINGS.RETRIEVE; - document.getElementById('sync_label').innerHTML = SETTINGS.SYNC; - document.getElementById('container_label').innerHTML = SETTINGS.CONTAINER; - document.getElementById('directory_label').innerHTML = SETTINGS.DIRECTORY; - document.getElementById('dirdialogue_label').innerHTML = SETTINGS.DIRDIALOGUE; - document.getElementById('sync_button').innerHTML = SETTINGS.SAVE; + localize(); </script> </body> </html> diff --git a/agkyra/nwgui/static/images/language/el.png b/agkyra/nwgui/static/images/language/el.png new file mode 100644 index 0000000000000000000000000000000000000000..1d630715a32389edfccb3d1eac7f9715fbf7b892 Binary files /dev/null and b/agkyra/nwgui/static/images/language/el.png differ diff --git a/agkyra/nwgui/static/images/language/en.png b/agkyra/nwgui/static/images/language/en.png new file mode 100644 index 0000000000000000000000000000000000000000..5d6ff425b5aa46118dbf89dc3811c0774a2eeed9 Binary files /dev/null and b/agkyra/nwgui/static/images/language/en.png differ diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 4ccf6898408102ce0aa34c5ee9d990ab2e51d528..49879326f49e425a1c6f41d60b38a9824bcd3097 100644 --- a/agkyra/protocol.py +++ b/agkyra/protocol.py @@ -234,7 +234,9 @@ class WebSocketProtocol(WebSocket): "url": <auth url>, "container": <container>, "directory": <local directory>, - "exclude": <file path> + "exclude": <file path>, + "language": <en|el>, + "sync_on_start": <true|false> } or {<ERROR>: <ERROR CODE>} -- PUT SETTINGS -- @@ -244,7 +246,9 @@ class WebSocketProtocol(WebSocket): "url": <auth url>, "container": <container>, "directory": <local directory>, - "exclude": <file path> + "exclude": <file path>, + "language": <en|el>, + "sync_on_start": <true|false> } HELPER: {"CREATED": 201, "action": "put settings",} or {<ERROR>: <ERROR CODE>, "action": "get settings",} @@ -266,7 +270,7 @@ class WebSocketProtocol(WebSocket): settings = dict( token=None, url=None, container=None, directory=None, - exclude=None) + exclude=None, sync_on_start=True, language="en") cnf = AgkyraConfig() essentials = ('url', 'token', 'container', 'directory') @@ -380,6 +384,10 @@ class WebSocketProtocol(WebSocket): self.settings['url'] = None self.set_status(code=STATUS['SETTINGS MISSING']) + self.settings['sync_on_start'] = ( + self.cnf.get('global', 'sync_on_start') == 'on') + self.settings['language'] = self.cnf.get('global', 'language') + # for option in ('container', 'directory', 'exclude'): for option in ('container', 'directory'): try: @@ -425,6 +433,11 @@ class WebSocketProtocol(WebSocket): self.cnf.set_sync(sync, option, self.settings[option] or '') changes = True + self.cnf.set('global', 'language', self.settings.get('language', 'en')) + sync_on_start = self.settings.get('sync_on_start', False) + self.cnf.set( + 'global', 'sync_on_start', 'on' if sync_on_start else 'off') + if changes: self.cnf.write() LOG.debug('Settings saved') diff --git a/agkyra/scripts/cli.py b/agkyra/scripts/cli.py index 8f5958968af8584f635903fa2bf4ae82aea232c5..45ec8c20e6af0f1f56c5cc47e37b8d4343e5654f 100755 --- a/agkyra/scripts/cli.py +++ b/agkyra/scripts/cli.py @@ -34,7 +34,7 @@ FORMATTER = logging.Formatter( "%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s") HANDLER.setFormatter(FORMATTER) LOGGER.addHandler(HANDLER) -LOGGER.setLevel(logging.DEBUG) +LOGGER.setLevel(logging.INFO) def main(): diff --git a/agkyra/scripts/gui.py b/agkyra/scripts/gui.py index f826d36f6e16885c38b3c423136b0b056bd94d58..ddc69533d378542e63f104ce2c1803999ae6aa73 100755 --- a/agkyra/scripts/gui.py +++ b/agkyra/scripts/gui.py @@ -34,7 +34,7 @@ FORMATTER = logging.Formatter( "%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s") HANDLER.setFormatter(FORMATTER) LOGGER.addHandler(HANDLER) -LOGGER.setLevel(logging.DEBUG) +LOGGER.setLevel(logging.INFO) def main(): diff --git a/agkyra/scripts/server.py b/agkyra/scripts/server.py index 6096a46c504e314f8608878731ab35ab7cd09c0a..fd86a1314dd5833ed1baaac49fa99f5c778dc3c2 100644 --- a/agkyra/scripts/server.py +++ b/agkyra/scripts/server.py @@ -26,7 +26,7 @@ FORMATTER = logging.Formatter( "%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s") HANDLER.setFormatter(FORMATTER) LOGGER.addHandler(HANDLER) -LOGGER.setLevel(logging.DEBUG) +LOGGER.setLevel(logging.INFO) def main(): diff --git a/agkyra/ui_data/common_el.json b/agkyra/ui_data/common_el.json index 2d97b775ae511f0a0289ee3142c268cc919aad62..ed37091a30a6268c4e14bbe8ef86f09d0e377258 100644 --- a/agkyra/ui_data/common_el.json +++ b/agkyra/ui_data/common_el.json @@ -48,6 +48,8 @@ }, "SETTINGS": { "TITLE": "Ξ‘Ο ΞΈΞΌΞ―ΟΞ΅ΞΉΟ ΟΟΞ�ΟΟΞ·", + "APPEARANCE": "ΞΞΌΟάνιΟΞ·", + "LANGUAGE": "ΞΞ»ΟΟΟΞ±", "CLOUD": "ΞΟΞΏΞΌΞ±ΞΊΟΟ ΟΞΌΞΞ½ΞΏ ΟΟΟΟΞ·ΞΌΞ± (Ξ½ΞΟΞΏΟ)", "URL": "URL Ξ½ΞΟΞΏΟ Ο", "TOKEN": "ΞλΡιδί token", diff --git a/agkyra/ui_data/common_en.json b/agkyra/ui_data/common_en.json index a05f75ff6792e7df25f45bda3f0d0de06d5aedcf..7c67bd0e78693ac12b111d19a9faea9ebec5cba1 100644 --- a/agkyra/ui_data/common_en.json +++ b/agkyra/ui_data/common_en.json @@ -48,6 +48,8 @@ }, "SETTINGS": { "TITLE": "User Settings", + "APPEARANCE": "Appearance", + "LANGUAGE": "Language", "CLOUD": "Cloud", "URL": "Cloud URL", "TOKEN": "User Token", diff --git a/agkyra/ui_data/languages.json b/agkyra/ui_data/languages.json new file mode 100644 index 0000000000000000000000000000000000000000..c32b5b9fa86b04ef2cce3a0208d8e78d5b10a936 --- /dev/null +++ b/agkyra/ui_data/languages.json @@ -0,0 +1,10 @@ +{ + "en": { + "name": "English", + "icon": "static/images/language/en.png" + }, + "el": { + "name": "Ξλληνικά", + "icon": "static/images/language/el.png" + } +} \ No newline at end of file