menu.html 7.71 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
41
var windows = {
  "settings": null,
  "about": null,
  "index": gui.Window.get()
}
function closeWindows() {
  for (win in windows) if (windows[win]) windows[win].close();
}

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

var menu = new gui.Menu();

// Progress and Pause
var start_syncing = 'Start Syncing';
var pause_syncing = 'Pause Syncing';
var paused = true;

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: 'NOT READY',
67
68
69
70
71
72
73
74
75
  type: 'normal',
  click: function() {
    if (paused) {post_start(socket);} else {post_pause(socket);}
  }
});
pause_item.enabled = false;
menu.append(pause_item);

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

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

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

menu.append(new gui.MenuItem({
  label: 'About',
141
  icon: 'static/images/about.png',
142
  iconIsTemplate: false,
143
144
145
146
  click: function () {
    if (windows['about']) windows['about'].close();
    windows['about'] = gui.Window.open("about.html", {
      toolbar: false, resizable: false, focus: true,
147
      width: 860, height: 620
148
149
150
151
152
153
154
155
    });
  }
}));

// Quit
menu.append(new gui.MenuItem({type: 'separator'}));
menu.append(new gui.MenuItem({
  label: 'Quit Agkyra',
156
  icon: 'static/images/exit.png',
157
  iconIsTemplate: false,
158
159
160
  click: function() {post_shutdown(socket);}
}));

161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
function deactivate_menu() {
  if (
      pause_item.enabled ||
      local_folder_menu.enabled ||
      pithos_page_menu.enabled) {
    progress_item.label = 'Settings window is open';
    pause_item.enabled = false;
    local_folder_menu.enabled = false;
    pithos_page_menu.enabled = false;
    tray.menu = menu;
  }
}


176
177
178
// Update progress
var client_ready = false;
window.setInterval(function() {
179
180
181
182
183
  if (globals.settings_are_open) {
    deactivate_menu();
    return;
  }

184
185
186
  if (globals.open_settings) {
    globals.open_settings = false;
    settings_menu.click();
187
188
    deactivate_menu();
    return;
189
190
  }

191
  var menu_modified = false;
192
  if (!client_ready) {
193
194
    if (!globals.authenticated) return;
    client_ready = true;
195
196
197
  }

  if (client_ready) {
198
    pause_item.enabled = (pause_item.label !== 'inactive');
199
200
201
202
203
204
    if (!settings_menu.enabled) {
      if (globals.settings.url) refresh_endpoints(globals.settings.url);
      settings_menu.enabled = true;
      tray.menu = menu;
    }
    if (globals.settings.url && !pithos_page_menu.enabled) {
205
206
207
      if (get_pithos_ui() != null) {
        pithos_page_menu.enabled = true;
        tray.menu = menu;
208
      } else { refresh_endpoints(globals.settings.url); }
209
210
211
212
    }
    if (!local_folder_menu.enabled) {
      if (globals.settings.directory) {
        local_folder_menu.enabled = true;
213
        tray.menu = menu;
214
215
216
217
218
219
220
      }
    }
  }

  var status = globals['status'];
  var new_progress = progress_item.label;
  var new_pause = pause_item.label;
221
222
223
224
225
226
227
228
  if (status.notification !== 0) {
    new_progress = notifications[status.notification];
    new_pause = 'inactive';
    if (progress_item.label !== new_progress) {
      notify_user(new_progress, 'critical');
    }
  }
  else if (!status.can_sync) {
Stavros Sachtouris's avatar
Stavros Sachtouris committed
229
230
    if (globals.just_opened) new_progress = 'Connecting...'
    else new_progress = 'Not able to sync'
231
232
    new_pause = 'inactive'
    pause_item.enabled = false;
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  } else {
    if (status.paused !== null) {
      switch(pause_item.label) {
        case pause_syncing: if (status.paused) {
            // Update to "Paused - start syncing"
            paused = true;
            new_pause = start_syncing;
            menu_modified = true;
          } // else continue syncing
        break;
        case start_syncing: if (!status.paused) {
            //update to "Syncing - pause syncing"
            paused = false;
            new_pause = pause_syncing;
            menu_modified = true;
          }
        break;
        default:
          if (status.paused) {new_pause = start_syncing; paused=true;}
          else {new_pause = pause_syncing; paused=false;}
          pause_item.enabled = true;
254
          menu_modified = true;
255
      }
256
    }
257
258
259
260

    var remaining = status.unsynced - status.synced;
    if (status.paused){
      if (remaining)
261
        new_progress = 'Pausing, ' + remaining + ' remain';
262
263
264
      else new_progress = 'Paused';
    } else {
      if (remaining)
265
        new_progress = 'Syncing, ' + remaining + ' remain';
266
267
      else new_progress = 'Running, all synced';
    }
268
  }
269
  if (new_pause !== pause_item.label.slice(0, new_pause.length)) {
270
271
272
    pause_item.label = new_pause;
    menu_modified = true;
  }
273
  if (new_progress !== progress_item.label) {
274
275
276
    progress_item.label = new_progress;
    menu_modified = true;
  }
277
  if (menu_modified) tray.menu = menu;
278
279
280
  get_status(socket);
}, 1500);

281
282
283
284
tray.menu = menu;

    </script>
</body>
285
</html>