Instead of using private #defines for the last argument to
[obnox/wireshark/wip.git] / gtk / proto_dlg.c
index 3dab0999718b6d544da3a0567981bfaad13355af..bddf89cf9ab5c783ae9093d82f8f89f72e04a9fe 100644 (file)
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
+#include <string.h>
 
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
-#include <string.h>
 
 #include <epan/prefs.h>
-#include "globals.h"
-#include "main.h"
-#include "util.h"
-#include "gui_utils.h"
-#include "dlg_utils.h"
-#include "proto_dlg.h"
-#include "simple_dialog.h"
-#include "compat_macros.h"
-#include "disabled_protos.h"
 #include <epan/filesystem.h>
-#include "help_dlg.h"
+
+#include "../globals.h"
+#include "../util.h"
+#include "../simple_dialog.h"
+#include "../disabled_protos.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_event_cb(GtkWidget *, GdkEvent *, gpointer);
 static void proto_ok_cb(GtkWidget *, gpointer);
@@ -51,25 +53,16 @@ static void proto_save_cb(GtkWidget *, gpointer);
 static void proto_cancel_cb(GtkWidget *, gpointer);
 static void proto_destroy_cb(GtkWidget *, gpointer);
 
-#if GTK_MAJOR_VERSION < 2
-static void show_proto_selection(GtkCList *proto_list);
-#else
 static void show_proto_selection(GtkListStore *proto_store);
-#endif
 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);
-#if GTK_MAJOR_VERSION < 2
-static void proto_list_select_cb(GtkCList *proto_list, gint row, gint col, 
-                                 GdkEventButton *ev, gpointer gp);
-static gboolean proto_list_keypress_cb(GtkWidget *pl, GdkEventKey *ev,
-                                   gpointer gp);
-#else
 static void status_toggled(GtkCellRendererToggle *, gchar *, gpointer);
-#endif
 
 static GtkWidget *proto_w = NULL;
 
@@ -82,11 +75,7 @@ typedef struct protocol_data {
   int                hfinfo_index;
   gboolean    enabled;
   gboolean    was_enabled;
-#if GTK_MAJOR_VERSION < 2
-  gint        row;
-#else
   GtkTreeIter iter;
-#endif
 } protocol_data_t;
 
 #define DISABLED "Disabled"
@@ -99,13 +88,9 @@ proto_cb(GtkWidget *w _U_, gpointer data _U_)
   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" };
-#if GTK_MAJOR_VERSION < 2
-  gint width;
-#else
   GtkListStore *proto_store;
   GtkCellRenderer *proto_rend;
   GtkTreeViewColumn *proto_col;
-#endif
 
 
   if (proto_w != NULL) {
@@ -113,13 +98,13 @@ proto_cb(GtkWidget *w _U_, gpointer data _U_)
     return;
   }
 
-  proto_w = dlg_window_new("Wireshark: Enabled Protocols");
-  gtk_window_set_default_size(GTK_WINDOW(proto_w), DEF_WIDTH * 2/3, DEF_HEIGHT);
+  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, 6);
-  gtk_container_border_width(GTK_CONTAINER(main_vb), 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);
 
@@ -130,129 +115,121 @@ proto_cb(GtkWidget *w _U_, gpointer data _U_)
   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_border_width(GTK_CONTAINER(proto_vb), 5);
+  gtk_container_set_border_width(GTK_CONTAINER(proto_vb), 5);
   gtk_widget_show(proto_vb);
-  
+
   proto_sw = scrolled_window_new(NULL, NULL);
-#if GTK_MAJOR_VERSION >= 2
   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(proto_sw), 
                                    GTK_SHADOW_IN);
-#endif
   gtk_box_pack_start(GTK_BOX(proto_vb), proto_sw, TRUE, TRUE, 0);
   gtk_widget_show(proto_sw);
 
