menu.html 8.21 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
34
35
36
37
38
39
40
var windows = {
  "settings": null,
  "about": null,
  "index": gui.Window.get()
}
function closeWindows() {
  for (win in windows) if (windows[win]) windows[win].close();
}

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

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
64
  icon: 'static/images/play_pause.png',
65
  iconIsTemplate: false,
66
  label: COMMON.MENU.INITIALIZING,
67
68
  type: 'normal',
  click: function() {
69
70
71
    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);
72
73
74
75
76
77
  }
});
pause_item.enabled = false;
menu.append(pause_item);

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

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

// Settings and About
menu.append(new gui.MenuItem({type: 'separator'}));
105
var settings_menu = new gui.MenuItem({
106
  label: COMMON.MENU.SETTINGS,
107
  icon: 'static/images/settings.png',
108
  iconIsTemplate: false,
109
  enabled: false,
110
  //kiosk: false,
111
  click: function () {
112
113
    globals.settings_are_open = true;
    globals.open_settings = false;
114
115
    export_settings(globals.settings);
    if (windows['settings']) windows['settings'].close();
116
117
    var old_settings = {};
    $.each(globals.settings, function(key, val) {old_settings[key]=val;});
118
119
    windows['settings'] = gui.Window.open("settings.html", {
      toolbar: false, focus: true,
120
      width: 860, height: 860
121
122
    });
    windows['settings'].on('closed', function() {
123
    log_debug('Settings windows is closed');
124
    globals.settings_are_open = false;
125
126
      var new_settings = import_settings();
      $.each(new_settings, function(key, setting) {
127
        log_debug('Compare ' + old_settings[key] + ' with ' + setting);
128
        if (old_settings[key] !== setting) {
129
          log_debug('Settings have been modified - updating...');
130
          check_menu_lang();
131
132
133
134
135
136
          put_settings(socket, new_settings);
          get_status(socket);
          get_settings(socket);
          return false;
        }
      });
137
138
    });
  },
139
140
});
menu.append(settings_menu);
141

142
143
var about_menu = new gui.MenuItem({
  label: COMMON.MENU.ABOUT,
144
  icon: 'static/images/about.png',
145
  iconIsTemplate: false,
146
147
  click: function () {
    if (windows['about']) windows['about'].close();
148
149
    windows['about'] = gui.Window.open(
        "about_" + globals.settings.language + ".html", {
150
      toolbar: false, resizable: false, focus: true,
151
      width: 860, height: 620
152
153
    });
  }
154
155
});
menu.append(about_menu);
156
157
158

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

167

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

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

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

218
219
// Update progress
window.setInterval(function() {
220
221
  check_menu_lang();
  var new_progress = COMMON.NOTIFICATION[globals.status.code];
222
  var new_pause = '';
223
  var tray_icon_off = false;
224
225
226
227
  switch(globals.status.code) {
    case STATUS['UNINITIALIZED']:
    case STATUS['INITIALIZING']:
    case STATUS['SHUTING DOWN']:
228
      notify('info');
229
      deactivate_menu();
230
      new_pause = COMMON.MENU.INACTIVE;
231
      tray_icon_off = true;
232
233
    break;
    case STATUS['SYNCING']:
234
      notify('info');
235
      activate_menu();
236
237
238
      new_progress += ', '+ COMMON.MENU.REMAINING.replace(
                    '%s', remaining(globals.status));
      new_pause = COMMON.MENU.PAUSE;
239
240
    break;
    case STATUS['PAUSING']:
241
      notify('info');
242
243
244
      new_progress += ', ' + COMMON.MENU.REMAINING.replace(
                      '%s', remaining(globals.status));
      new_pause = COMMON.MENU.WAITING;
245
246
247
      pause_item.enabled = false;
    break;
    case STATUS['PAUSED']:
248
      notify('info');
249
      activate_menu();
250
      new_pause = COMMON.MENU.START;
251
      if (remaining(globals.status) > 0)
252
253
        new_progress += ', '+ COMMON.MENU.REMAINING.replace(
                    '%s', remaining(globals.status));
254
255
256
257
258
259
260
    break;
    case STATUS['SETTINGS MISSING']:
    case STATUS['AUTH URL ERROR']:
    case STATUS['TOKEN ERROR']:
    case STATUS['DIRECTORY ERROR']:
    case STATUS['CONTAINER ERROR']:
      deactivate_menu();
261
      new_pause = COMMON.MENU.INACTIVE;
262
      settings_menu.enabled = true;
263
      notify('error');
264
    break;
265
    default: notify('warning'); break;
266
267
  }

268
  if (globals.open_settings) {
269
    new_progress = COMMON.MENU.SETTINGSOPEN;
270
271
    globals.open_settings = false;
    settings_menu.click();
272
    deactivate_menu();
273
  } else if (globals.settings_are_open) deactivate_menu();
274

275
276
  if (new_progress !== progress_item.label
  ||  new_pause !== pause_item.label) {
277
    progress_item.label = new_progress;
278
279
    pause_item.label = new_pause;
    tray.menu = menu;
280
  }
281
282
283
284
  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;
285
286
287
  get_status(socket);
}, 1500);

288
289
290
291
tray.menu = menu;

    </script>
</body>
292
</html>