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