menu.html 9.81 KB
Newer Older
1
<!DOCTYPE html>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!--
Copyright (C) 2015 GRNET S.A.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
18
<html>
19 20 21 22
<head>
  <meta charset="UTF-8" />
  <title>GUI for Agkyra Pithos+ Syncing Client</title>
</head>
23 24 25
<body>
    <script src="protocol.js"></script>
    <script src="settings.js"></script>
26
    <script src="notify.js"></script>
27
    <script src="static/js/jquery.js"></script>
28 29
    <script type="text/javascript">

30
// Setup GUI
31 32 33
var windows = {
  "settings": null,
  "about": null,
34 35
  "index": gui.Window.get(),
  "dialogue": null
36 37 38 39 40 41
}
function closeWindows() {
  for (win in windows) if (windows[win]) windows[win].close();
}

// GUI components
42 43 44
var tray_icon = {
  on: 'static/images/tray.png',
  off: 'static/images/tray_off.png'}
45
var tray = new gui.Tray({
46
  tooltip: COMMON.MENU.TITLE,
47
  icon: tray_icon.off,
48
  iconsAreTemplates: false
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
});

var menu = new gui.Menu();

// Progress and Pause

progress_item = new gui.MenuItem({
  // progress menu item
  label: 'Initializing',
  type: 'normal',
  enabled: false
});
menu.append(progress_item);
menu.append(new gui.MenuItem({type: 'separator'}));
pause_item = new gui.MenuItem({
  // pause menu item
65
  icon: 'static/images/play_pause.png',
66
  iconIsTemplate: false,
67
  label: COMMON.MENU.INITIALIZING,
68 69
  type: 'normal',
  click: function() {
70 71 72
    if (globals.status.code == STATUS['PAUSED']) post_start(socket);
    else if (globals.status.code == STATUS['SYNCING']) post_pause(socket);
    else log_debug('Illegal click - status code is ' + globals.status.code);
73 74 75 76 77 78
  }
});
pause_item.enabled = false;
menu.append(pause_item);

// Menu actions contents
79
var local_folder_menu = new gui.MenuItem({
80
  label: COMMON.MENU.FOLDER,
81
  icon: 'static/images/folder.png',
82
  iconIsTemplate: false,
83
  enabled: false,
84 85
  click: function () {
    var dir = globals['settings']['directory'];
86
    log_debug('Open ' + dir);
87
    gui.Shell.openItem(dir)
88
  }
89 90
})
menu.append(local_folder_menu);
91

92
var pithos_page_menu = new gui.MenuItem({
93
  label: COMMON.MENU.PITHOS,
94
  icon: 'static/images/pithos.png',
95
  iconIsTemplate: false,
96
  enabled: false,
97
  click: function () {
98
    log_debug('Visit ' + get_pithos_ui());
99
    gui.Shell.openExternal(get_pithos_ui());
100
  }
101 102
});
menu.append(pithos_page_menu);
103 104 105

// Settings and About
menu.append(new gui.MenuItem({type: 'separator'}));
106
var settings_menu = new gui.MenuItem({
107
  label: COMMON.MENU.SETTINGS,
108
  icon: 'static/images/settings.png',
109
  iconIsTemplate: false,
110
  enabled: false,
111
  //kiosk: false,
112
  click: function () {
113 114
    globals.settings_are_open = true;
    globals.open_settings = false;
115 116
    export_settings(globals.settings);
    if (windows['settings']) windows['settings'].close();
117 118
    var old_settings = {};
    $.each(globals.settings, function(key, val) {old_settings[key]=val;});
119 120
    windows['settings'] = gui.Window.open("settings.html", {
      toolbar: false, focus: true,
121
      width: 640, height: 420
122 123
    });
    windows['settings'].on('closed', function() {
124
    log_debug('Settings windows is closed');
125
    globals.settings_are_open = false;
126 127
      var new_settings = import_settings();
      $.each(new_settings, function(key, setting) {
128
        log_debug('Compare ' + old_settings[key] + ' with ' + setting);
129
        if (old_settings[key] !== setting) {
130
          log_debug('Settings have been modified - updating...');
131
          check_menu_lang();
132 133 134 135 136 137
          put_settings(socket, new_settings);
          get_status(socket);
          get_settings(socket);
          return false;
        }
      });
138 139
    });
  },
140 141
});
menu.append(settings_menu);
142 143 144 145 146 147 148 149 150 151 152 153 154
var help_menu = new gui.MenuItem({
  label: COMMON.MENU.HELP,
  icon: 'static/images/help.png',
  iconIsTemplate: false,
  click: function () {
    if (windows['help']) windows['help'].close();
    windows['help'] = gui.Window.open(
      'https://www.synnefo.org/docs/agkyra/latest/', {
      toolbar: false, resizable: true, focus: true, width: 700, height: 500
    });
  }
});
menu.append(help_menu);
155

156 157
var about_menu = new gui.MenuItem({
  label: COMMON.MENU.ABOUT,
158
  icon: 'static/images/about.png',
159
  iconIsTemplate: false,
160 161
  click: function () {
    if (windows['about']) windows['about'].close();
162 163
    windows['about'] = gui.Window.open(
        "about_" + globals.settings.language + ".html", {
164
      toolbar: false, resizable: false, focus: true, width: 640, height: 420
165 166
    });
  }
167 168
});
menu.append(about_menu);
169 170 171

// Quit
menu.append(new gui.MenuItem({type: 'separator'}));
172 173
var quit_menu = new gui.MenuItem({
  label: COMMON.MENU.QUIT,
174
  icon: 'static/images/exit.png',
175
  iconIsTemplate: false,
176
  click: function() {post_shutdown(socket);}
177 178
});
menu.append(quit_menu);
179

180

