2 * Routines for display filter dialog used by gui taps
3 * Copyright 2003 Lars Roland
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
39 #include "compat_macros.h"
40 #include "../simple_dialog.h"
41 #include "dlg_utils.h"
43 #include "../globals.h"
44 #include "filter_dlg.h"
45 #include <epan/stat_cmd_args.h>
46 #include "../stat_menu.h"
47 #include "gui_stat_menu.h"
48 #include "../tap_dfilter_dlg.h"
49 #include "gui_utils.h"
50 #include "gtkglobals.h"
53 typedef struct _tap_dfilter_dlg_list_item {
55 GtkWidget *filter_entry;
57 construct_args_t args;
58 struct _tap_dfilter_dlg_list_item *next;
59 } tap_dfilter_dlg_list_item;
61 static tap_dfilter_dlg_list_item *start_dlg_list=NULL;
62 static tap_dfilter_dlg_list_item *end_dlg_list=NULL;
63 static tap_dfilter_dlg_list_item *current_dlg = NULL;
66 tap_dfilter_dlg_cb(GtkWidget *w, gpointer data);
69 * Register a stat that has a display filter dialog.
70 * We register it both as a command-line stat and a menu item stat.
73 register_dfilter_stat(tap_dfilter_dlg *info, const char *name,
74 REGISTER_STAT_GROUP_E group)
78 register_stat_cmd_arg(info->init_string, info->tap_init_cb);
81 * This menu item will pop up a dialog box, so append "..."
84 full_name = g_strdup_printf("%s...", name);
85 register_stat_menu_item(full_name, group, tap_dfilter_dlg_cb, NULL,
90 void tap_dfilter_dlg_update (void)
92 tap_dfilter_dlg_list_item *dialog = start_dlg_list;
95 while(dialog != NULL) {
97 title = g_strdup_printf("Ethereal: %s: %s", dialog->cont.win_title , cf_get_display_name(&cfile));
98 gtk_window_set_title(GTK_WINDOW(dialog->dlg), title);
101 dialog = dialog->next;
106 dlg_destroy_cb(GtkWidget *item _U_, gpointer dialog_data)
108 tap_dfilter_dlg_list_item *dlg_data = (tap_dfilter_dlg_list_item *) dialog_data;
109 dlg_data->dlg = NULL;
113 tap_dfilter_dlg_start_button_clicked(GtkWidget *item _U_, gpointer dialog_data)
118 tap_dfilter_dlg_list_item *dlg_data = (tap_dfilter_dlg_list_item *) dialog_data;
120 filter=gtk_entry_get_text(GTK_ENTRY(dlg_data->filter_entry));
122 g_snprintf(str, sizeof(str), "%s", dlg_data->cont.init_string);
124 g_snprintf(str, sizeof(str), "%s,%s", dlg_data->cont.init_string, filter);
126 (dlg_data->cont.tap_init_cb)(str);
131 tap_dfilter_dlg_cb(GtkWidget *w _U_, gpointer data)
136 GtkWidget *filter_box, *filter_bt;
137 GtkWidget *bbox, *start_button, *cancel_button;
139 tap_dfilter_dlg *dlg_data = (tap_dfilter_dlg *) data;
144 if(dlg_data->index==-1) {
145 /* Dialog is not registered */
146 if(start_dlg_list==NULL) {
147 start_dlg_list = (tap_dfilter_dlg_list_item *) g_malloc(sizeof (tap_dfilter_dlg_list_item));
148 end_dlg_list = start_dlg_list;
149 end_dlg_list->cont.index = 0; /* first entry in list -> index = 0 */
151 end_dlg_list->next = (tap_dfilter_dlg_list_item *) g_malloc(sizeof (tap_dfilter_dlg_list_item));
152 end_dlg_list->next->cont.index = end_dlg_list->cont.index + 1;
153 end_dlg_list = end_dlg_list->next;
155 end_dlg_list->dlg = NULL;
156 end_dlg_list->filter_entry = NULL;
157 end_dlg_list->cont.win_title = dlg_data->win_title;
158 end_dlg_list->cont.init_string = dlg_data->init_string;
159 end_dlg_list->cont.tap_init_cb = dlg_data->tap_init_cb;
160 end_dlg_list->args.title = g_strdup_printf("%s Filter", dlg_data->win_title);
161 end_dlg_list->args.wants_apply_button = TRUE;
162 end_dlg_list->args.activate_on_ok = FALSE;
163 end_dlg_list->next = NULL;
164 dlg_data->index = end_dlg_list->cont.index;
165 current_dlg = end_dlg_list;
167 /* Dialog is registered, find it */
168 current_dlg = start_dlg_list;
169 while(dlg_data->index != current_dlg->cont.index)
171 if(current_dlg->next == NULL) {
172 /* could not find any dialog */
175 current_dlg = current_dlg->next;
179 /* if the window is already open, bring it to front */
180 if(current_dlg->dlg){
181 gdk_window_raise(current_dlg->dlg->window);
185 title = g_strdup_printf("Ethereal: %s: %s", current_dlg->cont.win_title , cf_get_display_name(&cfile));
187 current_dlg->dlg=dlg_window_new(title);
188 gtk_window_set_default_size(GTK_WINDOW(current_dlg->dlg), 300, -1);
191 dlg_box=gtk_vbox_new(FALSE, 10);
192 gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
193 gtk_container_add(GTK_CONTAINER(current_dlg->dlg), dlg_box);
194 gtk_widget_show(dlg_box);
197 filter_box=gtk_hbox_new(FALSE, 3);
200 filter_bt=BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY);
201 SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &(current_dlg->args));
202 gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, TRUE, 0);
203 gtk_widget_show(filter_bt);
206 current_dlg->filter_entry=gtk_entry_new();
207 SIGNAL_CONNECT(current_dlg->filter_entry, "changed", filter_te_syntax_check_cb, NULL);
209 /* filter prefs dialog */
210 OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, current_dlg->filter_entry);
211 /* filter prefs dialog */
213 gtk_box_pack_start(GTK_BOX(filter_box), current_dlg->filter_entry, TRUE, TRUE, 0);
214 filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
216 gtk_entry_set_text(GTK_ENTRY(current_dlg->filter_entry), filter);
218 gtk_widget_show(current_dlg->filter_entry);
220 gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
221 gtk_widget_show(filter_box);
224 bbox = dlg_button_row_new(ETHEREAL_STOCK_CREATE_STAT, GTK_STOCK_CANCEL, NULL);
225 gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
226 gtk_widget_show(bbox);
228 start_button = OBJECT_GET_DATA(bbox, ETHEREAL_STOCK_CREATE_STAT);
229 SIGNAL_CONNECT(start_button, "clicked",
230 tap_dfilter_dlg_start_button_clicked, current_dlg);
232 cancel_button = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
233 window_set_cancel_button(current_dlg->dlg, cancel_button, window_cancel_button_cb);
235 /* Catch the "activate" signal on the filter text entry, so that
236 if the user types Return there, we act as if the "Create Stat"
237 button had been selected, as happens if Return is typed if
238 some widget that *doesn't* handle the Return key has the input
240 dlg_set_activate(current_dlg->filter_entry, start_button);
242 /* Give the initial focus to the "Filter" entry box. */
243 gtk_widget_grab_focus(current_dlg->filter_entry);
245 gtk_widget_grab_default(start_button );
247 SIGNAL_CONNECT(current_dlg->dlg, "delete_event", window_delete_event_cb, NULL);
248 SIGNAL_CONNECT(current_dlg->dlg, "destroy", dlg_destroy_cb, current_dlg);
250 gtk_widget_show_all(current_dlg->dlg);
251 window_present(current_dlg->dlg);