diff options
author | Guy Harris <guy@alum.mit.edu> | 2013-07-27 22:37:26 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2013-07-27 22:37:26 +0000 |
commit | 210507cc7660b108f991382f44a45d63a225d754 (patch) | |
tree | 78746f785a24c5bd6faa48f14f1653d41f8d44e9 /ui/gtk | |
parent | 3663498a8b39f4159ca90eaee2fbc915df27712a (diff) | |
download | wireshark-210507cc7660b108f991382f44a45d63a225d754.tar.gz |
Have separate lists of recent capture filters for all interfaces, in
addition to a "global" list. Store all of those lists in the recent
file. Maintain the lists in ui/recent.c, rather than attaching them to
widgets; have the code that populates the combo boxes get the lists from
the ui/recent.c code.
This makes a little more of the code GUI-toolkit-independent, and should
fix bug 7278.
#BACKPORT 1.10, 1.8
svn path=/trunk/; revision=50956
Diffstat (limited to 'ui/gtk')
-rw-r--r-- | ui/gtk/Makefile.common | 1 | ||||
-rw-r--r-- | ui/gtk/capture_dlg.c | 36 | ||||
-rw-r--r-- | ui/gtk/cfilter_combo_utils.c | 95 | ||||
-rw-r--r-- | ui/gtk/cfilter_combo_utils.h | 2 |
4 files changed, 24 insertions, 110 deletions
diff --git a/ui/gtk/Makefile.common b/ui/gtk/Makefile.common index aeb90ec099..f10496b0b8 100644 --- a/ui/gtk/Makefile.common +++ b/ui/gtk/Makefile.common @@ -51,7 +51,6 @@ WIRESHARK_GTK_SRC = \ capture_file_dlg.c \ capture_if_dlg.c \ capture_info_dlg.c \ - cfilter_combo_utils.c \ color_dlg.c \ color_edit_dlg.c \ color_utils.c \ diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c index a22be5397b..ebbfe61e65 100644 --- a/ui/gtk/capture_dlg.c +++ b/ui/gtk/capture_dlg.c @@ -2613,6 +2613,7 @@ void options_interface_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColum gchar *tok, *name; GtkCellRenderer *renderer; GtkListStore *store; + const gchar *new_cfilter; window = (GtkWidget *)userdata; caller = gtk_widget_get_toplevel(GTK_WIDGET(window)); @@ -2898,21 +2899,28 @@ void options_interface_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColum /* Create the capture filter combo box*/ filter_cm = gtk_combo_box_text_new_with_entry(); - cfilter_list = (GList *)g_object_get_data(G_OBJECT(opt_edit_w), E_CFILTER_FL_KEY); - g_object_set_data(G_OBJECT(opt_edit_w), E_CFILTER_FL_KEY, cfilter_list); g_object_set_data(G_OBJECT(opt_edit_w), E_CFILTER_CM_KEY, filter_cm); filter_te = gtk_bin_get_child(GTK_BIN(filter_cm)); colorize_filter_te_as_empty(filter_te); g_signal_connect(filter_te, "changed", G_CALLBACK(capture_filter_check_syntax_cb), NULL); g_signal_connect(filter_te, "destroy", G_CALLBACK(capture_filter_destroy_cb), NULL); + cfilter_list = recent_get_cfilter_list(name); for (cf_entry = cfilter_list; cf_entry != NULL; cf_entry = g_list_next(cf_entry)) { - if (cf_entry->data && (strlen((const char *)cf_entry->data) > 0)) { - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(filter_cm), (const gchar *)cf_entry->data); + new_cfilter = (const gchar *)cf_entry->data; + /* If this is the current dfilter or the default cfilter, don't put + it in the list, as it'll be added later. */ + if ((device.cfilter == NULL || strcmp(device.cfilter, new_cfilter) != 0) && + (global_capture_opts.default_options.cfilter == NULL || strcmp(global_capture_opts.default_options.cfilter, new_cfilter) != 0)) { + gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), new_cfilter); } } if (global_capture_opts.default_options.cfilter && (strlen(global_capture_opts.default_options.cfilter) > 0)) { - gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), global_capture_opts.default_options.cfilter); + /* If this is the current dfilter, don't put it in the list, as it'll be + added later. */ + if (device.cfilter == NULL || strcmp(device.cfilter, global_capture_opts.default_options.cfilter) != 0) { + gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), global_capture_opts.default_options.cfilter); + } } if (device.cfilter && (strlen(device.cfilter) > 0)) { gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(filter_cm), device.cfilter); @@ -4505,6 +4513,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) gboolean if_present = TRUE; GList *all_cfilter_list, *cf_entry; window_geometry_t tl_geom; + const gchar *new_cfilter; if (interfaces_dialog_window_present()) { destroy_if_window(); @@ -4780,17 +4789,17 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) /* Create the capture filter combo box*/ all_filter_cm = gtk_combo_box_text_new_with_entry(); - all_cfilter_list = (GList *)g_object_get_data(G_OBJECT(cap_open_w), E_ALL_CFILTER_FL_KEY); - g_object_set_data(G_OBJECT(cap_open_w), E_ALL_CFILTER_FL_KEY, all_cfilter_list); g_object_set_data(G_OBJECT(cap_open_w), E_ALL_CFILTER_CM_KEY, all_filter_cm); all_filter_te = gtk_bin_get_child(GTK_BIN(all_filter_cm)); colorize_filter_te_as_empty(all_filter_te); g_signal_connect(all_filter_te, "changed", G_CALLBACK(capture_all_filter_check_syntax_cb), NULL); g_signal_connect(all_filter_te, "destroy", G_CALLBACK(capture_filter_destroy_cb), NULL); + all_cfilter_list = recent_get_cfilter_list(NULL); for (cf_entry = all_cfilter_list; cf_entry != NULL; cf_entry = g_list_next(cf_entry)) { - if (cf_entry->data && (strlen((const char *)cf_entry->data) > 0)) { - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(all_filter_cm), (const gchar *)cf_entry->data); + new_cfilter = (const gchar *)cf_entry->data; + if (global_capture_opts.default_options.cfilter == NULL || strcmp(global_capture_opts.default_options.cfilter, new_cfilter) != 0) { + gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(all_filter_cm), new_cfilter); } } if (global_capture_opts.default_options.cfilter && (strlen(global_capture_opts.default_options.cfilter) > 0)) { @@ -5308,14 +5317,17 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_) collect_ifaces(&global_capture_opts); if (capture_start(&global_capture_opts, &global_capture_session, main_window_update)) { - /* The capture succeeded, which means the capture filter syntax is - valid; add this capture filter to the recent capture filter list. */ + /* The capture succeeded, which means the capture filters specified are + valid; add them to the recent capture filter lists for the interfaces. */ for (i = 0; i < global_capture_opts.ifaces->len; i++) { interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i); if (interface_opts.cfilter) { - cfilter_combo_add_recent(interface_opts.cfilter); + recent_add_cfilter(interface_opts.name, interface_opts.cfilter); } } + if (global_capture_opts.default_options.cfilter) { + recent_add_cfilter(NULL, global_capture_opts.default_options.cfilter); + } } } diff --git a/ui/gtk/cfilter_combo_utils.c b/ui/gtk/cfilter_combo_utils.c deleted file mode 100644 index 47cbd54b19..0000000000 --- a/ui/gtk/cfilter_combo_utils.c +++ /dev/null @@ -1,95 +0,0 @@ -/* cfilter_combo_utils.c - * Capture filter combo box routines - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@wireshark.org> - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include <stdio.h> -#include <string.h> - -#include <gtk/gtk.h> - -#include "ui/recent.h" -#include "ui/recent_utils.h" - -#include "ui/gtk/main.h" -#include "ui/gtk/gtkglobals.h" -#include "ui/gtk/cfilter_combo_utils.h" - - -/* XXX: use a preference for this setting! */ -static guint cfilter_combo_max_recent = 20; - -static gboolean -cfilter_combo_add(gchar *s) { - GList *li; - GList *fl = (GList*)g_object_get_data(G_OBJECT(top_level), E_CFILTER_FL_KEY); - - li = g_list_first(fl); - while (li) { - /* If the filter is already in the list, remove the old one and - * append the new one at the latest position (at g_list_append() below) */ - if (li->data && strcmp(s, (char *)li->data) == 0) { - fl = g_list_remove(fl, li->data); - break; - } - li = li->next; - } - fl = g_list_append(fl, s); - g_object_set_data(G_OBJECT(top_level), E_CFILTER_FL_KEY, fl); - return TRUE; -} - - -/* write all non empty capture filters (until maximum count) - * of the combo box GList to the user's recent file */ -void - cfilter_combo_recent_write_all(FILE *rf) { - GList *cfilter_list = (GList*)g_object_get_data(G_OBJECT(top_level), E_CFILTER_FL_KEY); - GList *li; - guint max_count = 0; - - /* write all non empty capture filter strings to the recent file (until max count) */ - li = g_list_first(cfilter_list); - while (li && (max_count++ <= cfilter_combo_max_recent) ) { - if (li->data && strlen((const char *)li->data)) { - fprintf (rf, RECENT_KEY_CAPTURE_FILTER ": %s\n", (char *)li->data); - } - li = li->next; - } -} - -/* add a capture filter coming from the user's recent file to the cfilter combo box */ -gboolean - cfilter_combo_add_recent(const gchar *s) { - gchar *dupstr; - - if (s) { - dupstr = g_strdup(s); - if (!cfilter_combo_add(dupstr)) { - g_free(dupstr); - return FALSE; - } - } - return TRUE; -} diff --git a/ui/gtk/cfilter_combo_utils.h b/ui/gtk/cfilter_combo_utils.h index 37cd1636ac..e197175c39 100644 --- a/ui/gtk/cfilter_combo_utils.h +++ b/ui/gtk/cfilter_combo_utils.h @@ -30,8 +30,6 @@ */ #define E_CFILTER_CM_KEY "capture_filter_combo" -#define E_CFILTER_FL_KEY "capture_filter_list" #define E_ALL_CFILTER_CM_KEY "capture_all_filter_combo" -#define E_ALL_CFILTER_FL_KEY "capture_all_filter_list" #endif /* __CFILTER_COMBO_UTILS_H__ */ |