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