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

286
  if (globals.open_settings) {
287
    new_progress = COMMON.MENU.SETTINGSOPEN;
288
289
    globals.open_settings = false;
    settings_menu.click();
290
    deactivate_menu();
291
  } else if (globals.settings_are_open) deactivate_menu();
292

293
294
  if (new_progress !== progress_item.label
  ||  new_pause !== pause_item.label) {
295
    progress_item.label = new_progress;
296
297
    pause_item.label = new_pause;
    tray.menu = menu;
298
  }
299
300
301
302
  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;
303

304
305
306
  get_status(socket);
}, 1500);

307
308
309
310
tray.menu = menu;

    </script>
</body>
311
</html>