gconf_utils.h File Reference

A lightweight wrapper for gconf library. More...

#include <glib.h>
#include <gconf/gconf-client.h>
#include "er_error.h"
Include dependency graph for gconf_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ergconf_initialize ()
 Initialize GConf client. Note that GConf client talks to GConf daemon and has no access to files on disk. Changes are communicated to GConf daemon, who sends these values to every other client that is interested. The timing of writing changed values to disk is determined by GConf daemon and cannot be influenced through a GConf client.
void ergconf_finalize ()
 Release GConf client. Note this does not guarantee changes are written to disk now, because this is determined by the GConf daemon.
void ergconf_set_cb_value_changed (gconf_cb_value_changed_t callback)
 Set callback function for gconf value changed.
void ergconf_add_monitor_dir (const gchar *dir)
 Adds a gconf directory to be monitored. Value changes in this directory will be reported through the value-changed callback.
void ergconf_unset (const gchar *key)
 Unset the value of the specified key. This function clears the value of the key and set it to the default value defined in the schema file. If schema file doesn't define a default one then it will be set to gconf default (e.g. for integer it will be 0).
void ergconf_recursive_unset (const gchar *dir)
 Recursively unset all values in the specified directory and its sub-directories. This function clears the value of the keys and sets them to the default value defined in the schema file. If schema file doesn't define a default one then it will be set to gconf default (e.g. for integer it will be 0).
int ergconf_get_int (const gchar *key)
 Request the integer value stored at the specified key.
int ergconf_set_int (const gchar *key, int new_value)
 Change the value of key to new_value.
gboolean ergconf_get_bool (const gchar *key)
 Request the boolean value stored at the specified key.
int ergconf_set_bool (const gchar *key, gboolean new_value)
 Change the value of key to new_value.
gchar * ergconf_get_string (const gchar *key)
 Request the string value stored at the specified key.
int ergconf_set_string (const gchar *key, const gchar *new_value)
 Change the value of key to new_value.
GSList * ergconf_get_string_list (const gchar *key)
 Request the string list value stored at the specified key.
int ergconf_set_string_list (const gchar *key, const GSList *new_value)
 Change the value of key to new_value.
GByteArray * ergconf_get_byte_array (const gchar *key)
 Request the byte array value stored at the specified key.
int ergconf_set_byte_array (const gchar *key, const GByteArray *new_value)
 Change the value of key to new_value.
GHashTable * ergconf_get_string_hash (const gchar *dir)
 Get all key-value pairs from the specified GConf directory formatted as a hash table.
int ergconf_set_string_hash (const gchar *dir, const GHashTable *new_value)
 Set all key-value pairs in the specified GConf directory, assuming all key-value pairs in this GConf directory are of type string. Keys not present in new_value will be removed from the GConf directory. Sub-directories of the GConf directory are not affected.
GArray * ergconf_get_int_array (const gchar *key)
 Get the integer array stored at the specified GConf key.
int ergconf_set_int_array (const gchar *key, const GArray *new_value)
 Change value of specified GConf key into the supplied integer array.
GPtrArray * ergconf_get_int_tuples (const gchar *key, guint tuple_len)
 Get the list of integer tuples stored at the specified GConf key.
int ergconf_set_int_tuples (const gchar *key, const GPtrArray *value, guint tuple_len)
 Change value of the specified GConf key into the supplied array of integer tuples.
void ergconf_free_int_tuples (GPtrArray *tuple_list)
 Free a list of integer tuples.
GSList * ergconf_get_sub_dirs (const gchar *dir)
 Get a list of sub-directories in the specified GConf directory.
void ergconf_free_string_list (GSList *str_list)
 Free string list returned by e.g. get_value_string_list().
gboolean ergconf_dir_exist (const gchar *dir)
 Query whether the directory dir exists in the GConf database.
gboolean ergconf_is_default (const gchar *key)
 Returns if the key is set to the schema default value.

Variables

G_BEGIN_DECLS typedef void(* gconf_cb_value_changed_t )(const gchar *key, GConfValue *value)

Detailed Description

A lightweight wrapper for gconf library.

Definition in file gconf_utils.h.


Function Documentation

void ergconf_add_monitor_dir ( const gchar *  dir  ) 

Adds a gconf directory to be monitored. Value changes in this directory will be reported through the value-changed callback.

---------------------------------------------------------------------------

