Skip to content

Commit 0b0c0cd

Browse files
authored
add button to pause rsync snapshots (#469)
1 parent f17fb76 commit 0b0c0cd

File tree

5 files changed

+90
-11
lines changed

5 files changed

+90
-11
lines changed

src/Core/Main.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ public class Main : GLib.Object{
16651665

16661666
task.execute();
16671667

1668-
while (task.status == AppStatus.RUNNING){
1668+
while (this.task.status == AppStatus.RUNNING || this.task.status == AppStatus.PAUSED){
16691669
sleep(1000);
16701670
gtk_do_events();
16711671

src/Gtk/BackupBox.vala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,17 @@ class BackupBox : Gtk.Box{
131131
lbl_status.max_width_chars = 45;
132132
lbl_status.margin_bottom = 6;
133133
}
134-
134+
135+
public void pause() {
136+
this.spinner.active = false;
137+
this.lbl_msg.set_label(_("Paused"));
138+
}
139+
140+
public void resume() {
141+
this.spinner.active = true;
142+
this.lbl_msg.set_label("");
143+
}
144+
135145
private Gtk.Label add_count_label(Gtk.Box box, string text,
136146
ref Gtk.SizeGroup? sg_label, ref Gtk.SizeGroup? sg_value,
137147
int add_margin_bottom = 0){
@@ -264,7 +274,11 @@ class BackupBox : Gtk.Box{
264274
#endif
265275
}
266276

267-
lbl_msg.label = escape_html(App.progress_text);
277+
if(App.task.status == AppStatus.PAUSED) {
278+
lbl_msg.label = _("Paused");
279+
} else {
280+
lbl_msg.label = escape_html(App.progress_text);
281+
}
268282

269283
if (!checking)
270284
{

src/Gtk/BackupWindow.vala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class BackupWindow : Gtk.Window{
4848
private Gtk.Button btn_prev;
4949
private Gtk.Button btn_next;
5050
private Gtk.Button btn_cancel;
51+
private Gtk.Button btn_pause;
5152
private Gtk.Button btn_close;
5253

5354
private uint tmr_init;
@@ -188,6 +189,23 @@ class BackupWindow : Gtk.Window{
188189
this.destroy(); // TODO: Show error page
189190
});
190191

192+
// pause
193+
194+
btn_pause = add_button(bbox, _("Pause"), "", size_group, null);
195+
btn_pause.clicked.connect(() => {
196+
if (App.task != null){
197+
if(AppStatus.PAUSED == App.task.status) {
198+
App.task.resume();
199+
this.backup_box.resume();
200+
this.btn_pause.set_label(_("Pause"));
201+
} else {
202+
App.task.pause();
203+
this.backup_box.pause();
204+
this.btn_pause.set_label(_("Resume"));
205+
}
206+
}
207+
});
208+
191209
action_buttons_set_no_show_all(true);
192210
}
193211

@@ -197,6 +215,7 @@ class BackupWindow : Gtk.Window{
197215
btn_next.no_show_all = val;
198216
btn_close.no_show_all = val;
199217
btn_cancel.no_show_all = val;
218+
btn_pause.no_show_all = val;
200219
}
201220

202221

@@ -274,17 +293,25 @@ class BackupWindow : Gtk.Window{
274293

275294
switch(notebook.page){
276295
case Tabs.ESTIMATE:
296+
btn_prev.hide();
297+
btn_next.hide();
298+
btn_close.hide();
299+
btn_cancel.show();
300+
btn_pause.hide();
301+
break;
277302
case Tabs.BACKUP:
278303
btn_prev.hide();
279304
btn_next.hide();
280305
btn_close.hide();
281306
btn_cancel.show();
307+
btn_pause.show();
282308
break;
283309
case Tabs.BACKUP_DEVICE:
284310
btn_prev.show();
285311
btn_next.show();
286312
btn_close.show();
287313
btn_cancel.hide();
314+
btn_pause.hide();
288315
btn_prev.sensitive = false;
289316
btn_next.sensitive = true;
290317
btn_close.sensitive = true;
@@ -295,6 +322,7 @@ class BackupWindow : Gtk.Window{
295322
btn_close.show();
296323
btn_close.sensitive = true;
297324
btn_cancel.hide();
325+
btn_pause.hide();
298326
break;
299327
}
300328

src/Utility/AsyncTask.vala

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public abstract class AsyncTask : GLib.Object{
6262
public int exit_code = 0;
6363
public string error_msg = "";
6464
public GLib.Timer timer;
65+
private double timerOffset = 0.0; // milliseconds to be added to the current timer - this is to compensate for pauses (timer restarts)
6566
public double progress = 0.0;
6667
public double percent = 0.0;
6768
public int64 prg_count = 0;
@@ -371,7 +372,35 @@ public abstract class AsyncTask : GLib.Object{
371372
process_quit(child_pid);
372373
child_pid = 0;
373374

374-
log_debug("process_quit: %d".printf(child_pid));
375+
log_debug("process_quit: %d ".printf(child_pid));
376+
}
377+
}
378+
379+
public void pause(AppStatus status_to_update = AppStatus.PAUSED) {
380+
status = status_to_update;
381+
382+
if(0 != child_pid) {
383+
TeeJee.ProcessHelper.process_send_signal(this.child_pid, Posix.Signal.STOP, true);
384+
385+
// "pause" timer
386+
this.timerOffset += TeeJee.System.timer_elapsed(this.timer, true);
387+
388+
log_debug("process_paused: %d ".printf(this.child_pid));
389+
}
390+
}
391+
392+
// unpause (continue) the task
393+
public void resume(AppStatus status_to_update = AppStatus.RUNNING) {
394+
status = status_to_update;
395+
396+
if(0 != child_pid) {
397+
TeeJee.ProcessHelper.process_send_signal(this.child_pid, Posix.Signal.CONT, true);
398+
399+
// restart timer
400+
this.timer = new GLib.Timer();
401+
this.timer.start();
402+
403+
log_debug("process_resumed: %d ".printf(this.child_pid));
375404
}
376405
}
377406

@@ -399,22 +428,30 @@ public abstract class AsyncTask : GLib.Object{
399428
}
400429
}
401430

431+
private double elapsed {
432+
get {
433+
double elapsed = timerOffset;
434+
if(this.status != AppStatus.PAUSED) {
435+
elapsed += TeeJee.System.timer_elapsed(timer);
436+
}
437+
return elapsed;
438+
}
439+
}
440+
402441
public string stat_time_elapsed{
403442
owned get{
404-
long elapsed = (long) timer_elapsed(timer);
405-
return format_duration(elapsed);
443+
return TeeJee.Misc.format_duration(this.elapsed);
406444
}
407445
}
408446

409447
public string stat_time_remaining{
410448
owned get{
411-
if (progress > 0){
412-
long elapsed = (long) timer_elapsed(timer);
413-
long remaining = (long)((elapsed / progress) * (1.0 - progress));
449+
if (this.progress > 0){
450+
double remaining = ((this.elapsed / this.progress) * (1.0 - this.progress));
414451
if (remaining < 0){
415452
remaining = 0;
416453
}
417-
return format_duration(remaining);
454+
return TeeJee.Misc.format_duration(remaining);
418455
}
419456
else{
420457
return "???";

src/Utility/TeeJee.Misc.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace TeeJee.Misc {
7575

7676
// string formatting -------------------------------------------------
7777

78-
public string format_duration (long millis){
78+
public string format_duration (double millis){
7979

8080
/* Converts time in milliseconds to format '00:00:00.0' */
8181

0 commit comments

Comments
 (0)