diff options
author | Gerald Combs <gerald@wireshark.org> | 2009-11-04 00:02:52 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2009-11-04 00:02:52 +0000 |
commit | 5e34f2107600ccacc2079bdf8f64f7e774d1be35 (patch) | |
tree | 5d02db77a1e48440a5ef613e1b8245200d8c2d04 | |
parent | 8041e9732ee139e97d9a99158744b1cee4dadd26 (diff) | |
download | wireshark-5e34f2107600ccacc2079bdf8f64f7e774d1be35.tar.gz wireshark-5e34f2107600ccacc2079bdf8f64f7e774d1be35.tar.bz2 wireshark-5e34f2107600ccacc2079bdf8f64f7e774d1be35.zip |
Add the ability to push temporary (and highlighted) messages onto the
statusbar. This lets us notify the user about something significant
without having to pop up an annoying window. Replace a few dialogs with
statusbar messages.
svn path=/trunk/; revision=30810
-rw-r--r-- | file.c | 26 | ||||
-rw-r--r-- | gtk/filter_dlg.c | 2 | ||||
-rw-r--r-- | gtk/main_statusbar.c | 56 | ||||
-rw-r--r-- | gtk/main_statusbar.h | 7 | ||||
-rw-r--r-- | gtk/simple_dialog.c | 20 | ||||
-rw-r--r-- | simple_dialog.h | 10 |
6 files changed, 97 insertions, 24 deletions
@@ -3716,18 +3716,12 @@ find_packet(capture_file *cf, if (prefs.gui_find_wrap) { - simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, - "%sBeginning of capture exceeded!%s\n\n" - "Search is continued from the end of the capture.", - simple_dialog_primary_start(), simple_dialog_primary_end()); + simple_status("Search reached the beginning. Continuing at end."); fdata = cf->plist_end; /* wrap around */ } else { - simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, - "%sBeginning of capture exceeded!%s\n\n" - "Try searching forwards.", - simple_dialog_primary_start(), simple_dialog_primary_end()); + simple_status("Search reached the beginning."); fdata = start_fd; /* stay on previous packet */ } } @@ -3737,18 +3731,12 @@ find_packet(capture_file *cf, if (fdata == NULL) { if (prefs.gui_find_wrap) { - simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, - "%sEnd of capture exceeded!%s\n\n" - "Search is continued from the start of the capture.", - simple_dialog_primary_start(), simple_dialog_primary_end()); + simple_status("Search reached the end. Continuing at beginning."); fdata = cf->plist_start; /* wrap around */ } else { - simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, - "%sEnd of capture exceeded!%s\n\n" - "Try searching backwards.", - simple_dialog_primary_start(), simple_dialog_primary_end()); + simple_status("Search reached the end."); fdata = start_fd; /* stay on previous packet */ } } @@ -3828,15 +3816,13 @@ cf_goto_frame(capture_file *cf, guint fnumber) if (fdata == NULL) { /* we didn't find a packet with that packet number */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "There is no packet with the packet number %u.", fnumber); + simple_status("There is no packet number %u.", fnumber); return FALSE; /* we failed to go to that packet */ } if (!fdata->flags.passed_dfilter) { /* that packet currently isn't displayed */ /* XXX - add it to the set of displayed packets? */ - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "The packet number %u isn't currently being displayed.", fnumber); + simple_status("Packet number %u isn't displayed.", fnumber); return FALSE; /* we failed to go to that packet */ } diff --git a/gtk/filter_dlg.c b/gtk/filter_dlg.c index c12f7b8fde..803f8fd9e2 100644 --- a/gtk/filter_dlg.c +++ b/gtk/filter_dlg.c @@ -1339,7 +1339,7 @@ filter_te_syntax_check_cb(GtkWidget *w) */ msg = g_strdup_printf(" \"%s\" may have unexpected results (see the User's Guide)", (const char *) g_ptr_array_index(depr, 0)); - statusbar_push_filter_msg(msg); + statusbar_push_temporary_msg(msg); g_free(msg); } } else { diff --git a/gtk/main_statusbar.c b/gtk/main_statusbar.c index 3db900b26a..ef0b58a2b0 100644 --- a/gtk/main_statusbar.c +++ b/gtk/main_statusbar.c @@ -82,7 +82,7 @@ typedef enum { static GtkWidget *status_pane_left, *status_pane_right; -static GtkWidget *info_bar, *packets_bar, *profile_bar, *profile_bar_event; +static GtkWidget *info_bar, *info_bar_event, *packets_bar, *profile_bar, *profile_bar_event; static GtkWidget *expert_info_error, *expert_info_warn, *expert_info_note; static GtkWidget *expert_info_chat, *expert_info_none; @@ -97,7 +97,19 @@ static void packets_bar_new(void); static void profile_bar_new(void); static void status_expert_new(void); +/* Temporary message timeout */ +#define TEMPORARY_MSG_TIMEOUT (7 * 1000) +/* + * Reset the statusbar foreground and background colors + */ +static void +statusbar_reset_colors(void) +{ + /* Extra credit for adding a fade effect */ + gtk_widget_modify_text(info_bar, GTK_STATE_NORMAL, NULL); + gtk_widget_modify_bg(info_bar_event, GTK_STATE_NORMAL, NULL); +} /* * Push a message referring to file access onto the statusbar. @@ -113,6 +125,8 @@ statusbar_push_file_msg(const gchar *msg) return; } status_levels[STATUS_LEVEL_FILE]++; + + statusbar_reset_colors(); gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, msg); } @@ -143,6 +157,7 @@ statusbar_push_field_msg(const gchar *msg) } status_levels[STATUS_LEVEL_HELP]++; + statusbar_reset_colors(); gtk_statusbar_push(GTK_STATUSBAR(info_bar), help_ctx, msg); } @@ -172,6 +187,7 @@ statusbar_push_filter_msg(const gchar *msg) } status_levels[STATUS_LEVEL_FILTER]++; + statusbar_reset_colors(); gtk_statusbar_push(GTK_STATUSBAR(info_bar), filter_ctx, msg); } @@ -187,6 +203,37 @@ statusbar_pop_filter_msg(void) gtk_statusbar_pop(GTK_STATUSBAR(info_bar), filter_ctx); } +/* + * Timeout callback for statusbar_push_temporary_msg + */ +static gboolean +statusbar_remove_temporary_msg(gpointer data) +{ + guint msg_id = GPOINTER_TO_UINT(data); + + gtk_statusbar_remove(GTK_STATUSBAR(info_bar), main_ctx, msg_id); + statusbar_reset_colors(); + + return FALSE; +} + +/* + * Push a temporary message onto the statusbar. + */ +void +statusbar_push_temporary_msg(const gchar *msg) +{ + guint msg_id; + GdkColor black = { 0, 0, 0, 0 }; + GdkColor yellow = { 0, 0xFFFF, 0xFFFF, 0xAFFF }; + + msg_id = gtk_statusbar_push(GTK_STATUSBAR(info_bar), main_ctx, msg); + gtk_widget_modify_text(info_bar, GTK_STATE_NORMAL, &black); + gtk_widget_modify_bg(info_bar_event, GTK_STATE_NORMAL, &yellow); + + g_timeout_add(TEMPORARY_MSG_TIMEOUT, statusbar_remove_temporary_msg, GUINT_TO_POINTER(msg_id)); +} + GtkWidget * statusbar_new(void) @@ -247,6 +294,7 @@ void statusbar_widgets_emptying(GtkWidget *statusbar) { g_object_ref(G_OBJECT(info_bar)); + g_object_ref(G_OBJECT(info_bar_event)); g_object_ref(G_OBJECT(packets_bar)); g_object_ref(G_OBJECT(profile_bar)); g_object_ref(G_OBJECT(profile_bar_event)); @@ -273,7 +321,7 @@ statusbar_widgets_pack(GtkWidget *statusbar) gtk_box_pack_start(GTK_BOX(statusbar), expert_info_chat, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(statusbar), expert_info_none, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(statusbar), status_pane_left, TRUE, TRUE, 0); - gtk_paned_pack1(GTK_PANED(status_pane_left), info_bar, FALSE, FALSE); + gtk_paned_pack1(GTK_PANED(status_pane_left), info_bar_event, FALSE, FALSE); gtk_paned_pack2(GTK_PANED(status_pane_left), status_pane_right, TRUE, FALSE); gtk_paned_pack1(GTK_PANED(status_pane_right), packets_bar, TRUE, FALSE); gtk_paned_pack2(GTK_PANED(status_pane_right), profile_bar_event, FALSE, FALSE); @@ -312,8 +360,9 @@ info_bar_new(void) { int i; - /* tip: tooltips don't work on statusbars! */ + info_bar_event = gtk_event_box_new(); info_bar = gtk_statusbar_new(); + gtk_container_add(GTK_CONTAINER(info_bar_event), info_bar); main_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "main"); file_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "file"); help_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "help"); @@ -326,6 +375,7 @@ info_bar_new(void) } gtk_widget_show(info_bar); + gtk_widget_show(info_bar_event); } static void diff --git a/gtk/main_statusbar.h b/gtk/main_statusbar.h index d057248ac9..119a6fdb26 100644 --- a/gtk/main_statusbar.h +++ b/gtk/main_statusbar.h @@ -49,4 +49,11 @@ void statusbar_push_filter_msg(const gchar *msg); */ void statusbar_pop_filter_msg(void); +/** Push a temporary message onto the statusbar. The message is automatically + * removed at a later interval. + * + * @param msg The message + */ +void statusbar_push_temporary_msg(const gchar *msg); + #endif /* __MAIN_STATUSBAR_H__ */ diff --git a/gtk/simple_dialog.c b/gtk/simple_dialog.c index af929fc781..e4586fd452 100644 --- a/gtk/simple_dialog.c +++ b/gtk/simple_dialog.c @@ -38,6 +38,8 @@ #include "gtk/gui_utils.h" #include "gtk/stock_icons.h" +#include "main_statusbar.h" + #include "image/stock_dialog_error_48.xpm" #include "image/stock_dialog_info_48.xpm" #include "image/stock_dialog_warning_48.xpm" @@ -430,3 +432,21 @@ simple_dialog_format_message(const char *msg) } return str; } + +/* + * This doesn't create a window, but it falls into the realm of "telling the + * user what happened" and having it here means it can be called from file.c. + */ +void +simple_status(const gchar *msg_format, ...) +{ + va_list ap; + gchar *msg; + + va_start(ap, msg_format); + msg = g_strdup_vprintf(msg_format, ap); + va_end(ap); + + statusbar_push_temporary_msg(msg); + g_free(msg); +} diff --git a/simple_dialog.h b/simple_dialog.h index 0fc06f395a..1b503e9405 100644 --- a/simple_dialog.h +++ b/simple_dialog.h @@ -90,6 +90,7 @@ typedef enum { extern gpointer simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...) GNUC_FORMAT_CHECK(printf, 3, 4); + /** Create and show a simple dialog using a va_list. * * @param type type of dialog @@ -160,6 +161,15 @@ extern char *simple_dialog_format_message(const char *msg); */ extern void display_queued_messages(void); +/** Show a message in the status bar. + * + * @param msg Status message + */ +extern void simple_status(const gchar *msg_format, ...) + GNUC_FORMAT_CHECK(printf, 1, 2); + + + #ifdef __cplusplus } #endif /* __cplusplus */ |