2 * @file prefs.h Prefs API
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #ifndef _PURPLE_PREFS_H_
28 #define _PURPLE_PREFS_H_
33 * Preference data types.
35 typedef enum _PurplePrefType
37 PURPLE_PREF_NONE, /**< No type. */
38 PURPLE_PREF_BOOLEAN, /**< Boolean. */
39 PURPLE_PREF_INT, /**< Integer. */
40 PURPLE_PREF_STRING, /**< String. */
41 PURPLE_PREF_STRING_LIST, /**< List of strings. */
42 PURPLE_PREF_PATH, /**< Path. */
43 PURPLE_PREF_PATH_LIST /**< List of paths. */
48 * The type of callbacks for preference changes.
50 * @param name the name of the preference which has changed.
51 * @param type the type of the preferenced named @a name
52 * @param val the new value of the preferencs; should be cast to the correct
53 * type. For instance, to recover the value of a #PURPLE_PREF_INT
54 * preference, use <tt>GPOINTER_TO_INT(val)</tt>. Alternatively,
55 * just call purple_prefs_get_int(), purple_prefs_get_string_list()
57 * @param data Arbitrary data specified when the callback was connected with
58 * purple_prefs_connect_callback().
60 * @see purple_prefs_connect_callback()
62 typedef void (*PurplePrefCallback) (const char *name, PurplePrefType type,
63 gconstpointer val, gpointer data);
69 /**************************************************************************/
71 Preferences are named according to a directory-like structure.
72 Example: "/plugins/core/potato/is_from_idaho" (probably a boolean) */
73 /**************************************************************************/
77 * Returns the prefs subsystem handle.
79 * @return The prefs subsystem handle.
81 void *purple_prefs_get_handle(void);
84 * Initialize core prefs
86 void purple_prefs_init(void);
89 * Uninitializes the prefs subsystem.
91 void purple_prefs_uninit(void);
94 * Add a new typeless pref.
96 * @param name The name of the pref
98 void purple_prefs_add_none(const char *name);
101 * Add a new boolean pref.
103 * @param name The name of the pref
104 * @param value The initial value to set
106 void purple_prefs_add_bool(const char *name, gboolean value);
109 * Add a new integer pref.
111 * @param name The name of the pref
112 * @param value The initial value to set
114 void purple_prefs_add_int(const char *name, int value);
117 * Add a new string pref.
119 * @param name The name of the pref
120 * @param value The initial value to set
122 void purple_prefs_add_string(const char *name, const char *value);
125 * Add a new string list pref.
127 * @param name The name of the pref
128 * @param value The initial value to set
129 * @note This function takes a copy of the strings in the value list. The list
130 * itself and original copies of the strings are up to the caller to
133 void purple_prefs_add_string_list(const char *name, GList *value);
136 * Add a new path pref.
138 * @param name The name of the pref
139 * @param value The initial value to set
141 void purple_prefs_add_path(const char *name, const char *value);
144 * Add a new path list pref.
146 * @param name The name of the pref
147 * @param value The initial value to set
148 * @note This function takes a copy of the strings in the value list. The list
149 * itself and original copies of the strings are up to the caller to
152 void purple_prefs_add_path_list(const char *name, GList *value);
158 * @param name The name of the pref
160 void purple_prefs_remove(const char *name);
165 * @param oldname The old name of the pref
166 * @param newname The new name for the pref
168 void purple_prefs_rename(const char *oldname, const char *newname);
171 * Rename a boolean pref, toggling it's value
173 * @param oldname The old name of the pref
174 * @param newname The new name for the pref
176 void purple_prefs_rename_boolean_toggle(const char *oldname, const char *newname);
181 void purple_prefs_destroy(void);
186 * @param name The name of the pref
187 * @param value The value to set
189 void purple_prefs_set_generic(const char *name, gpointer value);
192 * Set boolean pref value
194 * @param name The name of the pref
195 * @param value The value to set
197 void purple_prefs_set_bool(const char *name, gboolean value);
200 * Set integer pref value
202 * @param name The name of the pref
203 * @param value The value to set
205 void purple_prefs_set_int(const char *name, int value);
208 * Set string pref value
210 * @param name The name of the pref
211 * @param value The value to set
213 void purple_prefs_set_string(const char *name, const char *value);
216 * Set string list pref value
218 * @param name The name of the pref
219 * @param value The value to set
221 void purple_prefs_set_string_list(const char *name, GList *value);
224 * Set path pref value
226 * @param name The name of the pref
227 * @param value The value to set
229 void purple_prefs_set_path(const char *name, const char *value);
232 * Set path list pref value
234 * @param name The name of the pref
235 * @param value The value to set
237 void purple_prefs_set_path_list(const char *name, GList *value);
241 * Check if a pref exists
243 * @param name The name of the pref
244 * @return TRUE if the pref exists. Otherwise FALSE.
246 gboolean purple_prefs_exists(const char *name);
251 * @param name The name of the pref
252 * @return The type of the pref
254 PurplePrefType purple_prefs_get_type(const char *name);
257 * Get boolean pref value
259 * @param name The name of the pref
260 * @return The value of the pref
262 gboolean purple_prefs_get_bool(const char *name);
265 * Get integer pref value
267 * @param name The name of the pref
268 * @return The value of the pref
270 int purple_prefs_get_int(const char *name);
273 * Get string pref value
275 * @param name The name of the pref
276 * @return The value of the pref
278 const char *purple_prefs_get_string(const char *name);
281 * Get string list pref value
283 * @param name The name of the pref
284 * @return The value of the pref
286 GList *purple_prefs_get_string_list(const char *name);
289 * Get path pref value
291 * @param name The name of the pref
292 * @return The value of the pref
294 const char *purple_prefs_get_path(const char *name);
297 * Get path list pref value
299 * @param name The name of the pref
300 * @return The value of the pref
302 GList *purple_prefs_get_path_list(const char *name);
305 * Returns a list of children for a pref
307 * @param name The parent pref
308 * @return A list of newly allocated strings denoting the names of the children.
309 * Returns @c NULL if there are no children or if pref doesn't exist.
310 * The caller must free all the strings and the list.
314 GList *purple_prefs_get_children_names(const char *name);
317 * Add a callback to a pref (and its children)
319 * @param handle The handle of the receiver.
320 * @param name The name of the preference
321 * @param cb The callback function
322 * @param data The data to pass to the callback function.
324 * @return An id to disconnect the callback
326 * @see purple_prefs_disconnect_callback
328 guint purple_prefs_connect_callback(void *handle, const char *name, PurplePrefCallback cb,
332 * Remove a callback to a pref
334 void purple_prefs_disconnect_callback(guint callback_id);
337 * Remove all pref callbacks by handle
339 void purple_prefs_disconnect_by_handle(void *handle);
342 * Trigger callbacks as if the pref changed
344 void purple_prefs_trigger_callback(const char *name);
349 gboolean purple_prefs_load(void);
352 * Rename legacy prefs and delete some that no longer exist.
354 void purple_prefs_update_old(void);
362 #endif /* _PURPLE_PREFS_H_ */