*/
#include <gconf/gconf-client.h>
+#include <config.h>
#include <string.h>
#include <glib/gi18n.h>
#include "modest-conf.h"
#include <stdio.h>
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,
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;
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
{
GConfClient *conf = NULL;
ModestConfPrivate *priv = MODEST_CONF_GET_PRIVATE(obj);
- GError *err = NULL;
+/* GError *err = NULL; */
+
priv->gconf_client = NULL;
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! */
}
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);
}
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);
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)
return FALSE;
}
- return gconf_client_set_int (priv->gconf_client, key, val, err);
+ return gconf_client_set_int (priv->gconf_client, key, val, err);
}
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);
}
GSList *val, ModestConfValueType list_type,
GError **err)
{
- ModestConfPrivate *priv;
- GConfValueType gconf_type;
+ ModestConfPrivate *priv;
+ GConfValueType gconf_type;
+ gboolean result;
- g_return_val_if_fail (self, FALSE);
- g_return_val_if_fail (key, FALSE);
-
- priv = MODEST_CONF_GET_PRIVATE(self);
+ g_return_val_if_fail (self, FALSE);
+ g_return_val_if_fail (key, FALSE);
- gconf_type = modest_conf_type_to_gconf_type (list_type, err);
- if (*err)
- return FALSE;
+ priv = MODEST_CONF_GET_PRIVATE(self);
+ gconf_type = modest_conf_type_to_gconf_type (list_type, err);
+ if (*err)
+ return FALSE;
- gboolean 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;
- }
+ 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", key);
-
- g_slist_free(debug_list);
- }
-
+ /* 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_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;
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:
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;
}
+
+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);
+}