Remove some GTK+-only code.
[metze/wireshark/wip.git] / epan / prefs.c
index 1ccf5ac18513ef144ea536f0da479b363663051e..c2d1dfc9ddd4891dcc034889e6aa596db1f08473 100644 (file)
@@ -10,6 +10,8 @@
 
 #include "config.h"
 
+#include "ws_diag_control.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -21,9 +23,7 @@
 #include <epan/address.h>
 #include <epan/addr_resolv.h>
 #include <epan/oids.h>
-#ifdef HAVE_GEOIP
-#include <epan/geoip_db.h>
-#endif
+#include <epan/maxmind_db.h>
 #include <epan/packet.h>
 #include <epan/prefs.h>
 #include <epan/proto.h>
@@ -97,13 +97,6 @@ static const enum_val_t gui_ptree_expander_style[] = {
     {NULL, NULL, -1}
 };
 
-/* GTK+ only. */
-static const enum_val_t gui_hex_dump_highlight_style[] = {
-    {"BOLD", "BOLD", 0},
-    {"INVERSE", "INVERSE", 1},
-    {NULL, NULL, -1}
-};
-
 static const enum_val_t gui_console_open_type[] = {
     {"NEVER", "NEVER", console_open_never},
     {"AUTOMATIC", "AUTOMATIC", console_open_auto},
@@ -125,8 +118,6 @@ static const enum_val_t gui_fileopen_style[] = {
     {NULL, NULL, -1}
 };
 
-/* GTK knows of two ways representing "both", vertical and horizontal aligned.
- * as this may not work on other guis, we use only "both" in general here */
 static const enum_val_t gui_toolbar_style[] = {
     {"ICONS", "ICONS", 0},
     {"TEXT", "TEXT", 1},
@@ -280,21 +271,6 @@ guint32 prefs_get_max_value(pref_t *pref)
     return pref->info.max_value;
 }
 
-void* prefs_get_control(pref_t *pref)
-{
-    return pref->control;
-}
-
-void prefs_set_control(pref_t *pref, void* control)
-{
-    pref->control = control;
-}
-
-int prefs_get_ordinal(pref_t *pref)
-{
-    return pref->ordinal;
-}
-
 /*
  * List of all modules with preference settings.
  */
@@ -321,7 +297,9 @@ prefs_init(void)
 static void
 free_string_like_preference(pref_t *pref)
 {
-    g_free(*pref->varp.string);
+DIAG_OFF(cast-qual)
+    g_free((char *)*pref->varp.string);
+DIAG_ON(cast-qual)
     *pref->varp.string = NULL;
     g_free(pref->default_val.string);
     pref->default_val.string = NULL;
@@ -349,10 +327,7 @@ free_pref(gpointer data, gpointer user_data _U_)
     case PREF_SAVE_FILENAME:
     case PREF_OPEN_FILENAME:
     case PREF_DIRNAME:
-        g_free(*pref->varp.string);
-        *pref->varp.string = NULL;
-        g_free(pref->default_val.string);
-        pref->default_val.string = NULL;
+        free_string_like_preference(pref);
         break;
     case PREF_RANGE:
     case PREF_DECODE_AS_RANGE:
@@ -402,6 +377,9 @@ prefs_cleanup(void)
     /* Clean the uats */
     uat_cleanup();
 
+    /* Shut down mmdbresolve */
+    maxmind_db_pref_cleanup();
+
     g_free(prefs.saved_at_version);
     g_free(gpf_path);
     gpf_path = NULL;
@@ -1383,6 +1361,18 @@ register_string_like_preference(module_t *module, const char *name,
     }
 }
 
+/*
+ * Assign to a string preference.
+ */
+static void
+pref_set_string_like_pref_value(pref_t *pref, const gchar *value)
+{
+DIAG_OFF(cast-qual)
+    g_free((void *)*pref->varp.string);
+DIAG_ON(cast-qual)
+    *pref->varp.string = g_strdup(value);
+}
+
 /*
  * For use by UI code that sets preferences.
  */
@@ -1419,11 +1409,10 @@ prefs_set_string_value(pref_t *pref, const char* value, pref_source_t source)
         if (*pref->varp.string) {
             if (strcmp(*pref->varp.string, value) != 0) {
                 changed = prefs_get_effect_flags(pref);
-                g_free(*pref->varp.string);
-                *pref->varp.string = g_strdup(value);
+                pref_set_string_like_pref_value(pref, value);
             }
         } else if (value) {
-            *pref->varp.string = g_strdup(value);
+            pref_set_string_like_pref_value(pref, value);
         }
         break;
     default:
@@ -2007,7 +1996,7 @@ pref_unstash(pref_t *pref, gpointer unstash_data_p)
             if (unstash_data->handle_decode_as) {
                 sub_dissectors = find_dissector_table(pref->name);
                 if (sub_dissectors != NULL) {
-                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)unstash_data->module->title);
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, unstash_data->module->title);
                     if (handle != NULL) {
                         dissector_change_uint(pref->name, *pref->varp.uint, handle);
                     }
