- added printing of estimated scan time remaining in progress

popup, based on a patch by
	  Jonas Berlin <xkr47@outerspace.dyndns.org>
merge-requests/2/head gitconversion
Stéphane Voltz 2008-09-23 19:37:56 +00:00
rodzic fe7c5b707c
commit 9d6c0a1c08
3 zmienionych plików z 86 dodań i 7 usunięć

Wyświetl plik

@ -1,3 +1,8 @@
2008-09-23 Stéphane Voltz <stef.dev@free.fr>
* src/progress.c src/progress.h: add an estimated time remaining
on the progress window, based on a patch by Jonas Berlin
<xkr47@outerspace.dyndns.org>
2008-08-05 Julien Blache <jb@jblache.org> 2008-08-05 Julien Blache <jb@jblache.org>
* src/scanadf.c: fetch_options(): get option descriptor for option 0 * src/scanadf.c: fetch_options(): get option descriptor for option 0
before getting the value for option 0. before getting the value for option 0.

Wyświetl plik

@ -20,6 +20,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "progress.h" #include "progress.h"
@ -33,25 +36,26 @@ progress_cancel (GtkWidget * widget, gpointer data)
Progress_t * Progress_t *
progress_new (char *title, char *text, GtkWindow *parent, progress_new (char *title, char *text, GtkWindow * parent,
GtkSignalFunc callback, gpointer callback_data) GtkSignalFunc callback, gpointer callback_data)
{ {
GtkWidget *button, *label; GtkWidget *button, *label;
GtkBox *vbox, *hbox; GtkBox *vbox, *hbox;
Progress_t *p; Progress_t *p;
#if GTK_MAJOR_VERSION < 2 #if GTK_MAJOR_VERSION < 2
gint x,y; gint x, y;
#endif #endif
p = (Progress_t *) malloc (sizeof (Progress_t)); p = (Progress_t *) malloc (sizeof (Progress_t));
p->callback = callback; p->callback = callback;
p->firstTime = 0;
p->shell = gtk_dialog_new (); p->shell = gtk_dialog_new ();
#if GTK_MAJOR_VERSION < 2 #if GTK_MAJOR_VERSION < 2
gtk_window_get_position (GTK_WINDOW(parent), &x, &y); gtk_window_get_position (GTK_WINDOW (parent), &x, &y);
gtk_widget_set_uposition (p->shell, x, y); gtk_widget_set_uposition (p->shell, x, y);
#else #else
gtk_window_set_transient_for (GTK_WINDOW (p->shell),parent); gtk_window_set_transient_for (GTK_WINDOW (p->shell), parent);
#endif #endif
gtk_window_set_title (GTK_WINDOW (p->shell), title); gtk_window_set_title (GTK_WINDOW (p->shell), title);
vbox = GTK_BOX (GTK_DIALOG (p->shell)->vbox); vbox = GTK_BOX (GTK_DIALOG (p->shell)->vbox);
@ -67,17 +71,26 @@ progress_new (char *title, char *text, GtkWindow *parent,
gtk_widget_set_usize (p->pbar, 200, 20); gtk_widget_set_usize (p->pbar, 200, 20);
gtk_box_pack_start (vbox, p->pbar, TRUE, TRUE, 0); gtk_box_pack_start (vbox, p->pbar, TRUE, TRUE, 0);
#ifdef HAVE_SYS_TIME_H
p->etaIndicator = gtk_label_new (ETA_LABEL ": ?");
gtk_misc_set_alignment (GTK_MISC (p->etaIndicator), 0.0, 0.5);
gtk_box_pack_start (vbox, p->etaIndicator, FALSE, TRUE, 0);
#endif
/* no cancel button if no callback */ /* no cancel button if no callback */
if (callback != NULL) if (callback != NULL)
{ {
button = gtk_toggle_button_new_with_label ("Cancel"); button = gtk_toggle_button_new_with_label ("Cancel");
gtk_signal_connect (GTK_OBJECT (button), "clicked", gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) progress_cancel, p); (GtkSignalFunc) progress_cancel, p);
gtk_box_pack_start (hbox, button, TRUE, TRUE, 0); gtk_box_pack_start (hbox, button, TRUE, TRUE, 0);
} }
gtk_widget_show (label); gtk_widget_show (label);
gtk_widget_show (p->pbar); gtk_widget_show (p->pbar);
#ifdef HAVE_SYS_TIME_H
gtk_widget_show (p->etaIndicator);
#endif
if (callback != NULL) if (callback != NULL)
gtk_widget_show (button); gtk_widget_show (button);
gtk_widget_show (GTK_WIDGET (p->shell)); gtk_widget_show (GTK_WIDGET (p->shell));
@ -98,6 +111,61 @@ progress_free (Progress_t * p)
void void
progress_update (Progress_t * p, gfloat newval) progress_update (Progress_t * p, gfloat newval)
{ {
if (p) #ifdef HAVE_SYS_TIME_H
gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval); struct timeval tv;
int now;
char buff[40];
int remaining;
#endif
if (!p)
{
return;
}
gtk_progress_bar_update (GTK_PROGRESS_BAR (p->pbar), newval);
#ifdef HAVE_SYS_TIME_H
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)
{
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), ETA_LABEL ": %d h %d min",
remaining / 3600, (remaining / 60) % 60);
}
else if (remaining >= 600)
{
snprintf (buff, sizeof (buff), ETA_LABEL ": %d min",
remaining / 60);
}
else if (remaining >= 60)
{
snprintf (buff, sizeof (buff), ETA_LABEL ": %d min %d sec",
remaining / 60, remaining % 60);
}
else
{
snprintf (buff, sizeof (buff), ETA_LABEL ": %d sec", remaining);
}
gtk_label_set_text (GTK_LABEL (p->etaIndicator), buff);
}
#endif
} }

Wyświetl plik

@ -18,12 +18,18 @@
#ifndef progress_h #ifndef progress_h
#define progress_h #define progress_h
#define ETA_LABEL "Estimated time remaining"
typedef struct Progress_t typedef struct Progress_t
{ {
GtkSignalFunc callback; GtkSignalFunc callback;
gpointer callback_data; gpointer callback_data;
GtkWidget *shell; GtkWidget *shell;
GtkWidget *pbar; GtkWidget *pbar;
GtkWidget *etaIndicator;
gfloat firstVal;
int firstTime;
int lastTime;
} }
Progress_t; Progress_t;