181 182 183 184 185 186 187
function activate_menu() {
  if (!pause_item.enabled) pause_item.enabled = true;
  if (!settings_menu.enabled) {
    if (globals.settings.url) refresh_endpoints(globals.settings.url);
    settings_menu.enabled = true;
    tray.menu = menu;
  }
188
  if ((!pithos_page_menu.enabled) && get_pithos_ui()){
189 190 191 192 193 194 195 196 197
    pithos_page_menu.enabled = true;
    tray.menu = menu;
  }
  if ((!local_folder_menu.enabled) && globals.settings.directory) {
    local_folder_menu.enabled = true;
    tray.menu = menu;
  }
}

198 199 200 201 202 203 204 205 206 207 208 209
function deactivate_menu() {
  if (
      pause_item.enabled ||
      local_folder_menu.enabled ||
      pithos_page_menu.enabled) {
    pause_item.enabled = false;
    local_folder_menu.enabled = false;
    pithos_page_menu.enabled = false;
    tray.menu = menu;
  }
}

210 211 212 213
function notify(level) {
  if (globals.notification !== globals.status.code) {
    // Notification has changed, raise notifier box
    globals.notification = globals.status.code;
214 215 216 217 218 219 220 221 222 223 224
    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;
225
    help_menu.label = COMMON.MENU.HELP;
226 227 228
    about_menu.label = COMMON.MENU.ABOUT;
    quit_menu.label = COMMON.MENU.QUIT;
    tray.menu = menu;
229 230 231
  }
}

232
// Update progress
233
var old_status = -1;
234
window.setInterval(function() {
235 236
  check_menu_lang();
  var new_progress = COMMON.NOTIFICATION[globals.status.code];
237
  var new_pause = '';
238
  var tray_icon_off = false;
239
  var dialogue_msg = null;
240
  var status_unchanged = (old_status == globals.status.code);
241
  switch(globals.status.code) {
242 243
    case STATUS['SETTINGS READY']:
      if (!status_unchanged) post_init(socket);
244 245 246
    case STATUS['UNINITIALIZED']:
    case STATUS['INITIALIZING']:
    case STATUS['SHUTING DOWN']:
247
      notify('info');
248
      deactivate_menu();
249
      new_pause = COMMON.MENU.INACTIVE;
250
      tray_icon_off = true;
251
    break;
252 253 254 255
    case STATUS['READY']:
      if (status_unchanged) break;
      post_start(socket);
    break;
256
    case STATUS['SYNCING']:
257
      notify('info');
258
      activate_menu();
259 260 261
      new_progress += ', '+ COMMON.MENU.REMAINING.replace(
                    '%s', remaining(globals.status));
      new_pause = COMMON.MENU.PAUSE;
262 263
    break;
    case STATUS['PAUSING']:
264
      notify('info');
265 266 267
      new_progress += ', ' + COMMON.MENU.REMAINING.replace(
                      '%s', remaining(globals.status));
      new_pause = COMMON.MENU.WAITING;
268 269 270
      pause_item.enabled = false;
    break;
    case STATUS['PAUSED']:
271
      notify('info');
272
      activate_menu();
273
      new_pause = COMMON.MENU.START;
274
      if (remaining(globals.status) > 0)
275 276
        new_progress += ', '+ COMMON.MENU.REMAINING.replace(
                    '%s', remaining(globals.status));
277 278
    break;
    case STATUS['DIRECTORY ERROR']:
279
      if (status_unchanged) break;
280 281
      dialogue_msg = COMMON.DIALOGUE[globals.status.code].replace(
        '%s', globals.settings.directory);
282
    case STATUS['CONTAINER ERROR']:
283
      if (status_unchanged) break;
284 285 286 287 288 289 290
      if (!dialogue_msg)
        dialogue_msg = COMMON.DIALOGUE[globals.status.code].replace(
          '%s', globals.settings.container);
      set_dialogue(dialogue_msg, COMMON.DIALOGUE, false);
      if (windows.dialogue === null) {
        windows['dialogue'] = gui.Window.open(
          'dialogue.html', {
291
            toolbar: false, focus: true, width: 550, height: 220});
292 293 294
        windows['dialogue'].on('closed', function() {
          var d = get_dialogue();
          if (d.response) post_force(socket);
295
          windows['dialogue'] = null;
296 297 298 299 300
        });
      }
    case STATUS['AUTH URL ERROR']:
    case STATUS['TOKEN ERROR']:
    case STATUS['SETTINGS MISSING']:
301
      if (status_unchanged) break;
302
      deactivate_menu();
303
      new_pause = COMMON.MENU.INACTIVE;
304
      settings_menu.enabled = true;
305
      notify('error');
306
    break;
307
    default: notify('warning'); break;
308 309
  }

310 311
  if (globals.open_settings && !globals.settings_are_open) {
    log_debug('OPEN SETTINGS IS ' + globals.open_settings);
312
    new_progress = COMMON.MENU.SETTINGSOPEN;
313 314
    globals.open_settings = false;
    settings_menu.click();
315
    deactivate_menu();
316
  } else if (globals.settings_are_open) deactivate_menu();
317

318 319
  if (new_progress !== progress_item.label
  ||  new_pause !== pause_item.label) {
320
    progress_item.label = new_progress;
321 322
    pause_item.label = new_pause;
    tray.menu = menu;
323
  }
324 325 326 327
  if (tray_icon_off && tray.icon !== tray_icon.off)
    tray.icon = tray_icon.off;
  else if (!(tray_icon_off || tray.icon === tray_icon.on))
    tray.icon = tray_icon.on;
328

329
  old_status = globals.status.code
330 331 332
  get_status(socket);
}, 1500);

333 334 335 336
tray.menu = menu;

    </script>
</body>
337
</html>