MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / prefs-int.h
blob7438bc30047fa54882eb4179a393663a09e556b7
1 /* prefs-int.h
2 * Definitions for implementation of preference handling routines;
3 * used by "friends" of the preferences type.
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #ifndef __PREFS_INT_H__
27 #define __PREFS_INT_H__
29 #include <stdio.h>
30 #include "ws_symbol_export.h"
31 #include <epan/wmem/wmem.h>
33 /**
34 *@file
37 struct pref_module {
38 const char *name; /**< name of module */
39 const char *title; /**< title of module (displayed in preferences list) */
40 const char *description; /**< Description of module (displayed in preferences notebook) */
41 void (*apply_cb)(void); /**< routine to call when preferences applied */
42 GList *prefs; /**< list of its preferences */
43 struct pref_module *parent; /**< parent module */
44 wmem_tree_t *submodules; /**< list of its submodules */
45 int numprefs; /**< number of non-obsolete preferences */
46 gboolean prefs_changed; /**< if TRUE, a preference has changed since we last checked */
47 gboolean obsolete; /**< if TRUE, this is a module that used to
48 * exist but no longer does
50 gboolean use_gui; /**< Determines whether or not the module will use the generic
51 * GUI interface/APIs with the preference value or if its own
52 * independent GUI will be provided. This allows all preferences
53 * to have a common API for reading/writing, but not require them to
54 * use simple GUI controls to change the options. In general, the "general"
55 * Wireshark preferences should have this set to FALSE, while the protocol
56 * modules will have this set to TRUE */
59 typedef struct {
60 module_t *module;
61 FILE *pf;
62 } write_pref_arg_t;
64 /**
65 * Module used for protocol preferences.
66 * With MSVC and a libwireshark.dll, we need a special declaration.
68 WS_DLL_PUBLIC module_t *protocols_module;
70 typedef void (*pref_custom_free_cb) (pref_t* pref);
71 typedef void (*pref_custom_reset_cb) (pref_t* pref);
72 typedef prefs_set_pref_e (*pref_custom_set_cb) (pref_t* pref, const gchar* value, gboolean* changed);
73 /* typedef void (*pref_custom_write_cb) (pref_t* pref, write_pref_arg_t* arg); Deprecated. */
74 /* pref_custom_type_name_cb should return NULL for internal / hidden preferences. */
75 typedef const char * (*pref_custom_type_name_cb) (void);
76 typedef char * (*pref_custom_type_description_cb) (void);
77 typedef gboolean (*pref_custom_is_default_cb) (pref_t* pref);
78 typedef char * (*pref_custom_to_str_cb) (pref_t* pref, gboolean default_val);
80 /** Structure to hold callbacks for PREF_CUSTOM type */
81 struct pref_custom_cbs {
82 pref_custom_free_cb free_cb;
83 pref_custom_reset_cb reset_cb;
84 pref_custom_set_cb set_cb;
85 /* pref_custom_write_cb write_cb; Deprecated. */
86 pref_custom_type_name_cb type_name_cb;
87 pref_custom_type_description_cb type_description_cb;
88 pref_custom_is_default_cb is_default_cb;
89 pref_custom_to_str_cb to_str_cb;
92 /**
93 * PREF_OBSOLETE is used for preferences that a module used to support
94 * but no longer supports; we give different error messages for them.
96 typedef enum {
97 PREF_UINT,
98 PREF_BOOL,
99 PREF_ENUM,
100 PREF_STRING,
101 PREF_RANGE,
102 PREF_STATIC_TEXT,
103 PREF_UAT,
104 PREF_FILENAME,
105 PREF_COLOR, /* XXX - These are only supported for "internal" (non-protocol) */
106 PREF_CUSTOM, /* use and not as a generic protocol preference */
107 PREF_OBSOLETE,
108 PREF_DIRNAME
109 } pref_type_t;
111 /** Struct to hold preference data */
112 struct preference {
113 const char *name; /**< name of preference */
114 const char *title; /**< title to use in GUI */
115 const char *description; /**< human-readable description of preference */
116 int ordinal; /**< ordinal number of this preference */
117 pref_type_t type; /**< type of that preference */
118 union { /* The Qt preference code assumes that these will all be pointers (and unique) */
119 guint *uint;
120 gboolean *boolp;
121 gint *enump;
122 const char **string;
123 range_t **range;
124 uat_t* uat;
125 color_t *colorp;
126 GList** list;
127 } varp; /**< pointer to variable storing the value */
128 union {
129 guint uint;
130 gboolean boolval;
131 gint enumval;
132 char *string;
133 range_t *range;
134 color_t color;
135 GList* list;
136 } stashed_val; /**< original value, when editing from the GUI */
137 union {
138 guint uint;
139 gboolean boolval;
140 gint enumval;
141 char *string;
142 range_t *range;
143 color_t color;
144 GList* list;
145 } default_val; /**< the default value of the preference */
146 union {
147 guint base; /**< input/output base, for PREF_UINT */
148 guint32 max_value; /**< maximum value of a range */
149 struct {
150 const enum_val_t *enumvals; /**< list of name & values */
151 gboolean radio_buttons; /**< TRUE if it should be shown as
152 radio buttons rather than as an
153 option menu or combo box in
154 the preferences tab */
155 } enum_info; /**< for PREF_ENUM */
156 } info; /**< display/text file information */
157 struct pref_custom_cbs custom_cbs; /**< for PREF_CUSTOM */
158 void *control; /**< handle for GUI control for this preference */
161 /* read_prefs_file: read in a generic config file and do a callback to */
162 /* pref_set_pair_fct() for every key/value pair found */
164 * Given a string of the form "<pref name>:<pref value>", as might appear
165 * as an argument to a "-o" option, parse it and set the preference in
166 * question.
167 * @return an indication of whether it succeeded or failed
168 * in some fashion.
170 typedef prefs_set_pref_e (*pref_set_pair_cb) (gchar *key, const gchar *value, void *private_data, gboolean return_range_errors);
172 /** read the preferences file (or similiar) and call the callback
173 * function to set each key/value pair found
175 WS_DLL_PUBLIC
177 read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct, void *private_data);
179 #endif /* prefs-int.h */