Fix build
[obnox/wireshark/wip.git] / gtk / prefs_dlg.c
index a83f0269e9f20df0afbe525cad8818a7c896d825..0d4f71e895c3864b9612b8f6e747d3c329c50802 100644 (file)
@@ -50,6 +50,7 @@
 #include "simple_dialog.h"
 #include "compat_macros.h"
 #include "help_dlg.h"
+#include "keys.h"
 
 #include <epan/prefs-int.h>
 
 #ifdef _WIN32
 #include "capture-wpcap.h"
 #endif /* _WIN32 */
-#endif /* HAVE_LIBPCAP */
+#ifdef HAVE_AIRPCAP
+#include "airpcap.h"
+#include "airpcap_loader.h"
+#include "airpcap_gui_utils.h"
+#endif
+#endif
 
 static void     prefs_main_ok_cb(GtkWidget *, gpointer);
 static void     prefs_main_apply_cb(GtkWidget *, gpointer);
@@ -75,6 +81,7 @@ static void   prefs_tree_select_cb(GtkTreeSelection *, gpointer);
 #define E_PREFSW_SCROLLW_KEY    "prefsw_scrollw"
 #define E_PREFSW_TREE_KEY       "prefsw_tree"
 #define E_PREFSW_NOTEBOOK_KEY   "prefsw_notebook"
+#define E_PREFSW_SAVE_BT_KEY    "prefsw_save_bt"
 #define E_PAGE_ITER_KEY         "page_iter"
 #define E_PAGE_MODULE_KEY       "page_module"
 #define E_PAGESW_FRAME_KEY      "pagesw_frame"
@@ -316,7 +323,7 @@ module_prefs_show(module_t *module, gpointer user_data)
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 
     /* Frame */
-    frame = gtk_frame_new(module->title);
+    frame = gtk_frame_new(module->description);
     gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), frame);
     OBJECT_SET_DATA(main_sw, E_PAGESW_FRAME_KEY, frame);
@@ -619,7 +626,7 @@ prefs_cb(GtkWidget *w _U_, gpointer dummy _U_)
   cts.is_protocol = FALSE;
   prefs_module_list_foreach(NULL, module_prefs_show, &cts);
 
-  /* Button row: OK and cancel buttons */
+  /* Button row: OK and alike buttons */
 
   if(topic_available(HELP_PREFERENCES_DIALOG)) {
     bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, NULL);
@@ -637,6 +644,7 @@ prefs_cb(GtkWidget *w _U_, gpointer dummy _U_)
 
   save_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_SAVE);
   SIGNAL_CONNECT(save_bt, "clicked", prefs_main_save_cb, prefs_w);
+  OBJECT_SET_DATA(prefs_w, E_PREFSW_SAVE_BT_KEY, save_bt);
 
   cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
   SIGNAL_CONNECT(cancel_bt, "clicked", prefs_main_cancel_cb, prefs_w);
@@ -653,6 +661,12 @@ prefs_cb(GtkWidget *w _U_, gpointer dummy _U_)
   SIGNAL_CONNECT(prefs_w, "destroy", prefs_main_destroy_cb, prefs_w);
 
   gtk_widget_show(prefs_w);
+
+  /* hide the Save button if the user uses implicit save */
+  if(!prefs.gui_use_pref_save) {
+    gtk_widget_hide(save_bt);
+  }
+
   window_present(prefs_w);
 
 #if GTK_MAJOR_VERSION >= 2
@@ -1062,6 +1076,67 @@ module_prefs_fetch(module_t *module, gpointer user_data)
   return 0;    /* keep fetching module preferences */
 }
 
