Clear the Info column before fetching anything from the packet, so that
[obnox/wireshark/wip.git] / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * $Id: prefs.h,v 1.27 2001/01/03 07:53:44 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef __PREFS_H__
27 #define __PREFS_H__
28
29 #include <glib.h>
30
31 #include "color.h"
32
33 #define PR_DEST_CMD  0
34 #define PR_DEST_FILE 1
35
36 typedef struct _e_prefs {
37   gint     pr_format;
38   gint     pr_dest;
39   gchar   *pr_file;
40   gchar   *pr_cmd;
41   GList   *col_list;
42   gint     num_cols;
43   color_t  st_client_fg, st_client_bg, st_server_fg, st_server_bg;
44   gboolean gui_scrollbar_on_right;
45   gboolean gui_plist_sel_browse;
46   gboolean gui_ptree_sel_browse;
47   gint     gui_ptree_line_style;
48   gint     gui_ptree_expander_style;
49   gboolean gui_hex_dump_highlight_style;
50   gchar   *gui_font_name;
51   color_t  gui_marked_fg;
52   color_t  gui_marked_bg;
53 } e_prefs;
54
55 extern e_prefs prefs;
56
57 /*
58  * Routines to let modules that have preference settings register
59  * themselves by name, and to let them register preference settings
60  * by name.
61  */
62 struct pref_module;
63
64 typedef struct pref_module module_t;
65
66 /*
67  * Register a module that will have preferences.
68  * Specify the name used for the module in the preferences file, the
69  * title used in the tab for it in a preferences dialog box, and a
70  * routine to call back when we apply the preferences.
71  * Note:
72  * In case of dissectors, the specified name should be the protocol
73  * name specified at the proto_register_protocol() call in order to
74  * make the "Protocol Properties..." menu item work.
75  */
76 module_t *prefs_register_module(const char *name, const char *title,
77     void (*apply_cb)(void));
78
79 typedef void (*module_cb)(module_t *module, gpointer user_data);
80
81 /*
82  * Register that a protocol has preferences.
83  */
84 module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
85
86 /*
87  * Call a callback function, with a specified argument, for each module.
88  */
89 void prefs_module_foreach(module_cb callback, gpointer user_data);
90
91 /*
92  * Call the "apply" callback function for each module if any of its
93  * preferences have changed, and then clear the flag saying its
94  * preferences have changed, as the module has been notified of that
95  * fact.
96  */
97 void prefs_apply_all(void);
98
99 struct preference;
100
101 typedef struct preference pref_t;
102
103 /*
104  * Returns TRUE if the given protocol has registered preferences
105  */
106 gboolean prefs_is_registered_protocol(char *name);
107
108 /*
109  * Returns the module title of a registered protocol (or NULL if unknown)
110  */
111 const char *prefs_get_title_by_name(char *name);
112
113 /*
114  * Register a preference with an unsigned integral value.
115  */
116 void prefs_register_uint_preference(module_t *module, const char *name,
117     const char *title, const char *description, guint base, guint *var);
118
119 /*
120  * Register a preference with an Boolean value.
121  */
122 void prefs_register_bool_preference(module_t *module, const char *name,
123     const char *title, const char *description, gboolean *var);
124
125 /*
126  * Register a preference with an enumerated value.
127  */
128 typedef struct {
129         char    *name;
130         gint    value;
131 } enum_val_t;
132
133 void prefs_register_enum_preference(module_t *module, const char *name,
134     const char *title, const char *description, gint *var,
135     const enum_val_t *enumvals, gboolean radio_buttons);
136
137 /*
138  * Register a preference with a character-string value.
139  */
140 void prefs_register_string_preference(module_t *module, const char *name,
141     const char *title, const char *description, char **var);
142
143 typedef void (*pref_cb)(pref_t *pref, gpointer user_data);
144
145 /*
146  * Call a callback function, with a specified argument, for each preference
147  * in a given module.
148  */
149 void prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data);
150
151 /*
152  * Register all non-dissector modules' preferences.
153  */
154 void prefs_register_modules(void);
155
156 /* Read the preferences file, fill in "prefs", and return a pointer to it.
157
158    If we got an error (other than "it doesn't exist") trying to read
159    the global preferences file, stuff the errno into "*gpf_errno_return"
160    and a pointer to the path of the file into "*gpf_path_return", and
161    return NULL.
162
163    If we got an error (other than "it doesn't exist") trying to read
164    the user's preferences file, stuff the errno into "*pf_errno_return"
165    and a pointer to the path of the file into "*pf_path_return", and
166    return NULL. */
167 e_prefs *read_prefs(int *, char **, int *, char **);
168
169 /* Write out "prefs" to the user's preferences file, and return 0.
170
171    If we got an error, stuff a pointer to the path of the preferences file
172    into "*pf_path_return", and return the errno. */
173 int write_prefs(char **);
174
175 /* Copy a set of preferences. */
176 void copy_prefs(e_prefs *dest, e_prefs *src);
177
178 /* Free a set of preferences. */
179 void free_prefs(e_prefs *pr);
180
181 /*
182  * Given a string of the form "<pref name>:<pref value>", as might appear
183  * as an argument to a "-o" option, parse it and set the preference in
184  * question.  Return an indication of whether it succeeded or failed
185  * in some fashion.
186  */
187 #define PREFS_SET_OK            0       /* succeeded */
188 #define PREFS_SET_SYNTAX_ERR    1       /* syntax error in string */
189 #define PREFS_SET_NO_SUCH_PREF  2       /* no such preference */
190
191 int prefs_set_pref(char *prefarg);
192
193 #endif /* prefs.h */