@@ -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 " ???" ;
0 commit comments