X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-conf.c;h=183ef1b3f026a41dfd78b52fe560b9f31ad997f3;hb=2cfe57ee3609ed5ce81739adf2a00c28a68d158f;hp=c6535e79dae573a2d5195263f24268c913a8bf8a;hpb=1f01526060a46ef283c748f34c6a650b16f6d176;p=modest diff --git a/src/modest-conf.c b/src/modest-conf.c index c6535e7..183ef1b 100644 --- a/src/modest-conf.c +++ b/src/modest-conf.c @@ -29,6 +29,7 @@ #include #include +#include #include "modest-conf.h" #include "modest-marshal.h" @@ -37,6 +38,8 @@ static void modest_conf_init (ModestConf *obj); static void modest_conf_finalize (GObject *obj); static void modest_conf_on_change (GConfClient *client, guint conn_id, GConfEntry *entry, gpointer data); +static GConfValueType modest_conf_type_to_gconf_type (ModestConfValueType value_type, + GError **err); /* list my signals */ enum { KEY_CHANGED_SIGNAL, @@ -219,54 +222,21 @@ modest_conf_get_bool (ModestConf* self, const gchar* key, GError **err) } - -gchar* -modest_conf_get_string_or_default (ModestConf* self, const gchar* key, - const gchar *defaultval) -{ - ModestConfPrivate *priv; - GConfValue *val; - const gchar *str; - - g_return_val_if_fail (self, g_strdup(defaultval)); - g_return_val_if_fail (key, g_strdup(defaultval)); - - priv = MODEST_CONF_GET_PRIVATE(self); - val = gconf_client_get (priv->gconf_client, key, NULL); - - if (!val) - str = defaultval; - else { - str = gconf_value_get_string (val); - gconf_value_free (val); - } - - return g_strdup (str); -} - - -gint -modest_conf_get_int_or_default (ModestConf* self, const gchar* key, - gint defaultval) +GSList * +modest_conf_get_list (ModestConf* self, const gchar* key, ModestConfValueType list_type, + GError **err) { - ModestConfPrivate *priv; - GConfValue *val; - gint retval; - - g_return_val_if_fail (self, defaultval); - g_return_val_if_fail (key, defaultval); + ModestConfPrivate *priv; + GConfValueType gconf_type; + + g_return_val_if_fail (self, NULL); + g_return_val_if_fail (key, NULL); - priv = MODEST_CONF_GET_PRIVATE(self); - val = gconf_client_get (priv->gconf_client, key, NULL); + priv = MODEST_CONF_GET_PRIVATE(self); - if (!val) - retval = defaultval; - else { - retval = gconf_value_get_int (val); - gconf_value_free (val); - } + gconf_type = modest_conf_type_to_gconf_type (list_type, err); - return retval; + return gconf_client_get_list (priv->gconf_client, key, gconf_type, err); } @@ -332,6 +302,25 @@ modest_conf_set_bool (ModestConf* self, const gchar* key, gboolean val, } +gboolean +modest_conf_set_list (ModestConf* self, const gchar* key, + GSList *val, ModestConfValueType list_type, + GError **err) +{ + ModestConfPrivate *priv; + GConfValueType gconf_type; + + g_return_val_if_fail (self, FALSE); + g_return_val_if_fail (key, FALSE); + + priv = MODEST_CONF_GET_PRIVATE(self); + + gconf_type = modest_conf_type_to_gconf_type (list_type, err); + if (*err) + return FALSE; + + return gconf_client_set_list (priv->gconf_client, key, gconf_type, val, err); +} GSList* @@ -392,24 +381,31 @@ modest_conf_key_exists (ModestConf* self, const gchar* key, GError **err) gchar* -modest_conf_key_escape (ModestConf *self, const gchar* key) +modest_conf_key_escape (const gchar* key) { g_return_val_if_fail (key, NULL); - + g_return_val_if_fail (strlen (key) > 0, g_strdup (key)); + return gconf_escape_key (key, strlen(key)); } gchar* -modest_conf_key_unescape (ModestConf *self, const gchar* key) +modest_conf_key_unescape (const gchar* key) { g_return_val_if_fail (key, NULL); return gconf_unescape_key (key, strlen(key)); } +gboolean +modest_conf_key_is_valid (const gchar* key) +{ + return gconf_valid_key (key, NULL); +} +/* hmmm... might need to make specific callback for specific keys */ static void modest_conf_on_change (GConfClient *client, guint conn_id, GConfEntry *entry, gpointer data) @@ -425,18 +421,12 @@ modest_conf_on_change (GConfClient *client, guint conn_id, GConfEntry *entry, key, event); } -GSList * -modest_conf_get_list (ModestConf* self, const gchar* key, ModestConfValueType list_type, GError **err) +static GConfValueType +modest_conf_type_to_gconf_type (ModestConfValueType value_type, GError **err) { - ModestConfPrivate *priv; - GConfValueType gconf_type; - - g_return_val_if_fail (self, NULL); - g_return_val_if_fail (key, NULL); - - priv = MODEST_CONF_GET_PRIVATE(self); + GConfValueType gconf_type = 0; - switch (list_type) { + switch (value_type) { case MODEST_CONF_VALUE_INT: gconf_type = GCONF_VALUE_INT; break; @@ -450,8 +440,8 @@ modest_conf_get_list (ModestConf* self, const gchar* key, ModestConfValueType li gconf_type = GCONF_VALUE_STRING; break; default: - return NULL; + /* FIXME: use MODEST_ERROR, and error code */ + *err = g_error_new_literal (0, 0, _("Invalid list value type")); } - - return gconf_client_get_list (priv->gconf_client, key, gconf_type, err); + return gconf_type; }