@@ -2056,7 +2045,7 @@ pref_unstash(pref_t *pref, gpointer unstash_data_p)
             if (unstash_data->handle_decode_as) {
                 sub_dissectors = find_dissector_table(pref->name);
                 if (sub_dissectors != NULL) {
-                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)unstash_data->module->title);
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, unstash_data->module->title);
                     if (handle != NULL) {
                         /* Delete all of the old values from the dissector table */
                         for (i = 0; i < (*pref->varp.range)->nranges; i++) {
@@ -2297,12 +2286,6 @@ stats_callback(void)
     if (prefs.tap_update_interval < 100 || prefs.tap_update_interval > 10000)
         prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
 
-#ifdef HAVE_LIBPORTAUDIO
-    /* Test for a sane max channels entry */
-    if (prefs.rtp_player_max_visible < 1 || prefs.rtp_player_max_visible > 10)
-        prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
-#endif
-
     /* burst resolution can't be less than 1 (ms) */
     if (prefs.st_burst_resolution < 1) {
         prefs.st_burst_resolution = 1;
@@ -3028,11 +3011,7 @@ prefs_register_modules(void)
     prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
     prefs_register_obsolete_preference(gui_module, "packet_list_sel_browse");
     prefs_register_obsolete_preference(gui_module, "protocol_tree_sel_browse");
-
-    prefs_register_bool_preference(gui_module, "tree_view_altern_colors",
-                                   "Alternating colors in TreeViews",
-                                   "Alternating colors in TreeViews?",
-                                   &prefs.gui_altern_colors);
+    prefs_register_obsolete_preference(gui_module, "tree_view_altern_colors");
 
     prefs_register_bool_preference(gui_module, "expert_composite_eyecandy",
                                    "Display Icons on Expert Composite Dialog Tabs",
@@ -3059,10 +3038,7 @@ prefs_register_modules(void)
                        "Protocol-tree expander style",
                        &prefs.gui_ptree_expander_style, gui_ptree_expander_style, FALSE);
 
-    prefs_register_enum_preference(gui_module, "hex_dump_highlight_style",
-                       "Hex dump highlight style",
-                       "Hex dump highlight style",
-                       &prefs.gui_hex_dump_highlight_style, gui_hex_dump_highlight_style, FALSE);
+    prefs_register_obsolete_preference(gui_module, "hex_dump_highlight_style");
 
     gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
 
@@ -3107,9 +3083,7 @@ prefs_register_modules(void)
 
     prefs_register_obsolete_preference(gui_font_module, "font_name");
 
-    register_string_like_preference(gui_font_module, "gtk2.font_name", "Font name",
-        "Font name for packet list, protocol tree, and hex dump panes. (GTK+)",
-        &prefs.gui_gtk2_font_name, PREF_STRING, NULL, TRUE);
+    prefs_register_obsolete_preference(gui_font_module, "gtk2.font_name");
 
     register_string_like_preference(gui_font_module, "qt.font_name", "Font name",
         "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
@@ -3232,11 +3206,7 @@ prefs_register_modules(void)
                                    "Save window maximized state at exit?",
                                    &prefs.gui_geometry_save_maximized);
 
-    /* GTK+ only */
-    prefs_register_bool_preference(gui_module, "macosx_style",
-                                   "Use macOS style",
-                                   "Use macOS style (macOS with native GTK only)?",
-                                   &prefs.gui_macosx_style);
+    prefs_register_obsolete_preference(gui_module, "macosx_style");
 
     prefs_register_obsolete_preference(gui_module, "geometry.main.x");
     prefs_register_obsolete_preference(gui_module, "geometry.main.y");
@@ -3291,18 +3261,8 @@ prefs_register_modules(void)
                        "Show version in the start page and/or main screen's title bar",
                        (gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE);
 
-    prefs_register_bool_preference(gui_module, "auto_scroll_on_expand",
-                                   "Automatically scroll packet details",
-                                   "When selecting a new packet, automatically scroll"
-                                   "to the packet detail item that matches the most"
-                                   "recently selected item",
-                                   &prefs.gui_auto_scroll_on_expand);
-
-    prefs_register_uint_preference(gui_module, "auto_scroll_percentage",
-                                   "Packet detail scroll percentage",
-                                   "The percentage down the view the recently expanded detail item should be scrolled",
-                                   10,
-                                   &prefs.gui_auto_scroll_percentage);
+    prefs_register_obsolete_preference(gui_module, "auto_scroll_on_expand");
+    prefs_register_obsolete_preference(gui_module, "auto_scroll_percentage");
 
     /* User Interface : Layout */
     gui_layout_module = prefs_register_subtree(gui_module, "Layout", "Layout", gui_layout_callback);
@@ -3485,7 +3445,7 @@ prefs_register_modules(void)
     prefs_register_bool_preference(capture_module, "auto_scroll", "Scroll packet list during capture",
         "Scroll packet list during capture?", &prefs.capture_auto_scroll);
 
-    /* GTK+ only */
+    /* GTK+ only, but we might implement this in Qt */
     prefs_register_bool_preference(capture_module, "show_info", "Show capture info dialog while capturing",
         "Show capture info dialog while capturing?", &prefs.capture_show_info);
 
@@ -3506,9 +3466,7 @@ prefs_register_modules(void)
         "Name Resolution", NULL, TRUE);
     addr_resolve_pref_init(nameres_module);
     oid_pref_init(nameres_module);
-#ifdef HAVE_GEOIP
-    geoip_db_pref_init(nameres_module);
-#endif
+    maxmind_db_pref_init(nameres_module);
 
     /* Printing */
     printing = prefs_register_module(NULL, "print", "Printing",
@@ -3546,13 +3504,7 @@ prefs_register_modules(void)
                                    10,
                                    &prefs.tap_update_interval);
 
-#ifdef HAVE_LIBPORTAUDIO
-    prefs_register_uint_preference(stats_module, "rtp_player_max_visible",
-                                   "Max visible channels in RTP Player",
-                                   "Determines maximum height of RTP Player window",
-                                   10,
-                                   &prefs.rtp_player_max_visible);
-#endif
+    prefs_register_obsolete_preference(stats_module, "rtp_player_max_visible");
 
     prefs_register_bool_preference(stats_module, "st_enable_burstinfo",
             "Enable the calculation of burst information",
@@ -4001,22 +3953,13 @@ pre_init_prefs(void)
     g_free(prefs.pr_cmd);
     prefs.pr_cmd     = g_strdup("lpr");
 
-    prefs.gui_altern_colors = FALSE;
     prefs.gui_expert_composite_eyecandy = FALSE;
     prefs.gui_ptree_line_style = 0;
     prefs.gui_ptree_expander_style = 1;
-    prefs.gui_hex_dump_highlight_style = 1; /* GTK+ only */
     prefs.filter_toolbar_show_in_statusbar = FALSE;
     prefs.restore_filter_after_following_stream = FALSE;
     prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
     prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
-    /* These will be g_freed, so they must be g_mallocated. */
-    g_free(prefs.gui_gtk2_font_name);
-#ifdef _WIN32
-    prefs.gui_gtk2_font_name         = g_strdup("Lucida Console 10");
-#else
-    prefs.gui_gtk2_font_name         = g_strdup("Monospace 10");
-#endif
     /* We try to find the best font in the Qt code */
     g_free(prefs.gui_qt_font_name);
     prefs.gui_qt_font_name           = g_strdup("");
@@ -4076,7 +4019,6 @@ pre_init_prefs(void)
     prefs.gui_geometry_save_position = TRUE;
     prefs.gui_geometry_save_size     = TRUE;
     prefs.gui_geometry_save_maximized= TRUE;
-    prefs.gui_macosx_style           = TRUE;
     prefs.gui_console_open           = console_open_never;
     prefs.gui_fileopen_style         = FO_STYLE_LAST_OPENED;
     prefs.gui_recent_df_entries_max  = 10;
@@ -4099,8 +4041,6 @@ pre_init_prefs(void)
     g_free(prefs.gui_start_title);
     prefs.gui_start_title            = g_strdup("The World's Most Popular Network Protocol Analyzer");
     prefs.gui_version_placement      = version_both;
-    prefs.gui_auto_scroll_on_expand  = FALSE;
-    prefs.gui_auto_scroll_percentage = 0;
     prefs.gui_layout_type            = layout_type_5;
     prefs.gui_layout_content_1       = layout_pane_content_plist;
     prefs.gui_layout_content_2       = layout_pane_content_pdetails;
@@ -4161,7 +4101,6 @@ pre_init_prefs(void)
 
 /* set the default values for the tap/statistics dialog box */
     prefs.tap_update_interval    = TAP_UPDATE_DEFAULT_INTERVAL;
-    prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
     prefs.st_enable_burstinfo = TRUE;
     prefs.st_burst_showcount = FALSE;
     prefs.st_burst_resolution = ST_DEF_BURSTRES;
@@ -5253,7 +5192,7 @@ deprecated_port_pref(gchar *pref_name, const gchar *value)
             if (p == value || *p != '\0')
                 return FALSE;        /* number was bad */
 
-            module = prefs_find_module((gchar*)port_prefs[i].module_name);
+            module = prefs_find_module(port_prefs[i].module_name);
             pref = prefs_find_preference(module, port_prefs[i].table_name);
             if (pref != NULL)
             {
@@ -5266,7 +5205,7 @@ deprecated_port_pref(gchar *pref_name, const gchar *value)
             {
                 sub_dissectors = find_dissector_table(port_prefs[i].table_name);
                 if (sub_dissectors != NULL) {
-                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_prefs[i].module_name);
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, port_prefs[i].module_name);
                     if (handle != NULL) {
                         dissector_change_uint(port_prefs[i].table_name, uval, handle);
                         decode_build_reset_list(port_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval), NULL, NULL);
@@ -5298,7 +5237,7 @@ deprecated_port_pref(gchar *pref_name, const gchar *value)
                     g_assert_not_reached();
                 }
 
-                module = prefs_find_module((gchar*)port_range_prefs[i].module_name);
+                module = prefs_find_module(port_range_prefs[i].module_name);
                 pref = prefs_find_preference(module, port_range_prefs[i].table_name);
                 if (pref != NULL)
                 {
@@ -5307,7 +5246,7 @@ deprecated_port_pref(gchar *pref_name, const gchar *value)
                         return FALSE;        /* number was bad */
                     }
 
-                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_range_prefs[i].module_name);
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, port_range_prefs[i].module_name);
                     if (handle != NULL) {
 
                         for (range_i = 0; range_i < (*pref->varp.range)->nranges; range_i++) {
@@ -5757,8 +5696,7 @@ set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
                 }
             } else if (strcmp(module->name, "taps") == 0) {
                 /* taps preferences moved to "statistics" module */
-                if (strcmp(dotp, "update_interval") == 0 ||
-                    strcmp(dotp, "rtp_player_max_visible") == 0)
+                if (strcmp(dotp, "update_interval") == 0)
                     pref = prefs_find_preference(stats_module, dotp);
             } else if (strcmp(module->name, "packet_list") == 0) {
                 /* packet_list preferences moved to protocol module */
@@ -5824,7 +5762,7 @@ set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
                 /* Name of preference is the dissector table */
                 sub_dissectors = find_dissector_table(pref->name);
                 if (sub_dissectors != NULL) {
-                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, module->title);
                     if (handle != NULL) {
                         if (uval != 0) {
                             dissector_change_uint(pref->name, uval, handle);
@@ -5899,7 +5837,7 @@ set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
                 /* Name of preference is the dissector table */
                 sub_dissectors = find_dissector_table(pref->name);
                 if (sub_dissectors != NULL) {
-                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, module->title);
                     if (handle != NULL) {
                         /* Delete all of the old values from the dissector table */
                                for (i = 0; i < (*pref->varp.range)->nranges; i++) {