2 * Definitions for preference handling routines
4 * $Id: prefs.h,v 1.61 2004/05/09 10:03:37 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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.
33 #define PR_DEST_FILE 1
36 #define DEF_HEIGHT 550
38 #define MAX_VAL_LEN 1024
40 /* only GTK1 *or* GTK2 font_name should be used */
41 #if GTK_MAJOR_VERSION < 2
42 #define PREFS_GUI_FONT_NAME gui_font_name1
44 #define PREFS_GUI_FONT_NAME gui_font_name2
48 * Convert a string listing name resolution types to a bitmask of
51 * Set "*name_resolve" to the bitmask, and return '\0', on success;
52 * return the bad character in the string on error.
54 char string_to_name_resolve(char *string, guint32 *name_resolve);
57 * Modes for the starting directory in File Open dialogs.
59 #define FO_STYLE_LAST_OPENED 0 /* start in last directory we looked at */
60 #define FO_STYLE_SPECIFIED 1 /* start in specified directory */
65 #define TB_STYLE_ICONS 0
66 #define TB_STYLE_TEXT 1
67 #define TB_STYLE_BOTH 2
70 * Types of layout of summary/details/hex panes.
73 layout_unused, /* entry currently unused */
87 layout_pane_content_none,
88 layout_pane_content_plist,
89 layout_pane_content_pdetails,
90 layout_pane_content_pbytes
91 } layout_pane_content_e;
94 typedef struct _e_prefs {
101 color_t st_client_fg, st_client_bg, st_server_fg, st_server_bg;
102 gboolean gui_scrollbar_on_right;
103 gboolean gui_plist_sel_browse;
104 gboolean gui_ptree_sel_browse;
105 gboolean gui_altern_colors;
106 gboolean filter_toolbar_show_in_statusbar;
107 gint gui_ptree_line_style;
108 gint gui_ptree_expander_style;
109 gboolean gui_hex_dump_highlight_style;
110 gint gui_toolbar_main_style;
111 gchar *gui_font_name1;
112 gchar *gui_font_name2;
113 color_t gui_marked_fg;
114 color_t gui_marked_bg;
115 gboolean gui_geometry_save_position;
116 gboolean gui_geometry_save_size;
117 gboolean gui_geometry_save_maximized;
118 guint gui_fileopen_style;
119 guint gui_recent_files_count_max;
120 gchar *gui_fileopen_dir;
121 layout_type_e gui_layout_type;
122 layout_pane_content_e gui_layout_content_1;
123 layout_pane_content_e gui_layout_content_2;
124 layout_pane_content_e gui_layout_content_3;
125 guint32 name_resolve;
126 gint name_resolve_concurrency;
127 gchar *capture_device;
128 gchar *capture_devices_descr;
129 gchar *capture_devices_hide;
130 gboolean capture_prom_mode;
131 gboolean capture_real_time;
132 gboolean capture_auto_scroll;
135 ETH_VAR_IMPORT e_prefs prefs;
138 * Routines to let modules that have preference settings register
139 * themselves by name, and to let them register preference settings
144 typedef struct pref_module module_t;
147 * Register a module that will have preferences.
148 * Specify the module under which to register it or NULL to register it
149 * at the top level, the name used for the module in the preferences file,
150 * the title used in the tab for it in a preferences dialog box, and a
151 * routine to call back when we apply the preferences.
153 * This should not be used for dissector preferences;
154 * "prefs_register_protocol()" should be used for that, so that the
155 * preferences go under the "Protocols" subtree, and so that the
156 * name is the protocol name specified at the "proto_register_protocol()"
157 * call so that the "Protocol Properties..." menu item works.
159 extern module_t *prefs_register_module(module_t *parent, const char *name,
160 const char *title, void (*apply_cb)(void));
163 * Register a subtree that will have modules under it.
164 * Specify the module under which to register it or NULL to register it
165 * at the top level and the title used in the tab for it in a preferences
168 extern module_t *prefs_register_subtree(module_t *parent, const char *title);
171 * Register that a protocol has preferences.
173 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
176 * Register that a protocol used to have preferences but no longer does,
177 * by creating an "obsolete" module for it.
179 extern module_t *prefs_register_protocol_obsolete(int id);
182 * Callback function for module list scanners.
184 typedef void (*module_cb)(module_t *module, gpointer user_data);
187 * Call a callback function, with a specified argument, for each module
188 * in a list of modules. If the list is NULL, searches the top-level
189 * list in the display tree of modules.
191 * Ignores "obsolete" modules; their sole purpose is to allow old
192 * preferences for dissectors that no longer have preferences to be
193 * silently ignored in preference files. Does not ignore subtrees,
194 * as this can be used when walking the display tree of modules.
196 extern void prefs_module_list_foreach(GList *module_list, module_cb callback,
200 * Call a callback function, with a specified argument, for each module
201 * in the list of all modules. (This list does not include subtrees.)
203 * Ignores "obsolete" modules; their sole purpose is to allow old
204 * preferences for dissectors that no longer have preferences to be
205 * silently ignored in preference files.
207 extern void prefs_modules_foreach(module_cb callback, gpointer user_data);
210 * Call the "apply" callback function for each module if any of its
211 * preferences have changed, and then clear the flag saying its
212 * preferences have changed, as the module has been notified of that
215 extern void prefs_apply_all(void);
219 typedef struct preference pref_t;
222 * Returns TRUE if the given protocol has registered preferences.
224 extern gboolean prefs_is_registered_protocol(char *name);
227 * Returns the module title of a registered protocol (or NULL if unknown).
229 extern const char *prefs_get_title_by_name(char *name);
232 * Register a preference with an unsigned integral value.
234 extern void prefs_register_uint_preference(module_t *module, const char *name,
235 const char *title, const char *description, guint base, guint *var);
238 * Register a preference with an Boolean value.
240 extern void prefs_register_bool_preference(module_t *module, const char *name,
241 const char *title, const char *description, gboolean *var);
244 * Register a preference with an enumerated value.
251 extern void prefs_register_enum_preference(module_t *module, const char *name,
252 const char *title, const char *description, gint *var,
253 const enum_val_t *enumvals, gboolean radio_buttons);
256 * Register a preference with a character-string value.
258 extern void prefs_register_string_preference(module_t *module, const char *name,
259 const char *title, const char *description, char **var);
262 * Register a preference that used to be supported but no longer is.
264 extern void prefs_register_obsolete_preference(module_t *module,
267 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
270 * Call a callback function, with a specified argument, for each preference
273 * If any of the callbacks return a non-zero value, stop and return that
274 * value, otherwise return 0.
276 extern guint prefs_pref_foreach(module_t *module, pref_cb callback,
280 * Register all non-dissector modules' preferences.
282 extern void prefs_register_modules(void);
284 /* Read the preferences file, fill in "prefs", and return a pointer to it.
286 If we got an error (other than "it doesn't exist") trying to read
287 the global preferences file, stuff the errno into "*gpf_errno_return"
288 on an open error and into "*gpf_read_errno_return" on a read error,
289 stuff a pointer to the path of the file into "*gpf_path_return", and
292 If we got an error (other than "it doesn't exist") trying to read
293 the user's preferences file, stuff the errno into "*pf_errno_return"
294 on an open error and into "*pf_read_errno_return" on a read error,
295 stuff a pointer to the path of the file into "*pf_path_return", and
297 extern e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
299 /* Write out "prefs" to the user's preferences file, and return 0.
301 If we got an error, stuff a pointer to the path of the preferences file
302 into "*pf_path_return", and return the errno. */
303 extern int write_prefs(char **);
305 /* Copy a set of preferences. */
306 extern void copy_prefs(e_prefs *dest, e_prefs *src);
308 /* Free a set of preferences. */
309 extern void free_prefs(e_prefs *pr);
312 * Given a string of the form "<pref name>:<pref value>", as might appear
313 * as an argument to a "-o" option, parse it and set the preference in
314 * question. Return an indication of whether it succeeded or failed
317 * XXX - should supply, for syntax errors, a detailed explanation of
320 #define PREFS_SET_OK 0 /* succeeded */
321 #define PREFS_SET_SYNTAX_ERR 1 /* syntax error in string */
322 #define PREFS_SET_NO_SUCH_PREF 2 /* no such preference */
323 #define PREFS_SET_OBSOLETE 3 /* preference used to exist but no longer does */
325 extern int prefs_set_pref(char *prefarg);