2000-01-10 01:44:00 +00:00
|
|
|
/* column_prefs.c
|
|
|
|
* Dialog box for column preferences
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2000-01-10 01:44:00 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-01-10 01:44:00 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-01-10 01:44:00 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-01-10 01:44:00 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-01-10 01:44:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-12-03 22:16:49 +00:00
|
|
|
#include <stdlib.h>
|
2009-05-04 14:46:51 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-10-20 04:26:40 +00:00
|
|
|
#include <gtk/gtk.h>
|
2000-01-10 01:44:00 +00:00
|
|
|
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2004-09-29 02:54:22 +00:00
|
|
|
#include <epan/column.h>
|
2008-04-13 00:55:59 +00:00
|
|
|
|
2013-01-23 19:04:36 +00:00
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
#include "ui/preference_utils.h"
|
2008-04-13 00:55:59 +00:00
|
|
|
|
2015-01-08 09:01:56 +00:00
|
|
|
#include "ui/gtk/old-gtk-compat.h"
|
2012-01-15 21:59:11 +00:00
|
|
|
#include "ui/gtk/prefs_column.h"
|
|
|
|
#include "ui/gtk/gui_utils.h"
|
2012-09-04 01:57:36 +00:00
|
|
|
#include "ui/gtk/packet_list.h"
|
2012-01-15 21:59:11 +00:00
|
|
|
#include "ui/gtk/filter_dlg.h"
|
|
|
|
#include "ui/gtk/filter_autocomplete.h"
|
2014-02-21 13:09:52 +00:00
|
|
|
#include "ui/gtk/stock_icons.h"
|
2002-11-03 17:38:45 +00:00
|
|
|
|
2010-09-22 20:56:14 +00:00
|
|
|
static GtkWidget *remove_bt, *field_te, *field_lb, *occurrence_te, *occurrence_lb, *fmt_cmb;
|
2009-05-04 14:46:51 +00:00
|
|
|
static gulong column_menu_changed_handler_id;
|
|
|
|
static gulong column_field_changed_handler_id;
|
2010-09-22 20:56:14 +00:00
|
|
|
static gulong column_occurrence_changed_handler_id;
|
2009-05-04 14:46:51 +00:00
|
|
|
static gulong column_row_deleted_handler_id;
|
2000-01-10 01:44:00 +00:00
|
|
|
|
2009-01-20 05:14:57 +00:00
|
|
|
static void column_list_new_cb(GtkWidget *, gpointer);
|
|
|
|
static void column_list_delete_cb(GtkWidget *, gpointer);
|
2009-05-04 14:46:51 +00:00
|
|
|
static void column_list_select_cb(GtkTreeSelection *, gpointer);
|
|
|
|
static void column_menu_changed_cb(GtkWidget *, gpointer);
|
|
|
|
static void column_field_changed_cb(GtkEditable *, gpointer);
|
2010-09-22 20:56:14 +00:00
|
|
|
static void column_occurrence_changed_cb(GtkEditable *, gpointer);
|
2009-01-20 05:14:57 +00:00
|
|
|
static void column_dnd_row_deleted_cb(GtkTreeModel *, GtkTreePath *, gpointer);
|
2009-01-20 20:49:33 +00:00
|
|
|
static gboolean column_title_changed_cb(GtkCellRendererText *, const gchar *, const gchar *, gpointer);
|
2000-01-10 01:44:00 +00:00
|
|
|
|
2010-09-22 20:56:14 +00:00
|
|
|
static char custom_occurrence_str[8] = "";
|
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
enum {
|
2013-01-11 18:26:35 +00:00
|
|
|
VISIBLE_COLUMN,
|
|
|
|
TITLE_COLUMN,
|
|
|
|
FORMAT_COLUMN,
|
|
|
|
DATA_COLUMN,
|
|
|
|
N_COLUMN /* The number of columns */
|
2010-06-20 16:23:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Visible toggled */
|
|
|
|
static void
|
|
|
|
visible_toggled(GtkCellRendererToggle *cell _U_, gchar *path_str, gpointer data)
|
|
|
|
{
|
2013-01-11 18:26:35 +00:00
|
|
|
GtkTreeModel *model = (GtkTreeModel *)data;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
|
|
|
|
GList *clp;
|
|
|
|
fmt_data *cfmt;
|
2010-06-20 16:23:43 +00:00
|
|
|
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_tree_model_get_iter(model, &iter, path);
|
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
2010-06-20 16:23:43 +00:00
|
|
|
|
2013-01-11 18:26:35 +00:00
|
|
|
cfmt = (fmt_data *) clp->data;
|
|
|
|
if (cfmt->visible)
|
|
|
|
cfmt->visible = FALSE;
|
|
|
|
else
|
|
|
|
cfmt->visible = TRUE;
|
2010-06-20 16:23:43 +00:00
|
|
|
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_list_store_set(GTK_LIST_STORE(model), &iter, VISIBLE_COLUMN, cfmt->visible, -1);
|
|
|
|
cfile.columns_changed = TRUE;
|
2010-06-20 16:23:43 +00:00
|
|
|
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_tree_path_free(path);
|
2010-06-20 16:23:43 +00:00
|
|
|
} /* visible_toggled */
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
/*
|
|
|
|
* Create and display the column selection widgets.
|
|
|
|
* Called as part of the creation of the Preferences notebook ( Edit ! Preferences )
|
|
|
|
*/
|
2000-01-10 01:44:00 +00:00
|
|
|
GtkWidget *
|
2008-10-19 13:40:52 +00:00
|
|
|
column_prefs_show(GtkWidget *prefs_window) {
|
2013-07-01 14:32:08 +00:00
|
|
|
GtkWidget *main_vb, *bottom_hb, *column_l, *add_bt, *grid, *lb;
|
|
|
|
GtkWidget *list_vb, *list_lb, *list_sc;
|
|
|
|
GtkWidget *add_remove_vb;
|
|
|
|
GtkWidget *props_fr, *props_hb;
|
|
|
|
GList *clp;
|
|
|
|
fmt_data *cfmt;
|
|
|
|
gint i;
|
|
|
|
gchar *fmt;
|
|
|
|
static const gchar *column_titles[] = {"Displayed", "Title", "Field type"};
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter first_iter;
|
|
|
|
gint first_row = TRUE;
|
2009-04-09 13:07:05 +00:00
|
|
|
|
|
|
|
/* Container for each row of widgets */
|
2012-04-21 16:40:14 +00:00
|
|
|
main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
|
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
2012-04-21 16:40:14 +00:00
|
|
|
list_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (list_vb), 5);
|
|
|
|
gtk_widget_show (list_vb);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vb), list_vb, TRUE, TRUE, 0);
|
|
|
|
|
2013-01-11 18:26:35 +00:00
|
|
|
list_lb = gtk_label_new (
|
|
|
|
"[The first list entry will be displayed as the leftmost column"
|
|
|
|
" - Drag and drop entries to change column order]");
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show (list_lb);
|
|
|
|
gtk_box_pack_start (GTK_BOX (list_vb), list_lb, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
list_sc = scrolled_window_new(NULL, NULL);
|
2009-05-04 14:46:51 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_sc), GTK_SHADOW_IN);
|
2012-07-20 21:35:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(list_vb), list_sc, TRUE, TRUE, 0);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show(list_sc);
|
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
store = gtk_list_store_new(N_COLUMN,
|
2013-01-11 18:26:35 +00:00
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
|
2011-07-11 18:18:35 +00:00
|
|
|
column_row_deleted_handler_id =
|
2009-05-04 14:46:51 +00:00
|
|
|
g_signal_connect(GTK_TREE_MODEL(store), "row-deleted", G_CALLBACK(column_dnd_row_deleted_cb), NULL);
|
2009-04-09 13:07:05 +00:00
|
|
|
|
|
|
|
column_l = tree_view_new(GTK_TREE_MODEL(store));
|
|
|
|
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(column_l), TRUE);
|
|
|
|
gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(column_l), FALSE);
|
|
|
|
gtk_tree_view_set_reorderable(GTK_TREE_VIEW(column_l), TRUE);
|
2011-07-12 06:54:01 +00:00
|
|
|
gtk_widget_set_tooltip_text(column_l, "Click on a title to change its name.\nDrag an item to change its order.");
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
renderer = gtk_cell_renderer_toggle_new();
|
|
|
|
g_signal_connect(renderer, "toggled", G_CALLBACK(visible_toggled), store);
|
|
|
|
column = gtk_tree_view_column_new_with_attributes(column_titles[VISIBLE_COLUMN], renderer, "active", VISIBLE_COLUMN, NULL);
|
|
|
|
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
|
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
|
|
|
|
g_signal_connect (renderer, "edited", G_CALLBACK(column_title_changed_cb), GTK_TREE_MODEL(store));
|
2010-06-20 16:23:43 +00:00
|
|
|
column = gtk_tree_view_column_new_with_attributes(column_titles[TITLE_COLUMN], renderer, "text", TITLE_COLUMN, NULL);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
renderer = gtk_cell_renderer_text_new();
|
2010-06-20 16:23:43 +00:00
|
|
|
column = gtk_tree_view_column_new_with_attributes(column_titles[FORMAT_COLUMN], renderer, "text", FORMAT_COLUMN, NULL);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
/* XXX - make this match the packet list prefs? */
|
|
|
|
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(column_l));
|
|
|
|
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
|
2009-05-04 14:46:51 +00:00
|
|
|
g_signal_connect(sel, "changed", G_CALLBACK(column_list_select_cb), NULL);
|
2009-04-09 13:07:05 +00:00
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(list_sc), column_l);
|
|
|
|
gtk_widget_show(column_l);
|
|
|
|
|
|
|
|
clp = g_list_first(prefs.col_list);
|
|
|
|
while (clp) {
|
|
|
|
cfmt = (fmt_data *) clp->data;
|
2011-11-13 22:51:49 +00:00
|
|
|
if (cfmt->fmt == COL_CUSTOM) {
|
2010-09-22 20:56:14 +00:00
|
|
|
if (cfmt->custom_occurrence) {
|
2011-11-13 22:51:49 +00:00
|
|
|
fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cfmt->fmt), cfmt->custom_field, cfmt->custom_occurrence);
|
2010-09-22 20:56:14 +00:00
|
|
|
} else {
|
2011-11-13 22:51:49 +00:00
|
|
|
fmt = g_strdup_printf("%s (%s)", col_format_desc(cfmt->fmt), cfmt->custom_field);
|
2010-09-22 20:56:14 +00:00
|
|
|
}
|
2009-04-09 13:07:05 +00:00
|
|
|
} else {
|
2009-07-20 11:42:28 +00:00
|
|
|
if (cfmt->custom_field) {
|
|
|
|
/* Delete custom_field from previous changes */
|
|
|
|
g_free (cfmt->custom_field);
|
|
|
|
cfmt->custom_field = NULL;
|
2010-09-22 20:56:14 +00:00
|
|
|
cfmt->custom_occurrence = 0;
|
2009-07-20 11:42:28 +00:00
|
|
|
}
|
2011-11-13 22:51:49 +00:00
|
|
|
fmt = g_strdup_printf("%s", col_format_desc(cfmt->fmt));
|
2009-04-09 13:07:05 +00:00
|
|
|
}
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_list_store_insert_with_values(store, &iter, G_MAXINT,
|
2013-01-11 18:26:35 +00:00
|
|
|
VISIBLE_COLUMN, cfmt->visible,
|
|
|
|
TITLE_COLUMN, cfmt->title, FORMAT_COLUMN, fmt, DATA_COLUMN, clp, -1);
|
2010-06-20 16:23:43 +00:00
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
if (first_row) {
|
|
|
|
first_iter = iter;
|
|
|
|
first_row = FALSE;
|
|
|
|
}
|
|
|
|
clp = clp->next;
|
|
|
|
g_free (fmt);
|
2004-01-17 12:12:57 +00:00
|
|
|
}
|
2009-04-09 13:07:05 +00:00
|
|
|
g_object_unref(G_OBJECT(store));
|
2009-01-20 20:49:33 +00:00
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
/* Bottom row: Add/remove buttons and properties */
|
2012-04-21 16:40:14 +00:00
|
|
|
bottom_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE);
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vb), bottom_hb, FALSE, FALSE, 0);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show(bottom_hb);
|
|
|
|
|
|
|
|
/* Add / remove buttons */
|
2012-04-21 16:40:14 +00:00
|
|
|
add_remove_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, TRUE);
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (add_remove_vb), 5);
|
|
|
|
gtk_box_pack_start (GTK_BOX (bottom_hb), add_remove_vb, FALSE, FALSE, 0);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show(add_remove_vb);
|
|
|
|
|
2014-02-21 13:09:52 +00:00
|
|
|
add_bt = ws_gtk_button_new_from_stock(GTK_STOCK_ADD);
|
2009-04-09 13:07:05 +00:00
|
|
|
g_signal_connect(add_bt, "clicked", G_CALLBACK(column_list_new_cb), column_l);
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (add_remove_vb), add_bt, FALSE, FALSE, 0);
|
2011-07-12 06:54:01 +00:00
|
|
|
gtk_widget_set_tooltip_text(add_bt, "Add a new column at the end of the list.");
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show(add_bt);
|
|
|
|
|
2014-02-21 13:09:52 +00:00
|
|
|
remove_bt = ws_gtk_button_new_from_stock(GTK_STOCK_REMOVE);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_set_sensitive(remove_bt, FALSE);
|
|
|
|
g_signal_connect(remove_bt, "clicked", G_CALLBACK(column_list_delete_cb), column_l);
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (add_remove_vb), remove_bt, FALSE, FALSE, 0);
|
2011-07-12 06:54:01 +00:00
|
|
|
gtk_widget_set_tooltip_text(remove_bt, "Remove the selected column.");
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show(remove_bt);
|
2011-07-11 18:18:35 +00:00
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
/* properties frame */
|
|
|
|
props_fr = gtk_frame_new("Properties");
|
|
|
|
gtk_box_pack_start (GTK_BOX (bottom_hb), props_fr, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show(props_fr);
|
|
|
|
|
|
|
|
/* Column name entry and format selection */
|
2013-01-11 18:26:35 +00:00
|
|
|
/* XXX: IMO, the grid should have a fixed width instead of
|
|
|
|
* expanding to the horizontal window width when the window
|
|
|
|
* is resized horizontally. However, I couldn't quite make
|
|
|
|
* things work properly when I tried to change the grid
|
|
|
|
* behavior.
|
|
|
|
*/
|
|
|
|
grid = ws_gtk_grid_new();
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(grid), 5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(props_fr), grid);
|
|
|
|
ws_gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
|
|
|
|
ws_gtk_grid_set_column_spacing(GTK_GRID(grid), 15);
|
|
|
|
gtk_widget_show(grid);
|
2009-04-09 13:07:05 +00:00
|
|
|
|
2009-07-20 11:42:28 +00:00
|
|
|
lb = gtk_label_new("Field type:");
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(lb), 0.0f, 0.5f);
|
2013-03-28 06:36:44 +00:00
|
|
|
ws_gtk_grid_attach_extended(GTK_GRID(grid), lb, 0, 0, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
|
2011-07-12 06:54:01 +00:00
|
|
|
gtk_widget_set_tooltip_text(lb, "Select which packet information to present in the column.");
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show(lb);
|
|
|
|
|
2012-04-21 16:40:14 +00:00
|
|
|
props_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE);
|
2013-03-28 06:36:44 +00:00
|
|
|
ws_gtk_grid_attach_extended(GTK_GRID(grid), props_hb, 1, 0, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
|
2011-07-12 06:54:01 +00:00
|
|
|
gtk_widget_set_tooltip_text(props_hb, "Select which packet information to present in the column.");
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_show(props_hb);
|
|
|
|
|
|
|
|
field_lb = gtk_label_new("Field name:");
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(field_lb), 0.0f, 0.5f);
|
2013-03-28 06:36:44 +00:00
|
|
|
ws_gtk_grid_attach_extended(GTK_GRID(grid), field_lb, 0, 1, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_widget_set_sensitive(field_lb, FALSE);
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_widget_set_tooltip_text(field_lb,
|
2013-06-03 20:34:50 +00:00
|
|
|
"Display filter field name to show when the field type is \"Custom\".");
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_widget_show(field_lb);
|
2009-04-09 13:07:05 +00:00
|
|
|
|
|
|
|
field_te = gtk_entry_new();
|
2014-12-19 08:21:20 +00:00
|
|
|
g_object_set_data (G_OBJECT(field_te), E_FILT_MULTI_FIELD_NAME_ONLY_KEY, (gpointer)"");
|
2009-04-09 13:07:05 +00:00
|
|
|
g_signal_connect(field_te, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
/* XXX: column_field_changed_cb will be called for every character entered in the entry box. */
|
|
|
|
/* Consider Changing logic so that the field is "accepted" only when a return is entered ?? */
|
|
|
|
/* Also: entry shouldn't be accepted if it's not a valid filter ? */
|
2011-07-11 18:18:35 +00:00
|
|
|
column_field_changed_handler_id =
|
2009-05-04 14:46:51 +00:00
|
|
|
g_signal_connect(field_te, "changed", G_CALLBACK(column_field_changed_cb), column_l);
|
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
g_object_set_data(G_OBJECT(main_vb), E_FILT_AUTOCOMP_PTR_KEY, NULL);
|
|
|
|
g_signal_connect(field_te, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
|
|
|
|
g_signal_connect(prefs_window, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
|
|
|
|
colorize_filter_te_as_empty(field_te);
|
2013-03-28 06:36:44 +00:00
|
|
|
ws_gtk_grid_attach_extended(GTK_GRID(grid), field_te, 1, 1, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_widget_set_sensitive(field_te, FALSE);
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_widget_set_tooltip_text(field_te,
|
2013-06-03 20:34:50 +00:00
|
|
|
"Display filter field name to show when the field type is \"Custom\".");
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_widget_show(field_te);
|
2009-04-09 13:07:05 +00:00
|
|
|
|
2010-09-22 20:56:14 +00:00
|
|
|
occurrence_lb = gtk_label_new("Field occurrence:");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(occurrence_lb), 0.0f, 0.5f);
|
2013-03-28 06:36:44 +00:00
|
|
|
ws_gtk_grid_attach_extended(GTK_GRID(grid), occurrence_lb, 2, 1, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_widget_set_sensitive(occurrence_lb, FALSE);
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_widget_set_tooltip_text(occurrence_lb,
|
2013-02-26 04:42:26 +00:00
|
|
|
"Field occurrence to use. "
|
2011-07-12 06:54:01 +00:00
|
|
|
"0=all (default), 1=first, 2=second, ..., -1=last.");
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_widget_show(occurrence_lb);
|
|
|
|
|
|
|
|
occurrence_te = gtk_entry_new();
|
2010-09-25 09:33:29 +00:00
|
|
|
gtk_entry_set_max_length (GTK_ENTRY(occurrence_te),4);
|
2012-12-26 05:57:06 +00:00
|
|
|
g_object_set_data (G_OBJECT(occurrence_te), "occurrence", (gpointer)"");
|
2010-09-22 20:56:14 +00:00
|
|
|
|
|
|
|
/* XXX: column_occurrence_changed_cb will be called for every character entered in the entry box. */
|
|
|
|
/* Consider Changing logic so that the field is "accepted" only when a return is entered ?? */
|
2011-07-11 18:18:35 +00:00
|
|
|
column_occurrence_changed_handler_id =
|
2010-09-22 20:56:14 +00:00
|
|
|
g_signal_connect(occurrence_te, "changed", G_CALLBACK(column_occurrence_changed_cb), column_l);
|
|
|
|
|
2013-03-28 06:36:44 +00:00
|
|
|
ws_gtk_grid_attach_extended(GTK_GRID(grid), occurrence_te, 3, 1, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_widget_set_sensitive(occurrence_te, FALSE);
|
2013-01-11 18:26:35 +00:00
|
|
|
gtk_widget_set_tooltip_text(occurrence_te,
|
2013-02-26 04:42:26 +00:00
|
|
|
"Field occurrence to use. "
|
2011-07-12 06:54:01 +00:00
|
|
|
"0=all (default), 1=first, 2=second, ..., -1=last.");
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_widget_show(occurrence_te);
|
|
|
|
|
2011-07-24 17:25:52 +00:00
|
|
|
fmt_cmb = gtk_combo_box_text_new();
|
2009-04-09 13:07:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NUM_COL_FMTS; i++)
|
2011-07-24 17:25:52 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(fmt_cmb), col_format_desc(i));
|
2009-04-09 13:07:05 +00:00
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
column_menu_changed_handler_id = g_signal_connect(fmt_cmb, "changed", G_CALLBACK(column_menu_changed_cb), column_l);
|
2009-04-09 13:07:05 +00:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive(fmt_cmb, FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(props_hb), fmt_cmb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(fmt_cmb);
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
/* select the first menu list row. */
|
|
|
|
/* Triggers call to column_list_select_cb(). */
|
2009-04-09 13:07:05 +00:00
|
|
|
gtk_tree_selection_select_iter(sel, &first_iter);
|
|
|
|
|
|
|
|
return(main_vb);
|
2000-01-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* To do: add input checking to each of these callbacks */
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-01-10 01:44:00 +00:00
|
|
|
static void
|
2009-01-20 20:49:33 +00:00
|
|
|
column_list_new_cb(GtkWidget *w _U_, gpointer data) {
|
2009-05-04 14:46:51 +00:00
|
|
|
gint cur_fmt;
|
2009-01-20 20:49:33 +00:00
|
|
|
const gchar *title = "New Column";
|
|
|
|
GtkTreeView *column_l = GTK_TREE_VIEW(data);
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeViewColumn *title_column;
|
2002-04-22 02:03:53 +00:00
|
|
|
|
2009-11-19 18:22:26 +00:00
|
|
|
cur_fmt = COL_NUMBER; /* Set the default new column type */
|
2010-09-22 20:56:14 +00:00
|
|
|
column_prefs_add_custom (cur_fmt, title, NULL, 0);
|
2002-11-03 17:38:45 +00:00
|
|
|
|
2009-01-20 20:49:33 +00:00
|
|
|
model = gtk_tree_view_get_model(column_l);
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, G_MAXINT,
|
|
|
|
VISIBLE_COLUMN, TRUE,
|
|
|
|
TITLE_COLUMN, title,
|
|
|
|
FORMAT_COLUMN, col_format_desc(cur_fmt),
|
|
|
|
DATA_COLUMN, g_list_last(prefs.col_list),
|
2002-11-03 17:38:45 +00:00
|
|
|
-1);
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
/* Triggers call to column_list_select_cb() */
|
|
|
|
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(column_l), &iter);
|
2002-11-03 17:38:45 +00:00
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
/* Set the cursor to the 'Title' column of the newly added row and enable editing */
|
|
|
|
/* XXX: If displaying the new title ["New column"] widens the title column of the */
|
|
|
|
/* treeview, then the set_cursor below doesn't properly generate an entry */
|
|
|
|
/* box around the title text. The width of the box appears to be the column */
|
|
|
|
/* width before the treeview title column was widened. Seems like a bug... */
|
|
|
|
/* I haven't found a work-around. */
|
|
|
|
path = gtk_tree_model_get_path(model, &iter);
|
2009-01-20 20:49:33 +00:00
|
|
|
title_column = gtk_tree_view_get_column(column_l, 0);
|
|
|
|
gtk_tree_view_set_cursor(column_l, path, title_column, TRUE);
|
|
|
|
gtk_tree_path_free(path);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = TRUE;
|
2000-01-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2000-01-10 01:44:00 +00:00
|
|
|
static void
|
2009-01-20 20:49:33 +00:00
|
|
|
column_list_delete_cb(GtkWidget *w _U_, gpointer data) {
|
|
|
|
GtkTreeView *column_l = GTK_TREE_VIEW(data);
|
2002-11-03 17:38:45 +00:00
|
|
|
GList *clp;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
2009-05-04 14:46:51 +00:00
|
|
|
GtkTreeIter new_iter;
|
2002-11-03 17:38:45 +00:00
|
|
|
|
2009-01-20 20:49:33 +00:00
|
|
|
sel = gtk_tree_view_get_selection(column_l);
|
2002-11-03 17:38:45 +00:00
|
|
|
if (gtk_tree_selection_get_selected(sel, &model, &iter))
|
|
|
|
{
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
2015-02-15 18:58:39 +00:00
|
|
|
column_prefs_remove_link(clp);
|
2002-11-03 17:38:45 +00:00
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
/* Change the row selection to the next row (if available) or */
|
|
|
|
/* the previous row (if available). If there's only one row */
|
|
|
|
/* in the store (no previous and no next), then the selection */
|
|
|
|
/* will not be changed. */
|
|
|
|
|
|
|
|
/* Note that gtk_tree_selection_select_iter() will trigger a */
|
|
|
|
/* call to column_list_select_cb(). */
|
|
|
|
|
|
|
|
new_iter = iter;
|
|
|
|
if ( gtk_tree_model_iter_next(model, &new_iter)) {
|
|
|
|
gtk_tree_selection_select_iter(sel, &new_iter);
|
|
|
|
} else { /* "gtk_tree_model_iter_prev" */
|
|
|
|
GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
|
|
|
|
if (gtk_tree_path_prev(path)) {
|
|
|
|
gtk_tree_model_get_iter(model, &new_iter, path);
|
|
|
|
gtk_tree_selection_select_iter(sel, &new_iter);
|
|
|
|
}
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the row from the list store. */
|
|
|
|
/* We prevent triggering call to column_row_deleted_cb() since */
|
|
|
|
/* the entry has already been removed from prefs.col_list and */
|
|
|
|
/* since rebuilding the list is not needed because the order */
|
|
|
|
/* of the list hasn't changed. */
|
|
|
|
|
|
|
|
g_signal_handler_block(model, column_row_deleted_handler_id);
|
|
|
|
|
|
|
|
/* list_store_remove below will trigger a call to */
|
|
|
|
/* column_list_select_cb() only when deleting the last entry in */
|
|
|
|
/* the column list. */
|
|
|
|
/* (This is because the selection in this case changes to */
|
|
|
|
/* "nothing selected" when the last row is removed. */
|
|
|
|
|
2002-11-03 17:38:45 +00:00
|
|
|
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
g_signal_handler_unblock (model, column_row_deleted_handler_id);
|
|
|
|
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = TRUE;
|
2008-02-23 21:26:07 +00:00
|
|
|
}
|
2002-04-22 02:03:53 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2009-01-20 20:49:33 +00:00
|
|
|
static gboolean
|
|
|
|
column_title_changed_cb(GtkCellRendererText *cell _U_, const gchar *str_path, const gchar *new_title, gpointer data) {
|
2009-04-09 13:07:05 +00:00
|
|
|
fmt_data *cfmt;
|
|
|
|
GList *clp;
|
|
|
|
GtkTreeModel *model = (GtkTreeModel *)data;
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_string (str_path);
|
|
|
|
GtkTreeIter iter;
|
2002-11-03 17:38:45 +00:00
|
|
|
|
2011-07-11 18:18:35 +00:00
|
|
|
gtk_tree_model_get_iter(model, &iter, path);
|
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_list_store_set(GTK_LIST_STORE(model), &iter, TITLE_COLUMN, new_title, -1);
|
2009-04-09 13:07:05 +00:00
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
2011-07-11 18:18:35 +00:00
|
|
|
if (clp) {
|
2009-04-09 13:07:05 +00:00
|
|
|
cfmt = (fmt_data *) clp->data;
|
|
|
|
g_free(cfmt->title);
|
2010-01-26 23:05:40 +00:00
|
|
|
cfmt->title = g_strdup(new_title);
|
2009-04-09 13:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = TRUE;
|
2011-07-11 18:18:35 +00:00
|
|
|
return TRUE;
|
2000-01-10 01:44:00 +00:00
|
|
|
}
|
2008-02-22 22:47:19 +00:00
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
/*
|
|
|
|
* column list row selection changed.
|
|
|
|
* Set the "Properties" widgets to match the currently selected column row item.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 22:47:19 +00:00
|
|
|
static void
|
2009-05-04 14:46:51 +00:00
|
|
|
column_list_select_cb(GtkTreeSelection *sel, gpointer data _U_)
|
|
|
|
{
|
|
|
|
fmt_data *cfmt;
|
|
|
|
GList *clp;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
2008-02-22 22:47:19 +00:00
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
/* if something was selected */
|
2008-02-22 22:47:19 +00:00
|
|
|
if (gtk_tree_selection_get_selected(sel, &model, &iter))
|
|
|
|
{
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
2009-05-04 14:46:51 +00:00
|
|
|
g_assert(clp != NULL);
|
|
|
|
cfmt = (fmt_data *) clp->data;
|
|
|
|
|
|
|
|
g_signal_handler_block (fmt_cmb, column_menu_changed_handler_id);
|
2011-11-13 22:51:49 +00:00
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(fmt_cmb), cfmt->fmt);
|
2009-05-04 14:46:51 +00:00
|
|
|
g_signal_handler_unblock(fmt_cmb, column_menu_changed_handler_id);
|
|
|
|
|
|
|
|
g_signal_handler_block (field_te, column_field_changed_handler_id);
|
2010-09-22 20:56:14 +00:00
|
|
|
g_signal_handler_block (occurrence_te, column_occurrence_changed_handler_id);
|
2011-11-13 22:51:49 +00:00
|
|
|
if (cfmt->fmt == COL_CUSTOM) {
|
2009-05-04 14:46:51 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_widget_set_sensitive(field_lb, TRUE);
|
|
|
|
gtk_widget_set_sensitive(field_te, TRUE);
|
2010-09-22 20:56:14 +00:00
|
|
|
g_snprintf(custom_occurrence_str, sizeof(custom_occurrence_str), "%d", cfmt->custom_occurrence);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(occurrence_te), custom_occurrence_str);
|
|
|
|
gtk_widget_set_sensitive(occurrence_lb, TRUE);
|
|
|
|
gtk_widget_set_sensitive(occurrence_te, TRUE);
|
2009-05-04 14:46:51 +00:00
|
|
|
} else {
|
|
|
|
gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_widget_set_sensitive(field_lb, FALSE);
|
|
|
|
gtk_widget_set_sensitive(field_te, FALSE);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_editable_delete_text(GTK_EDITABLE(occurrence_te), 0, -1);
|
|
|
|
gtk_widget_set_sensitive(occurrence_lb, FALSE);
|
|
|
|
gtk_widget_set_sensitive(occurrence_te, FALSE);
|
2009-05-04 14:46:51 +00:00
|
|
|
}
|
2010-09-22 20:56:14 +00:00
|
|
|
g_signal_handler_unblock(occurrence_te, column_occurrence_changed_handler_id);
|
2009-05-04 14:46:51 +00:00
|
|
|
g_signal_handler_unblock(field_te, column_field_changed_handler_id);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive(remove_bt, TRUE);
|
|
|
|
gtk_widget_set_sensitive(fmt_cmb, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_editable_delete_text(GTK_EDITABLE(occurrence_te), 0, -1);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive(remove_bt, FALSE);
|
|
|
|
gtk_widget_set_sensitive(field_te, FALSE);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_widget_set_sensitive(occurrence_te, FALSE);
|
2009-05-04 14:46:51 +00:00
|
|
|
gtk_widget_set_sensitive(fmt_cmb, FALSE);
|
2008-02-22 22:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-10 01:44:00 +00:00
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The user selected a new entry in the format combo-box;
|
|
|
|
* Note: column_menu_changed_cb is expected to be called only
|
|
|
|
* when the user changes the format combo-box.
|
|
|
|
* Action:
|
|
|
|
* If no selection active in the column list:
|
|
|
|
* Hide 'field"; desensitize buttons.
|
|
|
|
* XXX: Can this happen ?
|
|
|
|
* If a column list selection is active:
|
|
|
|
* 1. Update the display of "field" as req'd (depending upon
|
|
|
|
* whether the active combo-box entry is the "custom"
|
|
|
|
* format type).
|
|
|
|
* 2. Update the column_list and prefs.col_formats.
|
|
|
|
* Set columns_changed = TRUE.
|
|
|
|
*/
|
|
|
|
|
2000-01-10 01:44:00 +00:00
|
|
|
static void
|
2009-01-20 20:49:33 +00:00
|
|
|
column_menu_changed_cb(GtkWidget *w, gpointer data) {
|
|
|
|
GtkTreeView *column_l = GTK_TREE_VIEW(data);
|
2002-11-03 17:38:45 +00:00
|
|
|
fmt_data *cfmt;
|
2009-05-04 14:46:51 +00:00
|
|
|
gint cur_cb_fmt;
|
2002-11-03 17:38:45 +00:00
|
|
|
GList *clp;
|
2009-05-04 14:46:51 +00:00
|
|
|
gchar *fmt;
|
2002-11-03 17:38:45 +00:00
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2009-01-20 20:49:33 +00:00
|
|
|
sel = gtk_tree_view_get_selection(column_l);
|
2009-05-04 14:46:51 +00:00
|
|
|
if (! (gtk_tree_selection_get_selected(sel, &model, &iter)))
|
|
|
|
return; /* no column list selection [Can this happen ?]: ignore callback */
|
2002-11-03 17:38:45 +00:00
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
cur_cb_fmt = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
2009-05-04 14:46:51 +00:00
|
|
|
cfmt = (fmt_data *) clp->data;
|
2008-02-23 21:26:07 +00:00
|
|
|
|
2011-11-13 22:51:49 +00:00
|
|
|
g_assert(cur_cb_fmt != cfmt->fmt);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
/* The User has selected a new format in the combo-box */
|
|
|
|
/* (IE: combo-box format != current selected row format) */
|
|
|
|
/* Update field widgets, list_store, column format array */
|
|
|
|
/* entry as appropriate. */
|
2009-07-20 11:42:28 +00:00
|
|
|
g_signal_handler_block (field_te, column_field_changed_handler_id);
|
2010-09-22 20:56:14 +00:00
|
|
|
g_signal_handler_block (occurrence_te, column_occurrence_changed_handler_id);
|
2011-11-13 22:51:49 +00:00
|
|
|
if (cfmt->fmt == COL_CUSTOM) {
|
2009-05-04 14:46:51 +00:00
|
|
|
/* Changing from custom to non-custom */
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_editable_delete_text(GTK_EDITABLE(occurrence_te), 0, -1);
|
2009-05-04 14:46:51 +00:00
|
|
|
fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_widget_set_sensitive(field_lb, FALSE);
|
|
|
|
gtk_widget_set_sensitive(field_te, FALSE);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_widget_set_sensitive(occurrence_lb, FALSE);
|
|
|
|
gtk_widget_set_sensitive(occurrence_te, FALSE);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
} else if (cur_cb_fmt == COL_CUSTOM) {
|
|
|
|
/* Changing from non-custom to custom */
|
2009-07-20 11:42:28 +00:00
|
|
|
if (cfmt->custom_field == NULL)
|
|
|
|
cfmt->custom_field = g_strdup("");
|
2009-05-04 14:46:51 +00:00
|
|
|
/* The following doesn't trigger a call to menu_field_changed_cb() */
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
|
2010-09-22 20:56:14 +00:00
|
|
|
g_snprintf(custom_occurrence_str, sizeof(custom_occurrence_str), "%d", cfmt->custom_occurrence);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(occurrence_te), custom_occurrence_str);
|
|
|
|
|
|
|
|
if (cfmt->custom_occurrence) {
|
|
|
|
fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cur_cb_fmt), cfmt->custom_field, cfmt->custom_occurrence);
|
|
|
|
} else {
|
|
|
|
fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_cb_fmt), cfmt->custom_field);
|
|
|
|
}
|
2009-07-20 11:42:28 +00:00
|
|
|
gtk_widget_set_sensitive(field_lb, TRUE);
|
|
|
|
gtk_widget_set_sensitive(field_te, TRUE);
|
2010-09-22 20:56:14 +00:00
|
|
|
gtk_widget_set_sensitive(occurrence_lb, TRUE);
|
|
|
|
gtk_widget_set_sensitive(occurrence_te, TRUE);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Changing from non-custom to non-custom */
|
|
|
|
fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
|
2002-11-03 17:38:45 +00:00
|
|
|
}
|
2010-09-22 20:56:14 +00:00
|
|
|
g_signal_handler_unblock(occurrence_te, column_occurrence_changed_handler_id);
|
2009-07-20 11:42:28 +00:00
|
|
|
g_signal_handler_unblock(field_te, column_field_changed_handler_id);
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_list_store_set(GTK_LIST_STORE(model), &iter, FORMAT_COLUMN, fmt, -1);
|
2009-05-04 14:46:51 +00:00
|
|
|
g_free(fmt);
|
2011-11-13 22:51:49 +00:00
|
|
|
cfmt->fmt = cur_cb_fmt;
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = TRUE;
|
2000-01-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The user changed the custom field entry box or
|
|
|
|
* the field entry box has been updated because a new
|
|
|
|
* column row with custom format has been selected.
|
|
|
|
* If the current field entry matches that of the current
|
|
|
|
* column row, this is just an update because a new
|
|
|
|
* column row has been selected. Do nothing.
|
|
|
|
* If the two are different, then update the column row & etc.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
column_field_changed_cb(GtkEditable *te, gpointer data) {
|
|
|
|
fmt_data *cfmt;
|
|
|
|
GList *clp;
|
|
|
|
gchar *field, *fmt;
|
|
|
|
GtkTreeView *tree = (GtkTreeView *)data;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection(tree);
|
|
|
|
if ( ! (gtk_tree_selection_get_selected(sel, &model, &iter))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
field = gtk_editable_get_chars(te, 0, -1);
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
2009-05-04 14:46:51 +00:00
|
|
|
cfmt = (fmt_data *) clp->data;
|
|
|
|
if (strcmp(cfmt->custom_field, field) == 0) {
|
|
|
|
return; /* no action req'd */
|
|
|
|
}
|
|
|
|
|
2011-07-11 18:18:35 +00:00
|
|
|
/* The user has entered a new value in the field entry box: make the req'd changes */
|
2010-09-22 20:56:14 +00:00
|
|
|
if (cfmt->custom_occurrence) {
|
2011-11-13 22:51:49 +00:00
|
|
|
fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cfmt->fmt), field, cfmt->custom_occurrence);
|
2010-09-22 20:56:14 +00:00
|
|
|
} else {
|
2011-11-13 22:51:49 +00:00
|
|
|
fmt = g_strdup_printf("%s (%s)", col_format_desc(cfmt->fmt), field);
|
2010-09-22 20:56:14 +00:00
|
|
|
}
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_list_store_set(GTK_LIST_STORE(model), &iter, FORMAT_COLUMN, fmt, -1);
|
2009-05-04 14:46:51 +00:00
|
|
|
g_free(fmt);
|
|
|
|
g_free(cfmt->custom_field);
|
|
|
|
cfmt->custom_field = field;
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = TRUE;
|
2009-05-04 14:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-22 20:56:14 +00:00
|
|
|
/*
|
|
|
|
* The user changed the custom field occurrence entry box or
|
|
|
|
* the field occurrece entry box has been updated because a new
|
|
|
|
* column row with custom format has been selected.
|
|
|
|
* If the current field entry matches that of the current
|
|
|
|
* column row, this is just an update because a new
|
|
|
|
* column row has been selected. Do nothing.
|
|
|
|
* If the two are different, then update the column row & etc.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
column_occurrence_changed_cb(GtkEditable *te, gpointer data) {
|
|
|
|
fmt_data *cfmt;
|
|
|
|
gint occurrence;
|
|
|
|
GList *clp;
|
|
|
|
gchar *fmt;
|
|
|
|
GtkTreeView *tree = (GtkTreeView *)data;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection(tree);
|
|
|
|
if ( ! (gtk_tree_selection_get_selected(sel, &model, &iter))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
occurrence = (gint)strtol(gtk_editable_get_chars(te, 0, -1), NULL, 10);
|
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
|
|
|
cfmt = (fmt_data *) clp->data;
|
|
|
|
if (cfmt->custom_occurrence == occurrence) {
|
|
|
|
return; /* no action req'd */
|
|
|
|
}
|
|
|
|
|
2011-07-11 18:18:35 +00:00
|
|
|
/* The user has entered a new value in the field occurrence entry box: make the req'd changes */
|
2010-09-22 20:56:14 +00:00
|
|
|
if (occurrence) {
|
2011-11-13 22:51:49 +00:00
|
|
|
fmt = g_strdup_printf("%s (%s#%d)", col_format_desc(cfmt->fmt), cfmt->custom_field, occurrence);
|
2010-09-22 20:56:14 +00:00
|
|
|
} else {
|
2011-11-13 22:51:49 +00:00
|
|
|
fmt = g_strdup_printf("%s (%s)", col_format_desc(cfmt->fmt), cfmt->custom_field);
|
2010-09-22 20:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_list_store_set(GTK_LIST_STORE(model), &iter, FORMAT_COLUMN, fmt, -1);
|
|
|
|
g_free(fmt);
|
|
|
|
cfmt->custom_occurrence = occurrence;
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = TRUE;
|
2010-09-22 20:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-20 05:14:57 +00:00
|
|
|
/*
|
|
|
|
* Callback for the "row-deleted" signal emitted when a list item is dragged.
|
|
|
|
* http://library.gnome.org/devel/gtk/stable/GtkTreeModel.html#GtkTreeModel-rows-reordered
|
2011-07-11 18:18:35 +00:00
|
|
|
* says that DND deletes, THEN inserts the row.
|
2009-05-04 14:46:51 +00:00
|
|
|
*
|
|
|
|
* XXX: For the record: For Gtk+ 2.16.0 testing shows the actual sequence for drag-and-drop to be as follows:
|
|
|
|
* 1. Insert a new, empty row at the destination;
|
|
|
|
* 2. Emit a "row-inserted" signal on the model; invoke any row-inserted callbacks & etc;
|
|
|
|
* 3. Copy the source row data to the new (empty) destination row;
|
|
|
|
* 4. Delete the source row;
|
|
|
|
* 5. Emit a "row-deleted" signal; invoke any row-deleted callbacks & etc.
|
|
|
|
*
|
2011-07-11 18:18:35 +00:00
|
|
|
* The code below (invoked as a consequence of a "row-deleted" signal) rebuilds
|
2009-05-04 14:46:51 +00:00
|
|
|
* prefs.col_list by iterating over the (re-ordered) tree model.
|
2009-01-20 05:14:57 +00:00
|
|
|
*/
|
2000-01-10 01:44:00 +00:00
|
|
|
static void
|
2009-01-20 05:14:57 +00:00
|
|
|
column_dnd_row_deleted_cb(GtkTreeModel *model, GtkTreePath *path _U_, gpointer data _U_) {
|
2013-01-11 18:26:35 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GList *clp, *new_col_list = NULL;
|
|
|
|
gboolean items_left;
|
2009-04-09 13:07:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - This rebuilds prefs.col_list based on the current model. We
|
|
|
|
* might just want to do this when the prefs are applied
|
|
|
|
*/
|
|
|
|
for (items_left = gtk_tree_model_get_iter_first (model, &iter);
|
|
|
|
items_left;
|
|
|
|
items_left = gtk_tree_model_iter_next (model, &iter)) {
|
|
|
|
|
2010-06-20 16:23:43 +00:00
|
|
|
gtk_tree_model_get(model, &iter, DATA_COLUMN, &clp, -1);
|
2009-04-09 13:07:05 +00:00
|
|
|
if (clp) {
|
|
|
|
prefs.col_list = g_list_remove_link(prefs.col_list, clp);
|
|
|
|
new_col_list = g_list_concat(new_col_list, clp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prefs.col_list) {
|
|
|
|
g_warning("column_dnd_row_deleted_cb: prefs.col_list has %d leftover data",
|
|
|
|
g_list_length(prefs.col_list));
|
|
|
|
g_list_free(prefs.col_list);
|
2002-11-03 17:38:45 +00:00
|
|
|
}
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2009-04-09 13:07:05 +00:00
|
|
|
prefs.col_list = new_col_list;
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = TRUE;
|
2000-01-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2000-01-10 01:44:00 +00:00
|
|
|
void
|
2002-03-05 11:56:00 +00:00
|
|
|
column_prefs_fetch(GtkWidget *w _U_) {
|
2000-01-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2000-01-10 01:44:00 +00:00
|
|
|
void
|
2007-06-04 20:15:10 +00:00
|
|
|
column_prefs_apply(GtkWidget *w _U_)
|
|
|
|
{
|
|
|
|
/* Redraw the packet list if the columns were changed */
|
2012-09-03 15:12:49 +00:00
|
|
|
if(cfile.columns_changed) {
|
2012-09-04 02:35:25 +00:00
|
|
|
packet_list_recreate();
|
2012-09-03 15:12:49 +00:00
|
|
|
cfile.columns_changed = FALSE; /* Reset value */
|
2007-06-04 20:15:10 +00:00
|
|
|
}
|
2000-01-10 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 14:46:51 +00:00
|
|
|
|
2000-01-10 01:44:00 +00:00
|
|
|
void
|
2009-05-04 14:46:51 +00:00
|
|
|
column_prefs_destroy(GtkWidget *w _U_) {
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2015-02-15 18:58:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|