Add a routine to be used to put up alert boxes for invalid display
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 11 Feb 2004 00:55:28 +0000 (00:55 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 11 Feb 2004 00:55:28 +0000 (00:55 +0000)
filter expressions; use that in a number of places, so we use the same
alert box.  (More work is needed to figure out the right way to handle
some other "dfilter_compile()" failures.)

Use the error message from the display filter as the primary error, as
that's the message that tells you what the underlying problem is.  (The
GNOME HIG says "In most situations the user should only need the primary
text to make a quick decision", so the primary text should tell you
what's wrong with the filter, not just that it's invalid.  If there are
messages from the display filter code that don't give enough
information, or are a bit cryptic, such as "Unexpected end of filter
string," those should be fixed in the display filter code.)

Improve the error used if an empty filter is used for "find frame".

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

Makefile.common
alert_box.c [new file with mode: 0644]
alert_box.h [new file with mode: 0644]
file.c
gtk/file_dlg.c
gtk/find_dlg.c
gtk/io_stat.c
gtk/main.c

index 9eafb3500fafebb1706982f1879b83f644564d72..4d893cc2c77d19d75160640a74ff0d92eb6ea558 100644 (file)
@@ -3,7 +3,7 @@
 #     a) common to both files and
 #     b) portable between both files
 #
-# $Id: Makefile.common,v 1.11 2004/02/10 23:38:34 guy Exp $
+# $Id: Makefile.common,v 1.12 2004/02/11 00:55:26 guy Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@ethereal.com>
@@ -734,6 +734,8 @@ ethereal_SOURCES =  \
        $(DISSECTOR_SRC)        \
        $(ETHEREAL_COMMON_SRC)  \
        register.c      \
+       alert_box.c     \
+       alert_box.h     \
        capture.c       \
        capture.h       \
        file.c  \
diff --git a/alert_box.c b/alert_box.c
new file mode 100644 (file)
index 0000000..c2f8784
--- /dev/null
@@ -0,0 +1,56 @@
+/* alert_box.c
+ * Routines to put up various "standard" alert boxes used in multiple
+ * places
+ *
+ * $Id: alert_box.c,v 1.1 2004/02/11 00:55:26 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+
+#include <epan/dfilter/dfilter.h>
+
+#include "alert_box.h"
+
+#include "simple_dialog.h"
+
+/*
+ * Alert box for an invalid display filter expression.
+ * Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the
+ * error message for the filter.
+ *
+ * XXX - should this have a "Help" button that pops up the display filter
+ * help?
+ */
+void
+bad_dfilter_alert_box(const char *dftext)
+{
+  simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, 
+                "%s%s%s\n"
+                "\n"
+                "The filter expression \"%s\" is not a valid display filter.\n"
+                "See the help for a description of the display filter syntax.",
+                simple_dialog_primary_start(), dfilter_error_msg,
+                simple_dialog_primary_end(), dftext);
+}
diff --git a/alert_box.h b/alert_box.h
new file mode 100644 (file)
index 0000000..5c35d18
--- /dev/null
@@ -0,0 +1,44 @@
+/* alert_box.h
+ * Routines to put up various "standard" alert boxes used in multiple
+ * places
+ *
+ * $Id: alert_box.h,v 1.1 2004/02/11 00:55:27 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef __ALERT_BOX_H__
+#define __ALERT_BOX_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * Alert box for an invalid display filter expression.
+ * Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the
+ * error message for the filter.
+ */
+extern void bad_dfilter_alert_box(const char *dftext);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __ALERT_BOX_H__ */
diff --git a/file.c b/file.c
index 49ad7278c25000a8f58122436a8d090a9b0618be..23c47cb80588a9ea3ddd82b1e44fc7faed9f30d5 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
 /* file.c
  * File I/O routines
  *
- * $Id: file.c,v 1.357 2004/02/03 17:59:00 ulfl Exp $
+ * $Id: file.c,v 1.358 2004/02/11 00:55:27 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -994,12 +994,12 @@ filter_packets(capture_file *cf, gchar *dftext)
     if (!dfilter_compile(dftext, &dfcode)) {
       /* The attempt failed; report an error. */
       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, 
-          "%sInvalid display filter: \"%s\"!%s\n"
+          "%s%s%s\n"
           "\n"
-          "Unable to parse display filter string (%s),\n"
-          "see help for correct display filter syntax.",
-          simple_dialog_primary_start(), dftext, simple_dialog_primary_end(),
-          dfilter_error_msg);
+          "The display filter \"%s\" is not a valid display filter.\n"
+          "See the help for a description of the display filter syntax.",
+          simple_dialog_primary_start(), dfilter_error_msg,
+          simple_dialog_primary_end(), dftext);
       g_free(dftext);
       return 0;
     }
