Use "progdlg_t *" rather than "void *" as the handle for a progress
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 Jul 2000 07:01:58 +0000 (07:01 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 Jul 2000 07:01:58 +0000 (07:01 +0000)
dialog box; that lets us do some type-checking, but we can still typedef
it to an incompletely-defined structure to hide the implementation
details from the caller.

Make "create_progress_dlg()" take, as an argument, the title to put in
the "stop the operation" button, and use "Stop" rather than "Cancel" if
stopping the operation doesn't undo all the work it's done.

Thaw the clist if we break out of a "read the file" operation, as we
freeze it before the operation.

Have the handler for the "delete" event on the progress dialog box
return FALSE, to let GTK+ know that it should, in fact, delete the
window.  ("delete" event handlers should return TRUE if the window
shouldn't actually be deleted, FALSE if it should; they should not
return "void".)

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@2120 f5534014-38df-0310-8fa8-9805f1628bb7

file.c
gtk/progress_dlg.c
ui_util.h

diff --git a/file.c b/file.c
index f4e8a97ff6a3a4e0a7ac27ad626c3fb95637f8a7..5f8b3b5378cbfb2e0af8f000ea9b09df7bece575 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
 /* file.c
  * File I/O routines
  *
- * $Id: file.c,v 1.194 2000/07/03 09:34:05 guy Exp $
+ * $Id: file.c,v 1.195 2000/07/07 07:01:24 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -287,16 +287,16 @@ 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...";
-  size_t   msg_len;
-  char    *errmsg;
-  char     errmsg_errno[1024+1];
-  gchar    err_str[2048+1];
-  int      data_offset;
-  void    *progbar;
-  gboolean stop_flag;
-  int      file_pos;
-  float    prog_val;
+  gchar    *name_ptr, *load_msg, *load_fmt = " Loading: %s...";
+  size_t    msg_len;
+  char     *errmsg;
+  char      errmsg_errno[1024+1];
+  gchar     err_str[2048+1];
+  int       data_offset;
+  progdlg_t *progbar;
+  gboolean  stop_flag;
+  int       file_pos;
+  float     prog_val;
 
   name_ptr = get_basename(cf->filename);
 
@@ -318,7 +318,7 @@ read_cap_file(capture_file *cf, int *err)
   freeze_clist(cf);
 
   stop_flag = FALSE;
-  progbar = create_progress_dlg(load_msg, &stop_flag);
+  progbar = create_progress_dlg(load_msg, "Stop", &stop_flag);
   g_free(load_msg);
 
   while ((data_offset = wtap_read(cf->wth, err)) > 0) {
@@ -339,6 +339,7 @@ read_cap_file(capture_file *cf, int *err)
          file, and return READ_ABORTED so our caller can do whatever is
         appropriate when that happens. */
       cf->state = FILE_READ_ABORTED;   /* so that we're allowed to close it */
+      gtk_clist_thaw(GTK_CLIST(packet_list));  /* undo our freeze */
       close_cap_file(cf, info_bar);
       return (READ_ABORTED);
     }
