2 * Routines for handling preferences
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/column-info.h>
32 #include <epan/column.h>
33 #include <epan/filesystem.h>
34 #include <epan/prefs.h>
35 #include <epan/prefs-int.h>
38 #include "capture_opts.h"
39 #include "ui/capture_globals.h"
42 #include "ui/preference_utils.h"
43 #include "ui/simple_dialog.h"
46 pref_stash(pref_t
*pref
, gpointer unused _U_
)
51 pref
->stashed_val
.uint
= *pref
->varp
.uint
;
55 pref
->stashed_val
.boolval
= *pref
->varp
.boolp
;
59 pref
->stashed_val
.enumval
= *pref
->varp
.enump
;
65 g_free(pref
->stashed_val
.string
);
66 pref
->stashed_val
.string
= g_strdup(*pref
->varp
.string
);
70 g_free(pref
->stashed_val
.range
);
71 pref
->stashed_val
.range
= range_copy(*pref
->varp
.range
);
75 pref
->stashed_val
.color
= *pref
->varp
.colorp
;
78 case PREF_STATIC_TEXT
:
84 g_assert_not_reached();
91 pref_unstash(pref_t
*pref
, gpointer changed_p
)
93 gboolean
*pref_changed_p
= (gboolean
*)changed_p
;
95 /* Revert the preference to its saved value. */
99 if (*pref
->varp
.uint
!= pref
->stashed_val
.uint
) {
100 *pref_changed_p
= TRUE
;
101 *pref
->varp
.uint
= pref
->stashed_val
.uint
;
106 if (*pref
->varp
.boolp
!= pref
->stashed_val
.boolval
) {
107 *pref_changed_p
= TRUE
;
108 *pref
->varp
.boolp
= pref
->stashed_val
.boolval
;
113 if (*pref
->varp
.enump
!= pref
->stashed_val
.enumval
) {
114 *pref_changed_p
= TRUE
;
115 *pref
->varp
.enump
= pref
->stashed_val
.enumval
;
122 if (strcmp(*pref
->varp
.string
, pref
->stashed_val
.string
) != 0) {
123 *pref_changed_p
= TRUE
;
124 g_free((void *)*pref
->varp
.string
);
125 *pref
->varp
.string
= g_strdup(pref
->stashed_val
.string
);
130 if (!ranges_are_equal(*pref
->varp
.range
, pref
->stashed_val
.range
)) {
131 *pref_changed_p
= TRUE
;
132 g_free(*pref
->varp
.range
);
133 *pref
->varp
.range
= range_copy(pref
->stashed_val
.range
);
138 *pref
->varp
.colorp
= pref
->stashed_val
.color
;
141 case PREF_STATIC_TEXT
:
147 g_assert_not_reached();
154 reset_stashed_pref(pref_t
*pref
) {
155 switch (pref
->type
) {
158 pref
->stashed_val
.uint
= pref
->default_val
.uint
;
162 pref
->stashed_val
.boolval
= pref
->default_val
.boolval
;
166 pref
->stashed_val
.enumval
= pref
->default_val
.enumval
;
172 g_free(pref
->stashed_val
.string
);
173 pref
->stashed_val
.string
= g_strdup(pref
->default_val
.string
);
177 g_free(pref
->stashed_val
.range
);
178 pref
->stashed_val
.range
= range_copy(pref
->default_val
.range
);
182 memcpy(&pref
->stashed_val
.color
, &pref
->default_val
.color
, sizeof(color_t
));
185 case PREF_STATIC_TEXT
:
191 g_assert_not_reached();
197 pref_clean_stash(pref_t
*pref
, gpointer unused _U_
)
199 switch (pref
->type
) {
213 if (pref
->stashed_val
.string
!= NULL
) {
214 g_free(pref
->stashed_val
.string
);
215 pref
->stashed_val
.string
= NULL
;
220 if (pref
->stashed_val
.range
!= NULL
) {
221 g_free(pref
->stashed_val
.range
);
222 pref
->stashed_val
.range
= NULL
;
226 case PREF_STATIC_TEXT
:
233 g_assert_not_reached();
239 /* Fill in capture options with values from the preferences */
241 prefs_to_capture_opts(void)
244 /* Set promiscuous mode from the preferences setting. */
245 /* the same applies to other preferences settings as well. */
246 global_capture_opts
.default_options
.promisc_mode
= prefs
.capture_prom_mode
;
247 global_capture_opts
.use_pcapng
= prefs
.capture_pcap_ng
;
248 global_capture_opts
.show_info
= prefs
.capture_show_info
;
249 global_capture_opts
.real_time_mode
= prefs
.capture_real_time
;
250 auto_scroll_live
= prefs
.capture_auto_scroll
;
251 #endif /* HAVE_LIBPCAP */
255 prefs_main_write(void)
261 /* Create the directory that holds personal configuration files, if
263 if (create_persconffile_dir(&pf_dir_path
) == -1) {
264 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
,
265 "Can't create directory\n\"%s\"\nfor preferences file: %s.", pf_dir_path
,
269 /* Write the preferencs out. */
270 err
= write_prefs(&pf_path
);
272 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
,
273 "Can't open preferences file\n\"%s\": %s.", pf_path
,
281 column_prefs_add_custom(gint fmt
, const gchar
*title
, const gchar
*custom_field
, gint custom_occurrence
)
284 fmt_data
*cfmt
, *last_cfmt
;
286 cfmt
= (fmt_data
*) g_malloc(sizeof(fmt_data
));
288 * Because a single underscore is interpreted as a signal that the next character
289 * is going to be marked as accelerator for this header (i.e. is going to be
290 * shown underlined), escape it be inserting a second consecutive underscore.
292 cfmt
->title
= g_strdup(title
);
294 cfmt
->custom_field
= g_strdup(custom_field
);
295 cfmt
->custom_occurrence
= custom_occurrence
;
296 cfmt
->resolved
= TRUE
;
299 cfmt
->visible
= TRUE
;
300 clp
= g_list_last(prefs
.col_list
);
301 last_cfmt
= (fmt_data
*) clp
->data
;
302 if (last_cfmt
->fmt
== COL_INFO
) {
303 /* Last column is COL_INFO, add custom column before this */
304 prefs
.col_list
= g_list_insert(prefs
.col_list
, cfmt
, g_list_length(prefs
.col_list
)-1);
306 prefs
.col_list
= g_list_append(prefs
.col_list
, cfmt
);
309 cfmt
->visible
= FALSE
; /* Will be set to TRUE in visible_toggled() when added to list */
310 prefs
.col_list
= g_list_append(prefs
.col_list
, cfmt
);
315 column_prefs_remove_link(GList
*col_link
)
319 if (!col_link
|| !col_link
->data
) return;
321 cfmt
= (fmt_data
*) col_link
->data
;
324 g_free(cfmt
->custom_field
);
326 prefs
.col_list
= g_list_remove_link(prefs
.col_list
, col_link
);
330 column_prefs_remove_nth(gint col
)
332 column_prefs_remove_link(g_list_nth(prefs
.col_list
, col
));
341 * indent-tabs-mode: nil
344 * ex: set shiftwidth=2 tabstop=8 expandtab:
345 * :indentSize=2:tabSize=8:noTabs=true: