X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-conf.c;h=ca7d8be06ad5065cb03fa2f180fa4d897f85e2ff;hp=44632460965c4455a2722dffec01e321c4185cf4;hb=5a2f7c90ce1a6e578fe4dd2a50cfb4279f98cb50;hpb=99ebf602d6728ff8423c965eaf86fa84a7ce2de0 diff --git a/src/modest-conf.c b/src/modest-conf.c index 4463246..ca7d8be 100644 --- a/src/modest-conf.c +++ b/src/modest-conf.c @@ -28,18 +28,26 @@ */ #include +#include #include #include +#include "modest-defs.h" #include "modest-conf.h" #include "modest-marshal.h" +#include static void modest_conf_class_init (ModestConfClass *klass); + 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, @@ -53,8 +61,8 @@ struct _ModestConfPrivate { GConfClient *gconf_client; }; #define MODEST_CONF_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ - MODEST_TYPE_CONF, \ - ModestConfPrivate)) + MODEST_TYPE_CONF, \ + ModestConfPrivate)) /* globals */ static GObjectClass *parent_class = NULL; @@ -99,17 +107,17 @@ modest_conf_class_init (ModestConfClass *klass) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (ModestConfClass,key_changed), NULL, NULL, - modest_marshal_VOID__STRING_INT, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT); + modest_marshal_VOID__STRING_INT_INT, + G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); } 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 (); @@ -118,29 +126,25 @@ modest_conf_init (ModestConf *obj) return; } - gconf_client_add_dir (conf,MODEST_CONF_NAMESPACE, + priv->gconf_client = conf; + + /* All the tree will be listened */ + gconf_client_add_dir (priv->gconf_client, + "/apps/modest", 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; + &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); } - - priv->gconf_client = conf; /* all went well! */ } static void @@ -207,6 +211,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) @@ -226,17 +242,17 @@ GSList * modest_conf_get_list (ModestConf* self, const gchar* key, ModestConfValueType list_type, GError **err) { - ModestConfPrivate *priv; - GConfValueType gconf_type; + ModestConfPrivate *priv; + GConfValueType gconf_type; - g_return_val_if_fail (self, NULL); - g_return_val_if_fail (key, NULL); + g_return_val_if_fail (self, NULL); + g_return_val_if_fail (key, NULL); - priv = MODEST_CONF_GET_PRIVATE(self); + priv = MODEST_CONF_GET_PRIVATE(self); - gconf_type = modest_conf_type_to_gconf_type (list_type, err); + gconf_type = modest_conf_type_to_gconf_type (list_type, err); - return gconf_client_get_list (priv->gconf_client, key, gconf_type, err); + return gconf_client_get_list (priv->gconf_client, key, gconf_type, err); } @@ -250,6 +266,7 @@ modest_conf_set_string (ModestConf* self, const gchar* key, const gchar* val, g_return_val_if_fail (self,FALSE); g_return_val_if_fail (key, FALSE); + g_return_val_if_fail (val, FALSE); priv = MODEST_CONF_GET_PRIVATE(self); @@ -258,10 +275,9 @@ modest_conf_set_string (ModestConf* self, const gchar* key, const gchar* val, return FALSE; } - return gconf_client_set_string (priv->gconf_client, key, val, err); + return gconf_client_set_string (priv->gconf_client, key, val, err); } - gboolean modest_conf_set_int (ModestConf* self, const gchar* key, gint val, GError **err) @@ -278,7 +294,28 @@ modest_conf_set_int (ModestConf* self, const gchar* key, gint val, return FALSE; } - return gconf_client_set_int (priv->gconf_client, key, val, err); + 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); } @@ -297,8 +334,8 @@ modest_conf_set_bool (ModestConf* self, const gchar* key, gboolean val, g_warning ("modest: '%s' is not writable\n", key); return FALSE; } - - return gconf_client_set_bool (priv->gconf_client,key,val, err); + + return gconf_client_set_bool (priv->gconf_client, key, val, err); } @@ -307,19 +344,17 @@ modest_conf_set_list (ModestConf* self, const gchar* key, GSList *val, ModestConfValueType list_type, GError **err) { - ModestConfPrivate *priv; - GConfValueType gconf_type; + ModestConfPrivate *priv; + GConfValueType gconf_type; - g_return_val_if_fail (self, FALSE); - g_return_val_if_fail (key, FALSE); + g_return_val_if_fail (self, FALSE); + g_return_val_if_fail (key, FALSE); - priv = MODEST_CONF_GET_PRIVATE(self); + priv = MODEST_CONF_GET_PRIVATE(self); - gconf_type = modest_conf_type_to_gconf_type (list_type, err); - if (*err) - return FALSE; + gconf_type = modest_conf_type_to_gconf_type (list_type, err); - return gconf_client_set_list (priv->gconf_client, key, gconf_type, val, err); + return gconf_client_set_list (priv->gconf_client, key, gconf_type, val, err); } @@ -384,7 +419,7 @@ gchar* modest_conf_key_escape (const gchar* key) { g_return_val_if_fail (key, NULL); - g_return_val_if_fail (strlen (key) > 0, key); + g_return_val_if_fail (strlen (key) > 0, g_strdup (key)); return gconf_escape_key (key, strlen(key)); } @@ -404,10 +439,10 @@ 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, +modest_conf_on_change (GConfClient *client, + guint conn_id, + GConfEntry *entry, gpointer data) { ModestConfEvent event; @@ -418,13 +453,13 @@ modest_conf_on_change (GConfClient *client, guint conn_id, GConfEntry *entry, g_signal_emit (G_OBJECT(data), signals[KEY_CHANGED_SIGNAL], 0, - key, event); + key, event, conn_id); } static GConfValueType modest_conf_type_to_gconf_type (ModestConfValueType value_type, GError **err) { - GConfValueType gconf_type = 0; + GConfValueType gconf_type; switch (value_type) { case MODEST_CONF_VALUE_INT: @@ -441,7 +476,45 @@ modest_conf_type_to_gconf_type (ModestConfValueType value_type, GError **err) break; default: /* FIXME: use MODEST_ERROR, and error code */ - *err = g_error_new_literal (0, 0, _("Invalid list value type")); - } + 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"); + } return gconf_type; } + +void +modest_conf_listen_to_namespace (ModestConf *self, + const gchar *namespace) +{ + ModestConfPrivate *priv; + GError *error = NULL; + + 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_PRELOAD_NONE, + &error); +} + +void +modest_conf_forget_namespace (ModestConf *self, + const gchar *namespace) +{ + ModestConfPrivate *priv; + + g_return_if_fail (MODEST_IS_CONF (self)); + g_return_if_fail (namespace); + + priv = MODEST_CONF_GET_PRIVATE(self); + + /* Remove the namespace to the list of the namespaces that will + be observed */ + gconf_client_remove_dir (priv->gconf_client, namespace, NULL); +}