X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-conf.c;h=767f5b90c9ecf2e97a1105ed757a99262042ec54;hb=8376cf7ef539a483f17fc1e4d88a5ac91acaa24a;hp=ca44ae0949dd3fa659036f075cfc270e7d6b221e;hpb=bf6e43d62eff0df15430c31e01ecf3ad6f9dbaf7;p=modest diff --git a/src/modest-conf.c b/src/modest-conf.c index ca44ae0..767f5b9 100644 --- a/src/modest-conf.c +++ b/src/modest-conf.c @@ -28,6 +28,7 @@ */ #include +#include #include #include #include "modest-conf.h" @@ -35,12 +36,17 @@ #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, @@ -100,8 +106,8 @@ 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 @@ -109,7 +115,8 @@ modest_conf_init (ModestConf *obj) { GConfClient *conf = NULL; ModestConfPrivate *priv = MODEST_CONF_GET_PRIVATE(obj); - GError *err = NULL; +/* GError *err = NULL; */ + priv->gconf_client = NULL; @@ -118,29 +125,27 @@ 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; - } +/* 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! */ } @@ -260,10 +265,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) @@ -280,7 +284,7 @@ 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); } @@ -299,8 +303,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); } @@ -338,10 +342,11 @@ modest_conf_set_list (ModestConf* self, const gchar* key, 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", key); + "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; } @@ -427,10 +432,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; @@ -441,9 +446,10 @@ 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) { @@ -470,3 +476,58 @@ modest_conf_type_to_gconf_type (ModestConfValueType value_type, GError **err) } return gconf_type; } + +ModestConfNotificationId +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); + + 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); + + 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) +{ + 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); + + /* Notify every change under namespace */ + gconf_client_notify_remove (priv->gconf_client, id); +}