X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-conf.c;h=835d2873abd8ba803274fa1acadfa14034e92dd8;hp=767f5b90c9ecf2e97a1105ed757a99262042ec54;hb=4d39841513a3a7f7aa9d38ab97cb9fcc9171e80b;hpb=362784ce756b3f0e31cd451d9ac5e69b909d4053 diff --git a/src/modest-conf.c b/src/modest-conf.c index 767f5b9..835d287 100644 --- a/src/modest-conf.c +++ b/src/modest-conf.c @@ -31,7 +31,9 @@ #include #include #include +#include "modest-defs.h" #include "modest-conf.h" +#include "modest-error.h" #include "modest-marshal.h" #include @@ -114,10 +116,9 @@ static void modest_conf_init (ModestConf *obj) { GConfClient *conf = NULL; + GError *error = NULL; ModestConfPrivate *priv = MODEST_CONF_GET_PRIVATE(obj); -/* GError *err = NULL; */ - priv->gconf_client = NULL; conf = gconf_client_get_default (); @@ -125,28 +126,26 @@ modest_conf_init (ModestConf *obj) g_printerr ("modest: could not get gconf client\n"); return; } -/* gconf_client_add_dir (conf,MODEST_CONF_NAMESPACE, */ -/* GCONF_CLIENT_PRELOAD_NONE, */ -/* &err); */ -/* if (err) { */ -/* g_printerr ("modest: error %d with gconf_client_add_dir: '%s'\n", */ -/* err->code, err->message); */ -/* g_object_unref (conf); */ -/* g_error_free (err); */ -/* return; */ -/* } */ - -/* gconf_client_notify_add (conf, MODEST_CONF_NAMESPACE, */ -/* modest_conf_on_change, */ -/* obj, NULL, &err); */ -/* if (err) { */ -/* g_printerr ("modest: gconf_client_notify_add error %d: '%s'\n", */ -/* err->code, err->message); */ -/* g_object_unref (conf); */ -/* g_error_free (err); */ -/* return; */ -/* } */ - priv->gconf_client = conf; /* all went well! */ + + priv->gconf_client = conf; + + /* All the tree will be listened */ + gconf_client_add_dir (priv->gconf_client, + "/apps/modest", + GCONF_CLIENT_PRELOAD_NONE, + &error); + + /* Notify every change under namespace */ + if (!error) { + gconf_client_notify_add (priv->gconf_client, + "/apps/modest", + modest_conf_on_change, + obj, + NULL, + &error); + } else { + g_error_free (error); + } } static void @@ -213,6 +212,18 @@ modest_conf_get_int (ModestConf* self, const gchar* key, GError **err) return gconf_client_get_int (priv->gconf_client, key, err); } +gdouble +modest_conf_get_float (ModestConf* self, const gchar* key, GError **err) +{ + ModestConfPrivate *priv; + + g_return_val_if_fail (self, -1); + g_return_val_if_fail (key, -1); + + priv = MODEST_CONF_GET_PRIVATE(self); + + return gconf_client_get_float (priv->gconf_client, key, err); +} gboolean modest_conf_get_bool (ModestConf* self, const gchar* key, GError **err) @@ -287,6 +298,27 @@ modest_conf_set_int (ModestConf* self, const gchar* key, gint val, return gconf_client_set_int (priv->gconf_client, key, val, err); } +gboolean +modest_conf_set_float (ModestConf* self, + const gchar* key, + gdouble val, + GError **err) +{ + ModestConfPrivate *priv; + + g_return_val_if_fail (self,FALSE); + g_return_val_if_fail (key, FALSE); + + priv = MODEST_CONF_GET_PRIVATE(self); + + if (!gconf_client_key_is_writable(priv->gconf_client,key,err)) { + g_printerr ("modest: '%s' is not writable\n", key); + return FALSE; + } + + return gconf_client_set_float (priv->gconf_client, key, val, err); +} + gboolean modest_conf_set_bool (ModestConf* self, const gchar* key, gboolean val, @@ -315,7 +347,6 @@ modest_conf_set_list (ModestConf* self, const gchar* key, { ModestConfPrivate *priv; GConfValueType gconf_type; - gboolean result; g_return_val_if_fail (self, FALSE); g_return_val_if_fail (key, FALSE); @@ -323,31 +354,8 @@ modest_conf_set_list (ModestConf* self, const gchar* key, priv = MODEST_CONF_GET_PRIVATE(self); gconf_type = modest_conf_type_to_gconf_type (list_type, err); - if (*err) - return FALSE; - result = gconf_client_set_list (priv->gconf_client, key, gconf_type, val, err); - if(*err) { - g_warning("gconf_client_set_list() failed with key=%s. error=%s", key, - (*err)->message); - result = FALSE; - } - - /* TODO: Remove this, when we fix the problem: */ - /* This shows that sometimes set_list fails, while saying that it succeeded: */ - if (result) { - const gint debug_list_length_start = g_slist_length(val); - GSList* debug_list = gconf_client_get_list(priv->gconf_client, key, gconf_type, err); - const gint debug_list_length_after = g_slist_length(debug_list); - - if(debug_list_length_start != debug_list_length_after) - g_warning("modest_conf_set_list(): The list length after setting is " - "not the same as the specified list. key=%s. " - "We think that we fixed this, so tell us if you see this.", key); - g_slist_free(debug_list); - } - - return result; + return gconf_client_set_list (priv->gconf_client, key, gconf_type, val, err); } @@ -449,7 +457,6 @@ modest_conf_on_change (GConfClient *client, key, event, conn_id); } - static GConfValueType modest_conf_type_to_gconf_type (ModestConfValueType value_type, GError **err) { @@ -469,53 +476,38 @@ modest_conf_type_to_gconf_type (ModestConfValueType value_type, GError **err) gconf_type = GCONF_VALUE_STRING; break; default: - /* FIXME: use MODEST_ERROR, and error code */ gconf_type = GCONF_VALUE_INVALID; g_printerr ("modest: invalid list value type %d\n", value_type); - *err = g_error_new_literal (0, 0, "invalid list value type"); - } + *err = g_error_new_literal (MODEST_CONF_ERROR, + MODEST_CONF_ERROR_INVALID_VALUE, + "invalid list value type"); + } return gconf_type; } -ModestConfNotificationId +void modest_conf_listen_to_namespace (ModestConf *self, const gchar *namespace) { ModestConfPrivate *priv; GError *error = NULL; - ModestConfNotificationId notification_id; - g_return_val_if_fail (MODEST_IS_CONF (self), 0); - g_return_val_if_fail (namespace, 0); + g_return_if_fail (MODEST_IS_CONF (self)); + g_return_if_fail (namespace); priv = MODEST_CONF_GET_PRIVATE(self); /* Add the namespace to the list of the namespaces that will be observed */ - gconf_client_add_dir (priv->gconf_client, namespace, + gconf_client_add_dir (priv->gconf_client, + namespace, GCONF_CLIENT_PRELOAD_NONE, &error); - - if (error) - return 0; - - /* Notify every change under namespace */ - notification_id = gconf_client_notify_add (priv->gconf_client, - namespace, - modest_conf_on_change, - self, - NULL, - &error); - if (error) - return 0; - else - return notification_id; } void modest_conf_forget_namespace (ModestConf *self, - const gchar *namespace, - ModestConfNotificationId id) + const gchar *namespace) { ModestConfPrivate *priv; @@ -527,7 +519,4 @@ modest_conf_forget_namespace (ModestConf *self, /* Remove the namespace to the list of the namespaces that will be observed */ gconf_client_remove_dir (priv->gconf_client, namespace, NULL); - - /* Notify every change under namespace */ - gconf_client_notify_remove (priv->gconf_client, id); }