diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | file.c | 88 | ||||
-rw-r--r-- | gtk/progress_dlg.c | 167 | ||||
-rw-r--r-- | progress_dlg.h | 27 | ||||
-rw-r--r-- | proto_hier_stats.c | 14 |
5 files changed, 229 insertions, 68 deletions
@@ -1393,6 +1393,7 @@ Ulf Lamping <ulf.lamping[AT]web.de> { top-level item for the "Frame" protocol Put the source and destination MAC addresses into the top-level item for Ethernet + Added more information to progress dialog box } Alain Magloire <alainm[AT]rcsm.ece.mcgill.ca> was kind enough to @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.285 2002/08/02 23:35:46 jmayer Exp $ + * $Id: file.c,v 1.286 2002/08/28 10:07:26 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -96,7 +96,7 @@ static guint32 prevsec, prevusec; static void read_packet(capture_file *cf, long offset); -static void rescan_packets(capture_file *cf, const char *action, +static void rescan_packets(capture_file *cf, const char *action, const char *action_item, gboolean refilter, gboolean redissect); static void set_selected_row(int row); @@ -303,7 +303,7 @@ set_display_filename(capture_file *cf) read_status_t read_cap_file(capture_file *cf, int *err) { - gchar *name_ptr, *load_msg, *load_fmt = " Loading: %s..."; + gchar *name_ptr, *load_msg, *load_fmt = "%s"; size_t msg_len; char *errmsg; char errmsg_errno[1024+1]; @@ -311,11 +311,17 @@ read_cap_file(capture_file *cf, int *err) long data_offset; progdlg_t *progbar = NULL; gboolean stop_flag; - int file_pos; + /* + * XXX - should be "off_t", but Wiretap would need more work to handle + * the full size of "off_t" on platforms where it's more than a "long" + * as well. + */ + long file_pos; float prog_val; int fd; struct stat cf_stat; GTimeVal start_time; + gchar status_str[100]; name_ptr = get_basename(cf->filename); @@ -365,13 +371,16 @@ read_cap_file(capture_file *cf, int *err) } if (progbar == NULL) { /* Create the progress bar if necessary */ - progbar = delayed_create_progress_dlg(load_msg, "Stop", + progbar = delayed_create_progress_dlg("Loading", load_msg, "Stop", &stop_flag, &start_time, prog_val); if (progbar != NULL) g_free(load_msg); } - if (progbar != NULL) - update_progress_dlg(progbar, prog_val); + if (progbar != NULL) { + g_snprintf(status_str, sizeof(status_str), + "%luKB of %luKB", file_pos / 1024, cf->f_len / 1024); + update_progress_dlg(progbar, prog_val, status_str); + } cf->progbar_nextstep += cf->progbar_quantum; } @@ -882,20 +891,24 @@ filter_packets(capture_file *cf, gchar *dftext) /* Now rescan the packet list, applying the new filter, but not throwing away information constructed on a previous pass. */ - rescan_packets(cf, "Filtering", TRUE, FALSE); + if (dftext == NULL) { + rescan_packets(cf, "Resetting", "Filter", TRUE, FALSE); + } else { + rescan_packets(cf, "Filtering", dftext, TRUE, FALSE); + } return 1; } void colorize_packets(capture_file *cf) { - rescan_packets(cf, "Colorizing", FALSE, FALSE); + rescan_packets(cf, "Colorizing", "all frames", FALSE, FALSE); } void redissect_packets(capture_file *cf) { - rescan_packets(cf, "Reprocessing", TRUE, TRUE); + rescan_packets(cf, "Reprocessing", "all frames", TRUE, TRUE); } /* Rescan the list of packets, reconstructing the CList. @@ -903,6 +916,9 @@ redissect_packets(capture_file *cf) "action" describes why we're doing this; it's used in the progress dialog box. + "action_item" describes what we're doing; it's used in the progress + dialog box. + "refilter" is TRUE if we need to re-evaluate the filter expression. "redissect" is TRUE if we need to make the dissectors reconstruct @@ -910,19 +926,20 @@ redissect_packets(capture_file *cf) some dissector has changed, meaning some dissector might construct its state differently from the way it was constructed the last time). */ static void -rescan_packets(capture_file *cf, const char *action, gboolean refilter, - gboolean redissect) +rescan_packets(capture_file *cf, const char *action, const char *action_item, + gboolean refilter, gboolean redissect) { frame_data *fdata; progdlg_t *progbar = NULL; gboolean stop_flag; - long count; + int count; int err; frame_data *selected_frame; int selected_row; int row; float prog_val; GTimeVal start_time; + gchar status_str[100]; /* Which frame, if any, is the currently selected frame? XXX - should the selected frame or the focus frame be the "current" @@ -989,11 +1006,14 @@ rescan_packets(capture_file *cf, const char *action, gboolean refilter, if (progbar == NULL) /* Create the progress bar if necessary */ - progbar = delayed_create_progress_dlg(action, "Stop", &stop_flag, + progbar = delayed_create_progress_dlg(action, action_item, "Stop", &stop_flag, &start_time, prog_val); - if (progbar != NULL) - update_progress_dlg(progbar, prog_val); + if (progbar != NULL) { + g_snprintf(status_str, sizeof(status_str), + "%4u of %u frames", count, cf->count); + update_progress_dlg(progbar, prog_val, status_str); + } cf->progbar_nextstep += cf->progbar_quantum; } @@ -1085,7 +1105,7 @@ print_packets(capture_file *cf, print_args_t *print_args) frame_data *fdata; progdlg_t *progbar = NULL; gboolean stop_flag; - long count; + int count; int err; gint *col_widths = NULL; gint data_width; @@ -1098,6 +1118,7 @@ print_packets(capture_file *cf, print_args_t *print_args) epan_dissect_t *edt = NULL; float prog_val; GTimeVal start_time; + gchar status_str[100]; cf->print_fh = open_print_dest(print_args->to_file, print_args->dest); if (cf->print_fh == NULL) @@ -1183,11 +1204,14 @@ print_packets(capture_file *cf, print_args_t *print_args) if (progbar == NULL) /* Create the progress bar if necessary */ - progbar = delayed_create_progress_dlg("Printing", "Stop", &stop_flag, + progbar = delayed_create_progress_dlg("Printing", "selected frames", "Stop", &stop_flag, &start_time, prog_val); - if (progbar != NULL) - update_progress_dlg(progbar, prog_val); + if (progbar != NULL) { + g_snprintf(status_str, sizeof(status_str), + "%4u of %u frames", count, cf->count); + update_progress_dlg(progbar, prog_val, status_str); + } cf->progbar_nextstep += cf->progbar_quantum; } @@ -1297,12 +1321,13 @@ change_time_formats(capture_file *cf) frame_data *fdata; progdlg_t *progbar = NULL; gboolean stop_flag; - long count; + int count; int row; int i; GtkStyle *pl_style; float prog_val; GTimeVal start_time; + gchar status_str[100]; /* Are there any columns with time stamps in the "command-line-specified" format? @@ -1351,11 +1376,14 @@ change_time_formats(capture_file *cf) if (progbar == NULL) /* Create the progress bar if necessary */ - progbar = delayed_create_progress_dlg("Changing time display", "Stop", + progbar = delayed_create_progress_dlg("Changing", "time display", "Stop", &stop_flag, &start_time, prog_val); - if (progbar != NULL) - update_progress_dlg(progbar, prog_val); + if (progbar != NULL) { + g_snprintf(status_str, sizeof(status_str), + "%4u of %u frames", count, cf->count); + update_progress_dlg(progbar, prog_val, status_str); + } cf->progbar_nextstep += cf->progbar_quantum; } @@ -1417,13 +1445,14 @@ find_packet(capture_file *cf, dfilter_t *sfcode) frame_data *new_fd = NULL; progdlg_t *progbar = NULL; gboolean stop_flag; - long count; + int count; int err; gboolean frame_matched; int row; epan_dissect_t *edt; float prog_val; GTimeVal start_time; + gchar status_str[100]; start_fd = cf->current_frame; if (start_fd != NULL) { @@ -1458,11 +1487,14 @@ find_packet(capture_file *cf, dfilter_t *sfcode) /* Create the progress bar if necessary */ if (progbar == NULL) - progbar = delayed_create_progress_dlg("Searching", "Cancel", + progbar = delayed_create_progress_dlg("Searching", cf->sfilter, "Cancel", &stop_flag, &start_time, prog_val); - if (progbar != NULL) - update_progress_dlg(progbar, prog_val); + if (progbar != NULL) { + g_snprintf(status_str, sizeof(status_str), + "%4u of %u frames", count, cf->count); + update_progress_dlg(progbar, prog_val, status_str); + } cf->progbar_nextstep += cf->progbar_quantum; } diff --git a/gtk/progress_dlg.c b/gtk/progress_dlg.c index 81a6ca1be0..8e1ad889a7 100644 --- a/gtk/progress_dlg.c +++ b/gtk/progress_dlg.c @@ -1,12 +1,11 @@ /* progress_dlg.c * Routines for progress-bar (modal) dialog * - * $Id: progress_dlg.c,v 1.11 2002/07/30 10:13:16 guy Exp $ + * $Id: progress_dlg.c,v 1.12 2002/08/28 10:07:37 guy Exp $ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs - * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -41,6 +40,12 @@ static void stop_cb(GtkWidget *w, gpointer data); */ struct progdlg { GtkWidget *dlg_w; /* top-level window widget */ + GTimeVal start_time; + GtkLabel *status_lb; + GtkLabel *elapsed_lb; + GtkLabel *time_left_lb; + GtkLabel *percentage_lb; + gchar title[200]; }; /* @@ -49,10 +54,11 @@ struct progdlg { * needs in order to manipulate the dialog, and return a pointer to * it. * - * The first argument is the title to give the dialog box; the second - * argument is the string to put in the "stop this operation" button; - * the third argument is a pointer to a Boolean variable that will be - * set to TRUE if the user hits that button. + * The first argument is the task to do, e.g. "Loading". + * The second argument is the item to do, e.g. "capture.cap". + * The third argument is the string to put in the "stop this operation" button. + * The fourth argument is a pointer to a Boolean variable that will be + * set to TRUE if the user hits that button. * * XXX - provide a way to specify the progress in units, with the total * number of units specified as an argument when the progress dialog @@ -65,15 +71,22 @@ struct progdlg { * be read. */ progdlg_t * -create_progress_dlg(const gchar *title, const gchar *stop_title, +create_progress_dlg(const gchar *task_title, const gchar *item_title, const gchar *stop_title, gboolean *stop_flag) { progdlg_t *dlg; - GtkWidget *dlg_w, *main_vb, *title_lb, *prog_bar, *bbox, *stop_bt; + GtkWidget *dlg_w, *main_vb, *title_lb, *status_lb, *elapsed_lb, *time_left_lb, *percentage_lb; + GtkWidget *prog_bar, *bbox, *stop_bt; + GtkWidget *static_vb, *tmp_lb, *main_hb, *dynamic_vb, *percentage_hb; + gchar tmp[100]; + dlg = g_malloc(sizeof (progdlg_t)); - dlg_w = dlg_window_new(title); + g_snprintf(dlg->title, sizeof(dlg->title), "%s: %s", + task_title, item_title); + + dlg_w = dlg_window_new(dlg->title); gtk_window_set_modal(GTK_WINDOW(dlg_w), TRUE); /* @@ -83,30 +96,94 @@ create_progress_dlg(const gchar *title, const gchar *stop_title, gtk_container_border_width(GTK_CONTAINER(main_vb), 5); gtk_container_add(GTK_CONTAINER(dlg_w), main_vb); + + /* + * Static labels (left dialog side, labels aligned to the right) + */ + static_vb = gtk_vbox_new(FALSE, 1); + g_snprintf (tmp, sizeof(tmp), "%s:", task_title); + tmp_lb = gtk_label_new(tmp); + 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); + + /* - * Put the title here as a label indicating what we're + * Dynamic labels (right dialog side, labels aligned to the left) + */ + dynamic_vb = gtk_vbox_new(FALSE, 1); + + /* + * 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(title); - gtk_box_pack_start(GTK_BOX(main_vb), title_lb, FALSE, TRUE, 3); + title_lb = gtk_label_new(item_title); + 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, 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, 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, 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, 0.0); + dlg->time_left_lb = (GtkLabel *) time_left_lb; + /* - * The progress bar. + * 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); + prog_bar = gtk_progress_bar_new(); gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE); - gtk_box_pack_start(GTK_BOX(main_vb), prog_bar, FALSE, TRUE, 3); + gtk_box_pack_start(GTK_BOX(percentage_hb), prog_bar, FALSE, TRUE, 3); + + 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; /* - * Attach a pointer to the progress bar widget to the top-level - * widget. + * Attach a pointer to the progress bar widget to the top-level widget. */ gtk_object_set_data(GTK_OBJECT(dlg_w), PROG_BAR_KEY, prog_bar); /* + * 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: cancel button. * (We put it in an HButtonBox, even though there's only one * of them, so that it doesn't expand to the width of the window.) @@ -135,16 +212,20 @@ create_progress_dlg(const gchar *title, const gchar *stop_title, dlg->dlg_w = dlg_w; + g_get_current_time(&dlg->start_time); + return dlg; } progdlg_t * -delayed_create_progress_dlg(const gchar *title, const gchar *stop_title, - gboolean *stop_flag, GTimeVal *start_time, gfloat progress) +delayed_create_progress_dlg(const gchar *task_title, const gchar *item_title, + const gchar *stop_title, gboolean *stop_flag, + GTimeVal *start_time, gfloat progress) { GTimeVal time_now; gfloat delta_time; gfloat min_display; + progdlg_t *dlg; #define INIT_DELAY 0.5 * 1e6 #define MIN_DISPLAY_DEFAULT 2.0 * 1e6 @@ -195,7 +276,12 @@ delayed_create_progress_dlg(const gchar *title, const gchar *stop_title, if (progress >= (delta_time / (delta_time + min_display))) return NULL; - return create_progress_dlg(title, stop_title, stop_flag); + dlg = create_progress_dlg(task_title, item_title, stop_title, stop_flag); + + /* set dialog start_time to the start of processing, not box creation */ + dlg->start_time = *start_time; + + return dlg; } /* @@ -228,14 +314,51 @@ stop_cb(GtkWidget *w _U_, gpointer data) } /* - * Set the percentage value of the progress bar. + * Update the progress information of the progress dialog box. */ void -update_progress_dlg(progdlg_t *dlg, gfloat percentage) +update_progress_dlg(progdlg_t *dlg, gfloat percentage, gchar *status) { GtkWidget *dlg_w = dlg->dlg_w; GtkWidget *prog_bar; + GTimeVal time_now; + gfloat delta_time; + gulong ul_left; + gulong ul_elapsed; + gulong ul_percentage; + gchar tmp[100]; + + + /* calculate some timing values */ + g_get_current_time(&time_now); + + delta_time = (time_now.tv_sec - dlg->start_time.tv_sec) * 1e6 + + time_now.tv_usec - dlg->start_time.tv_usec; + ul_percentage = percentage * 100; + ul_elapsed = delta_time / 1000 / 1000; + + /* 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); + + g_snprintf(tmp, sizeof(tmp), "%02lu:%02lu", ul_elapsed / 60, ul_elapsed % 60); + gtk_label_set_text(dlg->elapsed_lb, tmp); + + /* show "Time Left" only, + * if at least 5% and 3 seconds running (to get a useful estimation) */ + if (ul_percentage >= 5 && delta_time >= 3 * 1e6) { + ul_left = (delta_time / percentage - delta_time) / 1000 / 1000; + + g_snprintf(tmp, sizeof(tmp), "%02lu:%02lu", ul_left / 60, ul_left % 60); + gtk_label_set_text(dlg->time_left_lb, tmp); + } + /* update progress bar */ prog_bar = gtk_object_get_data(GTK_OBJECT(dlg_w), PROG_BAR_KEY); gtk_progress_bar_update(GTK_PROGRESS_BAR(prog_bar), percentage); diff --git a/progress_dlg.h b/progress_dlg.h index 2afb7ef31a..974a4ce807 100644 --- a/progress_dlg.h +++ b/progress_dlg.h @@ -1,12 +1,11 @@ /* progress_dlg.h * Definitions for progress dialog box routines * - * $Id: progress_dlg.h,v 1.2 2002/07/30 10:13:14 guy Exp $ + * $Id: progress_dlg.h,v 1.3 2002/08/28 10:07:28 guy Exp $ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs - * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -40,30 +39,32 @@ typedef struct progdlg progdlg_t; * needs in order to manipulate the dialog, and return a pointer to * it. * - * The first argument is the title to give the dialog box; the second - * argument is the string to put in the "stop this operation" button; - * the third argument is a pointer to a Boolean variable that will be - * set to TRUE if the user hits that button. + * The first argument is the task to do, e.g. "Loading". + * The second argument is the item to do, e.g. "capture.cap". + * The third argument is the string to put in the "stop this operation" button. + * The fourth argument is a pointer to a Boolean variable that will be + * set to TRUE if the user hits that button. */ -progdlg_t *create_progress_dlg(const gchar *title, const gchar *stop_title, - gboolean *stop_flag); +progdlg_t *create_progress_dlg(const gchar *task_title, const gchar *item_title, + const gchar *stop_title, gboolean *stop_flag); /* Create a progress dialog, but only if it's not likely to disappear * immediately, which can be disconcerting for the user. * - * The first three arguments are as for create_progress_dlg(). + * The first four arguments are as for create_progress_dlg(). * Following those is a pointer to a GTimeVal structure which holds * the time at which the caller started to process the data, and the * current progress (0..1). */ -progdlg_t *delayed_create_progress_dlg(const gchar *title, +progdlg_t * +delayed_create_progress_dlg(const gchar *task_title, const gchar *item_title, const gchar *stop_title, gboolean *stop_flag, GTimeVal *start_time, gfloat progress); /* - * Set the percentage value of the progress bar. + * Update the progress information of the progress dialog box. */ -void update_progress_dlg(progdlg_t *dlg, gfloat percentage); +void update_progress_dlg(progdlg_t *dlg, gfloat percentage, gchar *status); /* * Destroy the progress bar. diff --git a/proto_hier_stats.c b/proto_hier_stats.c index db2e65ab91..b95c3aa538 100644 --- a/proto_hier_stats.c +++ b/proto_hier_stats.c @@ -1,7 +1,7 @@ /* proto_hier_stats.c * Routines for calculating statistics based on protocol. * - * $Id: proto_hier_stats.c,v 1.14 2002/07/30 10:13:14 guy Exp $ + * $Id: proto_hier_stats.c,v 1.15 2002/08/28 10:07:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -154,9 +154,10 @@ ph_stats_new(void) guint tot_packets, tot_bytes; progdlg_t *progbar = NULL; gboolean stop_flag; - long count; + int count; float prog_val; GTimeVal start_time; + gchar status_str[100]; /* Initialize the data */ ps = g_new(ph_stats_t, 1); @@ -196,11 +197,14 @@ ph_stats_new(void) if (progbar == NULL) /* Create the progress bar if necessary */ progbar = delayed_create_progress_dlg( - "Computing protocol statistics", "Stop", + "Computing", "protocol hierarchy statistics", "Stop", &stop_flag, &start_time, prog_val); - if (progbar != NULL) - update_progress_dlg(progbar, prog_val); + if (progbar != NULL) { + g_snprintf(status_str, sizeof(status_str), + "%4u of %u frames", count, cfile.count); + update_progress_dlg(progbar, prog_val, status_str); + } cfile.progbar_nextstep += cfile.progbar_quantum; } |