We can't save "child_process" as a HANDLE on UNIX - save it as an "int",
[obnox/wireshark/wip.git] / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * $Id: prefs.h,v 1.55 2004/01/20 18:47:22 ulfl Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifndef __PREFS_H__
26 #define __PREFS_H__
27
28 #include <glib.h>
29
30 #include "color.h"
31
32 #define PR_DEST_CMD  0
33 #define PR_DEST_FILE 1
34
35 #define DEF_WIDTH 750
36 #define DEF_HEIGHT 550
37
38 #define MAX_VAL_LEN  1024
39
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
43 #else
44 #define PREFS_GUI_FONT_NAME gui_font_name2
45 #endif
46
47 /*
48  * Convert a string listing name resolution types to a bitmask of
49  * those types.
50  *
51  * Set "*name_resolve" to the bitmask, and return '\0', on success;
52  * return the bad character in the string on error.
53  */
54 char string_to_name_resolve(char *string, guint32 *name_resolve);
55
56 /*
57  * Modes for the starting directory in File Open dialogs.
58  */
59 #define FO_STYLE_LAST_OPENED    0       /* start in last directory we looked at */
60 #define FO_STYLE_SPECIFIED      1       /* start in specified directory */
61
62 /*
63  * Toolbar styles.
64  */
65 #define TB_STYLE_ICONS          0
66 #define TB_STYLE_TEXT           1
67 #define TB_STYLE_BOTH           2
68
69 typedef struct _e_prefs {
70   gint     pr_format;
71   gint     pr_dest;
72   gchar   *pr_file;
73   gchar   *pr_cmd;
74   GList   *col_list;
75   gint     num_cols;
76   color_t  st_client_fg, st_client_bg, st_server_fg, st_server_bg;
77   gboolean gui_scrollbar_on_right;
78   gboolean gui_plist_sel_browse;
79   gboolean gui_ptree_sel_browse;
80   gboolean gui_altern_colors;
81   gint     gui_ptree_line_style;
82   gint     gui_ptree_expander_style;
83   gboolean gui_hex_dump_highlight_style;
84   gint     gui_toolbar_main_style;
85   gchar   *gui_font_name1;
86   gchar   *gui_font_name2;
87   color_t  gui_marked_fg;
88   color_t  gui_marked_bg;
89   gboolean gui_geometry_save_position;
90   gboolean gui_geometry_save_size;
91   gint     gui_geometry_main_x;
92   gint     gui_geometry_main_y;
93   gint     gui_geometry_main_width;
94   gint     gui_geometry_main_height;
95   guint    gui_fileopen_style;
96   guint    gui_recent_files_count_max;
97   gchar    *gui_fileopen_dir;
98   gchar    *gui_fileopen_remembered_dir;
99   guint32  name_resolve;
100   gint     name_resolve_concurrency;
101   gchar   *capture_device;
102   gchar   *capture_devices_descr;
103   gchar   *capture_devices_hide;
104   gboolean capture_prom_mode;
105   gboolean capture_real_time;
106   gboolean capture_auto_scroll;
107 } e_prefs;
108
109 extern e_prefs prefs;
110
111 /*
112  * Routines to let modules that have preference settings register
113  * themselves by name, and to let them register preference settings
114  * by name.
115  */
116 struct pref_module;
117
118 typedef struct pref_module module_t;
119
120 /*
121  * Register a module that will have preferences.
122  * Specify the module under which to register it or NULL to register it
123  * at the top level, the name used for the module in the preferences file,
124  * the title used in the tab for it in a preferences dialog box, and a
125  * routine to call back when we apply the preferences.
126  *
127  * This should not be used for dissector preferences;
128  * "prefs_register_protocol()" should be used for that, so that the
129  * preferences go under the "Protocols" subtree, and so that the
130  * name is the protocol name specified at the "proto_register_protocol()"
131  * call so that the "Protocol Properties..." menu item works.
132  */
133 extern module_t *prefs_register_module(module_t *parent, const char *name,
134     const char *title, void (*apply_cb)(void));
135
136 /*
137  * Register a subtree that will have modules under it.
138  * Specify the module under which to register it or NULL to register it
139  * at the top level and the title used in the tab for it in a preferences
140  * dialog box.
141  */
142 extern module_t *prefs_register_subtree(module_t *parent, const char *title);
143
144 /*
145  * Register that a protocol has preferences.
146  */
147 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
148
149 /*
150  * Register that a protocol used to have preferences but no longer does,
151  * by creating an "obsolete" module for it.
152  */
153 extern module_t *prefs_register_protocol_obsolete(int id);
154
155 /*
156  * Callback function for module list scanners.
157  */
158 typedef void (*module_cb)(module_t *module, gpointer user_data);
159
160 /*
161  * Call a callback function, with a specified argument, for each module
162  * in a list of modules.  If the list is NULL, searches the top-level
163  * list in the display tree of modules.
164  *
165  * Ignores "obsolete" modules; their sole purpose is to allow old
166  * preferences for dissectors that no longer have preferences to be
167  * silently ignored in preference files.  Does not ignore subtrees,
168  * as this can be used when walking the display tree of modules.
169  */
170 extern void prefs_module_list_foreach(GList *module_list, module_cb callback,
171     gpointer user_data);
172
173 /*
174  * Call a callback function, with a specified argument, for each module
175  * in the list of all modules.  (This list does not include subtrees.)
176  *
177  * Ignores "obsolete" modules; their sole purpose is to allow old
178  * preferences for dissectors that no longer have preferences to be
179  * silently ignored in preference files.
180  */
181 extern void prefs_modules_foreach(module_cb callback, gpointer user_data);
182
183 /*
184  * Call the "apply" callback function for each module if any of its
185  * preferences have changed, and then clear the flag saying its
186  * preferences have changed, as the module has been notified of that
187  * fact.
188  */
189 extern void prefs_apply_all(void);
190
191 struct preference;
192
193 typedef struct preference pref_t;
194
195 /*
196  * Returns TRUE if the given protocol has registered preferences.
197  */
198 extern gboolean prefs_is_registered_protocol(char *name);
199
200 /*
201  * Returns the module title of a registered protocol (or NULL if unknown).
202  */
203 extern const char *prefs_get_title_by_name(char *name);
204
205 /*
206  * Register a preference with an unsigned integral value.
207  */
208 extern void prefs_register_uint_preference(module_t *module, const char *name,
209     const char *title, const char *description, guint base, guint *var);
210
211 /*
212  * Register a preference with an Boolean value.
213  */
214 extern void prefs_register_bool_preference(module_t *module, const char *name,
215     const char *title, const char *description, gboolean *var);
216
217 /*
218  * Register a preference with an enumerated value.
219  */
220 typedef struct {
221         char    *name;
222         gint    value;
223 } enum_val_t;
224
225 extern void prefs_register_enum_preference(module_t *module, const char *name,
226     const char *title, const char *description, gint *var,
227     const enum_val_t *enumvals, gboolean radio_buttons);
228
229 /*
230  * Register a preference with a character-string value.
231  */
232 extern void prefs_register_string_preference(module_t *module, const char *name,
233     const char *title, const char *description, char **var);
234
235 /*
236  * Register a preference that used to be supported but no longer is.
237  */
238 extern void prefs_register_obsolete_preference(module_t *module,
239     const char *name);
240
241 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
242
243 /*
244  * Call a callback function, with a specified argument, for each preference
245  * in a given module.
246  *
247  * If any of the callbacks return a non-zero value, stop and return that
248  * value, otherwise return 0.
249  */
250 extern guint prefs_pref_foreach(module_t *module, pref_cb callback,
251     gpointer user_data);
252
253 /*
254  * Register all non-dissector modules' preferences.
255  */
256 extern void prefs_register_modules(void);
257
258 /* Read the preferences file, fill in "prefs", and return a pointer to it.
259
260    If we got an error (other than "it doesn't exist") trying to read
261    the global preferences file, stuff the errno into "*gpf_errno_return"
262    on an open error and into "*gpf_read_errno_return" on a read error,
263    stuff a pointer to the path of the file into "*gpf_path_return", and
264    return NULL.
265
266    If we got an error (other than "it doesn't exist") trying to read
267    the user's preferences file, stuff the errno into "*pf_errno_return"
268    on an open error and into "*pf_read_errno_return" on a read error,
269    stuff a pointer to the path of the file into "*pf_path_return", and
270    return NULL. */
271 extern e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
272
273 /* Write out "prefs" to the user's preferences file, and return 0.
274
275    If we got an error, stuff a pointer to the path of the preferences file
276    into "*pf_path_return", and return the errno. */
277 extern int write_prefs(char **);
278
279 /* Copy a set of preferences. */
280 extern void copy_prefs(e_prefs *dest, e_prefs *src);
281
282 /* Free a set of preferences. */
283 extern void free_prefs(e_prefs *pr);
284
285 /*
286  * Given a string of the form "<pref name>:<pref value>", as might appear
287  * as an argument to a "-o" option, parse it and set the preference in
288  * question.  Return an indication of whether it succeeded or failed
289  * in some fashion.
290  *
291  * XXX - should supply, for syntax errors, a detailed explanation of
292  * the syntax error.
293  */
294 #define PREFS_SET_OK            0       /* succeeded */
295 #define PREFS_SET_SYNTAX_ERR    1       /* syntax error in string */
296 #define PREFS_SET_NO_SUCH_PREF  2       /* no such preference */
297 #define PREFS_SET_OBSOLETE      3       /* preference used to exist but no longer does */
298
299 extern int prefs_set_pref(char *prefarg);
300
301 #endif /* prefs.h */