Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ public class Main : GLib.Object{

task.execute();

while (task.status == AppStatus.RUNNING){
while (this.task.status == AppStatus.RUNNING || this.task.status == AppStatus.PAUSED){
sleep(1000);
gtk_do_events();

Expand Down
18 changes: 16 additions & 2 deletions src/Gtk/BackupBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,17 @@ class BackupBox : Gtk.Box{
lbl_status.max_width_chars = 45;
lbl_status.margin_bottom = 6;
}


public void pause() {
this.spinner.active = false;
this.lbl_msg.set_label(_("Paused"));
}

public void resume() {
this.spinner.active = true;
this.lbl_msg.set_label("");
}

private Gtk.Label add_count_label(Gtk.Box box, string text,
ref Gtk.SizeGroup? sg_label, ref Gtk.SizeGroup? sg_value,
int add_margin_bottom = 0){
Expand Down Expand Up @@ -264,7 +274,11 @@ class BackupBox : Gtk.Box{
#endif
}

lbl_msg.label = escape_html(App.progress_text);
if(App.task.status == AppStatus.PAUSED) {
lbl_msg.label = _("Paused");
} else {
lbl_msg.label = escape_html(App.progress_text);
}

if (!checking)
{
Expand Down
28 changes: 28 additions & 0 deletions src/Gtk/BackupWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BackupWindow : Gtk.Window{
private Gtk.Button btn_prev;
private Gtk.Button btn_next;
private Gtk.Button btn_cancel;
private Gtk.Button btn_pause;
private Gtk.Button btn_close;

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

// pause

btn_pause = add_button(bbox, _("Pause"), "", size_group, null);
btn_pause.clicked.connect(() => {
if (App.task != null){
if(AppStatus.PAUSED == App.task.status) {
App.task.resume();
this.backup_box.resume();
this.btn_pause.set_label(_("Pause"));
} else {
App.task.pause();
this.backup_box.pause();
this.btn_pause.set_label(_("Resume"));
}
}
});

action_buttons_set_no_show_all(true);
}

Expand All @@ -197,6 +215,7 @@ class BackupWindow : Gtk.Window{
btn_next.no_show_all = val;
btn_close.no_show_all = val;
btn_cancel.no_show_all = val;
btn_pause.no_show_all = val;
}


Expand Down Expand Up @@ -274,17 +293,25 @@ class BackupWindow : Gtk.Window{

switch(notebook.page){
case Tabs.ESTIMATE:
btn_prev.hide();
btn_next.hide();
btn_close.hide();
btn_cancel.show();
btn_pause.hide();
break;
case Tabs.BACKUP:
btn_prev.hide();
btn_next.hide();
btn_close.hide();
btn_cancel.show();
btn_pause.show();
break;
case Tabs.BACKUP_DEVICE:
btn_prev.show();
btn_next.show();
btn_close.show();
btn_cancel.hide();
btn_pause.hide();
btn_prev.sensitive = false;
btn_next.sensitive = true;
btn_close.sensitive = true;
Expand All @@ -295,6 +322,7 @@ class BackupWindow : Gtk.Window{
btn_close.show();
btn_close.sensitive = true;
btn_cancel.hide();
btn_pause.hide();
break;
}

Expand Down
51 changes: 44 additions & 7 deletions src/Utility/AsyncTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public abstract class AsyncTask : GLib.Object{
public int exit_code = 0;
public string error_msg = "";
public GLib.Timer timer;
private double timerOffset = 0.0; // milliseconds to be added to the current timer - this is to compensate for pauses (timer restarts)
public double progress = 0.0;
public double percent = 0.0;
public int64 prg_count = 0;
Expand Down Expand Up @@ -371,7 +372,35 @@ public abstract class AsyncTask : GLib.Object{
process_quit(child_pid);
child_pid = 0;

log_debug("process_quit: %d".printf(child_pid));
log_debug("process_quit: %d ".printf(child_pid));
}
}

public void pause(AppStatus status_to_update = AppStatus.PAUSED) {
status = status_to_update;

if(0 != child_pid) {
TeeJee.ProcessHelper.process_send_signal(this.child_pid, Posix.Signal.STOP, true);

// "pause" timer
this.timerOffset += TeeJee.System.timer_elapsed(this.timer, true);

log_debug("process_paused: %d ".printf(this.child_pid));
}
}

// unpause (continue) the task
public void resume(AppStatus status_to_update = AppStatus.RUNNING) {
status = status_to_update;

if(0 != child_pid) {
TeeJee.ProcessHelper.process_send_signal(this.child_pid, Posix.Signal.CONT, true);

// restart timer
this.timer = new GLib.Timer();
this.timer.start();

log_debug("process_resumed: %d ".printf(this.child_pid));
}
}

Expand Down Expand Up @@ -399,22 +428,30 @@ public abstract class AsyncTask : GLib.Object{
}
}

private double elapsed {
get {
double elapsed = timerOffset;
if(this.status != AppStatus.PAUSED) {
elapsed += TeeJee.System.timer_elapsed(timer);
}
return elapsed;
}
}

public string stat_time_elapsed{
owned get{
long elapsed = (long) timer_elapsed(timer);
return format_duration(elapsed);
return TeeJee.Misc.format_duration(this.elapsed);
}
}

public string stat_time_remaining{
owned get{
if (progress > 0){
long elapsed = (long) timer_elapsed(timer);
long remaining = (long)((elapsed / progress) * (1.0 - progress));
if (this.progress > 0){
double remaining = ((this.elapsed / this.progress) * (1.0 - this.progress));
if (remaining < 0){
remaining = 0;
}
return format_duration(remaining);
return TeeJee.Misc.format_duration(remaining);
}
else{
return "???";
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/TeeJee.Misc.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace TeeJee.Misc {

// string formatting -------------------------------------------------

public string format_duration (long millis){
public string format_duration (double millis){

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

Expand Down
Loading