menu.html 6.58 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
19
20
21
22
<html>
<head><title>GUI for Agkyra Pithos+ Syncing Client</title></head>
<body>
    <script src="protocol.js"></script>
    <script src="settings.js"></script>
23
    <script src="static/js/jquery.js"></script>
24
25
    <script type="text/javascript">

26
// Setup GUI
27
28
29
30
31
32
33
34
35
36
37
38
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({
  title: 'Agkyra syncs with Pithos+',
39
  icon: 'static/images/tray.png'
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
});

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
59
  icon: 'static/images/play_pause.png',
60
  label: 'NOT READY',
61
62
63
64
65
66
67
68
69
  type: 'normal',
  click: function() {
    if (paused) {post_start(socket);} else {post_pause(socket);}
  }
});
pause_item.enabled = false;
menu.append(pause_item);

// Menu actions contents
70
var local_folder_menu = new gui.MenuItem({
71
  label: 'Open local folder',
72
  icon: 'static/images/folder.png',
73
  enabled: false,
74
75
  click: function () {
    var dir = globals['settings']['directory'];
76
    log_debug('Open ' + dir);
77
    gui.Shell.showItemInFolder(dir + path.sep + '.');
78
  }
79
80
})
menu.append(local_folder_menu);
81

82
var pithos_page_menu = new gui.MenuItem({
83
  label: 'Launch Pithos+ page',
84
  icon: 'static/images/pithos.png',
85
  enabled: false,
86
  click: function () {
87
    log_debug('Visit ' + get_pithos_ui());
88
    gui.Shell.openExternal(get_pithos_ui());
89
  }
90
91
});
menu.append(pithos_page_menu);
92
93
94

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

menu.append(new gui.MenuItem({
  label: 'About',
128
  icon: 'static/images/about.png',
129
130
131
132
  click: function () {
    if (windows['about']) windows['about'].close();
    windows['about'] = gui.Window.open("about.html", {
      toolbar: false, resizable: false, focus: true,
133
      width: 860, height: 620
134
135
136
137
138
139
140
141
    });
  }
}));

// Quit
menu.append(new gui.MenuItem({type: 'separator'}));
menu.append(new gui.MenuItem({
  label: 'Quit Agkyra',
142
  icon: 'static/images/exit.png',
143
144
145
  click: function() {post_shutdown(socket);}
}));

146
147
148
149

// Update progress
var client_ready = false;
window.setInterval(function() {
150
151
152
153
154
  if (globals.open_settings) {
    globals.open_settings = false;
    settings_menu.click();
  }

155
  var menu_modified = false;
156
  if (!client_ready) {
157
158
    if (!globals.authenticated) return;
    client_ready = true;
159
160
161
  }

  if (client_ready) {
162
163
164
165
166
167
    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) {
168
169
170
      if (get_pithos_ui() != null) {
        pithos_page_menu.enabled = true;
        tray.menu = menu;
171
      } else { refresh_endpoints(globals.settings.url); }
172
173
174
175
    }
    if (!local_folder_menu.enabled) {
      if (globals.settings.directory) {
        local_folder_menu.enabled = true;
176
        tray.menu = menu;
177
178
179
180
181
182
183
      }
    }
  }

  var status = globals['status'];
  var new_progress = progress_item.label;
  var new_pause = pause_item.label;
184
185
186
187
  if (!status.can_sync) {
    new_progress = 'Incomplete settings'
    new_pause = 'inactive'
    pause_item.enabled = false;
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
  } 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;
209
          menu_modified = true;
210
      }
211
    }
212
213
214
215
216
217
218
219
220
221
222

    var remaining = status.unsynced - status.synced;
    if (status.paused){
      if (remaining)
        new_progress = 'Pausing, ' + remaining + ' remaining';
      else new_progress = 'Paused';
    } else {
      if (remaining)
        new_progress = 'Syncing, ' + remaining + ' remaining';
      else new_progress = 'Running, all synced';
    }
223
  }
224
  if (new_pause !== pause_item.label.slice(0, new_pause.length)) {
225
226
227
    pause_item.label = new_pause;
    menu_modified = true;
  }
228
  if (new_progress !== progress_item.label) {
229
230
231
    progress_item.label = new_progress;
    menu_modified = true;
  }
232
  if (menu_modified) tray.menu = menu;
233
234
235
  get_status(socket);
}, 1500);

236
237
238
239
tray.menu = menu;

    </script>
</body>
240
</html>