From e427d3062be82355bdca744951d7fe01c39e55e6 Mon Sep 17 00:00:00 2001 From: Florian Boor Date: Mon, 12 Jun 2006 17:05:07 +0000 Subject: [PATCH] * Create signal on gconf key change and propagate event to account manager. pmo-trunk-r239 --- src/modest-account-mgr.c | 13 +++++++ src/modest-conf-gconf.c | 78 +++++++++++++++++++++++++++++++--------- src/modest-conf.h | 4 +-- src/modest-tny-account-store.c | 2 +- 4 files changed, 77 insertions(+), 20 deletions(-) diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 1eb0d6c..9196af6 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -35,6 +35,16 @@ static GObjectClass *parent_class = NULL; /* uncomment the following if you have defined any signals */ /* static guint signals[LAST_SIGNAL] = {0}; */ +static void +modest_account_mgr_check_change (ModestConf *conf, const gchar *key, + const gchar *new_value, gpointer user_data) +{ + ModestAccountMgr *amgr = user_data; + + g_message ("value changed: %s %s\n", key, new_value); +} + + GType modest_account_mgr_get_type (void) { @@ -118,6 +128,9 @@ modest_account_mgr_new (ModestConf * conf) * ModestConf should outlive the ModestAccountMgr though */ g_object_ref (G_OBJECT (priv->modest_conf = conf)); + + g_signal_connect (G_OBJECT (conf), "key-changed", + G_CALLBACK (modest_account_mgr_check_change), obj); return obj; } diff --git a/src/modest-conf-gconf.c b/src/modest-conf-gconf.c index 20d4385..c6668a6 100644 --- a/src/modest-conf-gconf.c +++ b/src/modest-conf-gconf.c @@ -16,8 +16,7 @@ static void modest_conf_on_change (GConfClient *client, guint conn_id, GConfEntry *entry, gpointer data); /* list my signals */ enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ + KEY_CHANGED_SIGNAL, LAST_SIGNAL }; @@ -31,8 +30,46 @@ struct _ModestConfPrivate { /* globals */ static GObjectClass *parent_class = NULL; -/* uncomment the following if you have defined any signals */ -/* static guint signals[LAST_SIGNAL] = {0}; */ +static guint signals[LAST_SIGNAL] = {0}; + +typedef void (*MarshalFunc_VOID__POINTER_POINTER) (gpointer data1, + gpointer arg_1, gpointer arg_2, gpointer data2); + + +static void +modest_marshal_VOID__POINTER_POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + MarshalFunc_VOID__POINTER_POINTER callback; + GCClosure *cc = (GCClosure*) closure; + gpointer data1, data2; + + g_return_if_fail (n_param_values == 3); + + if (G_CCLOSURE_SWAP_DATA (closure)) { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } else { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + + callback = (MarshalFunc_VOID__POINTER_POINTER) (marshal_data ? marshal_data : cc->callback); + + callback (data1, g_value_get_pointer (param_values + 1), + g_value_get_pointer (param_values + 2), data2); +} + +void +modest_conf_key_changed (ModestConf* self, const gchar *key, const gchar *new_value) +{ + +} + GType modest_conf_get_type (void) @@ -67,13 +104,16 @@ modest_conf_class_init (ModestConfClass *klass) gobject_class->finalize = modest_conf_finalize; g_type_class_add_private (gobject_class, sizeof(ModestConfPrivate)); - - /* signal definitions go here, e.g.: */ -/* signals[MY_SIGNAL_1] = */ -/* g_signal_new ("my_signal_1",....); */ -/* signals[MY_SIGNAL_2] = */ -/* g_signal_new ("my_signal_2",....); */ -/* etc. */ + + klass->key_changed = modest_conf_key_changed; + + signals[KEY_CHANGED_SIGNAL] = + g_signal_new ("key-changed", + G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(ModestConfClass, key_changed), + NULL, NULL, + modest_marshal_VOID__POINTER_POINTER, + G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); } static void @@ -92,8 +132,8 @@ modest_conf_init (ModestConf *obj) } /* FIXME: is PRELOAD_NONE the most efficient? */ - gconf_client_add_dir (conf,MODEST_CONF_NAMESPACE, - GCONF_CLIENT_PRELOAD_NONE,&err); + gconf_client_add_dir (conf, MODEST_CONF_NAMESPACE, + GCONF_CLIENT_PRELOAD_NONE, &err); if (err) { g_warning ("error with gconf_client_add_dir: %d:%s", err->code, err->message); @@ -302,15 +342,19 @@ static void modest_conf_on_change (GConfClient *client, guint conn_id, GConfEntry *entry, gpointer data) { - /* FIXME: emit a signal here */ - - if (!entry->value) + ModestConf *modest_conf = data; + + if (!entry->value) { g_print ("modest: key '%s' unset\n", gconf_entry_get_key (entry)); - else { + g_signal_emit (modest_conf, signals[KEY_CHANGED_SIGNAL], 0, + gconf_entry_get_key (entry), NULL); + } else { gchar *val = gconf_value_to_string (gconf_entry_get_value(entry)); g_print ("modest: key '%s' set to '%s'\n", gconf_entry_get_key (entry), val); + g_signal_emit (modest_conf, signals[KEY_CHANGED_SIGNAL], 0, + gconf_entry_get_key (entry), val); g_free (val); } } diff --git a/src/modest-conf.h b/src/modest-conf.h index 60b5f29..3899592 100644 --- a/src/modest-conf.h +++ b/src/modest-conf.h @@ -27,8 +27,8 @@ struct _ModestConf { struct _ModestConfClass { GObjectClass parent_class; - /* insert signal callback declarations, eg. */ - /* void (* my_event) (ModestConf* obj); */ + + void (* key_changed) (ModestConf* self, const gchar *key, const gchar *new_value); }; diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 549a7c6..86f7190 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -107,7 +107,7 @@ modest_tny_account_store_class_init (ModestTnyAccountStoreClass *klass) g_signal_new ("password_requested", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(ModestTnyAccountStoreClass,password_requested), + G_STRUCT_OFFSET(ModestTnyAccountStoreClass, password_requested), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); -- 1.7.9.5