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-or-later
15 #include <epan/column.h>
16 #include <wsutil/filesystem.h>
17 #include <epan/prefs.h>
18 #include <epan/prefs-int.h>
19 #include <epan/packet.h>
20 #include <epan/decode_as.h>
23 #include "capture_opts.h"
24 #include "ui/capture_globals.h"
27 #include "ui/preference_utils.h"
28 #include "ui/simple_dialog.h"
31 gboolean auto_scroll_live;
34 /* Fill in capture options with values from the preferences */
36 prefs_to_capture_opts(void)
39 /* Set promiscuous mode from the preferences setting. */
40 /* the same applies to other preferences settings as well. */
41 global_capture_opts.default_options.promisc_mode = prefs.capture_prom_mode;
42 global_capture_opts.use_pcapng = prefs.capture_pcap_ng;
43 global_capture_opts.show_info = prefs.capture_show_info; /* GTK+ only? */
44 global_capture_opts.real_time_mode = prefs.capture_real_time;
45 auto_scroll_live = prefs.capture_auto_scroll;
46 #endif /* HAVE_LIBPCAP */
50 prefs_main_write(void)
56 /* Create the directory that holds personal configuration files, if
58 if (create_persconffile_dir(&pf_dir_path) == -1) {
59 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
60 "Can't create directory\n\"%s\"\nfor preferences file: %s.", pf_dir_path,
64 /* Write the preferencs out. */
65 err = write_prefs(&pf_path);
67 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
68 "Can't open preferences file\n\"%s\": %s.", pf_path,
76 prefs_store_ext_helper(const char * module_name, const char *pref_name, const char *pref_value)
78 module_t * module = NULL;
80 unsigned int pref_changed = 0;
82 if ( ! prefs_is_registered_protocol(module_name))
85 module = prefs_find_module(module_name);
89 pref = prefs_find_preference(module, pref_name);
94 if (prefs_get_type(pref) == PREF_STRING )
96 pref_changed |= prefs_set_string_value(pref, pref_value, pref_stashed);
97 if ( ! pref_changed || prefs_get_string_value(pref, pref_stashed) != 0 )
98 pref_changed |= prefs_set_string_value(pref, pref_value, pref_current);
105 prefs_store_ext(const char * module_name, const char *pref_name, const char *pref_value)
107 unsigned int changed_flags = prefs_store_ext_helper(module_name, pref_name, pref_value);
112 prefs_to_capture_opts();
113 return changed_flags;
120 prefs_store_ext_multiple(const char * module, GHashTable * pref_values)
122 gboolean pref_changed = FALSE;
125 if ( ! prefs_is_registered_protocol(module))
128 keys = g_hash_table_get_keys(pref_values);
132 while ( keys != NULL )
134 gchar * pref_name = (gchar *)keys->data;
135 gchar * pref_value = (gchar *) g_hash_table_lookup(pref_values, keys->data);
137 if ( pref_name && pref_value )
139 if ( prefs_store_ext_helper(module, pref_name, pref_value) )
142 keys = g_list_next(keys);
149 prefs_to_capture_opts();
156 column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_fields, gint custom_occurrence)
159 fmt_data *cfmt, *last_cfmt;
162 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
164 * Because a single underscore is interpreted as a signal that the next character
165 * is going to be marked as accelerator for this header (i.e. is going to be
166 * shown underlined), escape it be inserting a second consecutive underscore.
168 cfmt->title = g_strdup(title);
170 cfmt->custom_fields = g_strdup(custom_fields);
171 cfmt->custom_occurrence = custom_occurrence;
172 cfmt->resolved = TRUE;
174 colnr = g_list_length(prefs.col_list);
177 cfmt->visible = TRUE;
178 clp = g_list_last(prefs.col_list);
179 last_cfmt = (fmt_data *) clp->data;
180 if (last_cfmt->fmt == COL_INFO) {
181 /* Last column is COL_INFO, add custom column before this */
183 prefs.col_list = g_list_insert(prefs.col_list, cfmt, colnr);
185 prefs.col_list = g_list_append(prefs.col_list, cfmt);
188 cfmt->visible = FALSE; /* Will be set to TRUE in visible_toggled() when added to list */
189 prefs.col_list = g_list_append(prefs.col_list, cfmt);
196 column_prefs_remove_link(GList *col_link)
200 if (!col_link || !col_link->data) return;
202 cfmt = (fmt_data *) col_link->data;
205 g_free(cfmt->custom_fields);
207 prefs.col_list = g_list_remove_link(prefs.col_list, col_link);
211 column_prefs_remove_nth(gint col)
213 column_prefs_remove_link(g_list_nth(prefs.col_list, col));
217 * Editor modelines - https://www.wireshark.org/tools/modelines.html
222 * indent-tabs-mode: nil
225 * ex: set shiftwidth=4 tabstop=8 expandtab:
226 * :indentSize=4:tabSize=8:noTabs=true: