aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-05-15 07:44:54 +0000
committerGuy Harris <guy@alum.mit.edu>2003-05-15 07:44:54 +0000
commite1647e4504d31f8260e23ec60c645735516060e0 (patch)
tree49ebcdcfb4b2a8c020befb29cf224778712b71b9 /gtk
parent86f3c38c4aef93560541c50e2f501e94802b337d (diff)
From Richard Urwin:
add support for a system-wide color filter file; fix a bug where "read_filters()" didn't close the file handle. Use the "get_datafile_path()" routine he added to construct the pathname of the Diameter directory, the global preferences file, and the manuf file. svn path=/trunk/; revision=7677
Diffstat (limited to 'gtk')
-rw-r--r--gtk/color_dlg.c161
-rw-r--r--gtk/color_filters.c188
-rw-r--r--gtk/color_filters.h5
3 files changed, 258 insertions, 96 deletions
diff --git a/gtk/color_dlg.c b/gtk/color_dlg.c
index 62ef62fc2c..770a4c9ac8 100644
--- a/gtk/color_dlg.c
+++ b/gtk/color_dlg.c
@@ -1,7 +1,7 @@
/* color_dlg.c
* Definitions for dialog boxes for color filters
*
- * $Id: color_dlg.c,v 1.23 2003/02/17 21:08:37 oabad Exp $
+ * $Id: color_dlg.c,v 1.24 2003/05/15 07:44:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -66,6 +66,8 @@ static void color_save_cb(GtkButton *button, gpointer user_data);
static void color_ok_cb(GtkButton *button, gpointer user_data);
static void color_cancel_cb(GtkWidget *widget, gpointer user_data);
static void color_apply_cb(GtkButton *button, gpointer user_data);
+static void color_revert_cb(GtkWidget *button, gpointer user_data);
+
static void edit_color_filter_dialog_new(GtkWidget *color_filters,
GtkWidget **colorize_filter_name,
@@ -152,6 +154,7 @@ colorize_dialog_new (void)
GtkWidget *color_ok;
GtkWidget *color_apply;
GtkWidget *color_save;
+ GtkWidget *color_revert;
GtkWidget *color_cancel;
#if GTK_MAJOR_VERSION >= 2
@@ -385,6 +388,17 @@ colorize_dialog_new (void)
gtk_tooltips_set_tip(tooltips, color_save, ("Save all filters to disk"), NULL);
#if GTK_MAJOR_VERSION < 2
+ color_revert = gtk_button_new_with_label (("Revert"));
+#else
+ color_revert = gtk_button_new_from_stock(GTK_STOCK_REVERT_TO_SAVED);
+#endif
+ gtk_widget_ref(color_revert);
+ OBJECT_SET_DATA_FULL(color_win, "color_revert", color_revert, gtk_widget_unref);
+ gtk_widget_show(color_revert);
+ gtk_box_pack_start(GTK_BOX (button_ok_hbox), color_revert, FALSE, FALSE, 5);
+ gtk_tooltips_set_tip(tooltips, color_revert, ("Delete filter file and revert to system-wide default filter set"), NULL);
+
+#if GTK_MAJOR_VERSION < 2
color_cancel = gtk_button_new_with_label (("Cancel"));
#else
color_cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
@@ -419,6 +433,8 @@ colorize_dialog_new (void)
OBJECT_SET_DATA(color_delete, COLOR_FILTERS_CL, color_filters);
SIGNAL_CONNECT(color_delete, "clicked", color_delete_cb, NULL);
SIGNAL_CONNECT(color_save, "clicked", color_save_cb, NULL);
+ SIGNAL_CONNECT(color_revert, "clicked", color_revert_cb, NULL);
+ OBJECT_SET_DATA(color_revert, COLOR_FILTERS_CL, color_filters);
SIGNAL_CONNECT(color_ok, "clicked", color_ok_cb, NULL);
SIGNAL_CONNECT(color_apply, "clicked", color_apply_cb, NULL);
SIGNAL_CONNECT(color_cancel, "clicked", color_cancel_cb, NULL);
@@ -770,77 +786,83 @@ color_edit_cb(GtkButton *button, gpointer user_data _U_)
/* Delete a color from the list. */
static void
-color_delete_cb(GtkWidget *widget, gpointer user_data _U_)
+color_delete(gint row, GtkWidget *color_filters)
{
- GtkWidget *color_filters;
- color_filter_t *colorf;
+ color_filter_t *colorf;
+
#if GTK_MAJOR_VERSION >= 2
GtkTreeModel *model;
GtkTreeIter iter;
- gint row;
+ gint rowsel;
GtkTreeSelection *sel;
- if(row_selected != -1) {
- /* The "selection changed" callback is called when the row is
- * removed, so we must remember the selected row. */
- row = row_selected;
- color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
- model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
- gtk_tree_model_iter_nth_child(model, &iter, NULL, row);
- gtk_tree_model_get(model, &iter, 4, &colorf, -1);
-
- /* Remove this color filter from the CList displaying the
- color filters. */
- gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
- num_of_filters--;
-
- /* Destroy any "Edit color filter" dialog boxes editing it. */
- if (colorf->edit_dialog != NULL)
- gtk_widget_destroy(colorf->edit_dialog);
-
- /* Remove the color filter from the list of color filters. */
- delete_color_filter(colorf);
-
- /* If we grab the focus after updating the selection, the first
- * row is always selected, so we do it before */
- gtk_widget_grab_focus(color_filters);
- /* Update the selection */
- if (row <= (num_of_filters-1)) {
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
- gtk_tree_model_iter_nth_child(model, &iter, NULL, row);
- gtk_tree_selection_select_iter(sel, &iter);
- }
- else if (num_of_filters > 0) {
- sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
- gtk_tree_model_iter_nth_child(model, &iter, NULL, num_of_filters-1);
- gtk_tree_selection_select_iter(sel, &iter);
- }
+
+ /* The "selection changed" callback is called when the row is
+ * removed, so we must remember the selected row. */
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(color_filters));
+ gtk_tree_model_iter_nth_child(model, &iter, NULL, row);
+ gtk_tree_model_get(model, &iter, 4, &colorf, -1);
+
+ /* Remove this color filter from the CList displaying the
+ color filters. */
+ gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
+ num_of_filters--;
+
+ /* Destroy any "Edit color filter" dialog boxes editing it. */
+ if (colorf->edit_dialog != NULL)
+ gtk_widget_destroy(colorf->edit_dialog);
+
+ /* Remove the color filter from the list of color filters. */
+ delete_color_filter(colorf);
+
+ /* If we grab the focus after updating the selection, the first
+ * row is always selected, so we do it before */
+ gtk_widget_grab_focus(color_filters);
+ /* Update the selection */
+ if (row_selected <= (num_of_filters-1)) {
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
+ gtk_tree_model_iter_nth_child(model, &iter, NULL, row_selected);
+ gtk_tree_selection_select_iter(sel, &iter);
+ }
+ else if (num_of_filters > 0) {
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(color_filters));
+ gtk_tree_model_iter_nth_child(model, &iter, NULL, num_of_filters-1);
+ gtk_tree_selection_select_iter(sel, &iter);
}
#else
- if(row_selected != -1){
- color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
- colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row_selected);
+ colorf = gtk_clist_get_row_data(GTK_CLIST(color_filters), row);
- /* Remove this color filter from the CList displaying the
- color filters. */
- gtk_clist_remove(GTK_CLIST(color_filters), row_selected);
- num_of_filters--;
+ /* Remove this color filter from the CList displaying the
+ color filters. */
+ gtk_clist_remove(GTK_CLIST(color_filters), row);
+ num_of_filters--;
- /* Destroy any "Edit color filter" dialog boxes editing it. */
- if (colorf->edit_dialog != NULL)
- gtk_widget_destroy(colorf->edit_dialog);
+ /* Destroy any "Edit color filter" dialog boxes editing it. */
+ if (colorf->edit_dialog != NULL)
+ gtk_widget_destroy(colorf->edit_dialog);
- /* Remove the color filter from the list of color filters. */
- delete_color_filter(colorf);
+ /* Remove the color filter from the list of color filters. */
+ delete_color_filter(colorf);
- /* Select the previous row, if there is one. */
- if (row_selected > 0) {
- row_selected--;
- gtk_clist_select_row(GTK_CLIST(color_filters), row_selected, 0);
- }
+ /* Select the previous row, if there is one. */
+ if (row <= row_selected && row_selected > 0) {
+ row_selected--;
+ gtk_clist_select_row(GTK_CLIST(color_filters), row_selected, 0);
}
#endif
}
+/* Delete the selected color from the list.*/
+static void
+color_delete_cb(GtkWidget *widget, gpointer user_data _U_)
+{
+ GtkWidget *color_filters;
+
+ if(row_selected != -1)
+ {
+ color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
+ color_delete (row_selected, color_filters);
+ }
+}
/* Save color filters to the color filter file. */
static void
@@ -852,6 +874,31 @@ color_save_cb(GtkButton *button _U_, gpointer user_data _U_)
}
+/* Remove all user defined color filters and revert to the global file. */
+static void
+color_revert_cb(GtkWidget *widget, gpointer user_data _U_)
+{
+ GtkWidget * color_filters;
+
+ color_filters = (GtkWidget *)OBJECT_GET_DATA(widget, COLOR_FILTERS_CL);
+
+ while (num_of_filters > 0)
+ {
+ color_delete (num_of_filters-1, color_filters);
+ }
+
+ if (!revert_filters())
+ simple_dialog(ESD_TYPE_CRIT, NULL, "Could not delete filter file: %s",
+ strerror(errno));
+
+ /* colorize list */
+ colorize_packets(&cfile);
+
+ /* Destroy the dialog box. */
+ gtk_widget_destroy(colorize_win);
+
+}
+
/* Exit dialog and apply new list of color filters to the capture. */
static void
color_ok_cb(GtkButton *button _U_, gpointer user_data _U_)
diff --git a/gtk/color_filters.c b/gtk/color_filters.c
index 89b635f248..25cdc5ebc2 100644
--- a/gtk/color_filters.c
+++ b/gtk/color_filters.c
@@ -1,7 +1,7 @@
/* color_filters.c
* Routines for color filters
*
- * $Id: color_filters.c,v 1.1 2003/01/08 01:59:42 guy Exp $
+ * $Id: color_filters.c,v 1.2 2003/05/15 07:44:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -45,14 +45,48 @@
#include "gtkglobals.h"
static gboolean read_filters(void);
+static gboolean read_global_filters(void);
GSList *filter_list;
-/* Initialize the filter structures (reading from file) */
+/* delete the specified filter */
+void
+delete_color_filter(color_filter_t *colorf)
+{
+ if (colorf->filter_name != NULL)
+ g_free(colorf->filter_name);
+ if (colorf->filter_text != NULL)
+ g_free(colorf->filter_text);
+ if (colorf->c_colorfilter != NULL)
+ dfilter_free(colorf->c_colorfilter);
+ filter_list = g_slist_remove(filter_list, colorf);
+ g_free(colorf);
+}
+
+/* delete the specified filter as an iterator*/
+static void
+delete_color_filter_it(gpointer filter_arg, gpointer ignored _U_)
+{
+ color_filter_t *colorf = filter_arg;
+
+ delete_color_filter(colorf);
+}
+
+/* delete all the filters */
+
+static void
+delete_all_color_filters (void)
+{
+ g_slist_foreach(filter_list, delete_color_filter_it, NULL);
+}
+
+/* Initialize the filter structures (reading from file) for general running, including app startup */
void
colfilter_init(void)
{
- read_filters();
+ delete_all_color_filters();
+ if (!read_filters())
+ read_global_filters();
}
/* Create a new filter */
@@ -75,19 +109,6 @@ new_color_filter(gchar *name, /* The name of the filter to create */
return colorf;
}
-/* delete the specified filter */
-void
-delete_color_filter(color_filter_t *colorf)
-{
- if (colorf->filter_name != NULL)
- g_free(colorf->filter_name);
- if (colorf->filter_text != NULL)
- g_free(colorf->filter_text);
- if (colorf->c_colorfilter != NULL)
- dfilter_free(colorf->c_colorfilter);
- filter_list = g_slist_remove(filter_list, colorf);
- g_free(colorf);
-}
static void
prime_edt(gpointer data, gpointer user_data)
@@ -108,9 +129,9 @@ filter_list_prime_edt(epan_dissect_t *edt)
}
-/* read filters from the file */
+/* read filters from the given file */
static gboolean
-read_filters(void)
+read_filters_file(gpointer file_arg)
{
/* TODO: Lots more syntax checking on the file */
/* I hate these fixed length names! TODO: make more dynamic */
@@ -121,23 +142,8 @@ read_filters(void)
guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b;
GdkColor fg_color, bg_color;
color_filter_t *colorf;
- gchar *path;
- FILE *f;
dfilter_t *temp_dfilter;
-
- /* decide what file to open (from dfilter code) */
- path = get_persconffile_path("colorfilters", FALSE);
- if ((f = fopen(path, "r")) == NULL) {
- if (errno != ENOENT) {
- simple_dialog(ESD_TYPE_CRIT, NULL,
- "Could not open filter file\n\"%s\": %s.", path,
- strerror(errno));
- }
- g_free((gchar *)path);
- return FALSE;
- }
- g_free((gchar *)path);
- path = NULL;
+ FILE *f = file_arg;
do {
if (fgets(buf,sizeof buf, f) == NULL)
@@ -193,8 +199,61 @@ read_filters(void)
gdkcolor_to_color_t(&colorf->fg_color, &fg_color);
} /* if sscanf */
} while(!feof(f));
+ fclose(f);
return TRUE;
}
+/* read filters from the user's filter file */
+static gboolean
+read_filters(void)
+{
+ /* TODO: Lots more syntax checking on the file */
+ /* I hate these fixed length names! TODO: make more dynamic */
+ /* XXX - buffer overflow possibility here
+ * sscanf blocks max size of name and filter_exp; buf is used for
+ * reading only */
+ gchar *path;
+ FILE *f;
+
+ /* decide what file to open (from dfilter code) */
+ path = get_persconffile_path("colorfilters", FALSE);
+ if ((f = fopen(path, "r")) == NULL) {
+ if (errno != ENOENT) {
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ "Could not open filter file\n\"%s\": %s.", path,
+ strerror(errno));
+ }
+ g_free((gchar *)path);
+ return FALSE;
+ }
+ g_free((gchar *)path);
+ path = NULL;
+
+ return read_filters_file(f);
+}
+
+/* read filters from the filter file */
+static gboolean
+read_global_filters(void)
+{
+ gchar *path;
+ FILE *f;
+
+ /* decide what file to open (from dfilter code) */
+ path = get_datafile_path("colorfilters");
+ if ((f = fopen(path, "r")) == NULL) {
+ if (errno != ENOENT) {
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ "Could not open global filter file\n\"%s\": %s.", path,
+ strerror(errno));
+ }
+ g_free((gchar *)path);
+ return FALSE;
+ }
+ g_free((gchar *)path);
+ path = NULL;
+
+ return read_filters_file(f);
+}
static void
write_filter(gpointer filter_arg, gpointer file_arg)
@@ -213,7 +272,17 @@ write_filter(gpointer filter_arg, gpointer file_arg)
colorf->fg_color.blue);
}
-/* save filters in filter file */
+/* save filters in a filter file */
+gboolean
+write_filters_file(FILE *f)
+{
+ fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Ethereal\n");
+ g_slist_foreach(filter_list, write_filter, f);
+ return TRUE;
+}
+
+/* save filters in users filter file */
+
gboolean
write_filters(void)
{
@@ -238,8 +307,53 @@ write_filters(void)
path, strerror(errno));
return FALSE;
}
- fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Ethereal\n");
- g_slist_foreach(filter_list, write_filter, f);
+ write_filters_file(f);
+ fclose(f);
+ return TRUE;
+}
+
+/* delete users filter file and reload global filters*/
+
+gboolean
+revert_filters(void)
+{
+ gchar *pf_dir_path;
+ const gchar *path;
+
+ /* Create the directory that holds personal configuration files,
+ if necessary. */
+ if (create_persconffile_dir(&pf_dir_path) == -1) {
+ simple_dialog(ESD_TYPE_WARN, NULL,
+ "Can't create directory\n\"%s\"\nfor color files: %s.",
+ pf_dir_path, strerror(errno));
+ g_free(pf_dir_path);
+ return FALSE;
+ }
+
+ path = get_persconffile_path("colorfilters", TRUE);
+ if (!deletefile(path))
+ return FALSE;
+
+ /* Reload the (global) filters - Note: this does not update the dialog. */
+ colfilter_init();
+ return TRUE;
+}
+
+
+/* save filters in some other filter file */
+
+gboolean
+write_other_filters(gchar *path)
+{
+ FILE *f;
+
+ if ((f = fopen(path, "w+")) == NULL) {
+ simple_dialog(ESD_TYPE_CRIT, NULL,
+ "Could not open\n%s\nfor writing: %s.",
+ path, strerror(errno));
+ return FALSE;
+ }
+ write_filters_file(f);
fclose(f);
return TRUE;
}
diff --git a/gtk/color_filters.h b/gtk/color_filters.h
index 046a672031..16154b3de4 100644
--- a/gtk/color_filters.h
+++ b/gtk/color_filters.h
@@ -1,7 +1,7 @@
/* color_filters.h
* Definitions for color filters
*
- * $Id: color_filters.h,v 1.1 2003/01/08 01:59:42 guy Exp $
+ * $Id: color_filters.h,v 1.2 2003/05/15 07:44:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -34,8 +34,9 @@
void colfilter_init(void);
gboolean write_filters(void);
+gboolean revert_filters(void);
color_filter_t *new_color_filter(gchar *name, gchar *filter_string);
void delete_color_filter(color_filter_t *colorf);
-
+gboolean write_other_filters(gchar *path);
#endif