@@ -825,7 +826,7 @@ void
 colorize_packets(capture_file *cf)
 {
   frame_data *fdata;
-  void *progbar;
+  progdlg_t *progbar;
   gboolean stop_flag;
   guint32 progbar_quantum;
   guint32 progbar_nextstep;
@@ -881,7 +882,7 @@ colorize_packets(capture_file *cf)
   count = 0;
 
   stop_flag = FALSE;
-  progbar = create_progress_dlg("Filtering", &stop_flag);
+  progbar = create_progress_dlg("Filtering", "Stop", &stop_flag);
 
   for (fdata = cf->plist; fdata != NULL; fdata = fdata->next) {
     /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
@@ -950,7 +951,7 @@ print_packets(capture_file *cf, print_args_t *print_args)
 {
   int         i;
   frame_data *fdata;
-  void       *progbar;
+  progdlg_t  *progbar;
   gboolean    stop_flag;
   guint32     progbar_quantum;
   guint32     progbar_nextstep;
@@ -1036,7 +1037,7 @@ print_packets(capture_file *cf, print_args_t *print_args)
   count = 0;
 
   stop_flag = FALSE;
-  progbar = create_progress_dlg("Printing", &stop_flag);
+  progbar = create_progress_dlg("Printing", "Stop", &stop_flag);
 
   /* Iterate through the list of packets, printing the packets that
      were selected by the current display filter.  */
@@ -1238,7 +1239,7 @@ find_packet(capture_file *cf, dfilter *sfcode)
   frame_data *start_fd;
   frame_data *fdata;
   frame_data *new_fd = NULL;
-  void *progbar;
+  progdlg_t *progbar;
   gboolean stop_flag;
   guint32 progbar_quantum;
   guint32 progbar_nextstep;
@@ -1262,7 +1263,7 @@ find_packet(capture_file *cf, dfilter *sfcode)
     progbar_quantum = cf->count/N_PROGBAR_UPDATES;
 
     stop_flag = FALSE;
-    progbar = create_progress_dlg("Searching", &stop_flag);
+    progbar = create_progress_dlg("Searching", "Cancel", &stop_flag);
 
     fdata = start_fd;
     for (;;) {
index 6d0090b25d892bfa0eea104d719bf48626685f31..93e629fd084f17d439251c0f4b0a6c5484f9c199 100644 (file)
@@ -1,7 +1,7 @@
 /* progress_dlg.c
  * Routines for progress-bar (modal) dialog
  *
- * $Id: progress_dlg.c,v 1.5 2000/07/05 05:50:00 guy Exp $
+ * $Id: progress_dlg.c,v 1.6 2000/07/07 07:01:58 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 
 #define        PROG_BAR_KEY    "progress_bar"
 
-static void delete_cb(GtkWidget *w, GdkEvent *event, gpointer data);
-static void cancel_cb(GtkWidget *w, gpointer data);
+static gint delete_event_cb(GtkWidget *w, GdkEvent *event, gpointer data);
+static void stop_cb(GtkWidget *w, gpointer data);
+static void destroy_cb(GtkWidget *w, gpointer data);
 
 /*
- * Create and pop up the progress dialog; return a pointer to it, as
- * a "void *", so that our caller doesn't have to know the GUI
- * implementation.
+ * Define the structure describing a progress dialog.
+ */
+struct progdlg {
+       GtkWidget *dlg_w;       /* top-level window widget */
+};
+
+/*
+ * 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.
  *
  * The first argument is the title to give the dialog box; the second
- * argument is a pointer to a Boolean variable that will be set to
- * TRUE if the user hits the "Cancel" button.
- *
- * XXX - should the button say "Cancel", or "Stop"?
+ * 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.
  *
  * XXX - provide a way to specify the progress in units, with the total
  * number of units specified as an argument when the progress dialog
@@ -57,15 +65,26 @@ static void cancel_cb(GtkWidget *w, gpointer data);
  * wouldn't always use it, as we have no idea how many packets are to
  * be read.
  */
-void *
-create_progress_dlg(gchar *title, gboolean *stop_flag)
+progdlg_t *
+create_progress_dlg(const gchar *title, const gchar *stop_title,
+    gboolean *stop_flag)
 {
+       progdlg_t *dlg;
        GtkWidget *dlg_w, *main_vb, *title_lb, *prog_bar, *bbox, *cancel_bt;
 
+       dlg = g_malloc(sizeof (progdlg_t));
+
        dlg_w = dlg_window_new();
        gtk_window_set_title(GTK_WINDOW(dlg_w), title);
        gtk_window_set_modal(GTK_WINDOW(dlg_w), TRUE);
 
+       /*
+        * Call a handler when the progress dialog box is destroyed, so
+        * we can free the "progdlg_t" to which it refers.
+        */
+       gtk_signal_connect(GTK_OBJECT(dlg_w), "destroy",
+           GTK_SIGNAL_FUNC(destroy_cb), dlg);
+
        /*
         * Container for dialog widgets.
         */
@@ -106,15 +125,16 @@ create_progress_dlg(gchar *title, gboolean *stop_flag)
        gtk_container_add(GTK_CONTAINER(main_vb), bbox);
   
        /*
-        * Allow user to either click a "Cancel" button, or the close button
-        * on the window, to stop an operation in progress.
+        * Allow user to either click a "stop this operation" button, or
+        * the close button on the window, to stop an operation in
+        * progress.
         */
-       cancel_bt = gtk_button_new_with_label("Cancel");
+       cancel_bt = gtk_button_new_with_label(stop_title);
        gtk_box_pack_start(GTK_BOX (bbox), cancel_bt, TRUE, TRUE, 0);
        gtk_signal_connect(GTK_OBJECT(cancel_bt), "clicked",
-           GTK_SIGNAL_FUNC(cancel_cb), (gpointer) stop_flag);
+           GTK_SIGNAL_FUNC(stop_cb), (gpointer) stop_flag);
        gtk_signal_connect(GTK_OBJECT(dlg_w), "delete_event",
-           GTK_SIGNAL_FUNC(delete_cb), (gpointer) stop_flag);
+           GTK_SIGNAL_FUNC(delete_event_cb), (gpointer) stop_flag);
        GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
        gtk_widget_grab_default(cancel_bt);
        GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
@@ -122,28 +142,30 @@ create_progress_dlg(gchar *title, gboolean *stop_flag)
 
        gtk_widget_show_all(dlg_w);
 
-       return dlg_w;   /* return as opaque pointer */
+       dlg->dlg_w = dlg_w;
+
+       return dlg;
 }
 
 /*
  * Called when the dialog box is to be deleted.
  * We just treat this the same way we treat clicking the "Cancel" button.
  */
-static void
-delete_cb(GtkWidget *w, GdkEvent *event, gpointer data)
+static gint
+delete_event_cb(GtkWidget *w, GdkEvent *event, gpointer data)
 {
-       cancel_cb(NULL, data);
+       stop_cb(NULL, data);
+       return FALSE;   /* go ahead and delete it */
 }
 
 /*
- * Called when the "Cancel" button is clicked.
+ * Called when the "stop this operation" button is clicked.
  * Set the Boolean to TRUE.
  */
 static void
-cancel_cb(GtkWidget *w, gpointer data)
+stop_cb(GtkWidget *w, gpointer data)
 {
        gboolean *stop_flag = (gboolean *) data;
-       GtkWidget *toplevel;
   
        *stop_flag = TRUE;
        if (w != NULL) {
@@ -151,8 +173,7 @@ cancel_cb(GtkWidget *w, gpointer data)
                 * The cancel button was clicked, so we have to destroy
                 * the dialog box ourselves.
                 */
-               toplevel = gtk_widget_get_toplevel(w);
-               destroy_progress_dlg(toplevel);
+               gtk_widget_destroy(GTK_WIDGET(gtk_widget_get_toplevel(w)));
        }
 }
 
@@ -160,9 +181,9 @@ cancel_cb(GtkWidget *w, gpointer data)
  * Set the percentage value of the progress bar.
  */
 void
-update_progress_dlg(void *dlg, gfloat percentage)
+update_progress_dlg(progdlg_t *dlg, gfloat percentage)
 {
-       GtkWidget *dlg_w = dlg;
+       GtkWidget *dlg_w = dlg->dlg_w;
        GtkWidget *prog_bar;
 
        prog_bar = gtk_object_get_data(GTK_OBJECT(dlg_w), PROG_BAR_KEY);
@@ -176,13 +197,23 @@ update_progress_dlg(void *dlg, gfloat percentage)
 }
 
 /*
- * Destroy the progress bar.
+ * Destroy the progress dialog.
  */
 void
-destroy_progress_dlg(void *dlg)
+destroy_progress_dlg(progdlg_t *dlg)
 {
-       GtkWidget *dlg_w = dlg;
+       GtkWidget *dlg_w = dlg->dlg_w;
 
-       gtk_grab_remove(GTK_WIDGET(dlg_w));
        gtk_widget_destroy(GTK_WIDGET(dlg_w));
 }
+
+/*
+ * Called when the top-level window is destroyed.
+ */
+static void
+destroy_cb(GtkWidget *w, gpointer data)
+{
+       progdlg_t *dlg = data;
+
+       g_free(dlg);
+}
index 2b4585e014c5622661448d2a01e49ac1228928f2..ebc66e3f11961a3c82c680ec144e8f654d8a90cd 100644 (file)
--- a/ui_util.h
+++ b/ui_util.h
@@ -1,7 +1,7 @@
 /* ui_util.h
  * Definitions for UI utility routines
  *
- * $Id: ui_util.h,v 1.5 2000/07/03 08:35:42 guy Exp $
+ * $Id: ui_util.h,v 1.6 2000/07/07 07:01:28 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -47,26 +47,33 @@ void destroy_packet_wins(void);
  * Progress (modal) dialog box routines.
  */
 
+struct progdlg;
+
+typedef struct progdlg progdlg_t;
+
 /*
- * Create and pop up the progress dialog; return a pointer to it, as
- * a "void *", so that our caller doesn't have to know the GUI
- * implementation.
+ * 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.
  *
  * The first argument is the title to give the dialog box; the second
- * argument is a pointer to a Boolean variable that will be set to
- * TRUE if the user hits the "Cancel" button.
+ * 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.
  */
-void *create_progress_dlg(gchar *title, gboolean *stop_flag);
+progdlg_t *create_progress_dlg(const gchar *title, const gchar *stop_title,
+    gboolean *stop_flag);
 
 /*
  * Set the percentage value of the progress bar.
  */
-void update_progress_dlg(void *dlg, gfloat percentage);
+void update_progress_dlg(progdlg_t *dlg, gfloat percentage);
 
 /*
  * Destroy the progress bar.
  */
-void destroy_progress_dlg(void *dlg);
+void destroy_progress_dlg(progdlg_t *dlg);
 
 #ifdef __cplusplus
 }