-#if GTK_MAJOR_VERSION < 2
-  proto_list = gtk_clist_new_with_titles(3, (gchar **) titles);
-  gtk_container_add(GTK_CONTAINER(proto_sw), proto_list);
-  gtk_clist_set_selection_mode(GTK_CLIST(proto_list), GTK_SELECTION_BROWSE);
-  gtk_clist_column_titles_passive(GTK_CLIST(proto_list));
-  gtk_clist_column_titles_show(GTK_CLIST(proto_list));
-  gtk_clist_set_column_auto_resize(GTK_CLIST(proto_list), 0, FALSE);
-  gtk_clist_set_column_auto_resize(GTK_CLIST(proto_list), 1, TRUE);
-  gtk_clist_set_column_auto_resize(GTK_CLIST(proto_list), 2, TRUE);
-  width = gdk_string_width(proto_list->style->font, DISABLED);
-  gtk_clist_set_column_width(GTK_CLIST(proto_list), 0, width);
-  SIGNAL_CONNECT(proto_list, "select-row", proto_list_select_cb, NULL);
-  SIGNAL_CONNECT(proto_list, "key-press-event", proto_list_keypress_cb, NULL);
-  show_proto_selection(GTK_CLIST(proto_list));
-#else
   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();
-  SIGNAL_CONNECT(proto_rend, "toggled", status_toggled, proto_store);
-  proto_col = gtk_tree_view_column_new_with_attributes(titles[0], proto_rend,
-                                                    "active", 0, NULL);
+  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);
+  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);
+  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));
-#endif
   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.5, 0.5);
+  gtk_misc_set_alignment(GTK_MISC(label), 0.5f, 0.5f);
   gtk_widget_show(label);
   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_set_spacing(GTK_BOX(bbox), 5);
   gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
   gtk_widget_show(bbox);
 
   /* Enable All */
   button = gtk_button_new_with_label("Enable All");
-  SIGNAL_CONNECT(button, "clicked", enable_all_cb, proto_list);
+  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_list);
+  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");
-  SIGNAL_CONNECT(button, "clicked", toggle_all_cb, proto_list);
+  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);
 
 
   /* Button row */
-  if(topic_available(HELP_ENABLED_PROTOCOLS_DIALOG)) {
-    bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
-  } else {
-    bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, NULL);
-  }
+  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);
 
-  ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
-  SIGNAL_CONNECT(ok_bt, "clicked", proto_ok_cb, proto_w);
+  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);
 
-  apply_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_APPLY);
-  SIGNAL_CONNECT(apply_bt, "clicked", proto_apply_cb, proto_w);
+  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 = OBJECT_GET_DATA(bbox, GTK_STOCK_SAVE);
-  SIGNAL_CONNECT(save_bt, "clicked", proto_save_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 = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
+  cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
   window_set_cancel_button(proto_w, cancel_bt, proto_cancel_cb);
 
-  if(topic_available(HELP_ENABLED_PROTOCOLS_DIALOG)) {
-    help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
-    SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_ENABLED_PROTOCOLS_DIALOG);
-  }
+  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);
 
-  SIGNAL_CONNECT(proto_w, "delete_event", proto_delete_event_cb, NULL);
-  SIGNAL_CONNECT(proto_w, "destroy", proto_destroy_cb, NULL);
+  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);
@@ -261,34 +238,15 @@ proto_cb(GtkWidget *w _U_, gpointer data _U_)
   window_present(proto_w);
 } /* proto_cb */
 
