00001 #ifndef __GCONF_UTILS_H__ 00002 #define __GCONF_UTILS_H__ 00003 00004 /** 00005 * \file gconf_utils.h 00006 * \brief A lightweight wrapper for gconf library. 00007 */ 00008 00009 /* 00010 * This file is part of liberutils. 00011 * 00012 * liberutils is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation, either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * liberutils is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00024 */ 00025 00026 /** 00027 * Copyright (C) 2009 iRex Technologies B.V. 00028 * All rights reserved. 00029 */ 00030 00031 //---------------------------------------------------------------------------- 00032 // Include Files 00033 //---------------------------------------------------------------------------- 00034 00035 // system include files, between < > 00036 #include <glib.h> 00037 #include <gconf/gconf-client.h> 00038 00039 // ereader include files, between < > 00040 00041 // local include files, between " " 00042 #include "er_error.h" 00043 00044 G_BEGIN_DECLS 00045 00046 00047 //---------------------------------------------------------------------------- 00048 // Macro Definitions 00049 //---------------------------------------------------------------------------- 00050 00051 00052 //---------------------------------------------------------------------------- 00053 // Forward Declarations 00054 //---------------------------------------------------------------------------- 00055 00056 00057 //---------------------------------------------------------------------------- 00058 // Type Declarations 00059 //---------------------------------------------------------------------------- 00060 00061 typedef void (*gconf_cb_value_changed_t) (const gchar* key, GConfValue* value); 00062 00063 00064 //---------------------------------------------------------------------------- 00065 // Global Constants 00066 //---------------------------------------------------------------------------- 00067 00068 00069 //============================================================================ 00070 // Public Functions 00071 //============================================================================ 00072 00073 /**--------------------------------------------------------------------------- 00074 * 00075 * Name : ergconf_initialize 00076 * 00077 * @brief Initialize GConf client. 00078 * Note that GConf client talks to GConf daemon and has no access to 00079 * files on disk. Changes are communicated to GConf daemon, who sends 00080 * these values to every other client that is interested. The timing 00081 * of writing changed values to disk is determined by GConf daemon 00082 * and cannot be influenced through a GConf client. 00083 * 00084 * @param -- 00085 * 00086 * @return -- 00087 * 00088 *--------------------------------------------------------------------------*/ 00089 void ergconf_initialize(); 00090 00091 /**--------------------------------------------------------------------------- 00092 * 00093 * Name : ergconf_finalize 00094 * 00095 * @brief Release GConf client. 00096 * Note this does not guarantee changes are written to disk now, 00097 * because this is determined by the GConf daemon. 00098 * 00099 * @param -- 00100 * 00101 * @return -- 00102 * 00103 *--------------------------------------------------------------------------*/ 00104 void ergconf_finalize(); 00105 00106 /**--------------------------------------------------------------------------- 00107 * 00108 * Name : ergconf_set_cb_value_changed 00109 * 00110 * @brief Set callback function for gconf value changed 00111 * 00112 * @param [in] callback - Function to be called on a value change in 00113 * one of the directories set with ergconf_add_monitor_dir. 00114 * 00115 * @return -- 00116 * 00117 *--------------------------------------------------------------------------*/ 00118 void ergconf_set_cb_value_changed(gconf_cb_value_changed_t callback); 00119 00120 /**--------------------------------------------------------------------------- 00121 * 00122 * Name : ergconf_add_monitor_dir 00123 * 00124 * @brief Adds a gconf directory to be monitored. 00125 * Value changes in this directory will be reported through the value-changed callback. 00126 * 00127 * @param -- 00128 * 00129 * @return -- 00130 * 00131 *--------------------------------------------------------------------------*/ 00132 void ergconf_add_monitor_dir(const gchar *dir); 00133 00134 /**--------------------------------------------------------------------------- 00135 * 00136 * Name : ergconf_unset 00137 * 00138 * @brief Unset the value of the specified key. 00139 * This function clears the value of the key and set it to the default 00140 * value defined in the schema file. If schema file doesn't define a 00141 * default one then it will be set to gconf default (e.g. for integer 00142 * it will be 0). 00143 * 00144 * @param [in] key - The GConf path of the key. 00145 * 00146 * @return -- 00147 * 00148 *--------------------------------------------------------------------------*/ 00149 void ergconf_unset(const gchar* key); 00150 00151 /**--------------------------------------------------------------------------- 00152 * 00153 * Name : ergconf_recursive_unset 00154 * 00155 * @brief Recursively unset all values in the specified directory and its 00156 * sub-directories. 00157 * This function clears the value of the keys and sets them to the 00158 * default value defined in the schema file. If schema file doesn't 00159 * define a default one then it will be set to gconf default (e.g. 00160 * for integer it will be 0). 00161 * 00162 * @param [in] dir - The specified directory. 00163 * 00164 * @return -- 00165 * 00166 *--------------------------------------------------------------------------*/ 00167 void ergconf_recursive_unset(const gchar *dir); 00168 00169 /**--------------------------------------------------------------------------- 00170 * 00171 * Name : ergconf_get_int 00172 * 00173 * @brief Request the integer value stored at the specified key. 00174 * 00175 * @param [in] key - The GConf path of the key. 00176 * 00177 * @return The integer value stored at the specified key. 00178 * 00179 *--------------------------------------------------------------------------*/ 00180 int ergconf_get_int(const gchar* key); 00181 00182 /**--------------------------------------------------------------------------- 00183 * 00184 * Name : ergconf_set_int 00185 * 00186 * @brief Change the value of key to new_value. 00187 * 00188 * @param [in] key - The GConf path of the key. 00189 * [in] new_value - The new value to be set. 00190 * 00191 * @return ER_OK on success, ER_SET_FAIL on error. 00192 * 00193 *--------------------------------------------------------------------------*/ 00194 int ergconf_set_int(const gchar* key, int new_value); 00195 00196 /**--------------------------------------------------------------------------- 00197 * 00198 * Name : ergconf_get_bool 00199 * 00200 * @brief Request the boolean value stored at the specified key. 00201 * 00202 * @param [in] key - The GConf path of the key. 00203 * 00204 * @return The boolean value stored at the specified key. 00205 * 00206 *--------------------------------------------------------------------------*/ 00207 gboolean ergconf_get_bool(const gchar* key); 00208 00209 /**--------------------------------------------------------------------------- 00210 * 00211 * Name : ergconf_set_bool 00212 * 00213 * @brief Change the value of key to new_value. 00214 * 00215 * @param [in] key - The GConf path of the key. 00216 * [in] new_value - The new value to be set. 00217 * 00218 * @return ER_OK on success, ER_SET_FAIL on error. 00219 * 00220 *--------------------------------------------------------------------------*/ 00221 int ergconf_set_bool(const gchar* key, gboolean new_value); 00222 00223 /**--------------------------------------------------------------------------- 00224 * 00225 * Name : ergconf_get_string 00226 * 00227 * @brief Request the string value stored at the specified key. 00228 * 00229 * @param [in] key - The GConf path of the key. 00230 * 00231 * @return A string value 00232 * or NULL on error. 00233 * Caller must use g_free() to release this string. 00234 * 00235 *--------------------------------------------------------------------------*/ 00236 gchar* ergconf_get_string(const gchar* key); 00237 00238 /**--------------------------------------------------------------------------- 00239 * 00240 * Name : ergconf_set_string 00241 * 00242 * @brief Change the value of key to new_value. 00243 * 00244 * @param [in] key - The GConf path of the key. 00245 * [in] new_value - The new value to be set. 00246 * 00247 * @return ER_OK on success, ER_SET_FAIL on error. 00248 * 00249 *--------------------------------------------------------------------------*/ 00250 int ergconf_set_string(const gchar* key, const gchar* new_value); 00251 00252 /**--------------------------------------------------------------------------- 00253 * 00254 * Name : ergconf_get_string_list 00255 * 00256 * @brief Request the string list value stored at the specified key. 00257 * 00258 * @param [in] key - The GConf path of the key. 00259 * 00260 * @return A list of strings, each one a gchar* specifying a sub-value of 'key'. 00261 * or NULL on error. 00262 * Caller must use ergconf_free_string_list() to release this list 00263 * and the strings it contains. 00264 * 00265 *--------------------------------------------------------------------------*/ 00266 GSList* ergconf_get_string_list(const gchar* key); 00267 00268 /**--------------------------------------------------------------------------- 00269 * 00270 * Name : ergconf_set_string_list 00271 * 00272 * @brief Change the value of key to new_value. 00273 * 00274 * @param [in] key - The GConf path of the key. 00275 * [in] new_value - The new value to be set, 00276 * formatted as a list of strings, each one a gchar*. 00277 * 00278 * @return ER_OK on success, ER_SET_FAIL on error. 00279 * 00280 *--------------------------------------------------------------------------*/ 00281 int ergconf_set_string_list(const gchar* key, const GSList *new_value); 00282 00283 /**--------------------------------------------------------------------------- 00284 * 00285 * Name : ergconf_get_byte_array 00286 * 00287 * @brief Request the byte array value stored at the specified key. 00288 * 00289 * @param [in] key - The GConf path of the key. 00290 * 00291 * @return A byte array representing the list of integer values stored at 'key' 00292 * or NULL on error. 00293 * Caller must use g_byte_array_free() to release this byte array. 00294 * 00295 *--------------------------------------------------------------------------*/ 00296 GByteArray* ergconf_get_byte_array(const gchar* key); 00297 00298 /**--------------------------------------------------------------------------- 00299 * 00300 * Name : ergconf_set_byte_array 00301 * 00302 * @brief Change the value of key to new_value. 00303 * 00304 * @param [in] key - The GConf path of the key. 00305 * [in] new_value - The new value to be set, 00306 * formatted as a byte array. 00307 * 00308 * @return ER_OK on success, ER_SET_FAIL on error. 00309 * 00310 *--------------------------------------------------------------------------*/ 00311 int ergconf_set_byte_array(const gchar* key, const GByteArray *new_value); 00312 00313 /**--------------------------------------------------------------------------- 00314 * 00315 * Name : ergconf_get_string_hash 00316 * 00317 * @brief Get all key-value pairs from the specified GConf directory 00318 * formatted as a hash table. 00319 * 00320 * @param [in] dir - The specified GConf directory. 00321 * 00322 * @return A hash table holding all key-value pairs in the specified GConf directory 00323 * or NULL on error. 00324 * Key from GConf is used as key in the hash table. 00325 * Value from GConf is converted to string and used as value in the hash table. 00326 * Caller must use g_hash_table_destroy() to release this hash table. 00327 * 00328 *--------------------------------------------------------------------------*/ 00329 GHashTable* ergconf_get_string_hash(const gchar* dir); 00330 00331 /**--------------------------------------------------------------------------- 00332 * 00333 * Name : ergconf_set_string_hash 00334 * 00335 * @brief Set all key-value pairs in the specified GConf directory, 00336 * assuming all key-value pairs in this GConf directory are of type string. 00337 * Keys not present in new_value will be removed from the GConf directory. 00338 * Sub-directories of the GConf directory are not affected. 00339 * 00340 * @param [in] dir - The specified GConf directory. 00341 * [in] new_value - A hash table holding all key-value pairs to be set 00342 * 00343 * @return ER_OK on success, ER_SET_FAIL on error. 00344 * 00345 *--------------------------------------------------------------------------*/ 00346 int ergconf_set_string_hash(const gchar* dir, const GHashTable *new_value); 00347 00348 /**--------------------------------------------------------------------------- 00349 * 00350 * Name : ergconf_get_int_array 00351 * 00352 * @brief Get the integer array stored at the specified GConf key. 00353 * 00354 * @param [in] key - The GConf path of the key. 00355 * 00356 * @return An array holding the integer values stored at this GConf key 00357 * or NULL on error. 00358 * The array hold elements of type gint. 00359 * Caller must use g_array_free() to release this array. 00360 * 00361 *--------------------------------------------------------------------------*/ 00362 GArray* ergconf_get_int_array(const gchar* key); 00363 00364 /**--------------------------------------------------------------------------- 00365 * 00366 * Name : ergconf_set_int_array 00367 * 00368 * @brief Change value of specified GConf key into the supplied integer array. 00369 * 00370 * @param [in] key - The GConf path of the key. 00371 * [in] new_value - An array holding 'gint' values to be stored 00372 * at the specified GConf path. 00373 * 00374 * @return ER_OK on success, ER_SET_FAIL on error. 00375 * 00376 *--------------------------------------------------------------------------*/ 00377 int ergconf_set_int_array(const gchar* key, const GArray* new_value); 00378 00379 /**--------------------------------------------------------------------------- 00380 * 00381 * Name : ergconf_get_int_tuples 00382 * 00383 * @brief Get the list of integer tuples stored at the specified GConf key. 00384 * 00385 * @param [in] key - The specified GConf key. 00386 * [in] tuple_len - Number of integers in a tuple. 00387 * 00388 * @return 00389 * An array of integer tuples, each length 'tuple_len', 00390 * or NULL on error. 00391 * The array holds a set of pointers to a tuple, 00392 * each tuple is a GArray of 'guint32' values with length 'tuple_len'. 00393 * Caller must use ergconf_free_int_tuples() to release this array 00394 * and the integer tuples it contains. 00395 * 00396 *--------------------------------------------------------------------------*/ 00397 GPtrArray* ergconf_get_int_tuples(const gchar* key, guint tuple_len); 00398 00399 /**--------------------------------------------------------------------------- 00400 * 00401 * Name : ergconf_set_int_tuples 00402 * 00403 * @brief Change value of the specified GConf key into the supplied array 00404 * of integer tuples. 00405 * 00406 * @param [in] key - The specified GConf key. 00407 * [in] value - An array of integer tuples, each length 'tuple_len'. 00408 * The array holds a set of pointers to a tuple, 00409 * each tuple is a GArray of 'guint32' values with length 'tuple_len'. 00410 * [in] tuple_len - Number of integers in a tuple. 00411 * 00412 * @return ER_OK on success, ER_SET_FAIL on error. 00413 * 00414 *--------------------------------------------------------------------------*/ 00415 int ergconf_set_int_tuples(const gchar* key, const GPtrArray* value, guint tuple_len); 00416 00417 /**--------------------------------------------------------------------------- 00418 * 00419 * Name : ergconf_free_int_tuples 00420 * 00421 * @brief Free a list of integer tuples 00422 * 00423 * @param [in] tuple_list - An array of integer tuples. 00424 * The array holds a set of pointers to a tuple, 00425 * each tuple is a GArray of 'guint32' values. 00426 * 00427 * @return -- 00428 * 00429 *--------------------------------------------------------------------------*/ 00430 void ergconf_free_int_tuples(GPtrArray* tuple_list); 00431 00432 /**--------------------------------------------------------------------------- 00433 * 00434 * Name : ergconf_get_sub_dirs 00435 * 00436 * @brief Get a list of sub-directories in the specified GConf directory. 00437 * 00438 * @param [in] dir - The specified GConf directory. 00439 * 00440 * @return A list of string, each one a gchar* specifying a sub-directory of 'dir'. 00441 * Caller must use ergconf_free_string_list() to release this list 00442 * and the strings it contains. 00443 * 00444 *--------------------------------------------------------------------------*/ 00445 GSList* ergconf_get_sub_dirs(const gchar *dir); 00446 00447 /**--------------------------------------------------------------------------- 00448 * 00449 * Name : ergconf_free_string_list 00450 * 00451 * @brief Free string list returned by e.g. get_value_string_list(). 00452 * 00453 * @param [in] str_list - The string list to be freed. 00454 * 00455 * @return -- 00456 * 00457 *--------------------------------------------------------------------------*/ 00458 void ergconf_free_string_list(GSList* str_list); 00459 00460 /**--------------------------------------------------------------------------- 00461 * 00462 * Name : ergconf_dir_exist 00463 * 00464 * @brief Query whether the directory dir exists in the GConf database. 00465 * 00466 * @param [in] dir - The specified directory to be checked. 00467 * 00468 * @return TRUE if it exists, FALSE if it doesn't exist. 00469 * 00470 *--------------------------------------------------------------------------*/ 00471 gboolean ergconf_dir_exist(const gchar* dir); 00472 00473 /**--------------------------------------------------------------------------- 00474 * 00475 * Name : ergconf_is_default 00476 * 00477 * @brief Returns if the key is set to the schema default value 00478 * 00479 * @param [in] key - The GConf path of the key. 00480 * 00481 * @return TRUE if it is default, FALSE if it doesn't. 00482 * 00483 *--------------------------------------------------------------------------*/ 00484 gboolean ergconf_is_default(const gchar* key); 00485 00486 00487 G_END_DECLS 00488 00489 #endif // __GCONF_UTILS_H__