Most developers have only 10 fingers, not 16. :-)
[obnox/wireshark/wip.git] / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * $Id$
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 /*
70  * Types of layout of summary/details/hex panes.
71  */
72 typedef enum {
73     layout_unused,  /* entry currently unused */
74     layout_type_5,
75     layout_type_2,
76     layout_type_1,
77     layout_type_4,
78     layout_type_3,
79     layout_type_6,
80     layout_type_max
81 } layout_type_e;
82
83 /*
84  * Types of pane.
85  */
86 typedef enum {
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;
92
93 /*
94  * open console behaviour (win32 only)
95  */
96 typedef enum {
97     console_open_never,
98     console_open_auto,
99     console_open_always
100 } console_open_e;
101
102
103 typedef struct _e_prefs {
104   gint     pr_format;
105   gint     pr_dest;
106   gchar   *pr_file;
107   gchar   *pr_cmd;
108   GList   *col_list;
109   gint     num_cols;
110   color_t  st_client_fg, st_client_bg, st_server_fg, st_server_bg;
111   gboolean gui_scrollbar_on_right;
112   gboolean gui_plist_sel_browse;
113   gboolean gui_ptree_sel_browse;
114   gboolean gui_altern_colors;
115   gboolean filter_toolbar_show_in_statusbar;
116   gint     gui_ptree_line_style;
117   gint     gui_ptree_expander_style;
118   gboolean gui_hex_dump_highlight_style;
119   gint     gui_toolbar_main_style;
120   gchar   *gui_font_name1;
121   gchar   *gui_font_name2;
122   color_t  gui_marked_fg;
123   color_t  gui_marked_bg;
124   gboolean gui_geometry_save_position;
125   gboolean gui_geometry_save_size;
126   gboolean gui_geometry_save_maximized;
127   console_open_e gui_console_open;
128   guint    gui_fileopen_style;
129   guint    gui_recent_files_count_max;
130   gchar    *gui_fileopen_dir;
131   gboolean gui_ask_unsaved;
132   gchar   *gui_webbrowser;
133   layout_type_e gui_layout_type;
134   layout_pane_content_e gui_layout_content_1;
135   layout_pane_content_e gui_layout_content_2;
136   layout_pane_content_e gui_layout_content_3;
137   guint32  name_resolve;
138   gint     name_resolve_concurrency;
139   gchar   *capture_device;
140   gchar   *capture_devices_descr;
141   gchar   *capture_devices_hide;
142   gboolean capture_prom_mode;
143   gboolean capture_real_time;
144   gboolean capture_auto_scroll;
145   gboolean capture_show_info;
146 } e_prefs;
147
148 ETH_VAR_IMPORT e_prefs prefs;
149
150 /*
151  * Routines to let modules that have preference settings register
152  * themselves by name, and to let them register preference settings
153  * by name.
154  */
155 struct pref_module;
156
157 typedef struct pref_module module_t;
158
159 /*
160  * Register a module that will have preferences.
161  * Specify the module under which to register it or NULL to register it
162  * at the top level, the name used for the module in the preferences file,
163  * the title used in the tab for it in a preferences dialog box, and a
164  * routine to call back when we apply the preferences.
165  *
166  * This should not be used for dissector preferences;
167  * "prefs_register_protocol()" should be used for that, so that the
168  * preferences go under the "Protocols" subtree, and so that the
169  * name is the protocol name specified at the "proto_register_protocol()"
170  * call so that the "Protocol Properties..." menu item works.
171  */
172 extern module_t *prefs_register_module(module_t *parent, const char *name,
173     const char *title, void (*apply_cb)(void));
174
175 /*
176  * Register a subtree that will have modules under it.
177  * Specify the module under which to register it or NULL to register it
178  * at the top level and the title used in the tab for it in a preferences
179  * dialog box.
180  */
181 extern module_t *prefs_register_subtree(module_t *parent, const char *title);
182
183 /*
184  * Register that a protocol has preferences.
185  */
186 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
187
188 /*
189  * Register that a protocol used to have preferences but no longer does,
190  * by creating an "obsolete" module for it.
191  */
192 extern module_t *prefs_register_protocol_obsolete(int id);
193
194 /*
195  * Callback function for module list scanners.
196  */
197 typedef void (*module_cb)(module_t *module, gpointer user_data);
198
199 /*
200  * Call a callback function, with a specified argument, for each module
201  * in a list of modules.  If the list is NULL, searches the top-level
202  * list in the display tree of modules.
203  *
204  * Ignores "obsolete" modules; their sole purpose is to allow old
205  * preferences for dissectors that no longer have preferences to be
206  * silently ignored in preference files.  Does not ignore subtrees,
207  * as this can be used when walking the display tree of modules.
208  */
209 extern void prefs_module_list_foreach(GList *module_list, module_cb callback,
210     gpointer user_data);
211
212 /*
213  * Call a callback function, with a specified argument, for each module
214  * in the list of all modules.  (This list does not include subtrees.)
215  *
216  * Ignores "obsolete" modules; their sole purpose is to allow old
217  * preferences for dissectors that no longer have preferences to be
218  * silently ignored in preference files.
219  */
220 extern void prefs_modules_foreach(module_cb callback, gpointer user_data);
221
222 /*
223  * Call the "apply" callback function for each module if any of its
224  * preferences have changed, and then clear the flag saying its
225  * preferences have changed, as the module has been notified of that
226  * fact.
227  */
228 extern void prefs_apply_all(void);
229
230 struct preference;
231
232 typedef struct preference pref_t;
233
234 /*
235  * Returns TRUE if the given protocol has registered preferences.
236  */
237 extern gboolean prefs_is_registered_protocol(char *name);
238
239 /*
240  * Returns the module title of a registered protocol (or NULL if unknown).
241  */
242 extern const char *prefs_get_title_by_name(char *name);
243
244 /*
245  * Register a preference with an unsigned integral value.
246  */
247 extern void prefs_register_uint_preference(module_t *module, const char *name,
248     const char *title, const char *description, guint base, guint *var);
249
250 /*
251  * Register a preference with an Boolean value.
252  */
253 extern void prefs_register_bool_preference(module_t *module, const char *name,
254     const char *title, const char *description, gboolean *var);
255
256 /*
257  * Register a preference with an enumerated value.
258  */
259 typedef struct {
260         char    *name;
261         char    *description;
262         gint    value;
263 } enum_val_t;
264
265 extern void prefs_register_enum_preference(module_t *module, const char *name,
266     const char *title, const char *description, gint *var,
267     const enum_val_t *enumvals, gboolean radio_buttons);
268
269 /*
270  * Register a preference with a character-string value.
271  */
272 extern void prefs_register_string_preference(module_t *module, const char *name,
273     const char *title, const char *description, char **var);
274
275 /*
276  * Register a preference that used to be supported but no longer is.
277  */
278 extern void prefs_register_obsolete_preference(module_t *module,
279     const char *name);
280
281 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
282
283 /*
284  * Call a callback function, with a specified argument, for each preference
285  * in a given module.
286  *
287  * If any of the callbacks return a non-zero value, stop and return that
288  * value, otherwise return 0.
289  */
290 extern guint prefs_pref_foreach(module_t *module, pref_cb callback,
291     gpointer user_data);
292
293 /*
294  * Register all non-dissector modules' preferences.
295  */
296 extern void prefs_register_modules(void);
297
298 /* Read the preferences file, fill in "prefs", and return a pointer to it.
299
300    If we got an error (other than "it doesn't exist") trying to read
301    the global preferences file, stuff the errno into "*gpf_errno_return"
302    on an open error and into "*gpf_read_errno_return" on a read error,
303    stuff a pointer to the path of the file into "*gpf_path_return", and
304    return NULL.
305
306    If we got an error (other than "it doesn't exist") trying to read
307    the user's preferences file, stuff the errno into "*pf_errno_return"
308    on an open error and into "*pf_read_errno_return" on a read error,
309    stuff a pointer to the path of the file into "*pf_path_return", and
310    return NULL. */
311 extern e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
312
313 /* Write out "prefs" to the user's preferences file, and return 0.
314
315    If we got an error, stuff a pointer to the path of the preferences file
316    into "*pf_path_return", and return the errno. */
317 extern int write_prefs(char **);
318
319 /* Copy a set of preferences. */
320 extern void copy_prefs(e_prefs *dest, e_prefs *src);
321
322 /* Free a set of preferences. */
323 extern void free_prefs(e_prefs *pr);
324
325 /*
326  * Given a string of the form "<pref name>:<pref value>", as might appear
327  * as an argument to a "-o" option, parse it and set the preference in
328  * question.  Return an indication of whether it succeeded or failed
329  * in some fashion.
330  *
331  * XXX - should supply, for syntax errors, a detailed explanation of
332  * the syntax error.
333  */
334 #define PREFS_SET_OK            0       /* succeeded */
335 #define PREFS_SET_SYNTAX_ERR    1       /* syntax error in string */
336 #define PREFS_SET_NO_SUCH_PREF  2       /* no such preference */
337 #define PREFS_SET_OBSOLETE      3       /* preference used to exist but no longer does */
338
339 extern int prefs_set_pref(char *prefarg);
340
341 #endif /* prefs.h */