diff --git a/agkyra/nwgui/menu.html b/agkyra/nwgui/menu.html index 50bb6e161abe6698435d56c4bc83b3c5d78356a0..7da3051eb2711cdbb030b9f6e67db053a7fe00d9 100644 --- a/agkyra/nwgui/menu.html +++ b/agkyra/nwgui/menu.html @@ -27,9 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. <script src="static/js/jquery.js"></script> <script type="text/javascript"> -var NOTIFICATION = COMMON.NOTIFICATION; -var MENU = COMMON.MENU; - // Setup GUI var windows = { "settings": null, @@ -42,7 +39,7 @@ function closeWindows() { // GUI components var tray = new gui.Tray({ - tooltip: MENU.TITLE, + tooltip: COMMON.MENU.TITLE, icon: 'static/images/tray.png', iconsAreTemplates: false }); @@ -63,7 +60,7 @@ pause_item = new gui.MenuItem({ // pause menu item icon: 'static/images/play_pause.png', iconIsTemplate: false, - label: MENU.INITIALIZING, + label: COMMON.MENU.INITIALIZING, type: 'normal', click: function() { if (globals.status.code == STATUS['PAUSED']) post_start(socket); @@ -76,7 +73,7 @@ menu.append(pause_item); // Menu actions contents var local_folder_menu = new gui.MenuItem({ - label: MENU.FOLDER, + label: COMMON.MENU.FOLDER, icon: 'static/images/folder.png', iconIsTemplate: false, enabled: false, @@ -89,7 +86,7 @@ var local_folder_menu = new gui.MenuItem({ menu.append(local_folder_menu); var pithos_page_menu = new gui.MenuItem({ - label: MENU.PITHOS, + label: COMMON.MENU.PITHOS, icon: 'static/images/pithos.png', iconIsTemplate: false, enabled: false, @@ -103,7 +100,7 @@ menu.append(pithos_page_menu); // Settings and About menu.append(new gui.MenuItem({type: 'separator'})); var settings_menu = new gui.MenuItem({ - label: MENU.SETTINGS, + label: COMMON.MENU.SETTINGS, icon: 'static/images/settings.png', iconIsTemplate: false, enabled: false, @@ -127,6 +124,7 @@ var settings_menu = new gui.MenuItem({ log_debug('Compare ' + old_settings[key] + ' with ' + setting); if (old_settings[key] !== setting) { log_debug('Settings have been modified - updating...'); + check_menu_lang(); put_settings(socket, new_settings); get_status(socket); get_settings(socket); @@ -138,8 +136,8 @@ var settings_menu = new gui.MenuItem({ }); menu.append(settings_menu); -menu.append(new gui.MenuItem({ - label: MENU.ABOUT, +var about_menu = new gui.MenuItem({ + label: COMMON.MENU.ABOUT, icon: 'static/images/about.png', iconIsTemplate: false, click: function () { @@ -149,16 +147,18 @@ menu.append(new gui.MenuItem({ width: 860, height: 620 }); } -})); +}); +menu.append(about_menu); // Quit menu.append(new gui.MenuItem({type: 'separator'})); -menu.append(new gui.MenuItem({ - label: MENU.QUIT, +var quit_menu = new gui.MenuItem({ + label: COMMON.MENU.QUIT, icon: 'static/images/exit.png', iconIsTemplate: false, click: function() {post_shutdown(socket);} -})); +}); +menu.append(quit_menu); function activate_menu() { @@ -194,13 +194,27 @@ function notify(level) { if (globals.notification !== globals.status.code) { // Notification has changed, raise notifier box globals.notification = globals.status.code; - notify_user(NOTIFICATION[globals.status.code], level); + notify_user( + COMMON.NOTIFICATION[globals.status.code], level, COMMON.NOTIFIER); + } +} + +function check_menu_lang() { + if (tray.tooltip !== COMMON.MENU.TITLE) { + tray.tooltip = COMMON.MENU.TITLE; + local_folder_menu.label = COMMON.MENU.FOLDER; + pithos_page_menu.label = COMMON.MENU.PITHOS; + settings_menu.label = COMMON.MENU.SETTINGS; + about_menu.label = COMMON.MENU.ABOUT; + quit_menu.label = COMMON.MENU.QUIT; + tray.menu = menu; } } // Update progress window.setInterval(function() { - var new_progress = NOTIFICATION[globals.status.code]; + check_menu_lang(); + var new_progress = COMMON.NOTIFICATION[globals.status.code]; var new_pause = ''; switch(globals.status.code) { case STATUS['UNINITIALIZED']: @@ -208,29 +222,29 @@ window.setInterval(function() { case STATUS['SHUTING DOWN']: notify('info'); deactivate_menu(); - new_pause = MENU.INACTIVE; + new_pause = COMMON.MENU.INACTIVE; break; case STATUS['SYNCING']: notify('info'); activate_menu(); - new_progress += ', ' - + MENU.REMAINING.replace('%s', remaining(globals.status)); - new_pause = MENU.PAUSE; + new_progress += ', '+ COMMON.MENU.REMAINING.replace( + '%s', remaining(globals.status)); + new_pause = COMMON.MENU.PAUSE; break; case STATUS['PAUSING']: notify('info'); - new_progress += ', ' - + MENU.REMAINING.replace('%s', remaining(globals.status)); - new_pause = MENU.WAITING; + new_progress += ', ' + COMMON.MENU.REMAINING.replace( + '%s', remaining(globals.status)); + new_pause = COMMON.MENU.WAITING; pause_item.enabled = false; break; case STATUS['PAUSED']: notify('info'); activate_menu(); - new_pause = MENU.START; + new_pause = COMMON.MENU.START; if (remaining(globals.status) > 0) - new_progress += ', ' - + MENU.REMAINING.replace('%s', remaining(globals.status)); + new_progress += ', '+ COMMON.MENU.REMAINING.replace( + '%s', remaining(globals.status)); break; case STATUS['SETTINGS MISSING']: case STATUS['AUTH URL ERROR']: @@ -238,7 +252,7 @@ window.setInterval(function() { case STATUS['DIRECTORY ERROR']: case STATUS['CONTAINER ERROR']: deactivate_menu(); - new_pause = MENU.INACTIVE; + new_pause = COMMON.MENU.INACTIVE; settings_menu.enabled = true; notify('error'); break; @@ -246,7 +260,7 @@ window.setInterval(function() { } if (globals.open_settings) { - new_progress = MENU.SETTINGSOPEN; + new_progress = COMMON.MENU.SETTINGSOPEN; globals.open_settings = false; settings_menu.click(); deactivate_menu(); diff --git a/agkyra/nwgui/notify.js b/agkyra/nwgui/notify.js index 4d889510ce11ed67d46048c1d2eae76b5deddee5..2d585a6bea009fd33fb4d5b202531e02b790e918 100644 --- a/agkyra/nwgui/notify.js +++ b/agkyra/nwgui/notify.js @@ -1,5 +1,4 @@ var gui = require('nw.gui'); -var NOTIFIER = COMMON.NOTIFIER; function is_up(code) { return (code / 100 >> 0) === 1; } function has_settings_error(code) { return (code / 200 >> 0) === 2; } @@ -7,11 +6,6 @@ function remaining(status) { return status.unsynced - (status.synced + status.failed); } -var ntf_title = { - 'info': NOTIFIER.INFO, - 'warning': NOTIFIER.WARNING, - 'error': NOTIFIER.ERROR -} var ntf_icon = { 'info': 'static/images/ntf_info.png', 'warning': 'static/images/ntf_warning.png', @@ -30,7 +24,7 @@ var notify_menu = new gui.MenuItem({ iconIsTemplate: false, }); -function notify_user(msg, level) { +function notify_user(msg, level, ntf_title) { var n = new Notification(ntf_title[level], { lang: 'utf-8', body: msg, icon: ntf_icon[level] }); diff --git a/agkyra/nwgui/protocol.js b/agkyra/nwgui/protocol.js index a75b7171a8daed67dd26e10ac9053cc24f19ed1b..de454420466aa38b834c00a2faed4df0d887e80b 100644 --- a/agkyra/nwgui/protocol.js +++ b/agkyra/nwgui/protocol.js @@ -21,15 +21,16 @@ var fs = require('fs'); // Read config file var cnf = JSON.parse(fs.readFileSync(gui.App.argv[0], encoding='utf-8')); -var COMMON = JSON.parse(fs.readFileSync(path.join('..', 'ui_data/common_en.json'))); - -var STATUS = COMMON['STATUS']; - -function log_debug(msg) { if (DEBUG) console.log(msg); } - -function send_json(socket, msg) { - socket.send(JSON.stringify(msg)); +function load_common(lang) { + var common_path = 'common_en.json'; + if (lang && lang !== globals.language) { + common_path = 'common_' + lang + '.json'; + globals.language = lang; + } + return JSON.parse(fs.readFileSync(path.join('..', 'ui_data', common_path))); } +var COMMON = load_common(); +var STATUS = COMMON.STATUS; var globals = { settings: { @@ -48,6 +49,12 @@ var globals = { notification: STATUS['UNINITIALIZED'] } +function log_debug(msg) { if (DEBUG) console.log(msg); } + +function send_json(socket, msg) { + socket.send(JSON.stringify(msg)); +} + // Protocol: requests ::: responses function post_ui_id(socket) { send_json(socket, {"method": "post", "ui_id": cnf['ui_id']}) @@ -86,7 +93,6 @@ function get_status(socket) { send_json(socket, {'method': 'get', 'path': 'status'}); } // expected response {"synced":.., "unsynced":.., "failed":..., code":..} - // Connect to helper var socket = new WebSocket(cnf['address']); socket.onopen = function() { @@ -124,6 +130,7 @@ socket.onmessage = function(e) { break; case 'get settings': log_debug(r); + if (r.language !== globals.language) COMMON = load_common(r.language); globals['settings'] = r; break; case 'put settings': diff --git a/agkyra/ui_data/common_el.json b/agkyra/ui_data/common_el.json index ed37091a30a6268c4e14bbe8ef86f09d0e377258..f68046c3fea5ec0d5f6a7a3562daf1410771f5d3 100644 --- a/agkyra/ui_data/common_el.json +++ b/agkyra/ui_data/common_el.json @@ -42,9 +42,9 @@ "QUIT": "ΞλΡίΟΞΉΞΌΞΏ ΞΞ³ΞΊΟ ΟΞ±Ο" }, "NOTIFIER": { - "INFO": "ΞΞ³ΞΊΟ ΟΞ±", - "WARNING": "ΞΞ³ΞΊΟ ΟΞ± - ΟΟΞΏΟΞΏΟΞ�!", - "ERROR": "ΞΞ³ΞΊΟ ΟΞ± - ΟΟάλμα!" + "info": "ΞΞ³ΞΊΟ ΟΞ±", + "warning": "ΞΞ³ΞΊΟ ΟΞ± - ΟΟΞΏΟΞΏΟΞ�!", + "error": "ΞΞ³ΞΊΟ ΟΞ± - ΟΟάλμα!" }, "SETTINGS": { "TITLE": "Ξ‘Ο ΞΈΞΌΞ―ΟΞ΅ΞΉΟ ΟΟΞ�ΟΟΞ·", diff --git a/agkyra/ui_data/common_en.json b/agkyra/ui_data/common_en.json index 7c67bd0e78693ac12b111d19a9faea9ebec5cba1..9bcbbdf4e2c65e1d18a5a2e5cb79c0eb4b093f12 100644 --- a/agkyra/ui_data/common_en.json +++ b/agkyra/ui_data/common_en.json @@ -42,9 +42,9 @@ "QUIT": "Quit Agkyra" }, "NOTIFIER": { - "INFO": "Agkyra notification", - "WARNING": "Agkyra warning", - "ERROR": "Agkyra error" + "info": "Agkyra notification", + "warning": "Agkyra warning", + "error": "Agkyra error" }, "SETTINGS": { "TITLE": "User Settings",