diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-04-16 23:17:13 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-04-16 23:17:13 +0000 |
commit | d209115ba38e1f5082ecdf702782da0f09a727d2 (patch) | |
tree | 16229621c009c052580c6152892a945af94e5bba /gtk/simple_dialog.c | |
parent | a0146ed5bedbbee168eb8f0fc226cd56fa1dbd92 (diff) |
Add a "report_failure()" routine to allow dissectors to report arbitrary
errors to the user. Use that, rather than "g_warning()", in the
Diameter dissector to report errors reading the dictionary.
Make the format argument to "simple_dialog()" a "const" pointer.
Fix up the read-error message in Tethereal to end with a newline.
If a simple dialog is requested before the main window or the
capture-control window is popped up, queue it up and pop the queued
messages up once the main or capture-control window is displayed.
svn path=/trunk/; revision=10616
Diffstat (limited to 'gtk/simple_dialog.c')
-rw-r--r-- | gtk/simple_dialog.c | 116 |
1 files changed, 86 insertions, 30 deletions
diff --git a/gtk/simple_dialog.c b/gtk/simple_dialog.c index a742f80b95..5e39d49a1d 100644 --- a/gtk/simple_dialog.c +++ b/gtk/simple_dialog.c @@ -1,7 +1,7 @@ /* simple_dialog.c * Simple message dialog box routines. * - * $Id: simple_dialog.c,v 1.30 2004/03/13 15:30:08 ulfl Exp $ + * $Id: simple_dialog.c,v 1.31 2004/04/16 23:16:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -45,35 +45,26 @@ static void simple_dialog_cancel_cb(GtkWidget *, gpointer); #define CALLBACK_BTN_KEY "ESD_Callback_Btn" #define CALLBACK_DATA_KEY "ESD_Callback_Data" -/* Simple dialog function - Displays a dialog box with the supplied message - * text. - * - * Args: - * type : One of ESD_TYPE_*. - * btn_mask : The value passed in determines which buttons are displayed. - * msg_format : Sprintf-style format of the text displayed in the dialog. - * ... : Argument list for msg_format - * - * - * XXX - if we haven't yet put up the main window, we should just - * queue up the message, etc., and wait until the main window pops up - * (or until we figure out that we're in a capture child and aren't - * going to pop up a main window) and pop up the alert boxes then, so - * that even stuff popped up before we put up the main window (such - * as file-open or file-read errors from dissectors' init routines) - * shows up on top. +/* + * Queue for messages requested before we have a main window. */ - -gpointer -simple_dialog(gint type, gint btn_mask, gchar *msg_format, ...) { +typedef struct { + gint type; + gint btn_mask; + char *message; +} queued_message_t; + +static GSList *message_queue; + +static GtkWidget * +display_simple_dialog(gint type, gint btn_mask, char *message) +{ GtkWidget *win, *main_vb, *top_hb, *type_pm, *msg_label, *bbox, *ok_bt, *bt; GdkPixmap *pixmap; GdkBitmap *mask; GtkStyle *style; GdkColormap *cmap; - va_list ap; - gchar message[2048]; gchar **icon; /* Main window */ @@ -156,11 +147,6 @@ simple_dialog(gint type, gint btn_mask, gchar *msg_format, ...) { gtk_container_add(GTK_CONTAINER(top_hb), type_pm); gtk_widget_show(type_pm); - /* Load our vararg list into the message string */ - va_start(ap, msg_format); - g_vsnprintf(message, sizeof(message), msg_format, ap); - va_end(ap); - msg_label = gtk_label_new(message); #if GTK_MAJOR_VERSION >= 2 @@ -240,6 +226,78 @@ simple_dialog(gint type, gint btn_mask, gchar *msg_format, ...) { return win; } +void +display_queued_messages(void) +{ + queued_message_t *queued_message; + + while (message_queue != NULL) { + queued_message = message_queue->data; + message_queue = g_slist_remove(message_queue, queued_message); + + display_simple_dialog(queued_message->type, queued_message->btn_mask, + queued_message->message); + + g_free(queued_message->message); + g_free(queued_message); + } +} + +/* Simple dialog function - Displays a dialog box with the supplied message + * text. + * + * Args: + * type : One of ESD_TYPE_*. + * btn_mask : The value passed in determines which buttons are displayed. + * msg_format : Sprintf-style format of the text displayed in the dialog. + * ... : Argument list for msg_format + */ + +gpointer +vsimple_dialog(gint type, gint btn_mask, const gchar *msg_format, va_list ap) +{ + gchar *message; + queued_message_t *queued_message; + GtkWidget *win; + + /* Format the message. */ + message = g_strdup_vprintf(msg_format, ap); + + /* If we don't yet have a main window, queue up the message for later + display. */ + if (top_level == NULL) { + queued_message = g_malloc(sizeof (queued_message_t)); + queued_message->type = type; + queued_message->btn_mask = btn_mask; + queued_message->message = message; + message_queue = g_slist_append(message_queue, queued_message); + return NULL; + } + + /* + * Do we have any queued up messages? If so, pop them up. + */ + display_queued_messages(); + + win = display_simple_dialog(type, btn_mask, message); + + g_free(message); + + return win; +} + +gpointer +simple_dialog(gint type, gint btn_mask, const gchar *msg_format, ...) +{ + va_list ap; + gpointer ret; + + va_start(ap, msg_format); + ret = vsimple_dialog(type, btn_mask, msg_format, ap); + va_end(ap); + return ret; +} + static void simple_dialog_cancel_cb(GtkWidget *w, gpointer win) { gint button = GPOINTER_TO_INT( OBJECT_GET_DATA(w, CALLBACK_BTN_KEY)); @@ -268,5 +326,3 @@ char * simple_dialog_primary_end(void) { return PRIMARY_TEXT_END; } - - |