*/
#include <gconf/gconf-client.h>
+#include <config.h>
#include <string.h>
#include <glib/gi18n.h>
#include "modest-conf.h"
GConfEntry *entry, gpointer data);
static GConfValueType modest_conf_type_to_gconf_type (ModestConfValueType value_type,
GError **err);
+
+
+static void
+modest_conf_maemo_fake_on_change (ModestConf *conf, const gchar* key, ModestConfEvent event);
+
/* list my signals */
enum {
KEY_CHANGED_SIGNAL,
GConfClient *conf = NULL;
ModestConfPrivate *priv = MODEST_CONF_GET_PRIVATE(obj);
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);
g_error_free (err);
return;
}
-
priv->gconf_client = conf; /* all went well! */
}
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);
+ if (gconf_client_set_string (priv->gconf_client, key, val, err)) {
+ modest_conf_maemo_fake_on_change (self, key, MODEST_CONF_EVENT_KEY_CHANGED);
+ return TRUE;
+ } else
+ return FALSE;
}
return FALSE;
}
- return gconf_client_set_int (priv->gconf_client, key, val, err);
+ if (gconf_client_set_int (priv->gconf_client, key, val, err)) {
+ modest_conf_maemo_fake_on_change (self, key, MODEST_CONF_EVENT_KEY_CHANGED);
+ return TRUE;
+ } else
+ return FALSE;
}
g_warning ("modest: '%s' is not writable\n", key);
return FALSE;
}
-
- return gconf_client_set_bool (priv->gconf_client,key,val, err);
+
+ if (gconf_client_set_bool (priv->gconf_client, key, val, err)) {
+ modest_conf_maemo_fake_on_change (self, key, MODEST_CONF_EVENT_KEY_CHANGED);
+ return TRUE;
+ } else
+ return FALSE;
}
"not the same as the specified list. key=%s", key);
g_slist_free(debug_list);
}
-
+
+ if (result)
+ modest_conf_maemo_fake_on_change (self, key, MODEST_CONF_EVENT_KEY_CHANGED);
+
return result;
}
retval = gconf_client_recursive_unset (priv->gconf_client,key,0,err);
gconf_client_suggest_sync (priv->gconf_client, NULL);
- return retval;
+ if (retval) {
+ modest_conf_maemo_fake_on_change (self, key, MODEST_CONF_EVENT_KEY_UNSET);
+ return TRUE;
+ } else
+ return FALSE;
}
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)
{
+ /*
+ * on maemo, there's a nasty bug in gconf, which makes it really
+ * slow, for updates and notifications. as an ugly hack, we turn off all
+ * gconf-based notifications, and send them ourselves, a short time
+ * after we do a change. this does not work for non-modest-conf
+ * changes of course...
+ */
+#ifndef MODEST_PLATFORM_MAEMO
+
ModestConfEvent event;
const gchar* key;
g_signal_emit (G_OBJECT(data),
signals[KEY_CHANGED_SIGNAL], 0,
key, event);
+#endif /*!MODEST_PLATFORM_MAEMO*/
}
+
static GConfValueType
modest_conf_type_to_gconf_type (ModestConfValueType value_type, GError **err)
{
}
return gconf_type;
}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+/* workaround for the b0rked dbus-gconf on maemo */
+/* fires a fake change notification after 0.3 secs */
+#ifdef MODEST_PLATFORM_MAEMO
+typedef struct {
+ GObject *obj;
+ gchar *key;
+} ChangeHelper;
+
+
+ChangeHelper*
+change_helper_new (ModestConf *conf, const gchar *key)
+{
+ ChangeHelper *helper = g_slice_alloc (sizeof(ChangeHelper));
+ helper->obj = g_object_ref(G_OBJECT(conf));
+ helper->key = g_strdup (key);
+ return helper;
+}
+
+static void
+change_helper_free (ChangeHelper *helper)
+{
+ g_object_unref (helper->obj);
+ g_free (helper->key);
+ helper->key = NULL;
+ helper->obj = NULL;
+ g_slice_free (ChangeHelper,helper);
+}
+
+static gboolean
+emit_change_cb (ChangeHelper *helper)
+{
+ if (!helper)
+ return FALSE;
+ g_signal_emit (G_OBJECT(helper->obj),signals[KEY_CHANGED_SIGNAL], 0,
+ helper->key, MODEST_CONF_EVENT_KEY_CHANGED);
+ change_helper_free (helper);
+
+ return FALSE;
+}
+
+static gboolean
+emit_remove_cb (ChangeHelper *helper)
+{
+ if (!helper)
+ return FALSE;
+ g_signal_emit (G_OBJECT(helper->obj),signals[KEY_CHANGED_SIGNAL], 0,
+ helper->key, MODEST_CONF_EVENT_KEY_UNSET);
+ change_helper_free (helper);
+
+ return FALSE;
+}
+#endif /* MODEST_PLATFORM_MAEMO */
+
+static void
+modest_conf_maemo_fake_on_change (ModestConf *conf, const gchar* key, ModestConfEvent event)
+{
+#ifdef MODEST_PLATFORM_MAEMO
+
+ ChangeHelper *helper = change_helper_new (conf,key);
+ g_timeout_add (100, /* after 100 ms */
+ (event == MODEST_CONF_EVENT_KEY_CHANGED)
+ ? (GSourceFunc)emit_change_cb : (GSourceFunc)emit_remove_cb,
+ (gpointer)helper);
+#endif /*MODEST_PLATFORM_MAEMO*/
+}
+//////////////////////////////////////////////////////////////////////////////////