Name : ergconf_add_monitor_dir

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 120 of file gconf_utils.c.

References client.

00121 {
00122     g_assert(client);
00123     g_assert(dir && *dir == '/');
00124     gconf_client_add_dir(client, dir, GCONF_CLIENT_PRELOAD_NONE, NULL);
00125 }

gboolean ergconf_dir_exist ( const gchar *  dir  ) 

Query whether the directory dir exists in the GConf database.

---------------------------------------------------------------------------

Name : ergconf_dir_exist

Parameters:
[in] dir - The specified directory to be checked.
Returns:
TRUE if it exists, FALSE if it doesn't exist.

--------------------------------------------------------------------------

Definition at line 591 of file gconf_utils.c.

References client.

00592 {
00593     return gconf_client_dir_exists(client, dir, NULL);
00594 }

void ergconf_finalize (  ) 

Release GConf client. Note this does not guarantee changes are written to disk now, because this is determined by the GConf daemon.

---------------------------------------------------------------------------

Name : ergconf_finalize

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 97 of file gconf_utils.c.

References client.

Referenced by main_quit().

00098 {
00099     if (client)
00100     {
00101         g_object_unref(client);
00102         client = NULL;
00103     }
00104 }

Here is the caller graph for this function:

void ergconf_free_int_tuples ( GPtrArray *  tuple_list  ) 

Free a list of integer tuples.

---------------------------------------------------------------------------

Name : ergconf_free_int_tuples

Parameters:
[in] tuple_list - An array of integer tuples. The array holds a set of pointers to a tuple, each tuple is a GArray of 'guint32' values.
Returns:
--

--------------------------------------------------------------------------

Definition at line 545 of file gconf_utils.c.

00546 {
00547     g_return_if_fail(tuple_list);
00548 
00549     unsigned int i;
00550     for (i = 0; i < tuple_list->len; i++)
00551     {
00552         GArray *tuple = g_ptr_array_index (tuple_list, i);
00553         g_array_free(tuple, TRUE);
00554     }
00555     g_ptr_array_free(tuple_list, TRUE);
00556 }

void ergconf_free_string_list ( GSList *  str_list  ) 

Free string list returned by e.g. get_value_string_list().

---------------------------------------------------------------------------

Name : ergconf_free_string_list

Parameters:
[in] str_list - The string list to be freed.
Returns:
--

--------------------------------------------------------------------------

Definition at line 576 of file gconf_utils.c.

References client.

00577 {
00578     GSList* p = str_list;
00579 
00580     g_assert(client);
00581 
00582     while (p)
00583     {
00584         g_free(p->data);
00585         p = p->next;
00586     }
00587 
00588     g_slist_free(str_list);
00589 }

gboolean ergconf_get_bool ( const gchar *  key  ) 

Request the boolean value stored at the specified key.

---------------------------------------------------------------------------

Name : ergconf_get_bool

Parameters:
[in] key - The GConf path of the key.
Returns:
The boolean value stored at the specified key.

--------------------------------------------------------------------------

Definition at line 159 of file gconf_utils.c.

References client.

00160 {
00161     g_assert(client);
00162     g_assert(key && *key);
00163     return gconf_client_get_bool(client, key, NULL);
00164 }

GByteArray* ergconf_get_byte_array ( const gchar *  key  ) 

Request the byte array value stored at the specified key.

---------------------------------------------------------------------------

Name : ergconf_get_byte_array

Parameters:
[in] key - The GConf path of the key.
Returns:
A byte array representing the list of integer values stored at 'key' or NULL on error. Caller must use g_byte_array_free() to release this byte array.

--------------------------------------------------------------------------

Definition at line 219 of file gconf_utils.c.

References client.

00220 {
00221     g_assert(client);
00222     g_assert(key && *key);
00223 
00224     GByteArray *ret = NULL;
00225     GConfValue *gc_value = gconf_client_get (client, key, NULL);
00226     if (gc_value == NULL )
00227     {
00228         return NULL;
00229     }
00230 
00231     if (gc_value->type == GCONF_VALUE_LIST &&
00232         gconf_value_get_list_type (gc_value) == GCONF_VALUE_INT)
00233     {
00234         GSList *elt;
00235 
00236         ret = g_byte_array_new ();
00237         for (elt = gconf_value_get_list (gc_value); elt != NULL; elt = g_slist_next (elt))
00238         {
00239             int i = gconf_value_get_int ((GConfValue *) elt->data);
00240             guint8 val = (guint8) (i & 0xFF);
00241 
00242             if (i < 0 || i > 255)
00243             {
00244                 g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
00245                        "value %d out-of-range for a byte value", i);
00246                 g_byte_array_free (ret, TRUE);
00247                 ret = NULL;
00248                 break;  // exit for loop
00249             }
00250 
00251             g_byte_array_append (ret, &val, 1);
00252         }
00253     }
00254 
00255     if (gc_value != NULL)
00256     {
00257         gconf_value_free (gc_value);
00258     }
00259     return ret;
00260 }

int ergconf_get_int ( const gchar *  key  ) 

Request the integer value stored at the specified key.

---------------------------------------------------------------------------

Name : ergconf_get_int

Parameters:
[in] key - The GConf path of the key.
Returns:
The integer value stored at the specified key.

--------------------------------------------------------------------------

Definition at line 141 of file gconf_utils.c.

References client.

00142 {
00143     g_assert(client);
00144     g_assert(key && *key);
00145     return gconf_client_get_int(client, key, NULL);
00146 }

GArray* ergconf_get_int_array ( const gchar *  key  ) 

Get the integer array stored at the specified GConf key.

---------------------------------------------------------------------------

Name : ergconf_get_int_array

Parameters:
[in] key - The GConf path of the key.
Returns:
An array holding the integer values stored at this GConf key or NULL on error. The array hold elements of type gint. Caller must use g_array_free() to release this array.

--------------------------------------------------------------------------

Definition at line 396 of file gconf_utils.c.

References client.

00397 {
00398     GConfValue *gc_value = NULL;
00399     GArray *ret = NULL;
00400 
00401     g_assert(client);
00402     g_assert(key && *key);
00403 
00404     gc_value = gconf_client_get (client, key, NULL);
00405     if (gc_value == NULL)
00406     {
00407         return NULL;
00408     }
00409 
00410     if (gc_value->type == GCONF_VALUE_LIST
00411         && gconf_value_get_list_type (gc_value) == GCONF_VALUE_INT)
00412     {
00413         GSList *elt;
00414 
00415         ret = g_array_new (FALSE, FALSE, sizeof (gint));
00416         for (elt = gconf_value_get_list (gc_value); elt != NULL; elt = g_slist_next (elt))
00417         {
00418             int i = gconf_value_get_int ((GConfValue *) elt->data);
00419             g_array_append_val (ret, i);
00420         }
00421     }
00422 
00423     if (gc_value != NULL)
00424     {
00425         gconf_value_free (gc_value);
00426     }
00427     return ret;
00428 }

GPtrArray* ergconf_get_int_tuples ( const gchar *  key,
guint  tuple_len 
)

Get the list of integer tuples stored at the specified GConf key.

---------------------------------------------------------------------------

Name : ergconf_get_int_tuples

Parameters:
[in] key - The specified GConf key. [in] tuple_len - Number of integers in a tuple.
Returns:
An array of integer tuples, each length 'tuple_len', or NULL on error. The array holds a set of pointers to a tuple, each tuple is a GArray of 'guint32' values with length 'tuple_len'. Caller must use ergconf_free_int_tuples() to release this array and the integer tuples it contains.

--------------------------------------------------------------------------

Definition at line 452 of file gconf_utils.c.

References client.

00453 {
00454     GConfValue *gc_value = NULL;
00455     GPtrArray *ret = NULL;
00456     GSList *values, *iter;
00457     GArray *tuple = NULL;
00458 
00459     g_assert(client);
00460     g_assert(key && *key);
00461     g_return_val_if_fail (tuple_len > 0, FALSE);
00462 
00463     if (!(gc_value = gconf_client_get (client, key, NULL)))
00464     {
00465         goto out;
00466     }
00467 
00468     if (   (gc_value->type != GCONF_VALUE_LIST)
00469         || (gconf_value_get_list_type (gc_value) != GCONF_VALUE_INT))
00470     {
00471         goto out;
00472     }
00473 
00474     values = gconf_value_get_list (gc_value);
00475     if (g_slist_length (values) % tuple_len != 0)
00476     {
00477         g_warning ("%s: %s format invalid; # elements not divisible by %d",
00478                    __func__, key, tuple_len);
00479         goto out;
00480     }
00481 
00482     ret = g_ptr_array_sized_new (1);
00483     for (iter = values; iter; iter = g_slist_next (iter))
00484     {
00485         int i = gconf_value_get_int ((GConfValue *) iter->data);
00486 
00487         if (tuple == NULL)
00488         {
00489             tuple = g_array_sized_new (FALSE, TRUE, sizeof (guint32), tuple_len);
00490         }
00491 
00492         g_array_append_val (tuple, i);
00493 
00494         /* Got all members; add to the array */
00495         if (tuple->len == tuple_len)
00496         {
00497             g_ptr_array_add (ret, tuple);
00498             tuple = NULL;
00499         }
00500     }
00501 
00502 out:
00503     if (gc_value)
00504     {
00505         gconf_value_free (gc_value);
00506     }
00507     return ret;
00508 }

