3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #ifndef _PURPLE_PREFS_H_
24 #define _PURPLE_PREFS_H_
27 * @section_id: libpurple-prefs
28 * @short_description: <filename>prefs.h</filename>
29 * @title: Preferences API
36 * @PURPLE_PREF_NONE: No type.
37 * @PURPLE_PREF_BOOLEAN: Boolean.
38 * @PURPLE_PREF_INT: Integer.
39 * @PURPLE_PREF_STRING: String.
40 * @PURPLE_PREF_STRING_LIST: List of strings.
41 * @PURPLE_PREF_PATH: Path.
42 * @PURPLE_PREF_PATH_LIST: List of paths.
44 * Preference data types.
52 PURPLE_PREF_STRING_LIST
,
60 * @name: the name of the preference which has changed.
61 * @type: the type of the preferenced named @name
62 * @val: the new value of the preferencs; should be cast to the correct
63 * type. For instance, to recover the value of a #PURPLE_PREF_INT
64 * preference, use <literal>GPOINTER_TO_INT(val)</literal>.
65 * Alternatively, just call purple_prefs_get_int(),
66 * purple_prefs_get_string_list() etc.
67 * @data: Arbitrary data specified when the callback was connected with
68 * purple_prefs_connect_callback().
70 * The type of callbacks for preference changes.
72 * See purple_prefs_connect_callback().
74 typedef void (*PurplePrefCallback
) (const char *name
, PurplePrefType type
,
75 gconstpointer val
, gpointer data
);
78 * PurplePrefCallbackData:
80 * Opaque type to carry callback information
84 typedef struct _PurplePrefCallbackData PurplePrefCallbackData
;
86 /** @copydoc _PurplePrefsUiOps */
87 typedef struct _PurplePrefsUiOps PurplePrefsUiOps
;
92 * Prefs UI operations. This allows overriding the prefs.xml storage with
95 * Unless specified otherwise, each entry provides an implementation for the
96 * corresponding purple_prefs_* method, and disables the prefs.xml code for it.
97 * This means that to do anything useful, all the methods must be implemented.
101 struct _PurplePrefsUiOps
103 void (*add_none
)(const char *name
);
104 void (*add_bool
)(const char *name
, gboolean value
);
105 void (*add_int
)(const char *name
, int value
);
106 void (*add_string
)(const char *name
, const char *value
);
107 void (*add_string_list
)(const char *name
, GList
*value
);
109 void (*set_bool
)(const char *name
, gboolean value
);
110 void (*set_int
)(const char *name
, int value
);
111 void (*set_string
)(const char *name
, const char *value
);
112 void (*set_string_list
)(const char *name
, GList
*value
);
114 gboolean (*get_bool
)(const char *name
);
115 int (*get_int
)(const char *name
);
116 const char *(*get_string
)(const char *name
);
117 GList
*(*get_string_list
)(const char *name
);
119 PurplePrefType (*get_type
)(const char *name
);
120 GList
*(*get_children_names
)(const char *name
);
122 gboolean (*exists
)(const char *name
);
123 void (*remove
)(const char *name
);
125 void (*rename
)(const char *oldname
, const char *newname
);
126 void (*rename_boolean_toggle
)(const char *oldname
, const char *newname
);
128 gboolean (*load
)(void);
130 void (*schedule_save
)(void);
134 * @name: The preference name.
135 * @data: The object to be passed when triggering the callback
137 * Called when a callback is added to a preference. The UI must keep
138 * track of it and call #purple_prefs_trigger_callback_object with the
141 * Returns: A pointer to a ui_data object.
143 void *(*connect_callback
)(const char *name
, PurplePrefCallbackData
*data
);
146 * disconnect_callback:
147 * @name The preference name
148 * @ui_data The object that was returned from the connect_callback UI OP.
150 * Called when a callback is removed from a preference. The ui_data
151 * object is the one returned from connect_callback.
153 void (*disconnect_callback
)(const char *name
, void *ui_data
);
155 void (*_purple_reserved1
)(void);
156 void (*_purple_reserved2
)(void);
157 void (*_purple_reserved3
)(void);
158 void (*_purple_reserved4
)(void);
163 /******************************************************************************
164 * UI Registration Functions
165 *****************************************************************************/
168 * purple_prefs_set_ui_ops:
169 * @ops: The UI operations structure.
171 * Sets the UI operations structure to be used for preferences.
175 void purple_prefs_set_ui_ops(PurplePrefsUiOps
*ops
);
178 * purple_prefs_get_ui_ops:
180 * Returns the UI operations structure used for preferences.
182 * Returns: (transfer none): The UI operations structure in use.
186 PurplePrefsUiOps
*purple_prefs_get_ui_ops(void);
188 /**************************************************************************/
190 Preferences are named according to a directory-like structure.
191 Example: "/plugins/core/potato/is_from_idaho" (probably a boolean) */
192 /**************************************************************************/
195 * purple_prefs_get_handle:
197 * Returns the prefs subsystem handle.
199 * Returns: The prefs subsystem handle.
201 void *purple_prefs_get_handle(void);
206 * Initialize core prefs
208 void purple_prefs_init(void);
211 * purple_prefs_uninit:
213 * Uninitializes the prefs subsystem.
215 void purple_prefs_uninit(void);
218 * purple_prefs_add_none:
219 * @name: The name of the pref
221 * Add a new typeless pref.
223 void purple_prefs_add_none(const char *name
);
226 * purple_prefs_add_bool:
227 * @name: The name of the pref
228 * @value: The initial value to set
230 * Add a new boolean pref.
232 void purple_prefs_add_bool(const char *name
, gboolean value
);
235 * purple_prefs_add_int:
236 * @name: The name of the pref
237 * @value: The initial value to set
239 * Add a new integer pref.
241 void purple_prefs_add_int(const char *name
, int value
);
244 * purple_prefs_add_string:
245 * @name: The name of the pref
246 * @value: The initial value to set
248 * Add a new string pref.
250 void purple_prefs_add_string(const char *name
, const char *value
);
253 * purple_prefs_add_string_list:
254 * @name: The name of the pref
255 * @value: (element-type utf8) (transfer none): The initial value to set
257 * Add a new string list pref.
259 * Note: This function takes a copy of the strings in the value list. The list
260 * itself and original copies of the strings are up to the caller to
263 void purple_prefs_add_string_list(const char *name
, GList
*value
);
266 * purple_prefs_add_path:
267 * @name: The name of the pref
268 * @value: The initial value to set
270 * Add a new path pref.
272 void purple_prefs_add_path(const char *name
, const char *value
);
275 * purple_prefs_add_path_list:
276 * @name: The name of the pref
277 * @value: (element-type utf8) (transfer none): The initial value to set
279 * Add a new path list pref.
281 * Note: This function takes a copy of the strings in the value list. The list
282 * itself and original copies of the strings are up to the caller to
285 void purple_prefs_add_path_list(const char *name
, GList
*value
);
289 * purple_prefs_remove:
290 * @name: The name of the pref
294 void purple_prefs_remove(const char *name
);
297 * purple_prefs_rename:
298 * @oldname: The old name of the pref
299 * @newname: The new name for the pref
303 void purple_prefs_rename(const char *oldname
, const char *newname
);
306 * purple_prefs_rename_boolean_toggle:
307 * @oldname: The old name of the pref
308 * @newname: The new name for the pref
310 * Rename a boolean pref, toggling it's value
312 void purple_prefs_rename_boolean_toggle(const char *oldname
, const char *newname
);
315 * purple_prefs_destroy:
319 void purple_prefs_destroy(void);
322 * purple_prefs_set_bool:
323 * @name: The name of the pref
324 * @value: The value to set
326 * Set boolean pref value
328 void purple_prefs_set_bool(const char *name
, gboolean value
);
331 * purple_prefs_set_int:
332 * @name: The name of the pref
333 * @value: The value to set
335 * Set integer pref value
337 void purple_prefs_set_int(const char *name
, int value
);
340 * purple_prefs_set_string:
341 * @name: The name of the pref
342 * @value: The value to set
344 * Set string pref value
346 void purple_prefs_set_string(const char *name
, const char *value
);
349 * purple_prefs_set_string_list:
350 * @name: The name of the pref
351 * @value: (element-type utf8) (transfer none): The value to set
353 * Set string list pref value
355 void purple_prefs_set_string_list(const char *name
, GList
*value
);
358 * purple_prefs_set_path:
359 * @name: The name of the pref
360 * @value: The value to set
362 * Set path pref value
364 void purple_prefs_set_path(const char *name
, const char *value
);
367 * purple_prefs_set_path_list:
368 * @name: The name of the pref
369 * @value: (element-type utf8) (transfer none): The value to set
371 * Set path list pref value
373 void purple_prefs_set_path_list(const char *name
, GList
*value
);
377 * purple_prefs_exists:
378 * @name: The name of the pref
380 * Check if a pref exists
382 * Returns: TRUE if the pref exists. Otherwise FALSE.
384 gboolean
purple_prefs_exists(const char *name
);
387 * purple_prefs_get_pref_type:
388 * @name: The name of the pref
392 * Returns: The type of the pref
394 PurplePrefType
purple_prefs_get_pref_type(const char *name
);
397 * purple_prefs_get_bool:
398 * @name: The name of the pref
400 * Get boolean pref value
402 * Returns: The value of the pref
404 gboolean
purple_prefs_get_bool(const char *name
);
407 * purple_prefs_get_int:
408 * @name: The name of the pref
410 * Get integer pref value
412 * Returns: The value of the pref
414 int purple_prefs_get_int(const char *name
);
417 * purple_prefs_get_string:
418 * @name: The name of the pref
420 * Get string pref value
422 * Returns: The value of the pref
424 const char *purple_prefs_get_string(const char *name
);
427 * purple_prefs_get_string_list:
428 * @name: The name of the pref
430 * Get string list pref value
432 * Returns: (element-type utf8): The value of the pref
434 GList
*purple_prefs_get_string_list(const char *name
);
437 * purple_prefs_get_path:
438 * @name: The name of the pref
440 * Get path pref value
442 * Returns: The value of the pref
444 const char *purple_prefs_get_path(const char *name
);
447 * purple_prefs_get_path_list:
448 * @name: The name of the pref
450 * Get path list pref value
452 * Returns: (element-type utf8): The value of the pref
454 GList
*purple_prefs_get_path_list(const char *name
);
457 * purple_prefs_get_children_names:
458 * @name: The parent pref
460 * Returns a list of children for a pref
462 * Returns: (element-type utf8): A list of newly allocated strings denoting the
463 * names of the children. Returns %NULL if there are no children or if
464 * pref doesn't exist. The caller must free all the strings and the list.
466 GList
*purple_prefs_get_children_names(const char *name
);
469 * purple_prefs_connect_callback:
470 * @handle: The handle of the receiver.
471 * @name: The name of the preference
472 * @cb: (scope call): The callback function
473 * @data: The data to pass to the callback function.
475 * Add a callback to a pref (and its children)
477 * See purple_prefs_disconnect_callback().
479 * Returns: An id to disconnect the callback
481 guint
purple_prefs_connect_callback(void *handle
, const char *name
, PurplePrefCallback cb
,
485 * purple_prefs_disconnect_callback:
487 * Remove a callback to a pref
489 void purple_prefs_disconnect_callback(guint callback_id
);
492 * purple_prefs_disconnect_by_handle:
494 * Remove all pref callbacks by handle
496 void purple_prefs_disconnect_by_handle(void *handle
);
499 * purple_prefs_trigger_callback:
501 * Trigger callbacks as if the pref changed
503 void purple_prefs_trigger_callback(const char *name
);
506 * purple_prefs_trigger_callback_object:
508 * Trigger callbacks as if the pref changed, taking a #PurplePrefCallbackData
513 void purple_prefs_trigger_callback_object(PurplePrefCallbackData
*data
);
520 gboolean
purple_prefs_load(void);
524 #endif /* _PURPLE_PREFS_H_ */