+#ifdef HAVE_AIRPCAP
+/*
+ * This function is used to apply changes and update the Wireless Toolbar
+ * whenever we apply some changes to the WEP preferences
+ */
+static void
+prefs_airpcap_update()
+{
+GtkWidget *decryption_cm;
+GtkWidget *decryption_en;
+gboolean wireshark_decryption_was_enabled;
+gboolean airpcap_decryption_was_enabled;
+gboolean wireshark_decryption_is_now_enabled;
+
+decryption_cm = GTK_WIDGET(OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY));
+decryption_en = GTK_WIDGET(GTK_ENTRY(GTK_COMBO(decryption_cm)->entry));
+
+if( g_strcasecmp(gtk_entry_get_text(GTK_ENTRY(decryption_en)),AIRPCAP_DECRYPTION_TYPE_STRING_WIRESHARK) == 0 )
+{
+wireshark_decryption_was_enabled = TRUE;
+airpcap_decryption_was_enabled = FALSE;
+}
+else if( g_strcasecmp(gtk_entry_get_text(GTK_ENTRY(decryption_en)),AIRPCAP_DECRYPTION_TYPE_STRING_AIRPCAP) == 0 )
+{
+wireshark_decryption_was_enabled = FALSE;
+airpcap_decryption_was_enabled = TRUE;
+}
+else if( g_strcasecmp(gtk_entry_get_text(GTK_ENTRY(decryption_en)),AIRPCAP_DECRYPTION_TYPE_STRING_NONE) == 0 )
+{
+wireshark_decryption_was_enabled = FALSE;
+airpcap_decryption_was_enabled = FALSE;
+}
+
+wireshark_decryption_is_now_enabled = wireshark_decryption_on();
+
+if(wireshark_decryption_is_now_enabled && airpcap_decryption_was_enabled)
+       {
+       set_airpcap_decryption(FALSE);
+       gtk_entry_set_text(GTK_ENTRY(decryption_en),AIRPCAP_DECRYPTION_TYPE_STRING_WIRESHARK);
+       }
+if(wireshark_decryption_is_now_enabled && !airpcap_decryption_was_enabled)
+       {
+       set_airpcap_decryption(FALSE);
+       gtk_entry_set_text(GTK_ENTRY(decryption_en),AIRPCAP_DECRYPTION_TYPE_STRING_WIRESHARK);
+       }
+else if(!wireshark_decryption_is_now_enabled && wireshark_decryption_was_enabled)
+       {
+       if(airpcap_decryption_was_enabled)
+               {
+               set_airpcap_decryption(TRUE);
+               gtk_entry_set_text(GTK_ENTRY(decryption_en),AIRPCAP_DECRYPTION_TYPE_STRING_AIRPCAP);
+               }
+       else
+               {
+               set_airpcap_decryption(FALSE);
+               gtk_entry_set_text(GTK_ENTRY(decryption_en),AIRPCAP_DECRYPTION_TYPE_STRING_NONE);
+               }
+       }
+}
+#endif
+
 static guint
 pref_clean(pref_t *pref, gpointer user_data _U_)
 {
@@ -1167,6 +1242,8 @@ prefs_main_fetch_all(GtkWidget *dlg, gboolean *must_redissect)
 static void
 prefs_main_apply_all(GtkWidget *dlg)
 {
+  GtkWidget *save_bt;
+
   /*
    * Apply the protocol preferences first - "gui_prefs_apply()" could
    * cause redissection, and we have to make sure the protocol
@@ -1191,6 +1268,14 @@ prefs_main_apply_all(GtkWidget *dlg)
 #endif /* HAVE_LIBPCAP */
   printer_prefs_apply(OBJECT_GET_DATA(dlg, E_PRINT_PAGE_KEY));
   nameres_prefs_apply(OBJECT_GET_DATA(dlg, E_NAMERES_PAGE_KEY));
+
+  /* show/hide the Save button - depending on setting */
+  save_bt = OBJECT_GET_DATA(prefs_w, E_PREFSW_SAVE_BT_KEY);
+  if(prefs.gui_use_pref_save) {
+    gtk_widget_show(save_bt);
+  } else {
+    gtk_widget_hide(save_bt);
+  }
 }
 
 
@@ -1235,16 +1320,63 @@ prefs_main_destroy_all(GtkWidget *dlg)
 }
 
 
