aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk/prefs_filter_expressions.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-06-22 11:34:48 -0400
committerMichael Mann <mmann78@netscape.net>2017-06-26 02:44:05 +0000
commit1b7f5d9f798634770656a82aaa2df30f7f01a9b0 (patch)
treed6f5e76b402f8125bb2ca25c6c88c6b99408880b /ui/gtk/prefs_filter_expressions.c
parent395775acce1ef9624fdf2030179683f37a27cd59 (diff)
Convert filter expressions preference data to a UAT.
The filter expressions data was shoved into the preference file in a very loose, non-arrayed form. It's much easier to manage in code (and for users in a separate file) as a UAT. The GTK GUI was hacked to use the existing UAT dialog rather than rewrite the pref_filter_expressions.c to support a UAT. Should be okay since it's deprecated. Change-Id: I688cebb4b7b6594878c1398365e79a205f1902d9 Ping-Bug: 13814 Reviewed-on: https://code.wireshark.org/review/22354 Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui/gtk/prefs_filter_expressions.c')
-rw-r--r--ui/gtk/prefs_filter_expressions.c376
1 files changed, 44 insertions, 332 deletions
diff --git a/ui/gtk/prefs_filter_expressions.c b/ui/gtk/prefs_filter_expressions.c
index f3ae59c..d721f47 100644
--- a/ui/gtk/prefs_filter_expressions.c
+++ b/ui/gtk/prefs_filter_expressions.c
@@ -25,356 +25,68 @@
#include <string.h>
#include <gtk/gtk.h>
-
+#include <epan/uat.h>
#include "ui/gtk/gui_utils.h"
-#include "ui/gtk/filter_expression_save_dlg.h"
+#include "ui/gtk/uat_gui.h"
#include "ui/gtk/prefs_filter_expressions.h"
#include "ui/gtk/stock_icons.h"
-static void filter_expressions_list_new_cb(GtkWidget *, gpointer);
-static void filter_expressions_list_remove_cb(GtkWidget *, gpointer);
-static gboolean filter_expressions_label_changed_cb(GtkCellRendererText *, const gchar *, const gchar *, gpointer);
-static gboolean filter_expressions_expression_changed_cb(GtkCellRendererText *, const gchar *, const gchar *, gpointer);
-
-#define E_FILTER_EXPRESSION_COLUMNL "filter_expression_columnl"
-#define E_FILTER_EXPRESSION_STORE "filter_expression_store"
-
-enum {
- ENABLED_COLUMN,
- LABEL_COLUMN,
- EXPRESSION_COLUMN,
- DATA_COLUMN,
- N_COLUMN /* The number of columns */
-};
-
-/* Visible toggled */
-static void
-enable_toggled(GtkCellRendererToggle *cell _U_, gchar *path_str, gpointer data)
-{
- GtkTreeModel *model = (GtkTreeModel *)data;
- GtkTreeIter iter;
- GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
- struct filter_expression *fe;
-
- gtk_tree_model_get_iter(model, &iter, path);
- gtk_tree_model_get(model, &iter, DATA_COLUMN, &fe, -1);
-
- fe->enabled = !fe->enabled;
-
- gtk_list_store_set(GTK_LIST_STORE(model), &iter, ENABLED_COLUMN,
- fe->enabled, -1);
-
- gtk_tree_path_free(path);
-} /* visible_toggled */
-
/*
- * Create and display the column selection widgets.
+ * Create and display the expression filter UAT
* Called as part of the creation of the Preferences notebook ( Edit ! Preferences )
*/
GtkWidget *
filter_expressions_prefs_show(void) {
- GtkWidget *main_vb, *bottom_hb, *column_l, *add_bt, *remove_bt;
- GtkWidget *list_vb, *list_lb, *list_sc;
- GtkWidget *add_remove_hb;
- GtkListStore *store;
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
- GtkTreeSelection *sel;
- GtkTreeIter iter;
- GtkTreeIter first_iter;
- gint first_row = TRUE;
- struct filter_expression *fe;
- static const gchar *column_titles[] = {"Enabled", "Label", "Filter Expression"};
-
- /* Container for each row of widgets */
- main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE);
- gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
- gtk_widget_show(main_vb);
-
- list_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
- 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);
-
- list_lb = gtk_label_new(("[The first list entry will be displayed as the "
- "first button right of the Save button - Drag and drop entries to "
- "change column order]"));
- 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);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_sc),
- GTK_SHADOW_IN);
- gtk_box_pack_start(GTK_BOX(list_vb), list_sc, TRUE, TRUE, 0);
- gtk_widget_show(list_sc);
-
- store = gtk_list_store_new(N_COLUMN,
- G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_POINTER);
-
- 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);
- gtk_widget_set_tooltip_text(column_l, "Click on a label or expression to "
- "change its name.\nDrag an item to change its order.\nTick 'Enable' "
- "to enable the filter in the buttons.");
- /* Enabled button */
- renderer = gtk_cell_renderer_toggle_new();
- g_signal_connect(renderer, "toggled", G_CALLBACK(enable_toggled), store);
- column = gtk_tree_view_column_new_with_attributes(
- column_titles[ENABLED_COLUMN], renderer, "active", ENABLED_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);
-
- /* Label editor */
- renderer = gtk_cell_renderer_text_new();
- g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
- g_signal_connect(renderer, "edited",
- G_CALLBACK(filter_expressions_label_changed_cb), GTK_TREE_MODEL(store));
- column = gtk_tree_view_column_new_with_attributes(
- column_titles[LABEL_COLUMN], renderer, "text", LABEL_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);
-
- /* Expression editor */
- renderer = gtk_cell_renderer_text_new();
- g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
- g_signal_connect(renderer, "edited",
- G_CALLBACK(filter_expressions_expression_changed_cb),
- GTK_TREE_MODEL(store));
- column = gtk_tree_view_column_new_with_attributes(
- column_titles[EXPRESSION_COLUMN], renderer, "text", EXPRESSION_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);
-
- /* 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);
-
- gtk_container_add(GTK_CONTAINER(list_sc), column_l);
- gtk_widget_show(column_l);
-
- fe = *pfilter_expression_head;
- while (fe != NULL) {
- fe->filter_index = -1;
- gtk_list_store_insert_with_values(store, &iter, G_MAXINT,
- ENABLED_COLUMN, fe->enabled,
- LABEL_COLUMN, fe->label,
- EXPRESSION_COLUMN, fe->expression,
- DATA_COLUMN, fe,
- -1);
-
- if (first_row) {
- first_iter = iter;
- first_row = FALSE;
- }
- fe = fe->next;
- }
- g_object_unref(G_OBJECT(store));
-
- /* Bottom row: Add/remove buttons */
- bottom_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE);
- gtk_box_pack_start(GTK_BOX(main_vb), bottom_hb, FALSE, TRUE, 0);
- gtk_widget_show(bottom_hb);
-
- /* Add button */
- add_remove_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, TRUE);
- gtk_container_set_border_width(GTK_CONTAINER(add_remove_hb), 5);
- gtk_box_pack_start(GTK_BOX(bottom_hb), add_remove_hb, FALSE, FALSE, 0);
- gtk_widget_show(add_remove_hb);
-
- add_bt = ws_gtk_button_new_from_stock(GTK_STOCK_ADD);
- g_signal_connect(add_bt, "clicked",
- G_CALLBACK(filter_expressions_list_new_cb), column_l);
- gtk_box_pack_start(GTK_BOX(add_remove_hb), add_bt, FALSE, FALSE, 0);
- gtk_widget_set_tooltip_text(add_bt,
- "Add a new row at the end of the list.");
- gtk_widget_show(add_bt);
-
- /* Remove button */
- remove_bt = ws_gtk_button_new_from_stock(GTK_STOCK_REMOVE);
- g_signal_connect(remove_bt, "clicked",
- G_CALLBACK(filter_expressions_list_remove_cb), column_l);
- gtk_box_pack_start(GTK_BOX(add_remove_hb), remove_bt, FALSE, FALSE, 0);
- gtk_widget_set_tooltip_text(remove_bt, "Remove the selected row.");
- gtk_widget_show(remove_bt);
-
- /* select the first menu list row. */
- /* Triggers call to column_list_select_cb(). */
- if (first_row == FALSE)
- gtk_tree_selection_select_iter(sel, &first_iter);
-
- g_object_set_data(G_OBJECT(main_vb), E_FILTER_EXPRESSION_COLUMNL, column_l);
- g_object_set_data(G_OBJECT(main_vb), E_FILTER_EXPRESSION_STORE, store);
-
- return(main_vb);
-}
-
-static void
-filter_expressions_list_remove_cb(GtkWidget *w _U_, gpointer data)
-{
- GtkTreeView *column_l = GTK_TREE_VIEW(data);
- GtkTreeSelection *sel;
- GtkTreeModel *model;
- GtkTreeIter iter;
- struct filter_expression *fe;
-
- sel = gtk_tree_view_get_selection(column_l);
- if (!gtk_tree_selection_get_selected(sel, &model, &iter))
- return;
-
- gtk_tree_model_get(model, &iter, DATA_COLUMN, &fe, -1);
- fe->deleted = TRUE;
-
- gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
-}
-
-static void
-filter_expressions_list_new_cb(GtkWidget *w _U_, gpointer data _U_)
-{
- const gchar *label = "New Label";
- const gchar *expression = "New Expression";
- GtkTreeView *fe_l = GTK_TREE_VIEW(data);
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkTreePath *path;
- GtkTreeViewColumn *label_column;
- struct filter_expression *fe;
-
- fe = filter_expression_new(label, expression, TRUE);
-
- model = gtk_tree_view_get_model(fe_l);
- gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, G_MAXINT,
- ENABLED_COLUMN, fe->enabled,
- LABEL_COLUMN, fe->label,
- EXPRESSION_COLUMN, fe->expression,
- DATA_COLUMN, fe,
- -1);
-
- /* Triggers call to column_list_select_cb() */
- gtk_tree_selection_select_iter(gtk_tree_view_get_selection(fe_l), &iter);
-
- /* 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);
- label_column = gtk_tree_view_get_column(fe_l, 2);
- gtk_tree_view_set_cursor(fe_l, path, label_column, TRUE);
- gtk_tree_path_free(path);
-}
-
-
-static gboolean
-filter_expressions_expression_changed_cb(GtkCellRendererText *cell _U_, const gchar *str_path, const gchar *new_expression, gpointer data)
-{
- struct filter_expression *fe;
- GtkTreeModel *model = (GtkTreeModel *)data;
- GtkTreePath *path = gtk_tree_path_new_from_string(str_path);
- GtkTreeIter iter;
-
- gtk_tree_model_get_iter(model, &iter, path);
- gtk_list_store_set(GTK_LIST_STORE(model), &iter, EXPRESSION_COLUMN,
- new_expression, -1);
-
- gtk_tree_model_get(model, &iter, DATA_COLUMN, &fe, -1);
- if (fe != NULL) {
- g_free(fe->expression);
- fe->expression = g_strdup(new_expression);
- }
-
- gtk_tree_path_free(path);
- return(TRUE);
-}
-
-static gboolean
-filter_expressions_label_changed_cb(GtkCellRendererText *cell _U_, const gchar *str_path, const gchar *new_label, gpointer data)
-{
- struct filter_expression *fe;
- GtkTreeModel *model = (GtkTreeModel *)data;
- GtkTreePath *path = gtk_tree_path_new_from_string(str_path);
- GtkTreeIter iter;
-
- gtk_tree_model_get_iter(model, &iter, path);
- gtk_list_store_set(GTK_LIST_STORE(model), &iter, LABEL_COLUMN, new_label, -1);
-
- gtk_tree_model_get(model, &iter, DATA_COLUMN, &fe, -1);
- if (fe != NULL) {
- g_free(fe->label);
- fe->label = g_strdup(new_label);
- }
-
- gtk_tree_path_free(path);
- return TRUE;
-}
-
-
-void
-filter_expressions_prefs_fetch(GtkWidget *w)
-{
- gboolean items_left;
- GtkTreeModel *model;
- GtkTreeView *column_l;
- GtkTreeIter iter;
- GtkListStore *store;
- struct filter_expression *fe;
- gint first_row = TRUE;
- gint indx = 0;
-
- column_l = (GtkTreeView *)g_object_get_data(G_OBJECT(w),
- E_FILTER_EXPRESSION_COLUMNL);
- model = gtk_tree_view_get_model(column_l);
- store = (GtkListStore *)g_object_get_data(G_OBJECT(w),
- E_FILTER_EXPRESSION_STORE);
-
- /* Record the order of the items in the list. */
- items_left = gtk_tree_model_get_iter_first(model, &iter);
- while (items_left) {
- gtk_tree_model_get(model, &iter, DATA_COLUMN, &fe, -1);
- if (fe != NULL)
- fe->filter_index = indx++;
- items_left = gtk_tree_model_iter_next (model, &iter);
- }
-
- filter_expression_reinit(FILTER_EXPRESSION_REINIT_DESTROY | FILTER_EXPRESSION_REINIT_CREATE);
-
- gtk_list_store_clear(store);
- fe = *pfilter_expression_head;
- while (fe != NULL) {
- fe->filter_index = -1;
- gtk_list_store_insert_with_values(store, &iter, G_MAXINT,
- ENABLED_COLUMN, fe->enabled,
- LABEL_COLUMN, fe->label,
- EXPRESSION_COLUMN, fe->expression,
- DATA_COLUMN, fe,
- -1);
-
- if (first_row) {
- first_row = FALSE;
- }
- fe = fe->next;
- }
+ GtkWidget *filter_window, *main_grid, *expression_lb, *expression_bt;
+ int row = 0;
+ const gchar *tooltips_text;
+
+ /* Main vertical box */
+ filter_window = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 7, FALSE);
+ gtk_container_set_border_width(GTK_CONTAINER(filter_window), 5);
+
+ /* Main grid */
+ main_grid = ws_gtk_grid_new();
+ gtk_box_pack_start(GTK_BOX(filter_window), main_grid, FALSE, FALSE, 0);
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_set_vexpand(GTK_WIDGET(main_grid), FALSE); /* Ignore VEXPAND requests from children */
+#endif
+ ws_gtk_grid_set_row_spacing(GTK_GRID(main_grid), 10);
+ ws_gtk_grid_set_column_spacing(GTK_GRID(main_grid), 15);
+ gtk_widget_show(main_grid);
+
+
+ /* Interface properties */
+ expression_lb = gtk_label_new("Display filter expressions:");
+ ws_gtk_grid_attach_defaults(GTK_GRID(main_grid), expression_lb, 0, row, 1, 1);
+ gtk_misc_set_alignment(GTK_MISC(expression_lb), 1.0f, 0.5f);
+ gtk_widget_show(expression_lb);
+
+ expression_bt = ws_gtk_button_new_from_stock(WIRESHARK_STOCK_EDIT);
+ tooltips_text = "Open a dialog box to configure display filter expression buttons.";
+ gtk_widget_set_tooltip_text(expression_lb, tooltips_text);
+ gtk_widget_set_tooltip_text(expression_bt, tooltips_text);
+ g_signal_connect(expression_bt, "clicked", G_CALLBACK(uat_window_cb), uat_get_table_by_name("Display expressions"));
+ ws_gtk_grid_attach_defaults(GTK_GRID(main_grid), expression_bt, 1, row, 1, 1);
+
+ /* Show 'em what we got */
+ gtk_widget_show_all(filter_window);
+
+ return(filter_window);
}
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
- * c-basic-offset: 4
+ * c-basic-offset: 8
* tab-width: 8
- * indent-tabs-mode: nil
+ * indent-tabs-mode: t
* End:
*
- * vi: set shiftwidth=4 tabstop=8 expandtab:
- * :indentSize=4:tabSize=8:noTabs=true:
- */
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */ \ No newline at end of file