diff options
author | Guy Harris <guy@alum.mit.edu> | 2005-11-12 11:05:02 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2005-11-12 11:05:02 +0000 |
commit | 0dbf17b690f9f79960d67f5f8a58ad0b1e90965f (patch) | |
tree | f6374552ea26d82fdeba18a3587c5ee7e63554a1 /gtk | |
parent | a78d2fbc63c42126d55b8b3871d19d25c4577761 (diff) | |
download | wireshark-0dbf17b690f9f79960d67f5f8a58ad0b1e90965f.tar.gz wireshark-0dbf17b690f9f79960d67f5f8a58ad0b1e90965f.tar.bz2 wireshark-0dbf17b690f9f79960d67f5f8a58ad0b1e90965f.zip |
Allow a progress dialog to have "Stop" or "Cancel" as the "terminate
button"; "Stop" should be used for operations that can only be stopped
(meaning that what it's already done isn't undone), not cancelled
(meaning that whatever it's already done *is* undone), for which
"Cancel" is used.
Allow the merging process to be cancelled.
Clean up indentation.
Update some comments.
svn path=/trunk/; revision=16489
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/packet_list.c | 2 | ||||
-rw-r--r-- | gtk/progress_dlg.c | 244 | ||||
-rw-r--r-- | gtk/proto_draw.c | 1 | ||||
-rw-r--r-- | gtk/rtp_analysis.c | 3 |
4 files changed, 129 insertions, 121 deletions
diff --git a/gtk/packet_list.c b/gtk/packet_list.c index 10e3cd4ec2..8b1e2bc789 100644 --- a/gtk/packet_list.c +++ b/gtk/packet_list.c @@ -642,7 +642,7 @@ packet_list_resize_columns(void) { time in order to get to the next progress bar step). */ if (progbar == NULL) progbar = delayed_create_progress_dlg("Resizing", "Resize Columns", - &progbar_stop_flag, &progbar_start_time, progbar_val); + TRUE, &progbar_stop_flag, &progbar_start_time, progbar_val); if (i >= progbar_nextstep) { /* let's not divide by zero. I should never be started diff --git a/gtk/progress_dlg.c b/gtk/progress_dlg.c index 1adb0a9743..135cd01767 100644 --- a/gtk/progress_dlg.c +++ b/gtk/progress_dlg.c @@ -63,7 +63,10 @@ struct progdlg { * * 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 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) * The fourth argument is a pointer to a Boolean variable that will be * set to TRUE if the user hits that button. * @@ -79,16 +82,16 @@ struct progdlg { */ progdlg_t * create_progress_dlg(const gchar *task_title, const gchar *item_title, - gboolean *stop_flag) + gboolean terminate_is_stop, gboolean *stop_flag) { - 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; + 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; gchar *item_title_dup; - dlg = g_malloc(sizeof (progdlg_t)); + dlg = g_malloc(sizeof (progdlg_t)); /* limit the item_title to some reasonable length */ item_title_dup = g_strdup(item_title); @@ -98,138 +101,140 @@ create_progress_dlg(const gchar *task_title, const gchar *item_title, dlg->title = g_strdup_printf("%s: %s", task_title, item_title_dup); - dlg_w = dlg_window_new(dlg->title); - gtk_window_set_modal(GTK_WINDOW(dlg_w), TRUE); + dlg_w = dlg_window_new(dlg->title); + gtk_window_set_modal(GTK_WINDOW(dlg_w), TRUE); - /* - * 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); - - /* - * 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); + /* + * 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); - /* - * 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; + /* + * 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); - /* - * 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); + /* + * 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); - prog_bar = gtk_progress_bar_new(); + prog_bar = gtk_progress_bar_new(); #if GTK_MAJOR_VERSION < 2 - gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE); + gtk_progress_set_activity_mode(GTK_PROGRESS(prog_bar), FALSE); #endif - 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; + gtk_box_pack_start(GTK_BOX(percentage_hb), prog_bar, FALSE, TRUE, 3); - /* - * Attach a pointer to the progress bar widget to the top-level widget. - */ - OBJECT_SET_DATA(dlg_w, PROG_BAR_KEY, prog_bar); + 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; - /* - * 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); + /* + * Attach a pointer to the progress bar widget to the top-level widget. + */ + OBJECT_SET_DATA(dlg_w, PROG_BAR_KEY, prog_bar); - /* Button row */ - bbox = dlg_button_row_new(GTK_STOCK_CANCEL, NULL); + /* + * 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); gtk_container_add(GTK_CONTAINER(main_vb), bbox); gtk_widget_show(bbox); - cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL); + cancel_bt = OBJECT_GET_DATA(bbox, terminate_is_stop ? GTK_STOCK_STOP : + GTK_STOCK_CANCEL); gtk_widget_grab_default(cancel_bt); - /* - * Allow user to either click the "Cancel" 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); + /* + * 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); - gtk_widget_show_all(dlg_w); + gtk_widget_show_all(dlg_w); - dlg->dlg_w = dlg_w; + dlg->dlg_w = dlg_w; - g_get_current_time(&dlg->start_time); - memset(&dlg->last_time, 0, sizeof(dlg->last_time)); + g_get_current_time(&dlg->start_time); + memset(&dlg->last_time, 0, sizeof(dlg->last_time)); g_free(task_title_dup); g_free(item_title_dup); - return dlg; + return dlg; } progdlg_t * delayed_create_progress_dlg(const gchar *task_title, const gchar *item_title, - gboolean *stop_flag, const GTimeVal *start_time, gfloat progress) + gboolean terminate_is_stop, gboolean *stop_flag, + const GTimeVal *start_time, gfloat progress) { GTimeVal time_now; gdouble delta_time; @@ -285,7 +290,8 @@ delayed_create_progress_dlg(const gchar *task_title, const gchar *item_title, if (progress >= (delta_time / (delta_time + min_display))) return NULL; - dlg = create_progress_dlg(task_title, item_title, stop_flag); + dlg = create_progress_dlg(task_title, item_title, terminate_is_stop, + stop_flag); /* set dialog start_time to the start of processing, not box creation */ dlg->start_time = *start_time; @@ -399,9 +405,9 @@ update_progress_dlg(progdlg_t *dlg, gfloat percentage, const gchar *status) void destroy_progress_dlg(progdlg_t *dlg) { - GtkWidget *dlg_w = dlg->dlg_w; + GtkWidget *dlg_w = dlg->dlg_w; - window_destroy(GTK_WIDGET(dlg_w)); + window_destroy(GTK_WIDGET(dlg_w)); g_free(dlg->title); - g_free(dlg); + g_free(dlg); } diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c index 0d0c8a47f9..5ef7d99fc5 100644 --- a/gtk/proto_draw.c +++ b/gtk/proto_draw.c @@ -1081,6 +1081,7 @@ packet_hex_print_common(GtkTextView *bv, const guint8 *pd, int len, int bstart, time in order to get to the next progress bar step). */ if (progbar == NULL) progbar = delayed_create_progress_dlg("Processing", "Packet Details", + TRUE, &progbar_stop_flag, &progbar_start_time, progbar_val); diff --git a/gtk/rtp_analysis.c b/gtk/rtp_analysis.c index 4489869b0f..966f50ef1b 100644 --- a/gtk/rtp_analysis.c +++ b/gtk/rtp_analysis.c @@ -2513,7 +2513,8 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t * return FALSE; } - progbar = create_progress_dlg("Saving voice in a file", dest, &stop_flag); + progbar = create_progress_dlg("Saving voice in a file", dest, TRUE, + &stop_flag); if (format == SAVE_AU_FORMAT) /* au format */ { |