-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathRestoreWindow.vala
More file actions
543 lines (399 loc) · 11.7 KB
/
RestoreWindow.vala
File metadata and controls
543 lines (399 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
/*
* RestoreWindow.vala
*
* Copyright 2012-2018 Tony George <teejeetech@gmail.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
using Gtk;
using Gee;
using TeeJee.Logging;
using TeeJee.FileSystem;
using TeeJee.JsonHelper;
using TeeJee.ProcessHelper;
using TeeJee.GtkHelper;
using TeeJee.System;
using TeeJee.Misc;
class RestoreWindow : Gtk.Window{
private Gtk.Box vbox_main;
private Gtk.Notebook notebook;
private Gtk.ButtonBox bbox_action;
// tabs
private RestoreDeviceBox restore_device_box;
private RestoreExcludeBox restore_exclude_box;
private ExcludeAppsBox exclude_apps_box;
private RestoreSummaryBox summary_box;
private RestoreBox check_box;
private RsyncLogBox log_box;
private RestoreBox restore_box;
private UsersBox users_box;
private RestoreFinishBox restore_finish_box;
// actions
private Gtk.Button btn_prev;
private Gtk.Button btn_next;
private Gtk.Button btn_cancel;
private Gtk.Button btn_close;
private uint tmr_init;
private int def_width = 500;
private int def_height = 500;
private bool success = false;
public bool check_before_restore = true;
public RestoreWindow() {
log_debug("RestoreWindow: RestoreWindow()");
this.title = App.mirror_system ? _("Clone System") : _("Restore Snapshot");
this.window_position = WindowPosition.CENTER;
this.modal = true;
this.set_default_size (def_width, def_height);
this.icon = IconManager.lookup("timeshift",16);
this.resize(def_width, def_height);
this.delete_event.connect(on_delete_event);
// vbox_main
vbox_main = new Gtk.Box(Orientation.VERTICAL, 6);
vbox_main.margin = 0;
add(vbox_main);
// add notebook
notebook = add_notebook(vbox_main, false, false);
Gtk.Label label;
label = new Gtk.Label(_("Restore Device"));
restore_device_box = new RestoreDeviceBox(this);
restore_device_box.margin = 12;
notebook.append_page (restore_device_box, label);
label = new Gtk.Label(_("Restore Exclude"));
restore_exclude_box = new RestoreExcludeBox(this);
restore_exclude_box.margin = 12;
notebook.append_page (restore_exclude_box, label);
label = new Gtk.Label(_("Exclude Apps"));
exclude_apps_box = new ExcludeAppsBox(this);
exclude_apps_box.margin = 12;
notebook.append_page (exclude_apps_box, label);
label = new Gtk.Label(_("Checking Restore Actions (Dry Run)"));
check_box = new RestoreBox(this);
check_box.margin = 12;
notebook.append_page (check_box, label);
label = new Gtk.Label(_("Confirm Actions"));
log_box = new RsyncLogBox(this);
log_box.margin = 12;
notebook.append_page (log_box, label);
label = new Gtk.Label(_("Users Home"));
var exclude_box = new ExcludeBox(this); // dummy - not used
users_box = new UsersBox(this, exclude_box, true);
users_box.margin = 12;
notebook.append_page (users_box, label);
label = new Gtk.Label(_("Summary"));
summary_box = new RestoreSummaryBox(this);
summary_box.margin = 12;
notebook.append_page (summary_box, label);
label = new Gtk.Label(_("Restore"));
restore_box = new RestoreBox(this);
restore_box.margin = 12;
notebook.append_page (restore_box, label);
label = new Gtk.Label(_("Finished"));
restore_finish_box = new RestoreFinishBox(this);
restore_finish_box.margin = 12;
notebook.append_page (restore_finish_box, label);
create_actions();
show_all();
gtk_do_events();
tmr_init = Timeout.add(100, init_delayed);
log_debug("RestoreWindow: RestoreWindow(): exit");
}
private bool init_delayed(){
if (tmr_init > 0){
Source.remove(tmr_init);
tmr_init = 0;
}
this.resize(def_width, def_height);
go_first();
return false;
}
private bool on_delete_event(Gdk.EventAny event){
save_changes();
return false; // close window
}
private void save_changes(){
App.cron_job_update();
}
private void create_actions(){
var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
vbox_main.add(hbox);
var bbox = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
bbox.margin = 12;
bbox.spacing = 6;
bbox.hexpand = true;
hbox.add(bbox);
bbox_action = bbox;
#if GTK3_18
bbox.set_layout (Gtk.ButtonBoxStyle.CENTER);
#endif
Gtk.SizeGroup size_group = null; //new Gtk.SizeGroup(SizeGroupMode.HORIZONTAL);
// previous
btn_prev = add_button(bbox, _("Previous"), "", size_group, null);
btn_prev.clicked.connect(()=>{
go_prev();
});
// next
btn_next = add_button(bbox, _("Next"), "", size_group, null);
btn_next.clicked.connect(()=>{
// finish any pending Gtk events before showing the next page
gtk_set_busy(true, this);
gtk_do_events();
gtk_set_busy(false, this);
go_next();
});
// close
btn_close = add_button(bbox, _("Cancel"), "", size_group, null);
btn_close.clicked.connect(()=>{
save_changes();
this.destroy();
});
// cancel
btn_cancel = add_button(bbox, _("Cancel"), "", size_group, null);
btn_cancel.clicked.connect(()=>{
if (!App.dry_run){
var title = _("Cancel restore?");
var msg = _("Cancelling the restore process will leave the target system in an inconsistent state. The system may fail to boot or you may run into various issues. After cancelling, you need to restore another snapshot, to bring the system to a consistent state. Click Yes to confirm.");
var dlg = new CustomMessageDialog(title, msg, Gtk.MessageType.ERROR, this, Gtk.ButtonsType.YES_NO);
var response = dlg.run();
dlg.destroy();
if (response != Gtk.ResponseType.YES){
return;
}
}
if (App.task != null){
App.task.stop(AppStatus.CANCELLED);
}
this.destroy(); // TODO: low: Show error page
});
btn_prev.hexpand = btn_next.hexpand = btn_cancel.hexpand = btn_close.hexpand = true;
action_buttons_set_no_show_all(true);
}
private void action_buttons_set_no_show_all(bool val){
btn_prev.no_show_all = val;
btn_next.no_show_all = val;
btn_close.no_show_all = val;
btn_cancel.no_show_all = val;
}
// navigation ----------------------------------------------------
private void go_first(){
// set initial tab
if (App.btrfs_mode){
if (App.snapshot_to_restore.subvolumes.has_key(App.home_subvolume_name)){
notebook.page = Tabs.USERS;
}
else {
notebook.page = Tabs.SUMMARY;
}
}
else{
notebook.page = Tabs.TARGET_DEVICE;
}
initialize_tab();
}
private void go_prev(){
switch(notebook.page){
case Tabs.RESTORE_EXCLUDE:
notebook.page = Tabs.TARGET_DEVICE;
break;
case Tabs.EXCLUDE_APPS:
notebook.page = Tabs.RESTORE_EXCLUDE;
//notebook.page = Tabs.TARGET_DEVICE;
break;
case Tabs.SUMMARY:
notebook.page = Tabs.RESTORE_EXCLUDE; // go to parent (RESTORE_EXCLUDE)
break;
case Tabs.TARGET_DEVICE:
case Tabs.RESTORE:
case Tabs.FINISH:
// btn_previous is disabled for this page
break;
}
initialize_tab();
}
private void go_next(){
if (!validate_current_tab()){
return;
}
switch(notebook.page){
case Tabs.TARGET_DEVICE:
if (!App.btrfs_mode && check_before_restore){
notebook.page = Tabs.CHECK;
}
else{
notebook.page = Tabs.SUMMARY;
}
break;
/*case Tabs.RESTORE_EXCLUDE:
if (restore_exclude_box.show_all_apps()){
notebook.page = Tabs.EXCLUDE_APPS;
}
else{
notebook.page = Tabs.SUMMARY;
}
break;
case Tabs.EXCLUDE_APPS:
notebook.page = Tabs.SUMMARY;
break;*/
case Tabs.CHECK:
notebook.page = Tabs.SHOW_LOG;
break;
case Tabs.SHOW_LOG:
notebook.page = Tabs.SUMMARY;
break;
case Tabs.USERS:
notebook.page = Tabs.SUMMARY;
break;
case Tabs.SUMMARY:
notebook.page = Tabs.RESTORE;
break;
case Tabs.RESTORE:
notebook.page = Tabs.FINISH;
break;
case Tabs.FINISH:
destroy();
break;
}
gtk_do_events();
initialize_tab();
}
private void initialize_tab(){
if (notebook.page < 0){ return; }
log_debug("initialize_tab: %d".printf(notebook.page));
// show/hide actions -----------------------------------
action_buttons_set_no_show_all(false);
switch(notebook.page){
case Tabs.RESTORE:
btn_prev.hide();
btn_next.hide();
btn_close.hide();
btn_cancel.show();
break;
case Tabs.CHECK:
btn_prev.hide();
btn_next.hide();
btn_close.hide();
btn_cancel.show();
btn_cancel.sensitive = true;
break;
case Tabs.TARGET_DEVICE:
case Tabs.RESTORE_EXCLUDE:
case Tabs.EXCLUDE_APPS:
case Tabs.SUMMARY:
case Tabs.USERS:
// cannot go back
btn_prev.show();
btn_next.show();
btn_close.show();
btn_cancel.hide();
btn_prev.sensitive = false;
btn_next.sensitive = true;
btn_close.sensitive = true;
break;
case Tabs.SHOW_LOG:
btn_prev.show();
btn_next.show();
btn_close.show();
btn_cancel.hide();
btn_prev.sensitive = false;
btn_next.sensitive = true;
btn_close.sensitive = true;
break;
case Tabs.FINISH:
btn_prev.show();
btn_next.show();
btn_close.show();
btn_cancel.hide();
btn_prev.sensitive = false;
btn_next.sensitive = false;
btn_close.sensitive = true;
break;
}
gtk_do_events();
// actions ---------------------------------------------------
switch(notebook.page){
case Tabs.TARGET_DEVICE:
restore_device_box.refresh(false); // false: App.init_mount_list() will be called before this window is shown
break;
case Tabs.RESTORE_EXCLUDE:
restore_exclude_box.refresh();
break;
case Tabs.EXCLUDE_APPS:
exclude_apps_box.refresh();
break;
case Tabs.CHECK:
App.dry_run = true;
success = check_box.restore();
go_next();
break;
case Tabs.SHOW_LOG:
if (file_exists(App.snapshot_to_restore.rsync_restore_log_file)){
log_box.open_log(App.snapshot_to_restore.rsync_restore_log_file);
}
else{
notebook.page = Tabs.FINISH;
initialize_tab();
restore_finish_box.update_message(false, _("Error running Rsync"), "");
}
break;
case Tabs.USERS:
users_box.refresh();
break;
case Tabs.SUMMARY:
summary_box.refresh();
break;
case Tabs.RESTORE:
App.dry_run = false;
success = restore_box.restore();
go_next();
break;
case Tabs.FINISH:
restore_finish_box.update_message(success,"","");
btn_close.label = _("Close");
//wait_and_close_window(1000, this); // do not auto-close restore window.
break;
}
gtk_do_events();
}
private bool validate_current_tab(){
if (notebook.page == Tabs.TARGET_DEVICE){
bool ok = restore_device_box.check_and_mount_devices();
if (ok){
App.add_app_exclude_entries();
}
return ok;
}
else if (notebook.page == Tabs.RESTORE_EXCLUDE){
App.save_exclude_list_selections();
}
else if (notebook.page == Tabs.EXCLUDE_APPS){
App.save_exclude_list_selections();
}
return true;
}
public enum Tabs{
// indexes here should match the order in which tabs were added to Notebook
TARGET_DEVICE = 0,
RESTORE_EXCLUDE = 1,
EXCLUDE_APPS = 2,
CHECK = 3,
SHOW_LOG = 4,
USERS = 5,
SUMMARY = 6,
RESTORE = 7,
FINISH = 8
}
}