hide implementation of module list
[metze/wireshark/wip.git] / epan / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #include <epan/range.h>
33
34 #define PR_DEST_CMD  0
35 #define PR_DEST_FILE 1
36
37 #define DEF_WIDTH 750
38 #define DEF_HEIGHT 550
39
40 #define MAX_VAL_LEN  1024
41
42 /* only GTK1 *or* GTK2 font_name should be used */
43 /* (we need to keep both in the preferences file but will only use the one suitable for the programs GTK version used) */
44 #if GTK_MAJOR_VERSION < 2
45 #define PREFS_GUI_FONT_NAME gui_font_name1
46 #else
47 #define PREFS_GUI_FONT_NAME gui_font_name2
48 #endif
49
50 /*
51  * Convert a string listing name resolution types to a bitmask of
52  * those types.
53  *
54  * Set "*name_resolve" to the bitmask, and return '\0', on success;
55  * return the bad character in the string on error.
56  */
57 char string_to_name_resolve(char *string, guint32 *name_resolve);
58
59 /*
60  * Modes for the starting directory in File Open dialogs.
61  */
62 #define FO_STYLE_LAST_OPENED    0       /* start in last directory we looked at */
63 #define FO_STYLE_SPECIFIED      1       /* start in specified directory */
64
65 /*
66  * Toolbar styles.
67  */
68 #define TB_STYLE_ICONS          0
69 #define TB_STYLE_TEXT           1
70 #define TB_STYLE_BOTH           2
71
72 /*
73  * Types of layout of summary/details/hex panes.
74  */
75 typedef enum {
76     layout_unused,  /* entry currently unused */
77     layout_type_5,
78     layout_type_2,
79     layout_type_1,
80     layout_type_4,
81     layout_type_3,
82     layout_type_6,
83     layout_type_max
84 } layout_type_e;
85
86 /*
87  * Types of pane.
88  */
89 typedef enum {
90     layout_pane_content_none,
91     layout_pane_content_plist,
92     layout_pane_content_pdetails,
93     layout_pane_content_pbytes
94 } layout_pane_content_e;
95
96 /*
97  * open console behaviour (win32 only)
98  */
99 typedef enum {
100     console_open_never,
101     console_open_auto,
102     console_open_always
103 } console_open_e;
104
105
106 typedef struct _e_prefs {
107   gint     pr_format;
108   gint     pr_dest;
109   gchar   *pr_file;
110   gchar   *pr_cmd;
111   GList   *col_list;
112   gint     num_cols;
113   color_t  st_client_fg, st_client_bg, st_server_fg, st_server_bg;
114   gboolean gui_scrollbar_on_right;
115   gboolean gui_plist_sel_browse;
116   gboolean gui_ptree_sel_browse;
117   gboolean gui_altern_colors;
118   gboolean filter_toolbar_show_in_statusbar;
119   gint     gui_ptree_line_style;
120   gint     gui_ptree_expander_style;
121   gboolean gui_hex_dump_highlight_style;
122   gint     gui_toolbar_main_style;
123   gchar   *gui_font_name1;
124   gchar   *gui_font_name2;
125   color_t  gui_marked_fg;
126   color_t  gui_marked_bg;
127   gchar   *gui_colorized_fg;
128   gchar   *gui_colorized_bg;
129   gboolean gui_geometry_save_position;
130   gboolean gui_geometry_save_size;
131   gboolean gui_geometry_save_maximized;
132   console_open_e gui_console_open;
133   guint    gui_recent_files_count_max;
134   guint    gui_fileopen_style;
135   gchar    *gui_fileopen_dir;
136   guint    gui_fileopen_preview;
137   gboolean gui_ask_unsaved;
138   gboolean gui_find_wrap;
139   gboolean gui_use_pref_save;
140   gchar   *gui_webbrowser;
141   gchar   *gui_window_title;
142   layout_type_e gui_layout_type;
143   layout_pane_content_e gui_layout_content_1;
144   layout_pane_content_e gui_layout_content_2;
145   layout_pane_content_e gui_layout_content_3;
146   gint     console_log_level;
147   guint32  name_resolve;
148   gint     name_resolve_concurrency;
149   gchar   *capture_device;
150   gchar   *capture_devices_descr;
151   gchar   *capture_devices_hide;
152   gboolean capture_prom_mode;
153   gboolean capture_real_time;
154   gboolean capture_auto_scroll;
155   gboolean capture_show_info;
156 } e_prefs;
157
158 WS_VAR_IMPORT e_prefs prefs;
159
160 /*
161  * Routines to let modules that have preference settings register
162  * themselves by name, and to let them register preference settings
163  * by name.
164  */
165 struct pref_module;
166
167 typedef struct pref_module module_t;
168
169 /*
170  * Register a module that will have preferences.
171  * Specify the module under which to register it or NULL to register it
172  * at the top level, the name used for the module in the preferences file,
173  * the title used in the tab for it in a preferences dialog box, and a
174  * routine to call back when we apply the preferences.
175  *
176  * This should not be used for dissector preferences;
177  * "prefs_register_protocol()" should be used for that, so that the
178  * preferences go under the "Protocols" subtree, and so that the
179  * name is the protocol name specified at the "proto_register_protocol()"
180  * call so that the "Protocol Properties..." menu item works.
181  */
182 extern module_t *prefs_register_module(module_t *parent, const char *name,
183     const char *title, const char *description, void (*apply_cb)(void));
184
185 /*
186  * Register a subtree that will have modules under it.
187  * Specify the module under which to register it or NULL to register it
188  * at the top level and the title used in the tab for it in a preferences
189  * dialog box.
190  */
191 extern module_t *prefs_register_subtree(module_t *parent, const char *title,
192     const char *description);
193
194 /*
195  * Register that a protocol has preferences.
196  */
197 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
198
199 /*
200  * Register that a protocol has preferences and group it under a single
201  * subtree 
202  */
203 #define PREFERENCE_GROUPING
204 extern module_t *prefs_register_protocol_subtree(const char *subtree, int id, 
205                                                  void (*apply_cb)(void));
206
207 /*
208  * Register that a protocol used to have preferences but no longer does,
209  * by creating an "obsolete" module for it.
210  */
211 extern module_t *prefs_register_protocol_obsolete(int id);
212
213 /*
214  * Callback function for module list scanners.
215  */
216 typedef guint (*module_cb)(module_t *module, gpointer user_data);
217
218 /*
219  * Returns TRUE if module has any submodules
220  */
221 extern gboolean prefs_module_has_submodules(module_t *module);
222
223 /*
224  * Call a callback function, with a specified argument, for each module
225  * in the list of all modules.  (This list does not include subtrees.)
226  *
227  * Ignores "obsolete" modules; their sole purpose is to allow old
228  * preferences for dissectors that no longer have preferences to be
229  * silently ignored in preference files.
230  */
231 extern guint prefs_modules_foreach(module_cb callback, gpointer user_data);
232
233 /*
234  * Call a callback function, with a specified argument, for each submodule
235  * of specified modules.  If the module is NULL, goes through the top-level
236  * list in the display tree of modules.
237  *
238  * Ignores "obsolete" modules; their sole purpose is to allow old
239  * preferences for dissectors that no longer have preferences to be
240  * silently ignored in preference files.  Does not ignore subtrees,
241  * as this can be used when walking the display tree of modules.
242  */
243 extern guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
244
245 /*
246  * Call the "apply" callback function for each module if any of its
247  * preferences have changed, and then clear the flag saying its
248  * preferences have changed, as the module has been notified of that
249  * fact.
250  */
251 extern void prefs_apply_all(void);
252
253 /*
254  * Call the "apply" callback function for a specific module if any of
255  * its preferences have changed, and then clear the flag saying its
256  * preferences have changed, as the module has been notified of that
257  * fact.
258  */
259 extern void prefs_apply(module_t *module);
260
261
262 struct preference;
263
264 typedef struct preference pref_t;
265
266 /*
267  * Returns TRUE if the given protocol has registered preferences.
268  */
269 extern gboolean prefs_is_registered_protocol(const char *name);
270
271 /*
272  * Returns the module title of a registered protocol (or NULL if unknown).
273  */
274 extern const char *prefs_get_title_by_name(const char *name);
275
276 /** Given a module name, return a pointer to its pref_module struct,
277  * or NULL if it's not found.
278  *
279  * @param name The preference module name.  Usually the same as the protocol
280  * name, e.g. "tcp".
281  * @return A pointer to the corresponding preference module, or NULL if it
282  * wasn't found.
283  */
284 extern module_t *prefs_find_module(const char *name);
285
286 /*
287  * Register a preference with an unsigned integral value.
288  */
289 extern void prefs_register_uint_preference(module_t *module, const char *name,
290     const char *title, const char *description, guint base, guint *var);
291
292 /*
293  * Register a preference with an Boolean value.
294  */
295 extern void prefs_register_bool_preference(module_t *module, const char *name,
296     const char *title, const char *description, gboolean *var);
297
298 /*
299  * Register a preference with an enumerated value.
300  */
301 typedef struct {
302         const char      *name;
303         const char      *description;
304         gint            value;
305 } enum_val_t;
306
307 extern void prefs_register_enum_preference(module_t *module, const char *name,
308     const char *title, const char *description, gint *var,
309     const enum_val_t *enumvals, gboolean radio_buttons);
310
311 /*
312  * Register a preference with a character-string value.
313  */
314 extern void prefs_register_string_preference(module_t *module, const char *name,
315     const char *title, const char *description, const char **var);
316
317 /*
318  * Register a preference with a ranged value.
319  */
320 extern void prefs_register_range_preference(module_t *module, const char *name,
321     const char *title, const char *description, range_t **var,
322     guint32 max_value);
323
324 /*
325  * Register a static text 'preference'. It can be used to add some info/explanation.
326  */
327 extern void prefs_register_static_text_preference(module_t *module, const char *name,
328     const char *title, const char *description);
329
330 /*
331  * Register a uat 'preference'. It adds a button that opens the uat's window in the
332  * preferences tab of the module.
333  */
334 extern void prefs_register_uat_preference(module_t *module,
335                                                                                   const char *name,
336                                                                                   const char* title,
337                                                                                   const char *description,
338                                                                                   void* uat);
339
340 /*
341  * Register a preference that used to be supported but no longer is.
342  */
343 extern void prefs_register_obsolete_preference(module_t *module,
344     const char *name);
345
346 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
347
348 /*
349  * Call a callback function, with a specified argument, for each preference
350  * in a given module.
351  *
352  * If any of the callbacks return a non-zero value, stop and return that
353  * value, otherwise return 0.
354  */
355 extern guint prefs_pref_foreach(module_t *module, pref_cb callback,
356     gpointer user_data);
357
358 /*
359  * Register all non-dissector modules' preferences.
360  */
361 extern void prefs_register_modules(void);
362
363 /* Read the preferences file, fill in "prefs", and return a pointer to it.
364
365    If we got an error (other than "it doesn't exist") trying to read
366    the global preferences file, stuff the errno into "*gpf_errno_return"
367    on an open error and into "*gpf_read_errno_return" on a read error,
368    stuff a pointer to the path of the file into "*gpf_path_return", and
369    return NULL.
370
371    If we got an error (other than "it doesn't exist") trying to read
372    the user's preferences file, stuff the errno into "*pf_errno_return"
373    on an open error and into "*pf_read_errno_return" on a read error,
374    stuff a pointer to the path of the file into "*pf_path_return", and
375    return NULL. */
376 extern e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
377
378 /* Write out "prefs" to the user's preferences file, and return 0.
379
380    If we got an error, stuff a pointer to the path of the preferences file
381    into "*pf_path_return", and return the errno. */
382 extern int write_prefs(char **);
383
384 /* Copy a set of preferences. */
385 extern void copy_prefs(e_prefs *dest, e_prefs *src);
386
387 /* Free a set of preferences. */
388 extern void free_prefs(e_prefs *pr);
389
390 /*
391  * Given a string of the form "<pref name>:<pref value>", as might appear
392  * as an argument to a "-o" option, parse it and set the preference in
393  * question.  Return an indication of whether it succeeded or failed
394  * in some fashion.
395  *
396  * XXX - should supply, for syntax errors, a detailed explanation of
397  * the syntax error.
398  */
399 typedef enum {
400     PREFS_SET_OK,               /* succeeded */
401     PREFS_SET_SYNTAX_ERR,       /* syntax error in string */
402     PREFS_SET_NO_SUCH_PREF,     /* no such preference */
403     PREFS_SET_OBSOLETE          /* preference used to exist but no longer does */
404 } prefs_set_pref_e;
405
406 extern prefs_set_pref_e prefs_set_pref(char *prefarg);
407
408 #endif /* prefs.h */