2 * Routines for handling preferences
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0+
16 #include <epan/column.h>
17 #include <wsutil/filesystem.h>
18 #include <epan/prefs.h>
19 #include <epan/prefs-int.h>
20 #include <epan/packet.h>
21 #include <epan/decode_as.h>
24 #include "capture_opts.h"
25 #include "ui/capture_globals.h"
28 #include "ui/preference_utils.h"
29 #include "ui/simple_dialog.h"
32 /* Fill in capture options with values from the preferences */
34 prefs_to_capture_opts(void)
37 /* Set promiscuous mode from the preferences setting. */
38 /* the same applies to other preferences settings as well. */
39 global_capture_opts.default_options.promisc_mode = prefs.capture_prom_mode;
40 global_capture_opts.use_pcapng = prefs.capture_pcap_ng;
41 global_capture_opts.show_info = prefs.capture_show_info; /* GTK+ only */
42 global_capture_opts.real_time_mode = prefs.capture_real_time;
43 auto_scroll_live = prefs.capture_auto_scroll;
44 #endif /* HAVE_LIBPCAP */
48 prefs_main_write(void)
54 /* Create the directory that holds personal configuration files, if
56 if (create_persconffile_dir(&pf_dir_path) == -1) {
57 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
58 "Can't create directory\n\"%s\"\nfor preferences file: %s.", pf_dir_path,
62 /* Write the preferencs out. */
63 err = write_prefs(&pf_path);
65 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
66 "Can't open preferences file\n\"%s\": %s.", pf_path,
74 prefs_store_ext_helper(const char * module_name, const char *pref_name, const char *pref_value)
76 module_t * module = NULL;
78 gboolean pref_changed = TRUE;
80 if ( ! prefs_is_registered_protocol(module_name))
83 module = prefs_find_module(module_name);
87 pref = prefs_find_preference(module, pref_name);
92 if (prefs_get_type(pref) == PREF_STRING )
94 pref_changed = prefs_set_string_value(pref, pref_value, pref_stashed);
95 if ( ! pref_changed || prefs_get_string_value(pref, pref_stashed) != 0 )
96 pref_changed = prefs_set_string_value(pref, pref_value, pref_current);
103 prefs_store_ext(const char * module_name, const char *pref_name, const char *pref_value)
105 if ( prefs_store_ext_helper(module_name, pref_name, pref_value) )
109 prefs_to_capture_opts();
117 prefs_store_ext_multiple(const char * module, GHashTable * pref_values)
119 gboolean pref_changed = FALSE;
122 if ( ! prefs_is_registered_protocol(module))
125 keys = g_hash_table_get_keys(pref_values);
129 while ( keys != NULL )
131 gchar * pref_name = (gchar *)keys->data;
132 gchar * pref_value = (gchar *) g_hash_table_lookup(pref_values, keys->data);
134 if ( pref_name && pref_value )
136 if ( prefs_store_ext_helper(module, pref_name, pref_value) )
139 keys = g_list_next(keys);
146 prefs_to_capture_opts();
153 column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_fields, gint custom_occurrence)
156 fmt_data *cfmt, *last_cfmt;
159 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
161 * Because a single underscore is interpreted as a signal that the next character
162 * is going to be marked as accelerator for this header (i.e. is going to be
163 * shown underlined), escape it be inserting a second consecutive underscore.
165 cfmt->title = g_strdup(title);
167 cfmt->custom_fields = g_strdup(custom_fields);
168 cfmt->custom_occurrence = custom_occurrence;
169 cfmt->resolved = TRUE;
171 colnr = g_list_length(prefs.col_list);
174 cfmt->visible = TRUE;
175 clp = g_list_last(prefs.col_list);
176 last_cfmt = (fmt_data *) clp->data;
177 if (last_cfmt->fmt == COL_INFO) {
178 /* Last column is COL_INFO, add custom column before this */
180 prefs.col_list = g_list_insert(prefs.col_list, cfmt, colnr);
182 prefs.col_list = g_list_append(prefs.col_list, cfmt);
185 cfmt->visible = FALSE; /* Will be set to TRUE in visible_toggled() when added to list */
186 prefs.col_list = g_list_append(prefs.col_list, cfmt);
193 column_prefs_remove_link(GList *col_link)
197 if (!col_link || !col_link->data) return;
199 cfmt = (fmt_data *) col_link->data;
202 g_free(cfmt->custom_fields);
204 prefs.col_list = g_list_remove_link(prefs.col_list, col_link);
208 column_prefs_remove_nth(gint col)
210 column_prefs_remove_link(g_list_nth(prefs.col_list, col));
214 * Editor modelines - https://www.wireshark.org/tools/modelines.html
219 * indent-tabs-mode: nil
222 * ex: set shiftwidth=4 tabstop=8 expandtab:
223 * :indentSize=4:tabSize=8:noTabs=true: