2 * Definitions for preference handling routines
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <epan/range.h>
35 #define PR_DEST_FILE 1
38 #define DEF_HEIGHT 550
40 #define MAX_VAL_LEN 1024
42 /* only GTK1 *or* GTK2 font_name should be used */
43 /* (we need to keep both in the preferences file but will only use the one suitable for the programs GTK version used) */
44 #if GTK_MAJOR_VERSION < 2
45 #define PREFS_GUI_FONT_NAME gui_font_name1
47 #define PREFS_GUI_FONT_NAME gui_font_name2
51 * Convert a string listing name resolution types to a bitmask of
54 * Set "*name_resolve" to the bitmask, and return '\0', on success;
55 * return the bad character in the string on error.
57 char string_to_name_resolve(char *string, guint32 *name_resolve);
60 * Modes for the starting directory in File Open dialogs.
62 #define FO_STYLE_LAST_OPENED 0 /* start in last directory we looked at */
63 #define FO_STYLE_SPECIFIED 1 /* start in specified directory */
68 #define TB_STYLE_ICONS 0
69 #define TB_STYLE_TEXT 1
70 #define TB_STYLE_BOTH 2
73 * Types of layout of summary/details/hex panes.
76 layout_unused, /* entry currently unused */
90 layout_pane_content_none,
91 layout_pane_content_plist,
92 layout_pane_content_pdetails,
93 layout_pane_content_pbytes
94 } layout_pane_content_e;
97 * open console behaviour (win32 only)
106 typedef struct _e_prefs {
113 color_t st_client_fg, st_client_bg, st_server_fg, st_server_bg;
114 gboolean gui_scrollbar_on_right;
115 gboolean gui_plist_sel_browse;
116 gboolean gui_ptree_sel_browse;
117 gboolean gui_altern_colors;
118 gboolean filter_toolbar_show_in_statusbar;
119 gint gui_ptree_line_style;
120 gint gui_ptree_expander_style;
121 gboolean gui_hex_dump_highlight_style;
122 gint gui_toolbar_main_style;
123 gchar *gui_font_name1;
124 gchar *gui_font_name2;
125 color_t gui_marked_fg;
126 color_t gui_marked_bg;
127 gboolean gui_geometry_save_position;
128 gboolean gui_geometry_save_size;
129 gboolean gui_geometry_save_maximized;
130 console_open_e gui_console_open;
131 guint gui_recent_files_count_max;
132 guint gui_fileopen_style;
133 gchar *gui_fileopen_dir;
134 guint gui_fileopen_preview;
135 gboolean gui_ask_unsaved;
136 gboolean gui_find_wrap;
137 gboolean gui_use_pref_save;
138 gchar *gui_webbrowser;
139 gchar *gui_window_title;
140 layout_type_e gui_layout_type;
141 layout_pane_content_e gui_layout_content_1;
142 layout_pane_content_e gui_layout_content_2;
143 layout_pane_content_e gui_layout_content_3;
144 gint console_log_level;
145 guint32 name_resolve;
146 gint name_resolve_concurrency;
147 gchar *capture_device;
148 gchar *capture_devices_descr;
149 gchar *capture_devices_hide;
150 gboolean capture_prom_mode;
151 gboolean capture_real_time;
152 gboolean capture_auto_scroll;
153 gboolean capture_show_info;
156 WS_VAR_IMPORT e_prefs prefs;
159 * Routines to let modules that have preference settings register
160 * themselves by name, and to let them register preference settings
165 typedef struct pref_module module_t;
168 * Register a module that will have preferences.
169 * Specify the module under which to register it or NULL to register it
170 * at the top level, the name used for the module in the preferences file,
171 * the title used in the tab for it in a preferences dialog box, and a
172 * routine to call back when we apply the preferences.
174 * This should not be used for dissector preferences;
175 * "prefs_register_protocol()" should be used for that, so that the
176 * preferences go under the "Protocols" subtree, and so that the
177 * name is the protocol name specified at the "proto_register_protocol()"
178 * call so that the "Protocol Properties..." menu item works.
180 extern module_t *prefs_register_module(module_t *parent, const char *name,
181 const char *title, const char *description, void (*apply_cb)(void));
184 * Register a subtree that will have modules under it.
185 * Specify the module under which to register it or NULL to register it
186 * at the top level and the title used in the tab for it in a preferences
189 extern module_t *prefs_register_subtree(module_t *parent, const char *title,
190 const char *description);
193 * Register that a protocol has preferences.
195 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
198 * Register that a protocol used to have preferences but no longer does,
199 * by creating an "obsolete" module for it.
201 extern module_t *prefs_register_protocol_obsolete(int id);
204 * Callback function for module list scanners.
206 typedef guint (*module_cb)(module_t *module, gpointer user_data);
209 * Call a callback function, with a specified argument, for each module
210 * in a list of modules. If the list is NULL, searches the top-level
211 * list in the display tree of modules.
213 * Ignores "obsolete" modules; their sole purpose is to allow old
214 * preferences for dissectors that no longer have preferences to be
215 * silently ignored in preference files. Does not ignore subtrees,
216 * as this can be used when walking the display tree of modules.
218 extern guint prefs_module_list_foreach(GList *module_list, module_cb callback,
222 * Call a callback function, with a specified argument, for each module
223 * in the list of all modules. (This list does not include subtrees.)
225 * Ignores "obsolete" modules; their sole purpose is to allow old
226 * preferences for dissectors that no longer have preferences to be
227 * silently ignored in preference files.
229 extern guint prefs_modules_foreach(module_cb callback, gpointer user_data);
232 * Call the "apply" callback function for each module if any of its
233 * preferences have changed, and then clear the flag saying its
234 * preferences have changed, as the module has been notified of that
237 extern void prefs_apply_all(void);
240 * Call the "apply" callback function for a specific module if any of
241 * its preferences have changed, and then clear the flag saying its
242 * preferences have changed, as the module has been notified of that
245 extern void prefs_apply(module_t *module);
250 typedef struct preference pref_t;
253 * Returns TRUE if the given protocol has registered preferences.
255 extern gboolean prefs_is_registered_protocol(const char *name);
258 * Returns the module title of a registered protocol (or NULL if unknown).
260 extern const char *prefs_get_title_by_name(const char *name);
262 /** Given a module name, return a pointer to its pref_module struct,
263 * or NULL if it's not found.
265 * @param name The preference module name. Usually the same as the protocol
267 * @return A pointer to the corresponding preference module, or NULL if it
270 extern module_t *prefs_find_module(const char *name);
273 * Register a preference with an unsigned integral value.
275 extern void prefs_register_uint_preference(module_t *module, const char *name,
276 const char *title, const char *description, guint base, guint *var);
279 * Register a preference with an Boolean value.
281 extern void prefs_register_bool_preference(module_t *module, const char *name,
282 const char *title, const char *description, gboolean *var);
285 * Register a preference with an enumerated value.
289 const char *description;
293 extern void prefs_register_enum_preference(module_t *module, const char *name,
294 const char *title, const char *description, gint *var,
295 const enum_val_t *enumvals, gboolean radio_buttons);
298 * Register a preference with a character-string value.
300 extern void prefs_register_string_preference(module_t *module, const char *name,
301 const char *title, const char *description, const char **var);
304 * Register a preference with a ranged value.
306 extern void prefs_register_range_preference(module_t *module, const char *name,
307 const char *title, const char *description, range_t **var,
311 * Register a static text 'preference'. It can be used to add some info/explanation.
313 extern void prefs_register_static_text_preference(module_t *module, const char *name,
314 const char *title, const char *description);
317 * Register a preference that used to be supported but no longer is.
319 extern void prefs_register_obsolete_preference(module_t *module,
322 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
325 * Call a callback function, with a specified argument, for each preference
328 * If any of the callbacks return a non-zero value, stop and return that
329 * value, otherwise return 0.
331 extern guint prefs_pref_foreach(module_t *module, pref_cb callback,
335 * Register all non-dissector modules' preferences.
337 extern void prefs_register_modules(void);
339 /* Read the preferences file, fill in "prefs", and return a pointer to it.
341 If we got an error (other than "it doesn't exist") trying to read
342 the global preferences file, stuff the errno into "*gpf_errno_return"
343 on an open error and into "*gpf_read_errno_return" on a read error,
344 stuff a pointer to the path of the file into "*gpf_path_return", and
347 If we got an error (other than "it doesn't exist") trying to read
348 the user's preferences file, stuff the errno into "*pf_errno_return"
349 on an open error and into "*pf_read_errno_return" on a read error,
350 stuff a pointer to the path of the file into "*pf_path_return", and
352 extern e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
354 /* Write out "prefs" to the user's preferences file, and return 0.
356 If we got an error, stuff a pointer to the path of the preferences file
357 into "*pf_path_return", and return the errno. */
358 extern int write_prefs(char **);
360 /* Copy a set of preferences. */
361 extern void copy_prefs(e_prefs *dest, e_prefs *src);
363 /* Free a set of preferences. */
364 extern void free_prefs(e_prefs *pr);
367 * Given a string of the form "<pref name>:<pref value>", as might appear
368 * as an argument to a "-o" option, parse it and set the preference in
369 * question. Return an indication of whether it succeeded or failed
372 * XXX - should supply, for syntax errors, a detailed explanation of
376 PREFS_SET_OK, /* succeeded */
377 PREFS_SET_SYNTAX_ERR, /* syntax error in string */
378 PREFS_SET_NO_SUCH_PREF, /* no such preference */
379 PREFS_SET_OBSOLETE /* preference used to exist but no longer does */
382 extern prefs_set_pref_e prefs_set_pref(char *prefarg);