-#if GTK_MAJOR_VERSION < 2
+/* 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_list_select_cb(GtkCList *proto_list, gint row, gint col, 
-                     GdkEventButton *ev _U_, gpointer gp _U_) {
-  protocol_data_t *p = gtk_clist_get_row_data(proto_list, row);
-  
-  if (row < 0 || col < 0)
-    return;
-
-  if (p->enabled)
-    p->enabled = FALSE;
-  else
-    p->enabled = TRUE;
-
-  gtk_clist_set_text(proto_list, row, 0, STATUS_TXT(p->enabled) );
-} /* proto_list_select_cb */
-
-static gboolean
-proto_list_keypress_cb(GtkWidget *pl, GdkEventKey *ev, gpointer gp _U_) {
-  GtkCList *proto_list = GTK_CLIST(pl);
-  
-  if (ev->keyval == GDK_space) {
-    proto_list_select_cb(proto_list, proto_list->focus_row, 0, NULL, gp);
-  }
-  return TRUE;
+proto_col_clicked_cb(GtkWidget *col _U_, GtkWidget *proto_list) {
+  gtk_widget_grab_focus(proto_list);
 }
 
-#else
+/* Status toggled */
 static void
 status_toggled(GtkCellRendererToggle *cell _U_, gchar *path_str, gpointer data)
 {
@@ -309,21 +267,15 @@ status_toggled(GtkCellRendererToggle *cell _U_, gchar *path_str, gpointer data)
 
   gtk_tree_path_free(path);
 } /* status toggled */
-#endif
 
 /* XXX - We need callbacks for Gtk2 */
 
-
 /* Toggle All */
 static void
 toggle_all_cb(GtkWidget *button _U_, gpointer pl)
 {
   GSList *entry;
-#if GTK_MAJOR_VERSION < 2
-  GtkCList *proto_list = GTK_CLIST(pl);
-#else
   GtkListStore *s = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pl)));
-#endif
 
   for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
     protocol_data_t *p = entry->data;
@@ -332,12 +284,8 @@ toggle_all_cb(GtkWidget *button _U_, gpointer pl)
       p->enabled = FALSE;
     else
       p->enabled = TRUE;
-    
-#if GTK_MAJOR_VERSION < 2
-    gtk_clist_set_text(proto_list, p->row, 0, STATUS_TXT(p->enabled) );
-#else
+
     gtk_list_store_set(s, &p->iter, 0, p->enabled, -1);
-#endif
   }
 }
 
@@ -345,44 +293,29 @@ toggle_all_cb(GtkWidget *button _U_, gpointer pl)
 static void
 set_active_all(GtkWidget *w, gboolean new_state)
 {
-
-#if GTK_MAJOR_VERSION < 2
-  GtkCList *proto_list = GTK_CLIST(w);
-#else
   GtkListStore *s = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(w)));
-#endif
   GSList *entry;
 
-#if GTK_MAJOR_VERSION < 2
-  gtk_clist_freeze(proto_list);
-#endif
   for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
     protocol_data_t *p = entry->data;
-    
+
     p->enabled = new_state;
-#if GTK_MAJOR_VERSION < 2
-    gtk_clist_set_text(proto_list, p->row, 0, STATUS_TXT(new_state) );
-#else
     gtk_list_store_set(s, &p->iter, 0, new_state, -1);
-#endif
   }
-#if GTK_MAJOR_VERSION < 2
-  gtk_clist_thaw(proto_list);
-#endif
 }
 
 /* Enable All */
 static void
 enable_all_cb(GtkWidget *button _U_, gpointer pl)
 {
-       set_active_all(pl, TRUE);
+  set_active_all(pl, TRUE);
 }
 
 /* Disable All */
 static void
 disable_all_cb(GtkWidget *button _U_, gpointer pl)
 {
-       set_active_all(pl, FALSE);
+  set_active_all(pl, FALSE);
 }
 
 static void
@@ -391,7 +324,6 @@ proto_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
   GSList *entry;
 
   proto_w = NULL;
-
   /* remove protocol list */
   if (protocol_list) {
     for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
@@ -407,14 +339,27 @@ proto_destroy_cb(GtkWidget *w _U_, gpointer data _U_)
    a higher-level handler that says "OK, we've been asked to delete
    this, so destroy it"? */
 static gboolean
-proto_delete_event_cb(GtkWidget *proto_w, GdkEvent *event _U_,
+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_write(gpointer parent_w _U_)
+/* 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;
@@ -423,17 +368,17 @@ static void proto_write(gpointer parent_w _U_)
   /* 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);
+    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);
+      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);
     }
   }
 }
@@ -448,12 +393,12 @@ proto_ok_cb(GtkWidget *ok_bt _U_, gpointer 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);
+    proto_write(parent_w);
   }
 
   window_destroy(GTK_WIDGET(parent_w));
   if (redissect)
-    cf_redissect_packets(&cfile);
+    redissect_packets();
 }
 
 static void
@@ -466,11 +411,12 @@ proto_apply_cb(GtkWidget *apply_bt _U_, gpointer 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);
+    proto_write(parent_w);
+    update_was_enabled();
   }
 
   if (redissect)
-    cf_redissect_packets(&cfile);
+    redissect_packets();
 }
 
 static void
@@ -481,7 +427,7 @@ proto_save_cb(GtkWidget *save_bt _U_, gpointer parent_w)
 
   if (set_proto_selection(GTK_WIDGET(parent_w))) {
     /* Redissect all the packets, and re-evaluate the display filter. */
-    cf_redissect_packets(&cfile);
+    redissect_packets();
   }
 }
 
@@ -493,7 +439,7 @@ proto_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
   redissect = revert_proto_selection();
   window_destroy(GTK_WIDGET(parent_w));
   if (redissect)
-    cf_redissect_packets(&cfile);
+    redissect_packets();
 }
 
 static gboolean
@@ -551,20 +497,12 @@ protocol_data_compare(gconstpointer a, gconstpointer b)
 }
 
 static void
-#if GTK_MAJOR_VERSION < 2
-show_proto_selection(GtkCList *proto_list)
-#else
-show_proto_selection(GtkListStore *proto_store)
-#endif
+create_protocol_list(void)
 {
-  GSList *entry;
   gint i;
   void *cookie;
   protocol_t *protocol;
   protocol_data_t *p;
-#if GTK_MAJOR_VERSION < 2
-  const gchar *proto_text[3];
-#endif
 
   /* Iterate over all the protocols */
 
@@ -577,27 +515,25 @@ show_proto_selection(GtkListStore *proto_store)
         p->abbrev = proto_get_protocol_short_name(protocol);
         p->hfinfo_index = i;
         p->enabled = proto_is_protocol_enabled(protocol);
-       p->was_enabled = p->enabled;
+        p->was_enabled = p->enabled;
         protocol_list = g_slist_insert_sorted(protocol_list,
                                            p, protocol_data_compare);
       }
   }
+}
+
+static void
+show_proto_selection(GtkListStore *proto_store)
+{
+  GSList *entry;
+  protocol_data_t *p;
+
+  if (protocol_list == NULL)
+    create_protocol_list();
 
   for (entry = protocol_list; entry != NULL; entry = g_slist_next(entry)) {
     p = entry->data;
 
-#if GTK_MAJOR_VERSION < 2
-    /* XXX - The preferred way to do this would be to have a check box
-     * in the first column.  GtkClists don't let us put arbitrary widgets
-     * in a cell, so we use the word "Disabled" instead.  We should be
-     * able to use check boxes in Gtk2, however.
-     */        
-    proto_text[0] = STATUS_TXT (p->enabled);
-    proto_text[1] = p->abbrev;
-    proto_text[2] = p->name;
-    p->row = gtk_clist_append(proto_list, (gchar **) proto_text);
-    gtk_clist_set_row_data(proto_list, p->row, p);
-#else
     gtk_list_store_append(proto_store, &p->iter);
     gtk_list_store_set(proto_store, &p->iter,
                        0, p->enabled,
@@ -605,7 +541,53 @@ show_proto_selection(GtkListStore *proto_store)
                        2, p->name,
                        3, p,
                       -1);
-#endif
   }
 
 } /* show_proto_selection */
+
+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();
+      }
+    }
+  }
+}
+
+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));
+}