Skip to content

Commit

Permalink
Add helper for tracking boolean settings
Browse files Browse the repository at this point in the history
Similar to already existing inteher and string helpers.
  • Loading branch information
spiiroin committed Jan 29, 2015
1 parent 7b00a3c commit 7f69e77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mce-gconf.c
Expand Up @@ -451,6 +451,29 @@ void mce_gconf_track_int(const gchar *key, gint *val, gint def,
g_free(path);
}

/** Get initial value of boolean setting and start tracking changes
*
* @param key key name
* @param val where to store the initial value
* @param def default value to use if getting key value fails;
* or -1 to leave *val unmodified
* @param cb change notification callback
* @param cb_id where to store notification callback id
*/
void mce_gconf_track_bool(const gchar *key, gboolean *val, gint def,
GConfClientNotifyFunc cb, guint *cb_id)
{
gchar *path = mce_gconf_get_path(key);

if( path && cb && cb_id )
mce_gconf_notifier_add(path, key, cb, cb_id);

if( !mce_gconf_get_bool(key, val) && def != -1 )
*val = (def != 0);

g_free(path);
}

/** Get initial value of integer setting and start tracking changes
*
* Note: Caller must release returned string with g_free() when it
Expand Down
2 changes: 2 additions & 0 deletions mce-gconf.h
Expand Up @@ -36,6 +36,8 @@ gboolean mce_gconf_notifier_add(const gchar *path, const gchar *key,
void mce_gconf_notifier_remove(guint id);
void mce_gconf_notifier_remove_cb(gpointer cb_id, gpointer user_data);

void mce_gconf_track_bool(const gchar *key, gboolean *val, gint def,
GConfClientNotifyFunc cb, guint *cb_id);
void mce_gconf_track_int(const gchar *key, gint *val, gint def,
GConfClientNotifyFunc cb, guint *cb_id);
void mce_gconf_track_string(const gchar *key, gchar **val, const gchar *def,
Expand Down

0 comments on commit 7f69e77

Please sign in to comment.