index 52aadc82ac73d56b3e86b6c987ffea3c55402d68..f998b6f2ca890fe3d653e91d10d7e27a83fb8187 100644 (file)
@@ -1,7 +1,7 @@
 /* file_dlg.c
  * Dialog boxes for handling files
  *
- * $Id: file_dlg.c,v 1.93 2004/02/04 01:10:36 guy Exp $
+ * $Id: file_dlg.c,v 1.94 2004/02/11 00:55:27 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -37,6 +37,7 @@
 #include "keys.h"
 #include "filter_prefs.h"
 #include "ui_util.h"
+#include "alert_box.h"
 #include "simple_dialog.h"
 #include "menu.h"
 #include "file_dlg.h"
@@ -385,8 +386,8 @@ file_open_ok_cb(GtkWidget *w, GtkFileSelection *fs) {
   filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY);
   rfilter = (gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
   if (!dfilter_compile(rfilter, &rfcode)) {
+    bad_dfilter_alert_box(rfilter);
     g_free(cf_name);
-    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
     return;
   }
 
index 47a3682385f957c090e9a8c1cca175b53936420c..9bf94d0f0fed1afed4e67763071f12c44697c761 100644 (file)
@@ -1,7 +1,7 @@
 /* find_dlg.c
  * Routines for "find frame" window
  *
- * $Id: find_dlg.c,v 1.45 2004/01/31 03:22:40 guy Exp $
+ * $Id: find_dlg.c,v 1.46 2004/02/11 00:55:28 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -38,6 +38,7 @@
 #include "ui_util.h"
 #include "find_dlg.h"
 #include "filter_prefs.h"
+#include "alert_box.h"
 #include "simple_dialog.h"
 #include "dlg_utils.h"
 #include "compat_macros.h"
@@ -574,7 +575,7 @@ find_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
      */
     if (!dfilter_compile(filter_text, &sfcode)) {
       /* The attempt failed; report an error. */
-      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
+      bad_dfilter_alert_box(filter_text);
       return;
     }
 
@@ -582,7 +583,7 @@ find_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
     if (sfcode == NULL) {
       /* Yes - complain. */
       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-         "You didn't specify a valid filter expression.");
+         "You specified a filter that doesn't test anything.");
       return;
     }
   }
index 0ce3abbeb0e0741d376f59fcdaf3e962ed21e57c..6eac1be01a9c5adfb8a062be34d2fd732860e270 100644 (file)
@@ -1,7 +1,7 @@
 /* io_stat.c
  * io_stat   2002 Ronnie Sahlberg
  *
- * $Id: io_stat.c,v 1.59 2004/01/31 03:22:41 guy Exp $
+ * $Id: io_stat.c,v 1.60 2004/02/11 00:55:28 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -44,6 +44,7 @@
 #include "menu.h"
 #include "../tap.h"
 #include "../register.h"
+#include "alert_box.h"
 #include "simple_dialog.h"
 #include "../globals.h"
 #include "../color.h"
@@ -1488,8 +1489,7 @@ filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio)
        /* first check if the filter string is valid. */
        filter=(char *)gtk_entry_get_text(GTK_ENTRY(gio->filter_field));
        if(!dfilter_compile(filter, &dfilter)) {
-               simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
-                   "Filter \"%s\" is invalid - %s", filter, dfilter_error_msg);
+               bad_dfilter_alert_box(filter);
                disable_graph(gio);
                io_stat_redraw(gio->io);
                return 0;
index fe45016880f62573d63813f992fde39bef37c155..cfedb0e3cd8d0347153e2479f423a22fb5f1a237 100644 (file)
@@ -1,6 +1,6 @@
 /* main.c
  *
- * $Id: main.c,v 1.391 2004/02/06 14:59:52 jmayer Exp $
+ * $Id: main.c,v 1.392 2004/02/11 00:55:28 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #include "pcap-util.h"
 #endif
 #include "statusbar.h"
+#include "alert_box.h"
 #include "simple_dialog.h"
 #include "dlg_utils.h"
 #include "proto_draw.h"
@@ -2701,7 +2702,7 @@ main(int argc, char *argv[])
     if (cf_name) {
       if (rfilter != NULL) {
         if (!dfilter_compile(rfilter, &rfcode)) {
-          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, dfilter_error_msg);
+          bad_dfilter_alert_box(rfilter);
           rfilter_parse_failed = TRUE;
         }
       }