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