2 * Dialog box for column preferences
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/prefs.h>
34 #include <epan/column_info.h>
35 #include <epan/column.h>
36 #include <epan/strutil.h>
38 #include "../globals.h"
40 #include "gtk/prefs_column.h"
41 #include "gtk/gtkglobals.h"
42 #include "gtk/gui_utils.h"
43 #ifdef NEW_PACKET_LIST
44 #include "gtk/new_packet_list.h"
46 #include "gtk/main_packet_list.h"
48 #include "gtk/filter_dlg.h"
49 #include "gtk/filter_autocomplete.h"
52 static GtkWidget *remove_bt, *field_te, *field_lb, *occurrence_te, *occurrence_lb, *fmt_cmb;
53 static gulong column_menu_changed_handler_id;
54 static gulong column_field_changed_handler_id;
55 static gulong column_occurrence_changed_handler_id;
56 static gulong column_row_deleted_handler_id;
58 static void column_list_new_cb(GtkWidget *, gpointer);
59 static void column_list_delete_cb(GtkWidget *, gpointer);
60 static void column_list_select_cb(GtkTreeSelection *, gpointer);
61 static void column_menu_changed_cb(GtkWidget *, gpointer);
62 static void column_field_changed_cb(GtkEditable *, gpointer);
63 static void column_occurrence_changed_cb(GtkEditable *, gpointer);
64 static void column_dnd_row_deleted_cb(GtkTreeModel *, GtkTreePath *, gpointer);
65 static gboolean column_title_changed_cb(GtkCellRendererText *, const gchar *, const gchar *, gpointer);
67 static char custom_occurrence_str[8] = "";
70 #ifdef NEW_PACKET_LIST
76 N_COLUMN /* The number of columns */
79 #ifdef NEW_PACKET_LIST
82 visible_toggled(GtkCellRendererToggle *cell _U_, gchar *path_str, gpointer data)
84 GtkTreeModel *model = (GtkTreeModel *)data;
86 GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
90 gtk_tree_model_get_iter(model, &iter, path);
91 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
93 cfmt = (fmt_data *) clp->data;
95 cfmt->visible = FALSE;
99 gtk_list_store_set(GTK_LIST_STORE(model), &iter, VISIBLE_COLUMN, cfmt->visible, -1);
100 cfile.cinfo.columns_changed = TRUE;
102 gtk_tree_path_free(path);
103 } /* visible_toggled */
107 * Create and display the column selection widgets.
108 * Called as part of the creation of the Preferences notebook ( Edit ! Preferences )
111 column_prefs_show(GtkWidget *prefs_window) {
112 GtkWidget *main_vb, *bottom_hb, *column_l, *add_bt, *tb, *lb;
113 GtkWidget *list_vb, *list_lb, *list_sc;
114 GtkWidget *add_remove_vb;
115 GtkWidget *props_fr, *props_hb;
121 #ifdef NEW_PACKET_LIST
122 const gchar *column_titles[] = {"Displayed", "Title", "Field type"};
124 const gchar *column_titles[] = {"Title", "Field type"};
127 GtkCellRenderer *renderer;
128 GtkTreeViewColumn *column;
129 GtkTreeSelection *sel;
131 GtkTreeIter first_iter;
132 gint first_row = TRUE;
134 GtkTooltips *tooltips = gtk_tooltips_new();
136 /* Container for each row of widgets */
137 main_vb = gtk_vbox_new(FALSE, 5);
138 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
139 gtk_widget_show(main_vb);
141 list_vb = gtk_vbox_new (FALSE, 0);
142 gtk_container_set_border_width (GTK_CONTAINER (list_vb), 5);
143 gtk_widget_show (list_vb);
144 gtk_box_pack_start (GTK_BOX (main_vb), list_vb, TRUE, TRUE, 0);
146 list_lb = gtk_label_new (("[The first list entry will be displayed as the leftmost column - Drag and drop entries to change column order]"));
147 gtk_widget_show (list_lb);
148 gtk_box_pack_start (GTK_BOX (list_vb), list_lb, FALSE, FALSE, 0);
150 list_sc = scrolled_window_new(NULL, NULL);
151 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_sc), GTK_SHADOW_IN);
152 gtk_container_add(GTK_CONTAINER(list_vb), list_sc);
153 gtk_widget_show(list_sc);
155 store = gtk_list_store_new(N_COLUMN,
156 #ifdef NEW_PACKET_LIST
159 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
160 column_row_deleted_handler_id =
161 g_signal_connect(GTK_TREE_MODEL(store), "row-deleted", G_CALLBACK(column_dnd_row_deleted_cb), NULL);
163 column_l = tree_view_new(GTK_TREE_MODEL(store));
164 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(column_l), TRUE);
165 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(column_l), FALSE);
166 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(column_l), TRUE);
167 gtk_tooltips_set_tip (tooltips, column_l,
168 "Click on a title to change its name.\nDrag an item to change its order.", NULL);
170 #ifdef NEW_PACKET_LIST
171 renderer = gtk_cell_renderer_toggle_new();
172 g_signal_connect(renderer, "toggled", G_CALLBACK(visible_toggled), store);
173 column = gtk_tree_view_column_new_with_attributes(column_titles[VISIBLE_COLUMN], renderer, "active", VISIBLE_COLUMN, NULL);
174 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
175 gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
178 renderer = gtk_cell_renderer_text_new();
179 g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
180 g_signal_connect (renderer, "edited", G_CALLBACK(column_title_changed_cb), GTK_TREE_MODEL(store));
181 column = gtk_tree_view_column_new_with_attributes(column_titles[TITLE_COLUMN], renderer, "text", TITLE_COLUMN, NULL);
182 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
183 gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
185 renderer = gtk_cell_renderer_text_new();
186 column = gtk_tree_view_column_new_with_attributes(column_titles[FORMAT_COLUMN], renderer, "text", FORMAT_COLUMN, NULL);
187 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
188 gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
190 /* XXX - make this match the packet list prefs? */
191 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(column_l));
192 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
193 g_signal_connect(sel, "changed", G_CALLBACK(column_list_select_cb), NULL);
195 gtk_container_add(GTK_CONTAINER(list_sc), column_l);
196 gtk_widget_show(column_l);
198 clp = g_list_first(prefs.col_list);
200 cfmt = (fmt_data *) clp->data;
201 cur_fmt = get_column_format_from_str(cfmt->fmt);
202 if (cur_fmt == COL_CUSTOM) {
203 if (cfmt->custom_occurrence) {
204 fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cur_fmt), cfmt->custom_field, cfmt->custom_occurrence);
206 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), cfmt->custom_field);
209 if (cfmt->custom_field) {
210 /* Delete custom_field from previous changes */
211 g_free (cfmt->custom_field);
212 cfmt->custom_field = NULL;
213 cfmt->custom_occurrence = 0;
215 fmt = g_strdup_printf("%s", col_format_desc(cur_fmt));
217 #if GTK_CHECK_VERSION(2,6,0)
218 gtk_list_store_insert_with_values(store, &iter, G_MAXINT,
220 gtk_list_store_append(store, &iter);
221 gtk_list_store_set(store, &iter,
223 #ifdef NEW_PACKET_LIST
224 VISIBLE_COLUMN, cfmt->visible,
226 TITLE_COLUMN, cfmt->title, FORMAT_COLUMN, fmt, DATA_COLUMN, clp, -1);
235 g_object_unref(G_OBJECT(store));
237 /* Bottom row: Add/remove buttons and properties */
238 bottom_hb = gtk_hbox_new(FALSE, 5);
239 gtk_box_pack_start (GTK_BOX (main_vb), bottom_hb, FALSE, TRUE, 0);
240 gtk_widget_show(bottom_hb);
242 /* Add / remove buttons */
243 add_remove_vb = gtk_vbox_new (TRUE, 0);
244 gtk_container_set_border_width (GTK_CONTAINER (add_remove_vb), 5);
245 gtk_box_pack_start (GTK_BOX (bottom_hb), add_remove_vb, FALSE, FALSE, 0);
246 gtk_widget_show(add_remove_vb);
248 add_bt = gtk_button_new_from_stock(GTK_STOCK_ADD);
249 g_signal_connect(add_bt, "clicked", G_CALLBACK(column_list_new_cb), column_l);
250 gtk_box_pack_start (GTK_BOX (add_remove_vb), add_bt, FALSE, FALSE, 0);
251 gtk_tooltips_set_tip (tooltips, add_bt,
252 "Add a new column at the end of the list.", NULL);
253 gtk_widget_show(add_bt);
255 remove_bt = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
256 gtk_widget_set_sensitive(remove_bt, FALSE);
257 g_signal_connect(remove_bt, "clicked", G_CALLBACK(column_list_delete_cb), column_l);
258 gtk_box_pack_start (GTK_BOX (add_remove_vb), remove_bt, FALSE, FALSE, 0);
259 gtk_tooltips_set_tip (tooltips, remove_bt,
260 "Remove the selected column.", NULL);
261 gtk_widget_show(remove_bt);
263 /* properties frame */
264 props_fr = gtk_frame_new("Properties");
265 gtk_box_pack_start (GTK_BOX (bottom_hb), props_fr, TRUE, TRUE, 0);
266 gtk_widget_show(props_fr);
268 /* Column name entry and format selection */
269 tb = gtk_table_new(2, 4, FALSE);
270 gtk_container_set_border_width(GTK_CONTAINER(tb), 5);
271 gtk_container_add(GTK_CONTAINER(props_fr), tb);
272 gtk_table_set_row_spacings(GTK_TABLE(tb), 10);
273 gtk_table_set_col_spacings(GTK_TABLE(tb), 15);
276 lb = gtk_label_new("Field type:");
277 gtk_misc_set_alignment(GTK_MISC(lb), 0.0f, 0.5f);
278 gtk_table_attach_defaults(GTK_TABLE(tb), lb, 0, 1, 0, 1);
279 gtk_tooltips_set_tip (tooltips, lb,
280 "Select which packet information to present in the column.", NULL);
283 props_hb = gtk_hbox_new(FALSE, 5);
284 gtk_table_attach(GTK_TABLE(tb), props_hb, 1, 2, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0);
285 gtk_tooltips_set_tip (tooltips, props_hb,
286 "Select which packet information to present in the column.", NULL);
287 gtk_widget_show(props_hb);
289 field_lb = gtk_label_new("Field name:");
290 gtk_misc_set_alignment(GTK_MISC(field_lb), 0.0f, 0.5f);
291 gtk_table_attach_defaults(GTK_TABLE(tb), field_lb, 0, 1, 1, 2);
292 gtk_widget_set_sensitive(field_lb, FALSE);
293 gtk_tooltips_set_tip (tooltips, field_lb,
294 "Field name used when field type is \"Custom\". "
295 "This string has the same syntax as a display filter string.", NULL);
296 gtk_widget_show(field_lb);
298 field_te = gtk_entry_new();
299 g_object_set_data (G_OBJECT(field_te), E_FILT_FIELD_NAME_ONLY_KEY, "");
300 g_signal_connect(field_te, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
302 /* XXX: column_field_changed_cb will be called for every character entered in the entry box. */
303 /* Consider Changing logic so that the field is "accepted" only when a return is entered ?? */
304 /* Also: entry shouldn't be accepted if it's not a valid filter ? */
305 column_field_changed_handler_id =
306 g_signal_connect(field_te, "changed", G_CALLBACK(column_field_changed_cb), column_l);
308 g_object_set_data(G_OBJECT(main_vb), E_FILT_AUTOCOMP_PTR_KEY, NULL);
309 g_signal_connect(field_te, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
310 g_signal_connect(prefs_window, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
311 colorize_filter_te_as_empty(field_te);
312 gtk_table_attach_defaults(GTK_TABLE(tb), field_te, 1, 2, 1, 2);
313 gtk_widget_set_sensitive(field_te, FALSE);
314 gtk_tooltips_set_tip (tooltips, field_te,
315 "Field name used when field type is \"Custom\". "
316 "This string has the same syntax as a display filter string.", NULL);
317 gtk_widget_show(field_te);
319 occurrence_lb = gtk_label_new("Field occurrence:");
320 gtk_misc_set_alignment(GTK_MISC(occurrence_lb), 0.0f, 0.5f);
321 gtk_table_attach_defaults(GTK_TABLE(tb), occurrence_lb, 2, 3, 1, 2);
322 gtk_widget_set_sensitive(occurrence_lb, FALSE);
323 gtk_tooltips_set_tip (tooltips, occurrence_lb,
324 "Field occurence to use. "
325 "0=all (default), 1=first, 2=second, ..., -1=last.", NULL);
326 gtk_widget_show(occurrence_lb);
328 occurrence_te = gtk_entry_new();
329 g_object_set_data (G_OBJECT(occurrence_te), "occurrence", "");
331 /* XXX: column_occurrence_changed_cb will be called for every character entered in the entry box. */
332 /* Consider Changing logic so that the field is "accepted" only when a return is entered ?? */
333 column_occurrence_changed_handler_id =
334 g_signal_connect(occurrence_te, "changed", G_CALLBACK(column_occurrence_changed_cb), column_l);
336 gtk_table_attach_defaults(GTK_TABLE(tb), occurrence_te, 3, 4, 1, 2);
337 gtk_widget_set_sensitive(occurrence_te, FALSE);
338 gtk_tooltips_set_tip (tooltips, occurrence_te,
339 "Field occurence to use. "
340 "0=all (default), 1=first, 2=second, ..., -1=last.", NULL);
341 gtk_widget_show(occurrence_te);
343 fmt_cmb = gtk_combo_box_new_text();
345 for (i = 0; i < NUM_COL_FMTS; i++)
346 gtk_combo_box_append_text(GTK_COMBO_BOX(fmt_cmb), col_format_desc(i));
348 column_menu_changed_handler_id = g_signal_connect(fmt_cmb, "changed", G_CALLBACK(column_menu_changed_cb), column_l);
350 gtk_widget_set_sensitive(fmt_cmb, FALSE);
351 gtk_box_pack_start(GTK_BOX(props_hb), fmt_cmb, FALSE, FALSE, 0);
352 gtk_widget_show(fmt_cmb);
354 /* select the first menu list row. */
355 /* Triggers call to column_list_select_cb(). */
356 gtk_tree_selection_select_iter(sel, &first_iter);
362 column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field, gint custom_occurrence)
365 fmt_data *cfmt, *last_cfmt;
367 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
369 * Because a single underscore is interpreted as a signal that the next character
370 * is going to be marked as accelerator for this header (i.e. is going to be
371 * shown underlined), escape it be inserting a second consecutive underscore.
373 cfmt->title = g_strdup(title);
374 cfmt->fmt = g_strdup(col_format_to_string(fmt));
375 cfmt->custom_field = g_strdup(custom_field);
376 cfmt->custom_occurrence = custom_occurrence;
377 cfmt->resolved = TRUE;
380 cfmt->visible = TRUE;
381 clp = g_list_last(prefs.col_list);
382 last_cfmt = (fmt_data *) clp->data;
383 if (strcmp(last_cfmt->fmt, "%i") == 0) {
384 /* Last column is COL_INFO, add custom column before this */
385 prefs.col_list = g_list_insert(prefs.col_list, cfmt, g_list_length(prefs.col_list)-1);
387 prefs.col_list = g_list_append(prefs.col_list, cfmt);
390 cfmt->visible = FALSE; /* Will be set to TRUE in visible_toggled() when added to list */
391 prefs.col_list = g_list_append(prefs.col_list, cfmt);
396 column_prefs_rename(gint col, const gchar *title)
398 GList *clp = g_list_nth(prefs.col_list, col);
399 fmt_data *cfmt = (fmt_data *) clp->data;
401 g_free (cfmt->title);
402 cfmt->title = g_strdup(title);
406 column_prefs_remove(gint col)
408 GList *clp = g_list_nth(prefs.col_list, col);
409 fmt_data *cfmt = (fmt_data *) clp->data;
413 g_free(cfmt->custom_field);
415 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
418 /* To do: add input checking to each of these callbacks */
421 column_list_new_cb(GtkWidget *w _U_, gpointer data) {
423 const gchar *title = "New Column";
424 GtkTreeView *column_l = GTK_TREE_VIEW(data);
428 GtkTreeViewColumn *title_column;
430 cur_fmt = COL_NUMBER; /* Set the default new column type */
431 column_prefs_add_custom (cur_fmt, title, NULL, 0);
433 model = gtk_tree_view_get_model(column_l);
434 #if GTK_CHECK_VERSION(2,6,0)
435 gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, G_MAXINT,
437 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
438 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
440 #ifdef NEW_PACKET_LIST
441 VISIBLE_COLUMN, TRUE,
444 FORMAT_COLUMN, col_format_desc(cur_fmt),
445 DATA_COLUMN, g_list_last(prefs.col_list),
448 /* Triggers call to column_list_select_cb() */
449 gtk_tree_selection_select_iter(gtk_tree_view_get_selection(column_l), &iter);
451 /* Set the cursor to the 'Title' column of the newly added row and enable editing */
452 /* XXX: If displaying the new title ["New column"] widens the title column of the */
453 /* treeview, then the set_cursor below doesn't properly generate an entry */
454 /* box around the title text. The width of the box appears to be the column */
455 /* width before the treeview title column was widened. Seems like a bug... */
456 /* I haven't found a work-around. */
457 path = gtk_tree_model_get_path(model, &iter);
458 title_column = gtk_tree_view_get_column(column_l, 0);
459 gtk_tree_view_set_cursor(column_l, path, title_column, TRUE);
460 gtk_tree_path_free(path);
462 cfile.cinfo.columns_changed = TRUE;
467 column_list_delete_cb(GtkWidget *w _U_, gpointer data) {
468 GtkTreeView *column_l = GTK_TREE_VIEW(data);
471 GtkTreeSelection *sel;
474 GtkTreeIter new_iter;
476 sel = gtk_tree_view_get_selection(column_l);
477 if (gtk_tree_selection_get_selected(sel, &model, &iter))
479 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
481 cfmt = (fmt_data *) clp->data;
484 g_free(cfmt->custom_field);
486 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
488 /* Change the row selection to the next row (if available) or */
489 /* the previous row (if available). If there's only one row */
490 /* in the store (no previous and no next), then the selection */
491 /* will not be changed. */
493 /* Note that gtk_tree_selection_select_iter() will trigger a */
494 /* call to column_list_select_cb(). */
497 if ( gtk_tree_model_iter_next(model, &new_iter)) {
498 gtk_tree_selection_select_iter(sel, &new_iter);
499 } else { /* "gtk_tree_model_iter_prev" */
500 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
501 if (gtk_tree_path_prev(path)) {
502 gtk_tree_model_get_iter(model, &new_iter, path);
503 gtk_tree_selection_select_iter(sel, &new_iter);
505 gtk_tree_path_free(path);
508 /* Remove the row from the list store. */
509 /* We prevent triggering call to column_row_deleted_cb() since */
510 /* the entry has already been removed from prefs.col_list and */
511 /* since rebuilding the list is not needed because the order */
512 /* of the list hasn't changed. */
514 g_signal_handler_block(model, column_row_deleted_handler_id);
516 /* list_store_remove below will trigger a call to */
517 /* column_list_select_cb() only when deleting the last entry in */
518 /* the column list. */
519 /* (This is because the selection in this case changes to */
520 /* "nothing selected" when the last row is removed. */
522 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
524 g_signal_handler_unblock (model, column_row_deleted_handler_id);
526 cfile.cinfo.columns_changed = TRUE;
532 column_title_changed_cb(GtkCellRendererText *cell _U_, const gchar *str_path, const gchar *new_title, gpointer data) {
535 GtkTreeModel *model = (GtkTreeModel *)data;
536 GtkTreePath *path = gtk_tree_path_new_from_string (str_path);
539 gtk_tree_model_get_iter(model, &iter, path);
541 gtk_list_store_set(GTK_LIST_STORE(model), &iter, TITLE_COLUMN, new_title, -1);
543 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
545 cfmt = (fmt_data *) clp->data;
547 cfmt->title = g_strdup(new_title);
550 gtk_tree_path_free (path);
551 cfile.cinfo.columns_changed = TRUE;
556 * column list row selection changed.
557 * Set the "Properties" widgets to match the currently selected column row item.
561 column_list_select_cb(GtkTreeSelection *sel, gpointer data _U_)
569 /* if something was selected */
570 if (gtk_tree_selection_get_selected(sel, &model, &iter))
572 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
573 g_assert(clp != NULL);
574 cfmt = (fmt_data *) clp->data;
575 cur_fmt = get_column_format_from_str(cfmt->fmt);
576 g_assert(cur_fmt != -1); /* It should always be valid */
578 g_signal_handler_block (fmt_cmb, column_menu_changed_handler_id);
579 gtk_combo_box_set_active(GTK_COMBO_BOX(fmt_cmb), cur_fmt);
580 g_signal_handler_unblock(fmt_cmb, column_menu_changed_handler_id);
582 g_signal_handler_block (field_te, column_field_changed_handler_id);
583 g_signal_handler_block (occurrence_te, column_occurrence_changed_handler_id);
584 if (cur_fmt == COL_CUSTOM) {
585 gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
586 gtk_widget_set_sensitive(field_lb, TRUE);
587 gtk_widget_set_sensitive(field_te, TRUE);
588 g_snprintf(custom_occurrence_str, sizeof(custom_occurrence_str), "%d", cfmt->custom_occurrence);
589 gtk_entry_set_text(GTK_ENTRY(occurrence_te), custom_occurrence_str);
590 gtk_widget_set_sensitive(occurrence_lb, TRUE);
591 gtk_widget_set_sensitive(occurrence_te, TRUE);
593 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
594 gtk_widget_set_sensitive(field_lb, FALSE);
595 gtk_widget_set_sensitive(field_te, FALSE);
596 gtk_editable_delete_text(GTK_EDITABLE(occurrence_te), 0, -1);
597 gtk_widget_set_sensitive(occurrence_lb, FALSE);
598 gtk_widget_set_sensitive(occurrence_te, FALSE);
600 g_signal_handler_unblock(occurrence_te, column_occurrence_changed_handler_id);
601 g_signal_handler_unblock(field_te, column_field_changed_handler_id);
603 gtk_widget_set_sensitive(remove_bt, TRUE);
604 gtk_widget_set_sensitive(fmt_cmb, TRUE);
608 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
609 gtk_editable_delete_text(GTK_EDITABLE(occurrence_te), 0, -1);
611 gtk_widget_set_sensitive(remove_bt, FALSE);
612 gtk_widget_set_sensitive(field_te, FALSE);
613 gtk_widget_set_sensitive(occurrence_te, FALSE);
614 gtk_widget_set_sensitive(fmt_cmb, FALSE);
620 * The user selected a new entry in the format combo-box;
621 * Note: column_menu_changed_cb is expected to be called only
622 * when the user changes the format combo-box.
624 * If no selection active in the column list:
625 * Hide 'field"; desensitize buttons.
626 * XXX: Can this happen ?
627 * If a column list selection is active:
628 * 1. Update the display of "field" as req'd (depending upon
629 * whether the active combo-box entry is the "custom"
631 * 2. Update the column_list and prefs.col_formats.
632 * Set columns_changed = TRUE.
636 column_menu_changed_cb(GtkWidget *w, gpointer data) {
637 GtkTreeView *column_l = GTK_TREE_VIEW(data);
643 GtkTreeSelection *sel;
647 sel = gtk_tree_view_get_selection(column_l);
648 if (! (gtk_tree_selection_get_selected(sel, &model, &iter)))
649 return; /* no column list selection [Can this happen ?]: ignore callback */
651 cur_cb_fmt = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
652 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
653 cfmt = (fmt_data *) clp->data;
654 cur_fmt = get_column_format_from_str(cfmt->fmt);
656 g_assert(cur_cb_fmt != cur_fmt);
658 /* The User has selected a new format in the combo-box */
659 /* (IE: combo-box format != current selected row format) */
660 /* Update field widgets, list_store, column format array */
661 /* entry as appropriate. */
662 g_signal_handler_block (field_te, column_field_changed_handler_id);
663 g_signal_handler_block (occurrence_te, column_occurrence_changed_handler_id);
664 if (cur_fmt == COL_CUSTOM) {
665 /* Changing from custom to non-custom */
666 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
667 gtk_editable_delete_text(GTK_EDITABLE(occurrence_te), 0, -1);
668 fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
669 gtk_widget_set_sensitive(field_lb, FALSE);
670 gtk_widget_set_sensitive(field_te, FALSE);
671 gtk_widget_set_sensitive(occurrence_lb, FALSE);
672 gtk_widget_set_sensitive(occurrence_te, FALSE);
674 } else if (cur_cb_fmt == COL_CUSTOM) {
675 /* Changing from non-custom to custom */
676 if (cfmt->custom_field == NULL)
677 cfmt->custom_field = g_strdup("");
678 /* The following doesn't trigger a call to menu_field_changed_cb() */
679 gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
680 g_snprintf(custom_occurrence_str, sizeof(custom_occurrence_str), "%d", cfmt->custom_occurrence);
681 gtk_entry_set_text(GTK_ENTRY(occurrence_te), custom_occurrence_str);
683 if (cfmt->custom_occurrence) {
684 fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cur_cb_fmt), cfmt->custom_field, cfmt->custom_occurrence);
686 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_cb_fmt), cfmt->custom_field);
688 gtk_widget_set_sensitive(field_lb, TRUE);
689 gtk_widget_set_sensitive(field_te, TRUE);
690 gtk_widget_set_sensitive(occurrence_lb, TRUE);
691 gtk_widget_set_sensitive(occurrence_te, TRUE);
694 /* Changing from non-custom to non-custom */
695 fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
697 g_signal_handler_unblock(occurrence_te, column_occurrence_changed_handler_id);
698 g_signal_handler_unblock(field_te, column_field_changed_handler_id);
700 gtk_list_store_set(GTK_LIST_STORE(model), &iter, FORMAT_COLUMN, fmt, -1);
703 cfmt->fmt = g_strdup(col_format_to_string(cur_cb_fmt));
704 cfile.cinfo.columns_changed = TRUE;
709 * The user changed the custom field entry box or
710 * the field entry box has been updated because a new
711 * column row with custom format has been selected.
712 * If the current field entry matches that of the current
713 * column row, this is just an update because a new
714 * column row has been selected. Do nothing.
715 * If the two are different, then update the column row & etc.
718 column_field_changed_cb(GtkEditable *te, gpointer data) {
723 GtkTreeView *tree = (GtkTreeView *)data;
724 GtkTreeSelection *sel;
728 sel = gtk_tree_view_get_selection(tree);
729 if ( ! (gtk_tree_selection_get_selected(sel, &model, &iter))) {
733 field = gtk_editable_get_chars(te, 0, -1);
734 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
735 cfmt = (fmt_data *) clp->data;
736 if (strcmp(cfmt->custom_field, field) == 0) {
737 return; /* no action req'd */
740 /* The user has entered a new value in the field entry box: make the req'd changes */
741 cur_fmt = get_column_format_from_str(cfmt->fmt);
742 if (cfmt->custom_occurrence) {
743 fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cur_fmt), field, cfmt->custom_occurrence);
745 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), field);
748 gtk_list_store_set(GTK_LIST_STORE(model), &iter, FORMAT_COLUMN, fmt, -1);
750 g_free(cfmt->custom_field);
751 cfmt->custom_field = field;
752 cfile.cinfo.columns_changed = TRUE;
757 * The user changed the custom field occurrence entry box or
758 * the field occurrece entry box has been updated because a new
759 * column row with custom format has been selected.
760 * If the current field entry matches that of the current
761 * column row, this is just an update because a new
762 * column row has been selected. Do nothing.
763 * If the two are different, then update the column row & etc.
766 column_occurrence_changed_cb(GtkEditable *te, gpointer data) {
772 GtkTreeView *tree = (GtkTreeView *)data;
773 GtkTreeSelection *sel;
777 sel = gtk_tree_view_get_selection(tree);
778 if ( ! (gtk_tree_selection_get_selected(sel, &model, &iter))) {
782 occurrence = (gint)strtol(gtk_editable_get_chars(te, 0, -1), NULL, 10);
783 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
784 cfmt = (fmt_data *) clp->data;
785 if (cfmt->custom_occurrence == occurrence) {
786 return; /* no action req'd */
789 /* The user has entered a new value in the field occurrence entry box: make the req'd changes */
790 cur_fmt = get_column_format_from_str(cfmt->fmt);
792 fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cur_fmt), cfmt->custom_field, occurrence);
794 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), cfmt->custom_field);
797 gtk_list_store_set(GTK_LIST_STORE(model), &iter, FORMAT_COLUMN, fmt, -1);
799 cfmt->custom_occurrence = occurrence;
800 cfile.cinfo.columns_changed = TRUE;
805 * Callback for the "row-deleted" signal emitted when a list item is dragged.
806 * http://library.gnome.org/devel/gtk/stable/GtkTreeModel.html#GtkTreeModel-rows-reordered
807 * says that DND deletes, THEN inserts the row.
809 * XXX: For the record: For Gtk+ 2.16.0 testing shows the actual sequence for drag-and-drop to be as follows:
810 * 1. Insert a new, empty row at the destination;
811 * 2. Emit a "row-inserted" signal on the model; invoke any row-inserted callbacks & etc;
812 * 3. Copy the source row data to the new (empty) destination row;
813 * 4. Delete the source row;
814 * 5. Emit a "row-deleted" signal; invoke any row-deleted callbacks & etc.
816 * The code below (invoked as a consequence of a "row-deleted" signal) rebuilds
817 * prefs.col_list by iterating over the (re-ordered) tree model.
820 column_dnd_row_deleted_cb(GtkTreeModel *model, GtkTreePath *path _U_, gpointer data _U_) {
822 GList *clp, *new_col_list = NULL;
826 * XXX - This rebuilds prefs.col_list based on the current model. We
827 * might just want to do this when the prefs are applied
829 for (items_left = gtk_tree_model_get_iter_first (model, &iter);
831 items_left = gtk_tree_model_iter_next (model, &iter)) {
833 gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
835 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
836 new_col_list = g_list_concat(new_col_list, clp);
839 if (prefs.col_list) {
840 g_warning("column_dnd_row_deleted_cb: prefs.col_list has %d leftover data",
841 g_list_length(prefs.col_list));
842 g_list_free(prefs.col_list);
845 prefs.col_list = new_col_list;
846 cfile.cinfo.columns_changed = TRUE;
851 column_prefs_fetch(GtkWidget *w _U_) {
856 column_prefs_apply(GtkWidget *w _U_)
858 /* Redraw the packet list if the columns were changed */
859 if(cfile.cinfo.columns_changed) {
860 #ifdef NEW_PACKET_LIST
861 new_packet_list_recreate();
863 packet_list_recreate();
865 cfile.cinfo.columns_changed = FALSE; /* Reset value */
871 column_prefs_destroy(GtkWidget *w _U_) {