/* proto_dlg.c
*
- * $Id: proto_dlg.c,v 1.19 2002/11/28 01:58:27 guy Exp $
+ * $Id$
*
- * Laurent Deniel <deniel@worldnet.fr>
+ * Laurent Deniel <laurent.deniel@free.fr>
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 2000 Gerald Combs
*
* This program is free software; you can redistribute it and/or
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+#include <string.h>
#include <gtk/gtk.h>
-#include <string.h>
+#include <gdk/gdkkeysyms.h>
+
+#include <epan/prefs.h>
+#include <epan/filesystem.h>
+
+#include "../globals.h"
+#include "../util.h"
+#include "../simple_dialog.h"
+#include "../disabled_protos.h"
-#include "prefs.h"
-#include "globals.h"
-#include "main.h"
-#include "util.h"
-#include "ui_util.h"
-#include "dlg_utils.h"
-#include "proto_dlg.h"
-#include "compat_macros.h"
+#include "gtk/main.h"
+#include "gtk/gui_utils.h"
+#include "gtk/dlg_utils.h"
+#include "gtk/proto_dlg.h"
+#include "gtk/help_dlg.h"
-static gboolean proto_delete_cb(GtkWidget *, gpointer);
+
+static gboolean proto_delete_event_cb(GtkWidget *, GdkEvent *, gpointer);
static void proto_ok_cb(GtkWidget *, gpointer);
static void proto_apply_cb(GtkWidget *, gpointer);
+static void proto_save_cb(GtkWidget *, gpointer);
static void proto_cancel_cb(GtkWidget *, gpointer);
static void proto_destroy_cb(GtkWidget *, gpointer);
-static void show_proto_selection(GtkWidget *main, GtkWidget *container);
+static void show_proto_selection(GtkListStore *proto_store);
static gboolean set_proto_selection(GtkWidget *);
static gboolean revert_proto_selection(void);
+static void proto_col_clicked_cb(GtkWidget *col _U_, GtkWidget *proto_list);
+
static void toggle_all_cb(GtkWidget *button, gpointer parent_w);
static void enable_all_cb(GtkWidget *button, gpointer parent_w);
static void disable_all_cb(GtkWidget *button, gpointer parent_w);
+static void status_toggled(GtkCellRendererToggle *, gchar *, gpointer);
static GtkWidget *proto_w = NULL;
static GSList *protocol_list = NULL;
typedef struct protocol_data {
- char *name;
- char *abbrev;
- int hfinfo_index;
- gboolean was_enabled;
+ const char *name;
+ const char *abbrev;
+ int hfinfo_index;
+ gboolean enabled;
+ gboolean was_enabled;
+ GtkTreeIter iter;
} protocol_data_t;
-void proto_cb(GtkWidget *w _U_, gpointer data _U_)
+#define DISABLED "Disabled"
+#define STATUS_TXT(x) ((x) ? "" : DISABLED)
+
+void
+proto_cb(GtkWidget *w _U_, gpointer data _U_)
{
- GtkWidget *main_vb, *bbox, *proto_nb, *apply_bt, *cancel_bt, *ok_bt,
- *label, *scrolled_w, *selection_vb, *button;
+ GtkWidget *main_vb, *bbox, *proto_list, *label, *proto_sw, *proto_frame,
+ *proto_vb, *button, *ok_bt, *apply_bt, *save_bt, *cancel_bt, *help_bt;
+ const gchar *titles[] = { "Status", "Protocol", "Description" };
+ GtkListStore *proto_store;
+ GtkCellRenderer *proto_rend;
+ GtkTreeViewColumn *proto_col;
+
if (proto_w != NULL) {
reactivate_window(proto_w);
return;
}
- proto_w = dlg_window_new("Ethereal: Protocol");
- SIGNAL_CONNECT(proto_w, "delete_event", proto_delete_cb, NULL);
- SIGNAL_CONNECT(proto_w, "destroy", proto_destroy_cb, NULL);
- WIDGET_SET_SIZE(proto_w, DEF_WIDTH * 2/3, DEF_HEIGHT * 2/3);
+ proto_w = dlg_conf_window_new("Wireshark: Enabled Protocols");
+ gtk_window_set_default_size(GTK_WINDOW(proto_w), DEF_WIDTH , DEF_HEIGHT);
/* Container for each row of widgets */
- main_vb = gtk_vbox_new(FALSE, 0);
- gtk_container_border_width(GTK_CONTAINER(main_vb), 1);
+ main_vb = gtk_vbox_new(FALSE, 6);
+ gtk_container_set_border_width(GTK_CONTAINER(main_vb), 6);
gtk_container_add(GTK_CONTAINER(proto_w), main_vb);
gtk_widget_show(main_vb);
- /* Protocol topics container */
-
- proto_nb = gtk_notebook_new();
- gtk_container_add(GTK_CONTAINER(main_vb), proto_nb);
- /* XXX do not know why I need this to fill all space around buttons */
- WIDGET_SET_SIZE(proto_nb, DEF_WIDTH * 2/3 - 50, DEF_HEIGHT * 2/3 - 50);
-
- /* Protocol selection panel ("enable/disable" protocols) */
-
- selection_vb = gtk_vbox_new(FALSE, 0);
- gtk_container_border_width(GTK_CONTAINER(selection_vb), 1);
- label = gtk_label_new("Button pressed: protocol decoding is enabled");
+ /* Protocol selection list ("enable/disable" protocols) */
+
+ proto_frame = gtk_frame_new("Enabled Protocols");
+ gtk_box_pack_start(GTK_BOX(main_vb), proto_frame, TRUE, TRUE, 0);
+ gtk_widget_show(proto_frame);
+
+ /* Protocol list */
+
+ proto_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(proto_frame), proto_vb);
+ gtk_container_set_border_width(GTK_CONTAINER(proto_vb), 5);
+ gtk_widget_show(proto_vb);
+
+ proto_sw = scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(proto_sw),
+ GTK_SHADOW_IN);
+ gtk_box_pack_start(GTK_BOX(proto_vb), proto_sw, TRUE, TRUE, 0);
+ gtk_widget_show(proto_sw);
+
+ proto_store = gtk_list_store_new(4, G_TYPE_BOOLEAN, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_POINTER);
+ show_proto_selection(proto_store);
+ /* default sort on "abbrev" column */
+ gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(proto_store), 1,
+ GTK_SORT_ASCENDING);
+
+ proto_list = tree_view_new(GTK_TREE_MODEL(proto_store));
+ gtk_container_add(GTK_CONTAINER(proto_sw), proto_list);
+
+ proto_rend = gtk_cell_renderer_toggle_new();
+ g_signal_connect(proto_rend, "toggled", G_CALLBACK(status_toggled), proto_store);
+ proto_col = gtk_tree_view_column_new_with_attributes(titles[0], proto_rend, "active", 0, NULL);
+ gtk_tree_view_column_set_sort_column_id(proto_col, 0);
+ g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
+
+ proto_rend = gtk_cell_renderer_text_new();
+ proto_col = gtk_tree_view_column_new_with_attributes(titles[1], proto_rend, "text", 1, NULL);
+ gtk_tree_view_column_set_sort_column_id(proto_col, 1);
+ g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
+
+ proto_rend = gtk_cell_renderer_text_new();
+ proto_col = gtk_tree_view_column_new_with_attributes(titles[2], proto_rend, "text", 2, NULL);
+ gtk_tree_view_column_set_sort_column_id(proto_col, 2);
+ g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);
+
+ gtk_tree_view_set_search_column(GTK_TREE_VIEW(proto_list), 1); /* col 1 in the *model* */
+ g_object_unref(G_OBJECT(proto_store));
+ gtk_widget_show(proto_list);
+
+ label = gtk_label_new("Disabling a protocol prevents higher "
+ "layer protocols from being displayed");
+ gtk_misc_set_alignment(GTK_MISC(label), 0.5f, 0.5f);
gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(selection_vb), label, FALSE, FALSE, 0);
- scrolled_w = scrolled_window_new(NULL, NULL);
- gtk_container_set_border_width(GTK_CONTAINER(scrolled_w), 1);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_w),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_ALWAYS);
- gtk_box_pack_start(GTK_BOX(selection_vb), scrolled_w, TRUE, TRUE, 0);
- show_proto_selection(proto_w, scrolled_w);
- gtk_widget_show(scrolled_w);
- gtk_widget_show(selection_vb);
- label = gtk_label_new("Decoding");
- gtk_notebook_append_page(GTK_NOTEBOOK(proto_nb), selection_vb, label);
- label = gtk_label_new("Note that when a protocol is disabled, "
- "all linked sub-protocols are as well");
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(selection_vb), label, FALSE, FALSE, 0);
-
+ gtk_box_pack_start(GTK_BOX(proto_vb), label, FALSE, FALSE, 5);
bbox = gtk_hbutton_box_new();
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
- gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
- gtk_box_pack_start(GTK_BOX(selection_vb), bbox, FALSE, FALSE, 0);
+ gtk_box_set_spacing(GTK_BOX(bbox), 5);
+ gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
gtk_widget_show(bbox);
- /* Toggle All */
- button = gtk_button_new_with_label("Toggle All");
- SIGNAL_CONNECT(button, "clicked", toggle_all_cb, proto_w);
- gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
- gtk_widget_show(button);
-
/* Enable All */
button = gtk_button_new_with_label("Enable All");
- SIGNAL_CONNECT(button, "clicked", enable_all_cb, proto_w);
+ g_signal_connect(button, "clicked", G_CALLBACK(enable_all_cb), proto_list);
gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
gtk_widget_show(button);
/* Disable All */
button = gtk_button_new_with_label("Disable All");
- SIGNAL_CONNECT(button, "clicked", disable_all_cb, proto_w);
+ g_signal_connect(button, "clicked", G_CALLBACK(disable_all_cb), proto_list);
gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
gtk_widget_show(button);
+ /* Invert */
+ button = gtk_button_new_with_label("Invert");
+ g_signal_connect(button, "clicked", G_CALLBACK(toggle_all_cb), proto_list);
+ gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
+ gtk_widget_show(button);
- /* XXX add other protocol-related panels here ... */
-
- gtk_widget_show(proto_nb);
-
- /* Ok, Apply, Cancel Buttons */
- bbox = gtk_hbutton_box_new();
- gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
- gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
- gtk_container_add(GTK_CONTAINER(main_vb), bbox);
+ /* Button row */
+ bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
+ gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
gtk_widget_show(bbox);
-#if GTK_MAJOR_VERSION < 2
- ok_bt = gtk_button_new_with_label ("OK");
-#else
- ok_bt = gtk_button_new_from_stock(GTK_STOCK_OK);
-#endif
- SIGNAL_CONNECT(ok_bt, "clicked", proto_ok_cb, proto_w);
- GTK_WIDGET_SET_FLAGS(ok_bt, GTK_CAN_DEFAULT);
- gtk_box_pack_start(GTK_BOX (bbox), ok_bt, TRUE, TRUE, 0);
+ ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
+ g_signal_connect(ok_bt, "clicked", G_CALLBACK(proto_ok_cb), proto_w);
gtk_widget_grab_default(ok_bt);
- gtk_widget_show(ok_bt);
-#if GTK_MAJOR_VERSION < 2
- apply_bt = gtk_button_new_with_label ("Apply");
-#else
- apply_bt = gtk_button_new_from_stock(GTK_STOCK_APPLY);
-#endif
- SIGNAL_CONNECT(apply_bt, "clicked", proto_apply_cb, proto_w);
- GTK_WIDGET_SET_FLAGS(apply_bt, GTK_CAN_DEFAULT);
- gtk_box_pack_start(GTK_BOX (bbox), apply_bt, TRUE, TRUE, 0);
- gtk_widget_show(apply_bt);
-
-#if GTK_MAJOR_VERSION < 2
- cancel_bt = gtk_button_new_with_label ("Cancel");
-#else
- cancel_bt = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
-#endif
- SIGNAL_CONNECT(cancel_bt, "clicked", proto_cancel_cb, proto_w);
- GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
- gtk_box_pack_start(GTK_BOX (bbox), cancel_bt, TRUE, TRUE, 0);
- gtk_widget_show(cancel_bt);
+ apply_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_APPLY);
+ g_signal_connect(apply_bt, "clicked", G_CALLBACK(proto_apply_cb), proto_w);
+
+ save_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_SAVE);
+ g_signal_connect(save_bt, "clicked", G_CALLBACK(proto_save_cb), proto_w);
+
+ cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
+ window_set_cancel_button(proto_w, cancel_bt, proto_cancel_cb);
+
+ help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
+ g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_ENABLED_PROTOCOLS_DIALOG);
- dlg_set_cancel(proto_w, cancel_bt);
+ g_signal_connect(proto_w, "delete_event", G_CALLBACK(proto_delete_event_cb), NULL);
+ g_signal_connect(proto_w, "destroy", G_CALLBACK(proto_destroy_cb), NULL);
gtk_quit_add_destroy(gtk_main_level(), GTK_OBJECT(proto_w));
+
gtk_widget_show(proto_w);
+ gtk_widget_grab_focus(proto_list); /* XXX: force focus to the tree_view. This hack req'd so "type-ahead find"
+ * will be effective after the window is displayed. The issue is
+ * that any call to gtk_tree_view_column_set_sort_column_id above
+ * apparently sets the focus to the column header button and thus
+ * type-ahead find is, in effect, disabled on the column.
+ * Also required: a grab_focus whenever the column header is
+ * clicked to change the column sort order since the click
+ * also changes the focus to the column header button.
+ * Is there a better way to do this ?
+ */
+
+ /* hide the Save button if the user uses implicit save */
+ if(!prefs.gui_use_pref_save) {
+ gtk_widget_hide(save_bt);
+ }
+
+ window_present(proto_w);
} /* proto_cb */
+/* protocol list column header clicked (to change sort) */
+/* grab_focus(treeview) req'd so that type-ahead find works. */
+/* (See comment above). */
+static void
+proto_col_clicked_cb(GtkWidget *col _U_, GtkWidget *proto_list) {
+ gtk_widget_grab_focus(proto_list);
+}
-/* Toggle All */
+/* Status toggled */
static void
-toggle_all_cb(GtkWidget *button _U_, gpointer parent_w)
+status_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);
+ protocol_data_t *p;
+ gtk_tree_model_get_iter(model, &iter, path);
+ gtk_tree_model_get(model, &iter, 3, &p, -1);
+
+ if (p->enabled)
+ p->enabled = FALSE;
+ else
+ p->enabled = TRUE;
+
+ gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, p->enabled, -1);
+
+ gtk_tree_path_free(path);
+} /* status toggled */
+
+/* XXX - We need callbacks for Gtk2 */
+
+/* Toggle All */
+static void
+toggle_all_cb(GtkWidget *button _U_, gpointer pl)
+{
GSList *entry;
+ GtkListStore *s = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pl)));
for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
- GtkWidget *button;
protocol_data_t *p = entry->data;
- button = (GtkWidget *)OBJECT_GET_DATA(parent_w, p->abbrev);
- /* gtk_toggle_button_toggled() didn't work for me... */
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
- !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
+ if (p->enabled)
+ p->enabled = FALSE;
+ else
+ p->enabled = TRUE;
+
+ gtk_list_store_set(s, &p->iter, 0, p->enabled, -1);
}
}
/* Enable/Disable All Helper */
static void
-set_active_all(gpointer parent_w, gboolean new_state)
+set_active_all(GtkWidget *w, gboolean new_state)
{
-
+ GtkListStore *s = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(w)));
GSList *entry;
for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
- GtkWidget *button;
protocol_data_t *p = entry->data;
- button = (GtkWidget *)OBJECT_GET_DATA(parent_w, p->abbrev);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), new_state);
+ p->enabled = new_state;
+ gtk_list_store_set(s, &p->iter, 0, new_state, -1);
}
}
/* Enable All */
static void
-enable_all_cb(GtkWidget *button _U_, gpointer parent_w)
+enable_all_cb(GtkWidget *button _U_, gpointer pl)
{
- set_active_all(parent_w, TRUE);
+ set_active_all(pl, TRUE);
}
/* Disable All */
static void
-disable_all_cb(GtkWidget *button _U_, gpointer parent_w)
+disable_all_cb(GtkWidget *button _U_, gpointer pl)
{
- set_active_all(parent_w, FALSE);
+ set_active_all(pl, FALSE);
}
-static void proto_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
+static void
+proto_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
{
GSList *entry;
- if (proto_w)
- gtk_widget_destroy(proto_w);
proto_w = NULL;
-
/* remove protocol list */
if (protocol_list) {
for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
XXX - that'll destroy the Protocols dialog; will that upset
a higher-level handler that says "OK, we've been asked to delete
this, so destroy it"? */
-static gboolean proto_delete_cb(GtkWidget *proto_w, gpointer dummy _U_)
+static gboolean
+proto_delete_event_cb(GtkWidget *proto_w_lcl, GdkEvent *event _U_,
+ gpointer dummy _U_)
{
- proto_cancel_cb(NULL, proto_w);
+ proto_cancel_cb(NULL, proto_w_lcl);
return FALSE;
}
-static void proto_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
+/* Update protocol_list 'was_enabled' to current value of 'enabled' */
+static void
+update_was_enabled(void)
+{
+ GSList *entry;
+
+ for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
+ protocol_data_t *p = entry->data;
+ p->was_enabled = p->enabled;
+ }
+}
+
+static void
+proto_write(gpointer parent_w _U_)
+{
+ char *pf_dir_path;
+ char *pf_path;
+ int pf_save_errno;
+
+ /* Create the directory that holds personal configuration files, if
+ necessary. */
+ if (create_persconffile_dir(&pf_dir_path) == -1) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Can't create directory\n\"%s\"\nfor disabled protocols file: %s.", pf_dir_path,
+ strerror(errno));
+ g_free(pf_dir_path);
+ } else {
+ save_disabled_protos_list(&pf_path, &pf_save_errno);
+ if (pf_path != NULL) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Could not save to your disabled protocols file\n\"%s\": %s.",
+ pf_path, strerror(pf_save_errno));
+ g_free(pf_path);
+ }
+ }
+}
+
+static void
+proto_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
+{
+ gboolean redissect;
+
+ /* update the selection now, so we'll save the right things */
+ redissect = set_proto_selection(GTK_WIDGET(parent_w));
+
+ /* if we don't have a Save button, just save the settings now */
+ if (!prefs.gui_use_pref_save) {
+ proto_write(parent_w);
+ }
+
+ window_destroy(GTK_WIDGET(parent_w));
+ if (redissect)
+ redissect_packets();
+}
+
+static void
+proto_apply_cb(GtkWidget *apply_bt _U_, gpointer parent_w)
{
gboolean redissect;
+ /* update the selection now, so we'll save the right things */
redissect = set_proto_selection(GTK_WIDGET(parent_w));
- gtk_widget_destroy(GTK_WIDGET(parent_w));
+
+ /* if we don't have a Save button, just save the settings now */
+ if (!prefs.gui_use_pref_save) {
+ proto_write(parent_w);
+ update_was_enabled();
+ }
+
if (redissect)
- redissect_packets(&cfile);
+ redissect_packets();
}
-static void proto_apply_cb(GtkWidget *apply_bt _U_, gpointer parent_w)
+static void
+proto_save_cb(GtkWidget *save_bt _U_, gpointer parent_w)
{
- if (set_proto_selection(GTK_WIDGET(parent_w)))
- redissect_packets(&cfile);
+
+ proto_write(parent_w);
+
+ if (set_proto_selection(GTK_WIDGET(parent_w))) {
+ /* Redissect all the packets, and re-evaluate the display filter. */
+ redissect_packets();
+ }
}
-static void proto_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
+static void
+proto_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
{
gboolean redissect;
redissect = revert_proto_selection();
- gtk_widget_destroy(GTK_WIDGET(parent_w));
+ window_destroy(GTK_WIDGET(parent_w));
if (redissect)
- redissect_packets(&cfile);
+ redissect_packets();
}
-static gboolean set_proto_selection(GtkWidget *parent_w)
+static gboolean
+set_proto_selection(GtkWidget *parent_w _U_)
{
GSList *entry;
gboolean need_redissect = FALSE;
for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
- GtkWidget *button;
protocol_data_t *p = entry->data;
+ protocol_t *protocol;
- button = (GtkWidget *)OBJECT_GET_DATA(parent_w, p->abbrev);
- if (proto_is_protocol_enabled(p->hfinfo_index) != GTK_TOGGLE_BUTTON (button)->active) {
- proto_set_decoding(p->hfinfo_index, GTK_TOGGLE_BUTTON (button)->active);
+ protocol = find_protocol_by_id(p->hfinfo_index);
+ if (proto_is_protocol_enabled(protocol) != p->enabled) {
+ proto_set_decoding(p->hfinfo_index, p->enabled);
need_redissect = TRUE;
}
}
} /* set_proto_selection */
-static gboolean revert_proto_selection(void)
+static gboolean
+revert_proto_selection(void)
{
GSList *entry;
gboolean need_redissect = FALSE;
*/
for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
protocol_data_t *p = entry->data;
+ protocol_t *protocol;
- if (proto_is_protocol_enabled(p->hfinfo_index) != p->was_enabled) {
+ protocol = find_protocol_by_id(p->hfinfo_index);
+ if (proto_is_protocol_enabled(protocol) != p->was_enabled) {
proto_set_decoding(p->hfinfo_index, p->was_enabled);
need_redissect = TRUE;
}
} /* revert_proto_selection */
-gint protocol_data_compare(gconstpointer a, gconstpointer b)
+static gint
+protocol_data_compare(gconstpointer a, gconstpointer b)
{
const protocol_data_t *ap = (const protocol_data_t *)a;
const protocol_data_t *bp = (const protocol_data_t *)b;
return strcmp(ap->abbrev, bp->abbrev);
}
-static void show_proto_selection(GtkWidget *main, GtkWidget *container)
+static void
+create_protocol_list(void)
{
-
-#define NB_COL 7
-
- GSList *entry;
- GtkTooltips *tooltips;
- GtkWidget *table;
- int i, t = 0, l = 0, nb_line, nb_proto = 0;
+ gint i;
void *cookie;
+ protocol_t *protocol;
protocol_data_t *p;
/* Iterate over all the protocols */
for (i = proto_get_first_protocol(&cookie); i != -1;
i = proto_get_next_protocol(&cookie)) {
- if (proto_can_disable_protocol(i)) {
+ if (proto_can_toggle_protocol(i)) {
p = g_malloc(sizeof(protocol_data_t));
+ protocol = find_protocol_by_id(i);
p->name = proto_get_protocol_name(i);
- p->abbrev = proto_get_protocol_filter_name(i);
+ p->abbrev = proto_get_protocol_short_name(protocol);
p->hfinfo_index = i;
- p->was_enabled = proto_is_protocol_enabled(i);
+ p->enabled = proto_is_protocol_enabled(protocol);
+ p->was_enabled = p->enabled;
protocol_list = g_slist_insert_sorted(protocol_list,
p, protocol_data_compare);
- nb_proto ++;
}
}
+}
- /* create a table (n x NB_COL) of buttons */
+static void
+show_proto_selection(GtkListStore *proto_store)
+{
+ GSList *entry;
+ protocol_data_t *p;
- nb_line = (nb_proto % NB_COL) ? nb_proto / NB_COL + 1 : nb_proto / NB_COL;
- table = gtk_table_new (nb_line, NB_COL, FALSE);
- gtk_table_set_row_spacings(GTK_TABLE (table), 1);
- gtk_table_set_col_spacings(GTK_TABLE (table), 1);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(container), table);
- gtk_widget_show(table);
+ if (protocol_list == NULL)
+ create_protocol_list();
- tooltips = gtk_tooltips_new();
+ for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
+ p = entry->data;
- nb_proto = 0;
+ gtk_list_store_append(proto_store, &p->iter);
+ gtk_list_store_set(proto_store, &p->iter,
+ 0, p->enabled,
+ 1, p->abbrev,
+ 2, p->name,
+ 3, p,
+ -1);
+ }
- for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
- GtkWidget *button;
+} /* show_proto_selection */
- p = entry->data;
- /* button label is the protocol abbrev */
- button = gtk_toggle_button_new_with_label(p->abbrev);
- /* tip is the complete protocol name */
- gtk_tooltips_set_tip(tooltips, button, p->name, NULL);
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
- proto_is_protocol_enabled(p->hfinfo_index));
- OBJECT_SET_DATA(main, p->abbrev, button);
- gtk_table_attach_defaults (GTK_TABLE (table), button, l, l+1, t, t+1);
- gtk_widget_show (button);
- if (++nb_proto % NB_COL) {
- l++;
- }
- else {
- l = 0;
- t++;
+static void
+proto_disable_dialog_cb(gpointer dialog _U_, gint btn, gpointer data)
+{
+ protocol_t *protocol;
+ gint id = GPOINTER_TO_INT(data);
+
+ if (btn == ESD_BTN_OK) {
+ /* Allow proto_dlg to work with the original settings */
+ if (protocol_list == NULL)
+ create_protocol_list();
+ /* Toggle the protocol if it's enabled and allowed */
+ protocol = find_protocol_by_id(id);
+ if (proto_is_protocol_enabled(protocol) == TRUE) {
+ if (proto_can_toggle_protocol(id) == TRUE) {
+ proto_set_decoding(id, FALSE);
+ redissect_packets();
+ }
}
}
+}
-} /* show_proto_selection */
+void
+proto_disable_cb(GtkWidget *w _U_, gpointer data _U_)
+{
+ header_field_info *hfinfo;
+ gint id;
+ gpointer dialog;
+
+ if (cfile.finfo_selected == NULL) {
+ /* There is no field selected */
+ return;
+ }
+
+ /* Find the id for the protocol for the selected field. */
+ hfinfo = cfile.finfo_selected->hfinfo;
+ if (hfinfo->parent == -1)
+ id = proto_get_id((protocol_t *)hfinfo->strings);
+ else
+ id = hfinfo->parent;
+
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL,
+ "Do you want to temporarily disable protocol: %s ?",
+ proto_registrar_get_abbrev(id));
+
+ simple_dialog_set_cb(dialog, proto_disable_dialog_cb, GINT_TO_POINTER(id));
+}