(Trivial) Fix spellling in a comment.
[metze/wireshark/wip.git] / epan / prefs-int.h
1 /* prefs-int.h
2  * Definitions for implementation of preference handling routines;
3  * used by "friends" of the preferences type.
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #ifndef __PREFS_INT_H__
27 #define __PREFS_INT_H__
28
29 #include <stdio.h>
30 #include "ws_symbol_export.h"
31 #include <epan/wmem/wmem.h>
32
33 /**
34  *@file
35  */
36
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
49                                  */
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 */
57 };
58
59 typedef struct {
60     module_t *module;
61     FILE     *pf;
62 } write_pref_arg_t;
63
64 /**
65  * Module used for protocol preferences.
66  * With MSVC and a libwireshark.dll, we need a special declaration.
67  */
68 WS_DLL_PUBLIC module_t *protocols_module;
69
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);
79
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;
90 };
91
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.
95  */
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;
110
111 typedef enum {
112         GUI_ALL,
113         GUI_GTK,
114         GUI_QT
115 } gui_type_t;
116
117 /** Struct to hold preference data */
118 struct preference {
119     const char *name;                /**< name of preference */
120     const char *title;               /**< title to use in GUI */
121     const char *description;         /**< human-readable description of preference */
122     int ordinal;                     /**< ordinal number of this preference */
123     pref_type_t type;                /**< type of that preference */
124     gui_type_t gui;                  /**< type of the GUI (QT, GTK or both) the preference is registered for */
125     union {                          /* The Qt preference code assumes that these will all be pointers (and unique) */
126         guint *uint;
127         gboolean *boolp;
128         gint *enump;
129         const char **string;
130         range_t **range;
131         struct epan_uat* uat;
132         color_t *colorp;
133         GList** list;
134     } varp;                          /**< pointer to variable storing the value */
135     union {
136         guint uint;
137         gboolean boolval;
138         gint enumval;
139         char *string;
140         range_t *range;
141         color_t color;
142         GList* list;
143     } stashed_val;                     /**< original value, when editing from the GUI */
144     union {
145         guint uint;
146         gboolean boolval;
147         gint enumval;
148         char *string;
149         range_t *range;
150         color_t color;
151         GList* list;
152     } default_val;                   /**< the default value of the preference */
153     union {
154       guint base;                    /**< input/output base, for PREF_UINT */
155       guint32 max_value;             /**< maximum value of a range */
156       struct {
157         const enum_val_t *enumvals;  /**< list of name & values */
158         gboolean radio_buttons;      /**< TRUE if it should be shown as
159                                           radio buttons rather than as an
160                                           option menu or combo box in
161                                           the preferences tab */
162       } enum_info;                   /**< for PREF_ENUM */
163     } info;                          /**< display/text file information */
164     struct pref_custom_cbs custom_cbs;   /**< for PREF_CUSTOM */
165     void    *control;                /**< handle for GUI control for this preference */
166 };
167
168 /* read_prefs_file: read in a generic config file and do a callback to */
169 /* pref_set_pair_fct() for every key/value pair found */
170 /**
171  * Given a string of the form "<pref name>:<pref value>", as might appear
172  * as an argument to a "-o" option, parse it and set the preference in
173  * question.
174  * @return an indication of whether it succeeded or failed
175  * in some fashion.
176  */
177 typedef prefs_set_pref_e (*pref_set_pair_cb) (gchar *key, const gchar *value, void *private_data, gboolean return_range_errors);
178
179 /** read the preferences file (or similiar) and call the callback
180  * function to set each key/value pair found
181  */
182 WS_DLL_PUBLIC
183 int
184 read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct, void *private_data);
185
186 #endif /* prefs-int.h */