+static void
+prefs_main_write(void)
+{
+  int err;
+  char *pf_dir_path;
+  char *pf_path;
+
+  /* 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 preferences file: %s.", pf_dir_path,
+      strerror(errno));
+     g_free(pf_dir_path);
+  } else {
+    /* Write the preferencs out. */
+    err = write_prefs(&pf_path);
+    if (err != 0) {
+       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+        "Can't open preferences file\n\"%s\": %s.", pf_path,
+        strerror(err));
+       g_free(pf_path);
+    }
+  }
+
+#ifdef HAVE_AIRPCAP
+/* 
+ * Load the Wireshark decryption keys (just set) and save 
+ * the changes to the adapters' registry 
+ */ 
+airpcap_load_decryption_keys(airpcap_if_list);
+#endif
+}
+
+
 static void
 prefs_main_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
 {
   gboolean must_redissect = FALSE;
 
   if (!prefs_main_fetch_all(parent_w, &must_redissect))
-    return; /* Errors in some preference setting */
+    return; /* Errors in some preference setting - already reported */
+
+  /* if we don't have a Save button, just save the settings now */
+  if (!prefs.gui_use_pref_save) {
+      prefs_main_write();
+  }
 
   prefs_main_apply_all(parent_w);
 
+  /* Fill in capture options with values from the preferences */
+  prefs_to_capture_opts();
+
+       #ifdef HAVE_AIRPCAP
+       prefs_airpcap_update();
+       #endif
+
   /* Now destroy the "Preferences" dialog. */
   window_destroy(GTK_WIDGET(parent_w));
 
@@ -1252,6 +1384,7 @@ prefs_main_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
     /* Redissect all the packets, and re-evaluate the display filter. */
     cf_redissect_packets(&cfile);
   }
+
 }
 
 static void
@@ -1260,10 +1393,22 @@ prefs_main_apply_cb(GtkWidget *apply_bt _U_, gpointer parent_w)
   gboolean must_redissect = FALSE;
 
   if (!prefs_main_fetch_all(parent_w, &must_redissect))
-    return; /* Errors in some preference setting */
+    return; /* Errors in some preference setting - already reported */
+
+  /* if we don't have a Save button, just save the settings now */
+  if (!prefs.gui_use_pref_save) {
+      prefs_main_write();
+  }
 
   prefs_main_apply_all(parent_w);
 
+  /* Fill in capture options with values from the preferences */
+  prefs_to_capture_opts();
+
+       #ifdef HAVE_AIRPCAP
+       prefs_airpcap_update();
+       #endif
+
   if (must_redissect) {
     /* Redissect all the packets, and re-evaluate the display filter. */
     cf_redissect_packets(&cfile);
@@ -1274,30 +1419,11 @@ static void
 prefs_main_save_cb(GtkWidget *save_bt _U_, gpointer parent_w)
 {
   gboolean must_redissect = FALSE;
-  int err;
-  char *pf_dir_path;
-  char *pf_path;
 
   if (!prefs_main_fetch_all(parent_w, &must_redissect))
-    return; /* Errors in some preference setting */
+    return; /* Errors in some preference setting - already reported */
 
-  /* 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 preferences file: %s.", pf_dir_path,
-      strerror(errno));
-     g_free(pf_dir_path);
-  } else {
-    /* Write the preferencs out. */
-    err = write_prefs(&pf_path);
-    if (err != 0) {
-       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-        "Can't open preferences file\n\"%s\": %s.", pf_path,
-        strerror(err));
-       g_free(pf_path);
-    }
-  }
+  prefs_main_write();
 
   /* Now apply those preferences.
      XXX - should we do this?  The user didn't click "OK" or "Apply".
@@ -1315,6 +1441,9 @@ prefs_main_save_cb(GtkWidget *save_bt _U_, gpointer parent_w)
        4) we did apply the protocol preferences, at least, in the past. */
   prefs_main_apply_all(parent_w);
 
+  /* Fill in capture options with values from the preferences */
+  prefs_to_capture_opts();
+
   if (must_redissect) {
     /* Redissect all the packets, and re-evaluate the display filter. */
     cf_redissect_packets(&cfile);