diff -ru sane-frontends-1.0.14-orig/src/progress.c sane-frontends-1.0.14/src/progress.c --- sane-frontends-1.0.14-orig/src/progress.c 2003-01-19 00:03:08.000000000 +0200 +++ sane-frontends-1.0.14/src/progress.c 2008-09-13 18:37:03.000000000 +0300 @@ -20,6 +20,7 @@ #include #include +#include #include #include "progress.h" @@ -45,6 +46,7 @@ p = (Progress_t *) malloc (sizeof (Progress_t)); p->callback = callback; + p->firstTime = 0; p->shell = gtk_dialog_new (); gtk_widget_set_uposition (p->shell, progress_x, progress_y); @@ -62,6 +64,10 @@ gtk_widget_set_usize (p->pbar, 200, 20); gtk_box_pack_start (vbox, p->pbar, TRUE, TRUE, 0); + p->etaIndicator = gtk_label_new ("Time remaining: ?"); + gtk_misc_set_alignment (GTK_MISC (p->etaIndicator), 1.0, 0.5); + gtk_box_pack_start (vbox, p->etaIndicator, FALSE, TRUE, 0); + button = gtk_toggle_button_new_with_label ("Cancel"); gtk_signal_connect (GTK_OBJECT (button), "clicked", (GtkSignalFunc) progress_cancel, p); @@ -69,6 +75,7 @@ gtk_widget_show (label); gtk_widget_show (p->pbar); + gtk_widget_show (p->etaIndicator); gtk_widget_show (button); gtk_widget_show (GTK_WIDGET (p->shell)); gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), 0); @@ -88,6 +95,40 @@ void progress_update (Progress_t * p, gfloat newval) { - if (p) - gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval); + struct timeval tv; + int now; + + if (!p) { + return; + } + + gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval); + + gettimeofday(&tv, NULL); + now = tv.tv_sec * 1000 + tv.tv_usec / 1000; + + if (p->firstTime == 0) { + p->lastTime = p->firstTime = now; + p->firstVal = newval; + return; + } + + if (newval > p->firstVal && now - p->lastTime > 1000) { + char buff[40]; + int remaining = (int) ((now - p->firstTime) * (1.0 - newval) / (newval - p->firstVal) / 1000.0 + 0.9); + + p->lastTime = now; + + if (remaining >= 3600) { + snprintf (buff, sizeof(buff), "Time remaining: %d h %d min", remaining / 3600, (remaining / 60) % 60); + } else if (remaining >= 600) { + snprintf (buff, sizeof(buff), "Time remaining: %d min", remaining / 60); + } else if (remaining >= 60) { + snprintf (buff, sizeof(buff), "Time remaining: %d min %d sec", remaining / 60, remaining % 60); + } else { + snprintf (buff, sizeof(buff), "Time remaining: %d sec", remaining); + } + + gtk_label_set_text (GTK_LABEL (p->etaIndicator), buff); + } } diff -ru sane-frontends-1.0.14-orig/src/progress.h sane-frontends-1.0.14/src/progress.h --- sane-frontends-1.0.14-orig/src/progress.h 2000-11-10 08:33:25.000000000 +0200 +++ sane-frontends-1.0.14/src/progress.h 2008-09-13 17:41:55.000000000 +0300 @@ -24,6 +24,10 @@ gpointer callback_data; GtkWidget *shell; GtkWidget *pbar; + GtkWidget *etaIndicator; + gfloat firstVal; + int firstTime; + int lastTime; } Progress_t;