2 * Definitions for implementation of preference handling routines;
3 * used by "friends" of the preferences type.
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #ifndef __PREFS_INT_H__
25 #define __PREFS_INT_H__
29 #endif /* __cplusplus */
32 #include "ws_symbol_export.h"
33 #include <epan/wmem/wmem.h>
40 const char *name; /**< name of module */
41 const char *title; /**< title of module (displayed in preferences list) */
42 const char *description; /**< Description of module (displayed in preferences notebook) */
43 void (*apply_cb)(void); /**< routine to call when preferences applied */
44 GList *prefs; /**< list of its preferences */
45 struct pref_module *parent; /**< parent module */
46 wmem_tree_t *submodules; /**< list of its submodules */
47 int numprefs; /**< number of non-obsolete preferences */
48 gboolean prefs_changed; /**< if TRUE, a preference has changed since we last checked */
49 gboolean obsolete; /**< if TRUE, this is a module that used to
50 * exist but no longer does
52 gboolean use_gui; /**< Determines whether or not the module will use the generic
53 * GUI interface/APIs with the preference value or if its own
54 * independent GUI will be provided. This allows all preferences
55 * to have a common API for reading/writing, but not require them to
56 * use simple GUI controls to change the options. In general, the "general"
57 * Wireshark preferences should have this set to FALSE, while the protocol
58 * modules will have this set to TRUE */
67 * Module used for protocol preferences.
68 * With MSVC and a libwireshark.dll, we need a special declaration.
70 WS_DLL_PUBLIC module_t *protocols_module;
72 typedef void (*pref_custom_free_cb) (pref_t* pref);
73 typedef void (*pref_custom_reset_cb) (pref_t* pref);
74 typedef prefs_set_pref_e (*pref_custom_set_cb) (pref_t* pref, const gchar* value, gboolean* changed);
75 /* typedef void (*pref_custom_write_cb) (pref_t* pref, write_pref_arg_t* arg); Deprecated. */
76 /* pref_custom_type_name_cb should return NULL for internal / hidden preferences. */
77 typedef const char * (*pref_custom_type_name_cb) (void);
78 typedef char * (*pref_custom_type_description_cb) (void);
79 typedef gboolean (*pref_custom_is_default_cb) (pref_t* pref);
80 typedef char * (*pref_custom_to_str_cb) (pref_t* pref, gboolean default_val);
82 /** Structure to hold callbacks for PREF_CUSTOM type */
83 struct pref_custom_cbs {
84 pref_custom_free_cb free_cb;
85 pref_custom_reset_cb reset_cb;
86 pref_custom_set_cb set_cb;
87 /* pref_custom_write_cb write_cb; Deprecated. */
88 pref_custom_type_name_cb type_name_cb;
89 pref_custom_type_description_cb type_description_cb;
90 pref_custom_is_default_cb is_default_cb;
91 pref_custom_to_str_cb to_str_cb;
95 * PREF_OBSOLETE is used for preferences that a module used to support
96 * but no longer supports; we give different error messages for them.
98 #define PREF_UINT (1u << 0)
99 #define PREF_BOOL (1u << 1)
100 #define PREF_ENUM (1u << 2)
101 #define PREF_STRING (1u << 3)
102 #define PREF_RANGE (1u << 4)
103 #define PREF_STATIC_TEXT (1u << 5)
104 #define PREF_UAT (1u << 6)
105 #define PREF_FILENAME (1u << 7)
106 #define PREF_COLOR (1u << 8) /* XXX - These are only supported for "internal" (non-protocol) */
107 #define PREF_CUSTOM (1u << 9) /* use and not as a generic protocol preference */
108 #define PREF_OBSOLETE (1u << 10)
109 #define PREF_DIRNAME (1u << 11)
110 #define PREF_DECODE_AS_UINT (1u << 12) /* XXX - These are only supported for "internal" (non-protocol) */
111 #define PREF_DECODE_AS_RANGE (1u << 13) /* use and not as a generic protocol preference */
119 /** Struct to hold preference data */
121 const char *name; /**< name of preference */
122 const char *title; /**< title to use in GUI */
123 const char *description; /**< human-readable description of preference */
124 int ordinal; /**< ordinal number of this preference */
125 int type; /**< type of that preference */
126 gui_type_t gui; /**< type of the GUI (QT, GTK or both) the preference is registered for */
127 union { /* The Qt preference code assumes that these will all be pointers (and unique) */
133 struct epan_uat* uat;
136 } varp; /**< pointer to variable storing the value */
145 } stashed_val; /**< original value, when editing from the GUI */
154 } default_val; /**< the default value of the preference */
156 guint base; /**< input/output base, for PREF_UINT */
157 guint32 max_value; /**< maximum value of a range */
159 const enum_val_t *enumvals; /**< list of name & values */
160 gboolean radio_buttons; /**< TRUE if it should be shown as
161 radio buttons rather than as an
162 option menu or combo box in
163 the preferences tab */
164 } enum_info; /**< for PREF_ENUM */
165 } info; /**< display/text file information */
166 struct pref_custom_cbs custom_cbs; /**< for PREF_CUSTOM */
167 void *control; /**< handle for GUI control for this preference. GTK+ only? */
170 /* read_prefs_file: read in a generic config file and do a callback to */
171 /* pref_set_pair_fct() for every key/value pair found */
173 * Given a string of the form "<pref name>:<pref value>", as might appear
174 * as an argument to a "-o" option, parse it and set the preference in
176 * @return an indication of whether it succeeded or failed
179 typedef prefs_set_pref_e (*pref_set_pair_cb) (gchar *key, const gchar *value, void *private_data, gboolean return_range_errors);
181 /** Set the value of a string-like preference. */
184 prefs_set_string_like_value(pref_t *pref, const gchar *value, gboolean *changed);
186 /** Set the value of a range preference. Return FALSE on error, TRUE otherwise. */
189 prefs_set_range_value(pref_t *pref, const gchar *value, gboolean *changed);
193 prefs_set_stashed_range_value(pref_t *pref, const gchar *value);
197 prefs_set_stashed_range(pref_t *pref, range_t *value);
201 prefs_get_stashed_range(pref_t *pref);
203 /** Add a range value of a range preference. */
206 prefs_range_add_value(pref_t *pref, guint32 val);
208 /** Remove a range value of a range preference. */
211 prefs_range_remove_value(pref_t *pref, guint32 val);
213 /** Set the value of an enum preference. */
216 prefs_set_enum_value(pref_t *pref, const gchar *value, gboolean *changed);
218 /** read the preferences file (or similar) and call the callback
219 * function to set each key/value pair found
223 read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct, void *private_data);
227 prefs_pref_is_default(pref_t *pref);
229 /** "Stash" a preference.
230 * Copy a preference to its stashed value. Can be called from prefs_pref_foreach().
232 * @param pref A preference.
233 * @param unused unused
236 guint pref_stash(pref_t *pref, gpointer unused _U_);
238 typedef struct pref_unstash_data
240 /* Used to set prefs_changed member to TRUE if the preference
241 differs from its stashed values. Also used by "decode as" types
242 to look up dissector short name */
244 /* Qt uses stashed values to then "applies" them
245 during unstash. Use this flag for that behavior */
246 gboolean handle_decode_as;
247 } pref_unstash_data_t;
249 /** "Unstash" a preference.
250 * Set a preference to its stashed value. Can be called from prefs_pref_foreach().
252 * @param pref A preference.
253 * @param unstash_data_p A pointer to a pref_unstash_data_t structure.
255 * @return Always returns 0.
258 guint pref_unstash(pref_t *pref, gpointer unstash_data_p);
260 /** Clean up a stashed preference.
261 * Can be called from prefs_pref_foreach().
263 * @param pref A preference.
264 * @param unused unused
266 * @return Always returns 0.
269 guint pref_clean_stash(pref_t *pref, gpointer unused _U_);
271 /** Set a stashed preference to its default value.
273 *@param pref A preference.
276 void reset_stashed_pref(pref_t *pref);
278 /** Convert a string list preference to a preference string.
280 * Given a GList of gchar pointers, create a quoted, comma-separated
281 * string. Should be used with prefs_get_string_list() and
282 * prefs_clear_string_list().
284 * @param sl String list.
285 * @return Quoted, joined, and wrapped string. May be empty.
289 join_string_list(GList *sl);
293 #endif /* __cplusplus */
295 #endif /* prefs-int.h */