Frameworks/libpurple.framework/Versions/0.6.2/Headers/prefs.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2539 Frameworks/libpurple.framework/Versions/0.6.0/Headers/prefs.h@2c9881ea8cdf
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file prefs.h Prefs API
     3  * @ingroup core
     4  */
     5 
     6 /* purple
     7  *
     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.
    11  *
    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.
    16  *
    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.
    21  *
    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
    25  *
    26  */
    27 #ifndef _PURPLE_PREFS_H_
    28 #define _PURPLE_PREFS_H_
    29 
    30 #include <glib.h>
    31 
    32 /**
    33  * Preference data types.
    34  */
    35 typedef enum _PurplePrefType
    36 {
    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.   */
    44 
    45 } PurplePrefType;
    46 
    47 /**
    48  * The type of callbacks for preference changes.
    49  *
    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().
    59  *
    60  * @see purple_prefs_connect_callback()
    61  */
    62 typedef void (*PurplePrefCallback) (const char *name, PurplePrefType type,
    63 		gconstpointer val, gpointer data);
    64 
    65 #ifdef __cplusplus
    66 extern "C" {
    67 #endif
    68 
    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 /*@{*/
    75 
    76 /**
    77  * Returns the prefs subsystem handle.
    78  *
    79  * @return The prefs subsystem handle.
    80  */
    81 void *purple_prefs_get_handle(void);
    82 
    83 /**
    84  * Initialize core prefs
    85  */
    86 void purple_prefs_init(void);
    87 
    88 /**
    89  * Uninitializes the prefs subsystem.
    90  */
    91 void purple_prefs_uninit(void);
    92 
    93 /**
    94  * Add a new typeless pref.
    95  *
    96  * @param name  The name of the pref
    97  */
    98 void purple_prefs_add_none(const char *name);
    99 
   100 /**
   101  * Add a new boolean pref.
   102  *
   103  * @param name  The name of the pref
   104  * @param value The initial value to set
   105  */
   106 void purple_prefs_add_bool(const char *name, gboolean value);
   107 
   108 /**
   109  * Add a new integer pref.
   110  *
   111  * @param name  The name of the pref
   112  * @param value The initial value to set
   113  */
   114 void purple_prefs_add_int(const char *name, int value);
   115 
   116 /**
   117  * Add a new string pref.
   118  *
   119  * @param name  The name of the pref
   120  * @param value The initial value to set
   121  */
   122 void purple_prefs_add_string(const char *name, const char *value);
   123 
   124 /**
   125  * Add a new string list pref.
   126  *
   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.
   132  */
   133 void purple_prefs_add_string_list(const char *name, GList *value);
   134 
   135 /**
   136  * Add a new path pref.
   137  *
   138  * @param name  The name of the pref
   139  * @param value The initial value to set
   140  */
   141 void purple_prefs_add_path(const char *name, const char *value);
   142 
   143 /**
   144  * Add a new path list pref.
   145  *
   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.
   151  */
   152 void purple_prefs_add_path_list(const char *name, GList *value);
   153 
   154 
   155 /**
   156  * Remove a pref.
   157  *
   158  * @param name The name of the pref
   159  */
   160 void purple_prefs_remove(const char *name);
   161 
   162 /**
   163  * Rename a pref
   164  *
   165  * @param oldname The old name of the pref
   166  * @param newname The new name for the pref
   167  */
   168 void purple_prefs_rename(const char *oldname, const char *newname);
   169 
   170 /**
   171  * Rename a boolean pref, toggling it's value
   172  *
   173  * @param oldname The old name of the pref
   174  * @param newname The new name for the pref
   175  */
   176 void purple_prefs_rename_boolean_toggle(const char *oldname, const char *newname);
   177 
   178 /**
   179  * Remove all prefs.
   180  */
   181 void purple_prefs_destroy(void);
   182 
   183 /**
   184  * Set raw pref value
   185  *
   186  * @param name  The name of the pref
   187  * @param value The value to set
   188  */
   189 void purple_prefs_set_generic(const char *name, gpointer value);
   190 
   191 /**
   192  * Set boolean pref value
   193  *
   194  * @param name  The name of the pref
   195  * @param value The value to set
   196  */
   197 void purple_prefs_set_bool(const char *name, gboolean value);
   198 
   199 /**
   200  * Set integer pref value
   201  *
   202  * @param name  The name of the pref
   203  * @param value The value to set
   204  */
   205 void purple_prefs_set_int(const char *name, int value);
   206 
   207 /**
   208  * Set string pref value
   209  *
   210  * @param name  The name of the pref
   211  * @param value The value to set
   212  */
   213 void purple_prefs_set_string(const char *name, const char *value);
   214 
   215 /**
   216  * Set string list pref value
   217  *
   218  * @param name  The name of the pref
   219  * @param value The value to set
   220  */
   221 void purple_prefs_set_string_list(const char *name, GList *value);
   222 
   223 /**
   224  * Set path pref value
   225  *
   226  * @param name  The name of the pref
   227  * @param value The value to set
   228  */
   229 void purple_prefs_set_path(const char *name, const char *value);
   230 
   231 /**
   232  * Set path list pref value
   233  *
   234  * @param name  The name of the pref
   235  * @param value The value to set
   236  */
   237 void purple_prefs_set_path_list(const char *name, GList *value);
   238 
   239 
   240 /**
   241  * Check if a pref exists
   242  *
   243  * @param name The name of the pref
   244  * @return TRUE if the pref exists.  Otherwise FALSE.
   245  */
   246 gboolean purple_prefs_exists(const char *name);
   247 
   248 /**
   249  * Get pref type
   250  *
   251  * @param name The name of the pref
   252  * @return The type of the pref
   253  */
   254 PurplePrefType purple_prefs_get_type(const char *name);
   255 
   256 /**
   257  * Get boolean pref value
   258  *
   259  * @param name The name of the pref
   260  * @return The value of the pref
   261  */
   262 gboolean purple_prefs_get_bool(const char *name);
   263 
   264 /**
   265  * Get integer pref value
   266  *
   267  * @param name The name of the pref
   268  * @return The value of the pref
   269  */
   270 int purple_prefs_get_int(const char *name);
   271 
   272 /**
   273  * Get string pref value
   274  *
   275  * @param name The name of the pref
   276  * @return The value of the pref
   277  */
   278 const char *purple_prefs_get_string(const char *name);
   279 
   280 /**
   281  * Get string list pref value
   282  *
   283  * @param name The name of the pref
   284  * @return The value of the pref
   285  */
   286 GList *purple_prefs_get_string_list(const char *name);
   287 
   288 /**
   289  * Get path pref value
   290  *
   291  * @param name The name of the pref
   292  * @return The value of the pref
   293  */
   294 const char *purple_prefs_get_path(const char *name);
   295 
   296 /**
   297  * Get path list pref value
   298  *
   299  * @param name The name of the pref
   300  * @return The value of the pref
   301  */
   302 GList *purple_prefs_get_path_list(const char *name);
   303 
   304 /**
   305  * Returns a list of children for a pref
   306  *
   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.
   311  *
   312  * @since 2.1.0
   313  */
   314 GList *purple_prefs_get_children_names(const char *name);
   315 
   316 /**
   317  * Add a callback to a pref (and its children)
   318  *
   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.
   323  *
   324  * @return An id to disconnect the callback
   325  *
   326  * @see purple_prefs_disconnect_callback
   327  */
   328 guint purple_prefs_connect_callback(void *handle, const char *name, PurplePrefCallback cb,
   329 		gpointer data);
   330 
   331 /**
   332  * Remove a callback to a pref
   333  */
   334 void purple_prefs_disconnect_callback(guint callback_id);
   335 
   336 /**
   337  * Remove all pref callbacks by handle
   338  */
   339 void purple_prefs_disconnect_by_handle(void *handle);
   340 
   341 /**
   342  * Trigger callbacks as if the pref changed
   343  */
   344 void purple_prefs_trigger_callback(const char *name);
   345 
   346 /**
   347  * Read preferences
   348  */
   349 gboolean purple_prefs_load(void);
   350 
   351 /**
   352  * Rename legacy prefs and delete some that no longer exist.
   353  */
   354 void purple_prefs_update_old(void);
   355 
   356 /*@}*/
   357 
   358 #ifdef __cplusplus
   359 }
   360 #endif
   361 
   362 #endif /* _PURPLE_PREFS_H_ */