menu.html 9.2 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
var about_menu = new gui.MenuItem({
  label: COMMON.MENU.ABOUT,
145
  icon: 'static/images/about.png',
146
  iconIsTemplate: false,
147 148
  click: function () {
    if (windows['about']) windows['about'].close();
149 150
    windows['about'] = gui.Window.open(
        "about_" + globals.settings.language + ".html", {
151
      toolbar: false, resizable: false, focus: true,
152
      width: 640, height: 420
153 154
    });
  }
155 156
});
menu.append(about_menu);
157 158 159

// Quit
menu.append(new gui.MenuItem({type: 'separator'}));
160 161
var quit_menu = new gui.MenuItem({
  label: COMMON.MENU.QUIT,
162
  icon: 'static/images/exit.png',
163
  iconIsTemplate: false,
164
  click: function() {post_shutdown(socket);}
165 166
});
menu.append(quit_menu);
167

168

169 170 171 172 173 174 175
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;
  }
176
  if ((!pithos_page_menu.enabled) && get_pithos_ui()){
177 178 179 180 181 182 183 184 185
    pithos_page_menu.enabled = true;
    tray.menu = menu;
  }
  if ((!local_folder_menu.enabled) && globals.settings.directory) {
    local_folder_menu.enabled = true;
    tray.menu = menu;
  }
}

186 187 188 189 190 191 192 193 194 195 196 197
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;
  }
}

198 199 200 201
function notify(level) {
  if (globals.notification !== globals.status.code) {
    // Notification has changed, raise notifier box
    globals.notification = globals.status.code;
202 203 204 205 206 207 208 209 210 211 212 213 214 215
    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;
216 217 218
  }
}

219
// Update progress
220
var old_status = -1;
221
window.setInterval(function() {
222 223
  check_menu_lang();
  var new_progress = COMMON.NOTIFICATION[globals.status.code];
224
  var new_pause = '';
225
  var tray_icon_off = false;
226
  var dialogue_msg = null;
227
  var status_unchanged = (old_status == globals.status.code);
228 229 230 231
  switch(globals.status.code) {
    case STATUS['UNINITIALIZED']:
    case STATUS['INITIALIZING']:
    case STATUS['SHUTING DOWN']:
232
      notify('info');
233
      deactivate_menu();
234
      new_pause = COMMON.MENU.INACTIVE;
235
      tray_icon_off = true;
236 237
    break;
    case STATUS['SYNCING']:
238
      notify('info');
239
      activate_menu();
240 241 242
      new_progress += ', '+ COMMON.MENU.REMAINING.replace(
                    '%s', remaining(globals.status));
      new_pause = COMMON.MENU.PAUSE;
243 244
    break;
    case STATUS['PAUSING']:
245
      notify('info');
246 247 248
      new_progress += ', ' + COMMON.MENU.REMAINING.replace(
                      '%s', remaining(globals.status));
      new_pause = COMMON.MENU.WAITING;
249 250 251
      pause_item.enabled = false;
    break;
    case STATUS['PAUSED']:
252
      notify('info');
253
      activate_menu();
254
      new_pause = COMMON.MENU.START;
255
      if (remaining(globals.status) > 0)
256 257
        new_progress += ', '+ COMMON.MENU.REMAINING.replace(
                    '%s', remaining(globals.status));
258 259
    break;
    case STATUS['DIRECTORY ERROR']:
260
      if (status_unchanged) break;
261 262
      dialogue_msg = COMMON.DIALOGUE[globals.status.code].replace(
        '%s', globals.settings.directory);
263
    case STATUS['CONTAINER ERROR']:
264
      if (status_unchanged) break;
265 266 267 268 269 270 271
      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', {
272
            toolbar: false, focus: true, width: 550, height: 220});
273 274 275
        windows['dialogue'].on('closed', function() {
          var d = get_dialogue();
          if (d.response) post_force(socket);
276
          windows['dialogue'] = null;
277 278 279 280 281
        });
      }
    case STATUS['AUTH URL ERROR']:
    case STATUS['TOKEN ERROR']:
    case STATUS['SETTINGS MISSING']:
282
      if (status_unchanged) break;
283
      deactivate_menu();
284
      new_pause = COMMON.MENU.INACTIVE;
285
      settings_menu.enabled = true;
286
      notify('error');
287
    break;
288
    default: notify('warning'); break;
289 290
  }

291 292
  if (globals.open_settings && !globals.settings_are_open) {
    log_debug('OPEN SETTINGS IS ' + globals.open_settings);
293
    new_progress = COMMON.MENU.SETTINGSOPEN;
294 295
    globals.open_settings = false;
    settings_menu.click();
296
    deactivate_menu();
297
  } else if (globals.settings_are_open) deactivate_menu();
298

299 300
  if (new_progress !== progress_item.label
  ||  new_pause !== pause_item.label) {
301
    progress_item.label = new_progress;
302 303
    pause_item.label = new_pause;
    tray.menu = menu;
304
  }
305 306 307 308
  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;
309

310
  old_status = globals.status.code
311 312 313
  get_status(socket);
}, 1500);

314 315 316 317
tray.menu = menu;

    </script>
</body>
318
</html>