From db8f21ca2e5e1dc4a898d8051843900b6429b24d Mon Sep 17 00:00:00 2001 From: g Date: Mon, 20 Oct 2003 20:52:46 +0000 Subject: [PATCH] Show files processed ratio in the serialization progress dialog. git-svn-id: file:///srv/svn/gliv/trunk@130 dbf4865f-1ec6-0310-8412-f61adeb1ccb1 committer: g --- src/collection.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/collection.c b/src/collection.c index 324b9dc..b52487b 100644 --- a/src/collection.c +++ b/src/collection.c @@ -128,6 +128,7 @@ static const gchar *get_a_file(const gchar * title) /*** Progress dialog ***/ static GtkLabel *file_label; +static GtkLabel *ratio_label; static GtkProgressBar *progress; static GtkWindow *progress_window; static GtkLabel *elapsed_label, *total_label, *remaining_label; @@ -169,6 +170,10 @@ static void create_progress_dialog(const gchar * filename, gboolean serialize, file_label = GTK_LABEL(gtk_label_new(NULL)); gtk_widget_show(GTK_WIDGET(file_label)); + ratio_label = GTK_LABEL(gtk_label_new(NULL)); + gtk_widget_show(GTK_WIDGET(ratio_label)); + + progress = GTK_PROGRESS_BAR(gtk_progress_bar_new()); gtk_widget_show(GTK_WIDGET(progress)); @@ -182,15 +187,16 @@ static void create_progress_dialog(const gchar * filename, gboolean serialize, gtk_widget_show(GTK_WIDGET(cancel)); - table = GTK_TABLE(gtk_table_new(6, 2, TRUE)); + table = GTK_TABLE(gtk_table_new(7, 2, TRUE)); gtk_table_attach_defaults(table, GTK_WIDGET(file_label), 0, 2, 0, 1); - gtk_table_attach_defaults(table, GTK_WIDGET(progress), 0, 2, 1, 2); + gtk_table_attach_defaults(table, GTK_WIDGET(ratio_label), 0, 2, 1, 2); + gtk_table_attach_defaults(table, GTK_WIDGET(progress), 0, 2, 2, 3); - elapsed_label = add_time_display(table, _("Elapsed time"), 2); - remaining_label = add_time_display(table, _("Remaining time"), 3); - total_label = add_time_display(table, _("Total time"), 4); + elapsed_label = add_time_display(table, _("Elapsed time"), 3); + remaining_label = add_time_display(table, _("Remaining time"), 4); + total_label = add_time_display(table, _("Total time"), 5); - gtk_table_attach_defaults(table, GTK_WIDGET(cancel), 1, 2, 5, 6); + gtk_table_attach_defaults(table, GTK_WIDGET(cancel), 1, 2, 6, 7); gtk_widget_show(GTK_WIDGET(table)); @@ -243,12 +249,13 @@ static void update_times(time_t elapsed_time, g_free(text); } -static void update_progress(const gchar * filename, gfloat ratio) +static void update_progress(const gchar * filename, gint id, gint count) { const gchar *base; static GTimeVal last = { 0, 0 }; time_t current_time, elapsed_time, total_time, remaining_time; size_t len; + gchar *ratio_text; if (filename == NULL) { /* Last update. */ @@ -298,14 +305,18 @@ static void update_progress(const gchar * filename, gfloat ratio) gtk_label_set_text(file_label, base); } - gtk_progress_bar_set_fraction(progress, ratio); + ratio_text = g_strdup_printf("%d / %d", id, count - 1); + gtk_label_set_text(ratio_label, ratio_text); + g_free(ratio_text); + + gtk_progress_bar_set_fraction(progress, (gdouble) id / (count - 1)); current_time = time(NULL); elapsed_time = current_time - start_time; - if (ratio == 0.0) + if (id == 0) total_time = 0; else - total_time = (time_t) ((gfloat) elapsed_time / ratio); + total_time = elapsed_time * (count - 1) / id; remaining_time = total_time - elapsed_time; @@ -407,25 +418,13 @@ static gboolean write_thumb(tree_item * item, FILE * file) return fwrite(gdk_pixbuf_get_pixels(thumb), 1, len, file) == len; } -static gchar *get_path(tree_item * item, serialization_data * work) -{ - gchar *path = item->path; - - if (path[0] == '/') - path = g_strdup(path); - else - path = g_build_filename(work->cwd, path, NULL); - - return path; -} - static gboolean serialize_file(GNode * tree, serialization_data * work) { tree_item *item = tree->data; FILE *file = work->file; gchar *path; - update_progress(item->path, (gfloat) work->file_id / (work->count - 1)); + update_progress(item->path, work->file_id, work->count); WRITE(file, ""); @@ -726,7 +725,7 @@ gint load_dot_gliv_from_file(FILE * file, gboolean reverse) goto error; items[i] = item; - update_progress(item->path, (gfloat) i / (count - 1)); + update_progress(item->path, i, count); if (cancel) { i++; @@ -737,7 +736,7 @@ gint load_dot_gliv_from_file(FILE * file, gboolean reverse) CHECK_MAGIC(file, ""); - update_progress(NULL, 1.0); + update_progress(NULL, count - 1, count); filenames = g_new(gchar *, count); for (i = 0; i < count; i++) { if (reverse) -- 2.11.4.GIT