gchar* ergconf_get_string ( const gchar *  key  ) 

Request the string value stored at the specified key.

---------------------------------------------------------------------------

Name : ergconf_get_string

Parameters:
[in] key - The GConf path of the key.
Returns:
A string value or NULL on error. Caller must use g_free() to release this string.

--------------------------------------------------------------------------

Definition at line 177 of file gconf_utils.c.

References client.

Referenced by load_settings().

00178 {
00179     g_assert(client);
00180     g_assert(key && *key);
00181     return gconf_client_get_string(client, key, NULL);
00182 }

Here is the caller graph for this function:

GHashTable* ergconf_get_string_hash ( const gchar *  dir  ) 

Get all key-value pairs from the specified GConf directory formatted as a hash table.

---------------------------------------------------------------------------

Name : ergconf_get_string_hash

Parameters:
[in] dir - The specified GConf directory.
Returns:
A hash table holding all key-value pairs in the specified GConf directory or NULL on error. Key from GConf is used as key in the hash table. Value from GConf is converted to string and used as value in the hash table. Caller must use g_hash_table_destroy() to release this hash table.

--------------------------------------------------------------------------

Definition at line 282 of file gconf_utils.c.

References client.

00283 {
00284     g_assert(client);
00285     g_assert(dir && *dir);
00286 
00287     char *gc_key = NULL;
00288     int prefix_len = strlen (dir);
00289     GSList *iter;
00290     GSList *gconf_entries = gconf_client_all_entries (client, dir, NULL);
00291 
00292     if (gconf_entries == NULL)
00293     {
00294         return NULL;
00295     }
00296 
00297     GHashTable *ret = g_hash_table_new_full (g_str_hash,
00298                                              g_str_equal,
00299                                              (GDestroyNotify) g_free,
00300                                              (GDestroyNotify) g_free);
00301 
00302     for (iter = gconf_entries; iter; iter = iter->next)
00303     {
00304         GConfEntry *entry = (GConfEntry *) iter->data;
00305 
00306         gc_key = (char *) gconf_entry_get_key (entry);
00307         gc_key += prefix_len + 1; /* get rid of the full path */
00308 
00309         const GConfValue *gc_val = gconf_entry_get_value (entry);
00310 
00311         if (gc_val)
00312         {
00313             const char *gc_str = gconf_value_get_string (gc_val);
00314 
00315             if (gc_str != NULL && strlen (gc_str) > 0)
00316             {
00317                 g_hash_table_insert (ret, gconf_unescape_key (gc_key, -1), g_strdup (gc_str));
00318             }
00319         }
00320         gconf_entry_free (entry);
00321     }
00322 
00323     g_slist_free (gconf_entries);
00324     return ret;
00325 }

GSList* ergconf_get_string_list ( const gchar *  key  ) 

Request the string list value stored at the specified key.

---------------------------------------------------------------------------

Name : ergconf_get_string_list

Parameters:
[in] key - The GConf path of the key.
Returns:
A list of strings, each one a gchar* specifying a sub-value of 'key'. or NULL on error. Caller must use ergconf_free_string_list() to release this list and the strings it contains.

--------------------------------------------------------------------------

Definition at line 196 of file gconf_utils.c.

References client.

00197 {
00198     g_assert(client);
00199     g_assert(key && *key);
00200     return gconf_client_get_list(client, key, GCONF_VALUE_STRING, NULL);
00201 }

GSList* ergconf_get_sub_dirs ( const gchar *  dir  ) 

Get a list of sub-directories in the specified GConf directory.

---------------------------------------------------------------------------

Name : ergconf_get_sub_dirs

