Change pidgin_convert_buddy_icon() to be more accommodating when attempting
[pidgin-git.git] / libpurple / prefs.h
blob2d02f3f2e7b9233b6325117fba43cec3237b1afc
1 /**
2 * @file prefs.h Prefs API
3 * @ingroup core
4 */
6 /* purple
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_
30 #include <glib.h>
32 /**
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. */
45 } PurplePrefType;
47 /**
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()
56 * etc.
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);
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
69 /**************************************************************************/
70 /** @name Prefs API
71 Preferences are named according to a directory-like structure.
72 Example: "/plugins/core/potato/is_from_idaho" (probably a boolean) */
73 /**************************************************************************/
74 /*@{*/
76 /**
77 * Returns the prefs subsystem handle.
79 * @return The prefs subsystem handle.
81 void *purple_prefs_get_handle(void);
83 /**
84 * Initialize core prefs
86 void purple_prefs_init(void);
88 /**
89 * Uninitializes the prefs subsystem.
91 void purple_prefs_uninit(void);
93 /**
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
131 * free.
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
150 * free.
152 void purple_prefs_add_path_list(const char *name, GList *value);
156 * Remove a pref.
158 * @param name The name of the pref
160 void purple_prefs_remove(const char *name);
163 * Rename a pref
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);
179 * Remove all prefs.
181 void purple_prefs_destroy(void);
184 * Set raw pref value
186 * @param name The name of the pref
187 * @param value The value to set
189 * @deprecated We're not really sure what purpose this function serves, so it
190 * will be removed in 3.0.0. Preferences values set using this
191 * function aren't serialized to prefs.xml, which could be
192 * misleading. There is also no purple_prefs_get_generic, which
193 * means that if you can't really get the value (other in a
194 * connected callback). If you think you have a use for this then
195 * please let us know.
197 /* TODO: When this is removed, also remove struct purple_pref->value.generic */
198 void purple_prefs_set_generic(const char *name, gpointer value);
201 * Set boolean pref value
203 * @param name The name of the pref
204 * @param value The value to set
206 void purple_prefs_set_bool(const char *name, gboolean value);
209 * Set integer pref value
211 * @param name The name of the pref
212 * @param value The value to set
214 void purple_prefs_set_int(const char *name, int value);
217 * Set string pref value
219 * @param name The name of the pref
220 * @param value The value to set
222 void purple_prefs_set_string(const char *name, const char *value);
225 * Set string list pref value
227 * @param name The name of the pref
228 * @param value The value to set
230 void purple_prefs_set_string_list(const char *name, GList *value);
233 * Set path pref value
235 * @param name The name of the pref
236 * @param value The value to set
238 void purple_prefs_set_path(const char *name, const char *value);
241 * Set path list pref value
243 * @param name The name of the pref
244 * @param value The value to set
246 void purple_prefs_set_path_list(const char *name, GList *value);
250 * Check if a pref exists
252 * @param name The name of the pref
253 * @return TRUE if the pref exists. Otherwise FALSE.
255 gboolean purple_prefs_exists(const char *name);
258 * Get pref type
260 * @param name The name of the pref
261 * @return The type of the pref
263 PurplePrefType purple_prefs_get_type(const char *name);
266 * Get boolean pref value
268 * @param name The name of the pref
269 * @return The value of the pref
271 gboolean purple_prefs_get_bool(const char *name);
274 * Get integer pref value
276 * @param name The name of the pref
277 * @return The value of the pref
279 int purple_prefs_get_int(const char *name);
282 * Get string pref value
284 * @param name The name of the pref
285 * @return The value of the pref
287 const char *purple_prefs_get_string(const char *name);
290 * Get string list pref value
292 * @param name The name of the pref
293 * @return The value of the pref
295 GList *purple_prefs_get_string_list(const char *name);
298 * Get path pref value
300 * @param name The name of the pref
301 * @return The value of the pref
303 const char *purple_prefs_get_path(const char *name);
306 * Get path list pref value
308 * @param name The name of the pref
309 * @return The value of the pref
311 GList *purple_prefs_get_path_list(const char *name);
314 * Returns a list of children for a pref
316 * @param name The parent pref
317 * @return A list of newly allocated strings denoting the names of the children.
318 * Returns @c NULL if there are no children or if pref doesn't exist.
319 * The caller must free all the strings and the list.
321 * @since 2.1.0
323 GList *purple_prefs_get_children_names(const char *name);
326 * Add a callback to a pref (and its children)
328 * @param handle The handle of the receiver.
329 * @param name The name of the preference
330 * @param cb The callback function
331 * @param data The data to pass to the callback function.
333 * @return An id to disconnect the callback
335 * @see purple_prefs_disconnect_callback
337 guint purple_prefs_connect_callback(void *handle, const char *name, PurplePrefCallback cb,
338 gpointer data);
341 * Remove a callback to a pref
343 void purple_prefs_disconnect_callback(guint callback_id);
346 * Remove all pref callbacks by handle
348 void purple_prefs_disconnect_by_handle(void *handle);
351 * Trigger callbacks as if the pref changed
353 void purple_prefs_trigger_callback(const char *name);
356 * Read preferences
358 gboolean purple_prefs_load(void);
361 * Rename legacy prefs and delete some that no longer exist.
363 void purple_prefs_update_old(void);
365 /*@}*/
367 #ifdef __cplusplus
369 #endif
371 #endif /* _PURPLE_PREFS_H_ */