2000-07-03 08:36:52 +00:00
|
|
|
/* progress_dlg.c
|
|
|
|
* Routines for progress-bar (modal) dialog
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-07-03 08:36:52 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2000-07-03 08:36:52 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-07-03 08:36:52 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-07-03 08:36:52 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-07-03 08:36:52 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2004-01-02 13:27:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2002-09-05 18:48:52 +00:00
|
|
|
#include <gtk/gtk.h>
|
2000-07-03 08:36:52 +00:00
|
|
|
#include "gtkglobals.h"
|
2000-07-05 02:45:42 +00:00
|
|
|
#include "dlg_utils.h"
|
2005-08-20 12:09:48 +00:00
|
|
|
#include "gui_utils.h"
|
2001-03-24 02:07:22 +00:00
|
|
|
#include "progress_dlg.h"
|
2002-11-11 15:39:06 +00:00
|
|
|
#include "compat_macros.h"
|
2000-07-03 08:36:52 +00:00
|
|
|
|
|
|
|
#define PROG_BAR_KEY "progress_bar"
|
|
|
|
|
2000-07-07 07:01:58 +00:00
|
|
|
static gint delete_event_cb(GtkWidget *w, GdkEvent *event, gpointer data);
|
|
|
|
static void stop_cb(GtkWidget *w, gpointer data);
|
2000-07-03 08:36:52 +00:00
|
|
|
|
|
|
|
/*
|
2000-07-07 07:01:58 +00:00
|
|
|
* Define the structure describing a progress dialog.
|
|
|
|
*/
|
|
|
|
struct progdlg {
|
|
|
|
GtkWidget *dlg_w; /* top-level window widget */
|
2002-08-28 10:07:37 +00:00
|
|
|
GTimeVal start_time;
|
2004-01-02 13:27:00 +00:00
|
|
|
GTimeVal last_time; /* last time it was updated */
|
|
|
|
|
2002-08-28 10:07:37 +00:00
|
|
|
GtkLabel *status_lb;
|
|
|
|
GtkLabel *elapsed_lb;
|
|
|
|
GtkLabel *time_left_lb;
|
|
|
|
GtkLabel *percentage_lb;
|
2004-02-01 13:12:10 +00:00
|
|
|
gchar *title;
|
2000-07-07 07:01:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create and pop up the progress dialog; allocate a "progdlg_t"
|
|
|
|
* and initialize it to contain all information the implementation
|
|
|
|
* needs in order to manipulate the dialog, and return a pointer to
|
|
|
|
* it.
|
2000-07-03 08:36:52 +00:00
|
|
|
*
|
2002-08-28 10:07:37 +00:00
|
|
|
* The first argument is the task to do, e.g. "Loading".
|
|
|
|
* The second argument is the item to do, e.g. "capture.cap".
|
2005-11-12 11:05:02 +00:00
|
|
|
* The third argument is TRUE if the "terminate this operation" button should
|
|
|
|
* be a "Stop" button (meaning that the operation is stopped, but not undone),
|
|
|
|
* and FALSE if it should be a "Cancel" button (meaning that it's stopped
|
|
|
|
* and anything it's done would be undone)
|
2002-08-28 10:07:37 +00:00
|
|
|
* The fourth argument is a pointer to a Boolean variable that will be
|
|
|
|
* set to TRUE if the user hits that button.
|
2000-07-03 08:36:52 +00:00
|
|
|
*
|
|
|
|
* XXX - provide a way to specify the progress in units, with the total
|
|
|
|
* number of units specified as an argument when the progress dialog
|
|
|
|
* is created; updates would be given in units, with the progress dialog
|
|
|
|
* code computing the percentage, and the progress bar would have a
|
|
|
|
* label "0" on the left and <total number of units> on the right, with
|
|
|
|
* a label in the middle giving the number of units we've processed
|
|
|
|
* so far. This could be used when filtering packets, for example; we
|
|
|
|
* wouldn't always use it, as we have no idea how many packets are to
|
|
|
|
* be read.
|
|
|
|
*/
|
2000-07-07 07:01:58 +00:00
|
|
|
progdlg_t *
|
2002-11-03 17:38:45 +00:00
|
|
|
create_progress_dlg(const gchar *task_title, const gchar *item_title,
|
2005-11-12 11:05:02 +00:00
|
|
|
gboolean terminate_is_stop, gboolean *stop_flag)
|
2000-07-03 08:36:52 +00:00
|
|
|
{
|
2005-11-12 11:05:02 +00:00
|
|
|
progdlg_t *dlg;
|
|
|
|
GtkWidget *dlg_w, *main_vb, *title_lb, *status_lb, *elapsed_lb, *time_left_lb, *percentage_lb;
|
|
|
|
GtkWidget *prog_bar, *bbox, *cancel_bt;
|
|
|
|
GtkWidget *static_vb, *tmp_lb, *main_hb, *dynamic_vb, *percentage_hb;
|
|
|
|
gchar *task_title_dup;
|
2004-02-01 13:12:10 +00:00
|
|
|
gchar *item_title_dup;
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
dlg = g_malloc(sizeof (progdlg_t));
|
2000-07-07 07:01:58 +00:00
|
|
|
|
2004-02-01 13:12:10 +00:00
|
|
|
/* limit the item_title to some reasonable length */
|
|
|
|
item_title_dup = g_strdup(item_title);
|
|
|
|
if (strlen(item_title_dup) > 110) {
|
2008-02-01 01:07:58 +00:00
|
|
|
strncpy(&item_title_dup[100], "...", 4);
|
2004-02-01 13:12:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dlg->title = g_strdup_printf("%s: %s", task_title, item_title_dup);
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
dlg_w = dlg_window_new(dlg->title);
|
|
|
|
gtk_window_set_modal(GTK_WINDOW(dlg_w), TRUE);
|
2000-07-03 08:36:52 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
/*
|
|
|
|
* Container for dialog widgets.
|
|
|
|
*/
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 1);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(dlg_w), main_vb);
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
/*
|
|
|
|
* Static labels (left dialog side, labels aligned to the right)
|
|
|
|
*/
|
|
|
|
static_vb = gtk_vbox_new(FALSE, 1);
|
|
|
|
task_title_dup = g_strdup_printf ("%s:", task_title);
|
|
|
|
tmp_lb = gtk_label_new(task_title_dup);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0, 0.0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
|
|
|
|
tmp_lb = gtk_label_new("Status:");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0, 0.0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
|
|
|
|
tmp_lb = gtk_label_new("Elapsed Time:");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0, 0.0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
|
|
|
|
tmp_lb = gtk_label_new("Time Left:");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0, 0.0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
|
|
|
|
tmp_lb = gtk_label_new("Progress:");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0, 0.0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dynamic labels (right dialog side, labels aligned to the left)
|
|
|
|
*/
|
|
|
|
dynamic_vb = gtk_vbox_new(FALSE, 1);
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
/*
|
|
|
|
* Put the item_title here as a label indicating what we're
|
|
|
|
* doing; set its alignment and padding so it's aligned on the
|
|
|
|
* left.
|
|
|
|
*/
|
|
|
|
title_lb = gtk_label_new(item_title_dup);
|
|
|
|
gtk_box_pack_start(GTK_BOX(dynamic_vb), title_lb, FALSE, TRUE, 3);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(title_lb), 0.0, 0.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(title_lb), 0, 0);
|
|
|
|
|
|
|
|
/* same for "Status" */
|
|
|
|
status_lb = gtk_label_new("");
|
|
|
|
gtk_box_pack_start(GTK_BOX(dynamic_vb), status_lb, FALSE, TRUE, 3);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(status_lb), 0.0, 0.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(status_lb), 0, 0);
|
|
|
|
dlg->status_lb = (GtkLabel *) status_lb;
|
|
|
|
|
|
|
|
/* same for "Elapsed Time" */
|
|
|
|
elapsed_lb = gtk_label_new("00:00");
|
|
|
|
gtk_box_pack_start(GTK_BOX(dynamic_vb), elapsed_lb, FALSE, TRUE, 3);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(elapsed_lb), 0.0, 0.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(elapsed_lb), 0, 0);
|
|
|
|
dlg->elapsed_lb = (GtkLabel *) elapsed_lb;
|
|
|
|
|
|
|
|
/* same for "Time Left" */
|
|
|
|
time_left_lb = gtk_label_new("--:--");
|
|
|
|
gtk_box_pack_start(GTK_BOX(dynamic_vb), time_left_lb, FALSE, TRUE, 3);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(time_left_lb), 0.0, 0.0);
|
|
|
|
gtk_misc_set_padding(GTK_MISC(time_left_lb), 0, 0);
|
|
|
|
dlg->time_left_lb = (GtkLabel *) time_left_lb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The progress bar (in its own horizontal box, including
|
|
|
|
* percentage value)
|
|
|
|
*/
|
|
|
|
percentage_hb = gtk_hbox_new(FALSE, 1);
|
|
|
|
gtk_box_pack_start(GTK_BOX(dynamic_vb), percentage_hb, FALSE, TRUE, 3);
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
prog_bar = gtk_progress_bar_new();
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2005-11-12 11:05:02 +00:00
|
|
|
gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE);
|
2002-11-03 17:38:45 +00:00
|
|
|
#endif
|
2005-11-12 11:05:02 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(percentage_hb), prog_bar, FALSE, TRUE, 3);
|
2000-07-03 08:36:52 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
percentage_lb = gtk_label_new(" 0%");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(percentage_lb), 0.0, 0.0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(percentage_hb), percentage_lb, FALSE, TRUE, 3);
|
|
|
|
dlg->percentage_lb = (GtkLabel *) percentage_lb;
|
2000-07-03 08:36:52 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
/*
|
|
|
|
* Attach a pointer to the progress bar widget to the top-level widget.
|
|
|
|
*/
|
|
|
|
OBJECT_SET_DATA(dlg_w, PROG_BAR_KEY, prog_bar);
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
/*
|
|
|
|
* Static and dynamic boxes are now complete
|
|
|
|
*/
|
|
|
|
main_hb = gtk_hbox_new(FALSE, 1);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), static_vb, FALSE, TRUE, 3);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), dynamic_vb, FALSE, TRUE, 3);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), main_hb, FALSE, TRUE, 3);
|
|
|
|
|
|
|
|
/* Button row */
|
|
|
|
bbox = dlg_button_row_new(terminate_is_stop ? GTK_STOCK_STOP :
|
|
|
|
GTK_STOCK_CANCEL, NULL);
|
2004-01-21 22:00:28 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), bbox);
|
|
|
|
gtk_widget_show(bbox);
|
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
cancel_bt = OBJECT_GET_DATA(bbox, terminate_is_stop ? GTK_STOCK_STOP :
|
|
|
|
GTK_STOCK_CANCEL);
|
2004-01-21 22:00:28 +00:00
|
|
|
gtk_widget_grab_default(cancel_bt);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
/*
|
|
|
|
* Allow user to either click the "Cancel"/"Stop" button, or
|
|
|
|
* the close button on the window, to stop an operation in
|
|
|
|
* progress.
|
|
|
|
*/
|
|
|
|
SIGNAL_CONNECT(cancel_bt, "clicked", stop_cb, stop_flag);
|
|
|
|
SIGNAL_CONNECT(dlg_w, "delete_event", delete_event_cb, stop_flag);
|
2000-07-03 08:36:52 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
gtk_widget_show_all(dlg_w);
|
2000-07-03 08:36:52 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
dlg->dlg_w = dlg_w;
|
2000-07-07 07:01:58 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
g_get_current_time(&dlg->start_time);
|
|
|
|
memset(&dlg->last_time, 0, sizeof(dlg->last_time));
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2004-02-01 13:12:10 +00:00
|
|
|
g_free(task_title_dup);
|
|
|
|
g_free(item_title_dup);
|
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
return dlg;
|
2000-07-03 08:36:52 +00:00
|
|
|
}
|
|
|
|
|
2002-07-30 10:13:16 +00:00
|
|
|
progdlg_t *
|
2002-08-28 21:04:11 +00:00
|
|
|
delayed_create_progress_dlg(const gchar *task_title, const gchar *item_title,
|
2005-11-12 11:05:02 +00:00
|
|
|
gboolean terminate_is_stop, gboolean *stop_flag,
|
|
|
|
const GTimeVal *start_time, gfloat progress)
|
2002-07-30 10:13:16 +00:00
|
|
|
{
|
2002-11-03 17:38:45 +00:00
|
|
|
GTimeVal time_now;
|
2004-01-05 18:11:28 +00:00
|
|
|
gdouble delta_time;
|
|
|
|
gdouble min_display;
|
2002-11-03 17:38:45 +00:00
|
|
|
progdlg_t *dlg;
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-08-28 22:28:43 +00:00
|
|
|
#define INIT_DELAY 0.1 * 1e6
|
2002-07-30 10:13:16 +00:00
|
|
|
#define MIN_DISPLAY_DEFAULT 2.0 * 1e6
|
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
/* Create a progress dialog, but only if it's not likely to disappear
|
|
|
|
* immediately, which can be disconcerting for the user.
|
|
|
|
*
|
|
|
|
* Arguments are as for create_progress_dlg(), plus:
|
|
|
|
*
|
|
|
|
* (a) A pointer to a GTimeVal structure which holds the time at which
|
|
|
|
* the caller started to process the data.
|
|
|
|
* (b) The current progress as a real number between 0 and 1.
|
|
|
|
*/
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
g_get_current_time(&time_now);
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
/* Get the time elapsed since the caller started processing the data */
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
delta_time = (time_now.tv_sec - start_time->tv_sec) * 1e6 +
|
|
|
|
time_now.tv_usec - start_time->tv_usec;
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
/* Do nothing for the first INIT_DELAY microseconds */
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
if (delta_time < INIT_DELAY)
|
|
|
|
return NULL;
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
/* If we create the progress dialog we want it to be displayed for a
|
|
|
|
* minimum of MIN_DISPLAY_DEFAULT microseconds. However, if we
|
|
|
|
* previously estimated that the progress dialog didn't need to be
|
|
|
|
* created and the caller's processing is slowing down (perhaps due
|
|
|
|
* to the action of the operating system's scheduler on a compute-
|
|
|
|
* intensive task), we tail off the minimum display time such that
|
|
|
|
* the progress dialog will always be created after
|
|
|
|
* 2*MIN_DISPLAY_DEFAULT microseconds.
|
|
|
|
*/
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
if (delta_time <= INIT_DELAY + MIN_DISPLAY_DEFAULT)
|
|
|
|
min_display = MIN_DISPLAY_DEFAULT;
|
|
|
|
else
|
|
|
|
min_display = 2 * MIN_DISPLAY_DEFAULT - delta_time;
|
|
|
|
/* = MIN_DISPLAY_DEFAULT - (delta_time - MIN_DISPLAY_DEFAULT) */
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
/* Assuming the progress increases linearly, see if the progress
|
|
|
|
* dialog would be displayed for at least min_display microseconds if
|
|
|
|
* we created it now.
|
|
|
|
*/
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
if (progress >= (delta_time / (delta_time + min_display)))
|
|
|
|
return NULL;
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
dlg = create_progress_dlg(task_title, item_title, terminate_is_stop,
|
|
|
|
stop_flag);
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2006-11-21 00:40:36 +00:00
|
|
|
/*
|
|
|
|
* Flush out the dialog so we don't see an "empty" one until first update.
|
|
|
|
*/
|
|
|
|
while (gtk_events_pending())
|
|
|
|
gtk_main_iteration();
|
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
/* set dialog start_time to the start of processing, not box creation */
|
|
|
|
dlg->start_time = *start_time;
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
return dlg;
|
2002-07-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
2000-07-03 08:36:52 +00:00
|
|
|
/*
|
|
|
|
* Called when the dialog box is to be deleted.
|
2000-07-07 23:09:15 +00:00
|
|
|
* Set the "stop" flag to TRUE, and return TRUE - we don't want the dialog
|
|
|
|
* box deleted now, our caller will do so when they see that the
|
|
|
|
* "stop" flag is TRUE and abort the operation.
|
2000-07-03 08:36:52 +00:00
|
|
|
*/
|
2000-07-07 07:01:58 +00:00
|
|
|
static gint
|
2002-03-05 11:56:00 +00:00
|
|
|
delete_event_cb(GtkWidget *w _U_, GdkEvent *event _U_, gpointer data)
|
2000-07-03 08:36:52 +00:00
|
|
|
{
|
2000-07-07 23:09:15 +00:00
|
|
|
gboolean *stop_flag = (gboolean *) data;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-07-07 23:09:15 +00:00
|
|
|
*stop_flag = TRUE;
|
|
|
|
return TRUE;
|
2000-07-03 08:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-07-07 07:01:58 +00:00
|
|
|
* Called when the "stop this operation" button is clicked.
|
2000-07-07 23:09:15 +00:00
|
|
|
* Set the "stop" flag to TRUE; we don't have to destroy the dialog
|
|
|
|
* box, as our caller will do so when they see that the "stop" flag is
|
|
|
|
* true and abort the operation.
|
2000-07-03 08:36:52 +00:00
|
|
|
*/
|
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
stop_cb(GtkWidget *w _U_, gpointer data)
|
2000-07-03 08:36:52 +00:00
|
|
|
{
|
|
|
|
gboolean *stop_flag = (gboolean *) data;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-07-03 08:36:52 +00:00
|
|
|
*stop_flag = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-08-28 10:07:37 +00:00
|
|
|
* Update the progress information of the progress dialog box.
|
2000-07-03 08:36:52 +00:00
|
|
|
*/
|
|
|
|
void
|
2005-08-06 14:03:14 +00:00
|
|
|
update_progress_dlg(progdlg_t *dlg, gfloat percentage, const gchar *status)
|
2000-07-03 08:36:52 +00:00
|
|
|
{
|
2000-07-07 07:01:58 +00:00
|
|
|
GtkWidget *dlg_w = dlg->dlg_w;
|
2000-07-03 08:36:52 +00:00
|
|
|
GtkWidget *prog_bar;
|
2002-08-28 10:07:37 +00:00
|
|
|
GTimeVal time_now;
|
2004-01-05 18:11:28 +00:00
|
|
|
gdouble delta_time;
|
2002-08-28 10:07:37 +00:00
|
|
|
gulong ul_left;
|
|
|
|
gulong ul_elapsed;
|
|
|
|
gulong ul_percentage;
|
|
|
|
gchar tmp[100];
|
|
|
|
|
|
|
|
|
|
|
|
/* calculate some timing values */
|
|
|
|
g_get_current_time(&time_now);
|
2004-01-02 13:27:00 +00:00
|
|
|
|
|
|
|
delta_time = (time_now.tv_sec - dlg->last_time.tv_sec) * 1e6 +
|
|
|
|
time_now.tv_usec - dlg->last_time.tv_usec;
|
|
|
|
|
|
|
|
/* after the first time don't update more than every 100ms */
|
|
|
|
if (dlg->last_time.tv_sec && delta_time < 100*1000)
|
|
|
|
return;
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2004-01-02 13:27:00 +00:00
|
|
|
dlg->last_time = time_now;
|
2002-08-28 10:07:37 +00:00
|
|
|
delta_time = (time_now.tv_sec - dlg->start_time.tv_sec) * 1e6 +
|
|
|
|
time_now.tv_usec - dlg->start_time.tv_usec;
|
2004-01-02 13:27:00 +00:00
|
|
|
|
2003-12-23 00:16:46 +00:00
|
|
|
ul_percentage = (gulong) (percentage * 100);
|
|
|
|
ul_elapsed = (gulong) (delta_time / 1000 / 1000);
|
2004-01-02 13:27:00 +00:00
|
|
|
|
2002-08-28 10:07:37 +00:00
|
|
|
/* update labels */
|
|
|
|
g_snprintf(tmp, sizeof(tmp), "%lu%% of %s", ul_percentage, dlg->title);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(dlg_w), tmp);
|
|
|
|
|
|
|
|
gtk_label_set_text(dlg->status_lb, status);
|
|
|
|
|
|
|
|
g_snprintf(tmp, sizeof(tmp), "%lu%%", ul_percentage);
|
|
|
|
gtk_label_set_text(dlg->percentage_lb, tmp);
|
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
g_snprintf(tmp, sizeof(tmp), "%02lu:%02lu", ul_elapsed / 60,
|
|
|
|
ul_elapsed % 60);
|
2002-08-28 10:07:37 +00:00
|
|
|
gtk_label_set_text(dlg->elapsed_lb, tmp);
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
/* show "Time Left" only,
|
2002-08-28 10:07:37 +00:00
|
|
|
* if at least 5% and 3 seconds running (to get a useful estimation) */
|
|
|
|
if (ul_percentage >= 5 && delta_time >= 3 * 1e6) {
|
2003-12-23 00:16:46 +00:00
|
|
|
ul_left = (gulong) ((delta_time / percentage - delta_time) / 1000 / 1000);
|
2002-08-28 10:07:37 +00:00
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
g_snprintf(tmp, sizeof(tmp), "%02lu:%02lu", ul_left / 60,
|
|
|
|
ul_left % 60);
|
2002-08-28 10:07:37 +00:00
|
|
|
gtk_label_set_text(dlg->time_left_lb, tmp);
|
|
|
|
}
|
2000-07-03 08:36:52 +00:00
|
|
|
|
2002-08-28 10:07:37 +00:00
|
|
|
/* update progress bar */
|
2002-11-11 15:39:06 +00:00
|
|
|
prog_bar = OBJECT_GET_DATA(dlg_w, PROG_BAR_KEY);
|
2002-11-03 17:38:45 +00:00
|
|
|
#if GTK_MAJOR_VERSION < 2
|
2000-07-03 08:36:52 +00:00
|
|
|
gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), percentage);
|
2002-11-03 17:38:45 +00:00
|
|
|
#else
|
|
|
|
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(prog_bar), percentage);
|
|
|
|
#endif
|
2000-07-03 08:36:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush out the update and process any input events.
|
|
|
|
*/
|
|
|
|
while (gtk_events_pending())
|
|
|
|
gtk_main_iteration();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-07-07 07:01:58 +00:00
|
|
|
* Destroy the progress dialog.
|
2000-07-03 08:36:52 +00:00
|
|
|
*/
|
|
|
|
void
|
2000-07-07 07:01:58 +00:00
|
|
|
destroy_progress_dlg(progdlg_t *dlg)
|
2000-07-03 08:36:52 +00:00
|
|
|
{
|
2005-11-12 11:05:02 +00:00
|
|
|
GtkWidget *dlg_w = dlg->dlg_w;
|
2000-07-03 08:36:52 +00:00
|
|
|
|
2005-11-12 11:05:02 +00:00
|
|
|
window_destroy(GTK_WIDGET(dlg_w));
|
2004-02-01 13:12:10 +00:00
|
|
|
g_free(dlg->title);
|
2005-11-12 11:05:02 +00:00
|
|
|
g_free(dlg);
|
2000-07-07 07:01:58 +00:00
|
|
|
}
|