Parameters:
[in] dir - The specified GConf directory.
Returns:
A list of string, each one a gchar* specifying a sub-directory of 'dir'. Caller must use ergconf_free_string_list() to release this list and the strings it contains.

--------------------------------------------------------------------------

Definition at line 558 of file gconf_utils.c.

References client.

00559 {
00560     g_assert(client);
00561     g_assert(dir && *dir);
00562 
00563     GError *err = NULL;
00564     GSList *list = gconf_client_all_dirs(client, dir, &err);
00565 
00566     if (err != NULL )
00567     {
00568         g_warning ("Error while reading connection: %s", err->message);
00569         g_error_free (err);
00570         return NULL;
00571     }
00572 
00573     return list;
00574 }

void ergconf_initialize (  ) 

Initialize GConf client. Note that GConf client talks to GConf daemon and has no access to files on disk. Changes are communicated to GConf daemon, who sends these values to every other client that is interested. The timing of writing changed values to disk is determined by GConf daemon and cannot be influenced through a GConf client.

---------------------------------------------------------------------------

Name : ergconf_initialize

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 88 of file gconf_utils.c.

References client, and on_value_changed().

Referenced by main().

00089 {
00090     if (client == NULL)
00091     {
00092         client = gconf_client_get_default();
00093         g_signal_connect(G_OBJECT(client), "value-changed", G_CALLBACK(on_value_changed), NULL);
00094     }
00095 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean ergconf_is_default ( const gchar *  key  ) 

Returns if the key is set to the schema default value.

---------------------------------------------------------------------------

Name : ergconf_is_default

Parameters:
[in] key - The GConf path of the key.
Returns:
TRUE if it is default, FALSE if it doesn't.

--------------------------------------------------------------------------

Definition at line 596 of file gconf_utils.c.

References client.

00597 {
00598     g_assert(client);
00599     g_assert(key && *key);
00600     GConfEntry *entry = gconf_client_get_entry(client, key, NULL, TRUE, NULL);
00601     return gconf_entry_get_is_default(entry);
00602 }

void ergconf_recursive_unset ( const gchar *  dir  ) 

Recursively unset all values in the specified directory and its sub-directories. This function clears the value of the keys and sets them to the default value defined in the schema file. If schema file doesn't define a default one then it will be set to gconf default (e.g. for integer it will be 0).

---------------------------------------------------------------------------

Name : ergconf_recursive_unset

Parameters:
[in] dir - The specified directory.
Returns:
--

--------------------------------------------------------------------------

Definition at line 134 of file gconf_utils.c.

References client.

00135 {
00136     g_assert(client);
00137     g_assert(dir && *dir);
00138     gconf_client_recursive_unset (client, dir, 0, NULL);
00139 }

int ergconf_set_bool ( const gchar *  key,
gboolean  new_value 
)

Change the value of key to new_value.

---------------------------------------------------------------------------

Name : ergconf_set_bool

Parameters:
[in] key - The GConf path of the key. [in] new_value - The new value to be set.
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 166 of file gconf_utils.c.

References client, ER_FAIL, and ER_OK.

00167 {
00168     gboolean ok;
00169 
00170     g_assert(client);
00171     g_assert(key && *key);
00172     
00173     ok = gconf_client_set_bool(client, key, new_value, NULL);
00174     return (ok ?  ER_OK : ER_FAIL);
00175 }

int ergconf_set_byte_array ( const gchar *  key,
const GByteArray *  new_value 
)

Change the value of key to new_value.

---------------------------------------------------------------------------

Name : ergconf_set_byte_array

Parameters:
[in] key - The GConf path of the key. [in] new_value - The new value to be set, formatted as a byte array.
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 262 of file gconf_utils.c.

References client, ER_FAIL, and ER_OK.

00263 {
00264     gboolean ok;
00265     GSList *list = NULL;
00266 
00267     g_assert(client);
00268     g_assert(key && *key);
00269 
00270     unsigned int i;
00271     for (i = 0; i < new_value->len; i++)
00272     {
00273         list = g_slist_append(list, GINT_TO_POINTER ((int) new_value->data[i]));
00274     }
00275 
00276     ok = gconf_client_set_list (client, key, GCONF_VALUE_INT, list, NULL);
00277 
00278     g_slist_free (list);
00279     return (ok ? ER_OK : ER_FAIL);
00280 }

void ergconf_set_cb_value_changed ( gconf_cb_value_changed_t  callback  ) 

Set callback function for gconf value changed.

---------------------------------------------------------------------------

Name : ergconf_set_cb_value_changed

Parameters:
[in] callback - Function to be called on a value change in one of the directories set with ergconf_add_monitor_dir.
Returns:
--

--------------------------------------------------------------------------

Definition at line 106 of file gconf_utils.c.

References g_cb_value_changed.

00107 {
00108     g_cb_value_changed = callback;
00109 }

int ergconf_set_int ( const gchar *  key,
int  new_value 
)

Change the value of key to new_value.

---------------------------------------------------------------------------

Name : ergconf_set_int

Parameters:
[in] key - The GConf path of the key. [in] new_value - The new value to be set.
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 148 of file gconf_utils.c.

References client, ER_FAIL, and ER_OK.

00149 {
00150     gboolean ok;
00151 
00152     g_assert(client);
00153     g_assert(key && *key);
00154 
00155     ok = gconf_client_set_int(client, key, new_value, NULL);
00156     return (ok ?  ER_OK : ER_FAIL);
00157 }

int ergconf_set_int_array ( const gchar *  key,
const GArray *  new_value 
)

Change value of specified GConf key into the supplied integer array.

---------------------------------------------------------------------------

Name : ergconf_set_int_array

Parameters:
[in] key - The GConf path of the key. [in] new_value - An array holding 'gint' values to be stored at the specified GConf path.
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 430 of file gconf_utils.c.

References client, ER_FAIL, and ER_OK.

00431 {
00432     gboolean ret = FALSE;
00433     GSList *list = NULL;
00434 
00435     g_assert(client);
00436     g_assert(key && *key);
00437     g_return_val_if_fail(new_value != NULL, FALSE);
00438 
00439     unsigned int i;
00440     for (i = 0; i < new_value->len; i++)
00441     {
00442         gint val = g_array_index (new_value, gint, i);
00443         list = g_slist_append (list, GINT_TO_POINTER(val));
00444     }
00445 
00446     ret = gconf_client_set_list (client, key, GCONF_VALUE_INT, list, NULL);
00447 
00448     g_slist_free (list);
00449     return ret == TRUE ? ER_OK : ER_FAIL;
00450 }

int ergconf_set_int_tuples ( const gchar *  key,
const GPtrArray *  value,
guint  tuple_len 
)

Change value of the specified GConf key into the supplied array of integer tuples.

---------------------------------------------------------------------------

Name : ergconf_set_int_tuples

Parameters:
[in] key - The specified GConf key. [in] value - An array of integer tuples, each length 'tuple_len'. The array holds a set of pointers to a tuple, each tuple is a GArray of 'guint32' values with length 'tuple_len'. [in] tuple_len - Number of integers in a tuple.
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 510 of file gconf_utils.c.

References client, ER_FAIL, and ER_OK.

00511 {
00512     GSList *list = NULL;
00513     gboolean ret = FALSE;
00514 
00515     g_assert(client);
00516     g_assert(key && *key);
00517     g_return_val_if_fail(value != NULL, FALSE);
00518     g_return_val_if_fail (tuple_len > 0, FALSE);
00519 
00520     unsigned int i;
00521     for (i = 0; i < value->len; i++)
00522     {
00523         GArray *tuple = g_ptr_array_index (value, i);
00524 
00525         if (tuple->len != tuple_len)
00526         {
00527             g_warning ("%s: invalid IPv4 address/route structure!", __func__);
00528             goto out;
00529         }
00530 
00531         unsigned int j;
00532         for (j = 0; j < tuple_len; j++)
00533         {
00534             list = g_slist_append (list, GUINT_TO_POINTER (g_array_index (tuple, guint32, j)));
00535         }
00536     }
00537 
00538     ret = gconf_client_set_list (client, key, GCONF_VALUE_INT, list, NULL);
00539 
00540 out:
00541     g_slist_free (list);
00542     return ret == TRUE ? ER_OK : ER_FAIL;
00543 }

int ergconf_set_string ( const gchar *  key,
const gchar *  new_value 
)

Change the value of key to new_value.

---------------------------------------------------------------------------

Name : ergconf_set_string

Parameters:
[in] key - The GConf path of the key. [in] new_value - The new value to be set.
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 184 of file gconf_utils.c.

References client, ER_FAIL, and ER_OK.

Referenced by save_settings().

00185 {
00186     gboolean ok;
00187 
00188     g_assert(client);
00189     g_assert(key && *key);
00190     g_assert(new_value);
00191 
00192     ok = gconf_client_set_string(client, key, new_value, NULL);
00193     return (ok ?  ER_OK : ER_FAIL);
00194 }

Here is the caller graph for this function:

int ergconf_set_string_hash ( const gchar *  dir,
const GHashTable *  new_value 
)

Set all key-value pairs in the specified GConf directory, assuming all key-value pairs in this GConf directory are of type string. Keys not present in new_value will be removed from the GConf directory. Sub-directories of the GConf directory are not affected.

---------------------------------------------------------------------------

Name : ergconf_set_string_hash

Parameters:
[in] dir - The specified GConf directory. [in] new_value - A hash table holding all key-value pairs to be set
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 327 of file gconf_utils.c.

References client, ER_OK, ergconf_unset(), find_gconf_key(), FindKeyInfo::found, and write_properties_stringhash().

00328 {
00329     GSList *existing = NULL;
00330     GSList *iter;
00331 
00332     g_assert(client);
00333     g_assert(dir && *dir);
00334     g_return_val_if_fail(new_value != NULL, FALSE);
00335 
00336     /* Delete GConf entries that are not in the hash table to be written */
00337     existing = gconf_client_all_entries (client, dir, NULL);
00338     for (iter = existing; iter; iter = g_slist_next (iter))
00339     {
00340         GConfEntry *entry = (GConfEntry *) iter->data;
00341         char *basename = g_path_get_basename (entry->key);
00342         FindKeyInfo fk_info = { basename, FALSE };
00343 
00344         g_hash_table_foreach ( (GHashTable*)new_value,  // const_cast
00345                                find_gconf_key,
00346                                &fk_info );
00347         //TODO: Why not use g_hash_table_lookup_extended() here ??
00348         //TODO  Seems we don't need FindKeyInfo and find_gconf_key then.
00349         /* Be sure to never delete "special" VPN keys */
00350         if (fk_info.found == FALSE)
00351         {
00352             ergconf_unset (entry->key);
00353         }
00354 
00355         gconf_entry_free (entry);
00356         g_free (basename);
00357     }
00358     g_slist_free (existing);
00359 
00360     /* Now update entries and write new ones */
00361     g_hash_table_foreach ( (GHashTable*)new_value,  // const_cast
00362                            write_properties_stringhash,
00363                            (gpointer)dir );
00364     return ER_OK;
00365 }

Here is the call graph for this function:

int ergconf_set_string_list ( const gchar *  key,
const GSList *  new_value 
)

Change the value of key to new_value.

---------------------------------------------------------------------------

Name : ergconf_set_string_list

Parameters:
[in] key - The GConf path of the key. [in] new_value - The new value to be set, formatted as a list of strings, each one a gchar*.
Returns:
ER_OK on success, ER_SET_FAIL on error.

--------------------------------------------------------------------------

Definition at line 203 of file gconf_utils.c.

References client, ER_FAIL, and ER_OK.

00204 {
00205     gboolean ok;
00206 
00207     g_assert(client);
00208     g_assert(key && *key);
00209     g_return_val_if_fail (new_value != NULL, FALSE);
00210 
00211     ok = gconf_client_set_list ( client, 
00212                                  key,
00213                                  GCONF_VALUE_STRING,
00214                                  (GSList*)new_value,  // const_cast
00215                                  NULL );
00216     return (ok ?  ER_OK : ER_FAIL);
00217 }

void ergconf_unset ( const gchar *  key  ) 

Unset the value of the specified key. This function clears the value of the key and set it to the default value defined in the schema file. If schema file doesn't define a default one then it will be set to gconf default (e.g. for integer it will be 0).

---------------------------------------------------------------------------

Name : ergconf_unset

Parameters:
[in] key - The GConf path of the key.
Returns:
--

--------------------------------------------------------------------------

Definition at line 127 of file gconf_utils.c.

References client.

Referenced by ergconf_set_string_hash().

00128 {
00129     g_assert(client);
00130     g_assert(key && *key);
00131     gconf_client_unset(client, key, NULL);
00132 }

Here is the caller graph for this function:


Variable Documentation

G_BEGIN_DECLS typedef void(* gconf_cb_value_changed_t)(const gchar *key, GConfValue *value)

Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Generated by  doxygen 1.6.2-20100208