* Create signal on gconf key change and propagate event to account manager.
authorFlorian Boor <florian@kernelconcepts.de>
Mon, 12 Jun 2006 17:05:07 +0000 (17:05 +0000)
committerFlorian Boor <florian@kernelconcepts.de>
Mon, 12 Jun 2006 17:05:07 +0000 (17:05 +0000)
pmo-trunk-r239

src/modest-account-mgr.c
src/modest-conf-gconf.c
src/modest-conf.h
src/modest-tny-account-store.c

index 1eb0d6c..9196af6 100644 (file)
@@ -35,6 +35,16 @@ static GObjectClass *parent_class = NULL;
 /* uncomment the following if you have defined any signals */
 /* static guint signals[LAST_SIGNAL] = {0}; */
 
 /* 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)
 {
 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));
         * 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;
 }
 
        return obj;
 }
 
index 20d4385..c6668a6 100644 (file)
@@ -16,8 +16,7 @@ static void   modest_conf_on_change    (GConfClient *client, guint conn_id,
                                          GConfEntry *entry, gpointer data);
 /* list my signals */
 enum {
                                          GConfEntry *entry, gpointer data);
 /* list my signals */
 enum {
-       /* MY_SIGNAL_1, */
-       /* MY_SIGNAL_2, */
+       KEY_CHANGED_SIGNAL,
        LAST_SIGNAL
 };
 
        LAST_SIGNAL
 };
 
@@ -31,8 +30,46 @@ struct _ModestConfPrivate {
 /* globals */
 static GObjectClass *parent_class = NULL;
 
 /* 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)
 
 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));
        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
 }
 
 static void
@@ -92,8 +132,8 @@ modest_conf_init (ModestConf *obj)
        }
 
        /* FIXME: is PRELOAD_NONE the most efficient? */
        }
 
        /* 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);
        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)
 {
 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));
                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);
                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);
        }
 }
                g_free (val);
        }
 }
index 60b5f29..3899592 100644 (file)
@@ -27,8 +27,8 @@ struct _ModestConf {
 
 struct _ModestConfClass {
        GObjectClass parent_class;
 
 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);
 };
 
 
 };
 
 
index 549a7c6..86f7190 100644 (file)
@@ -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_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);
                              NULL, NULL,
                              g_cclosure_marshal_VOID__POINTER,
                              G_TYPE_NONE, 1, G_TYPE_POINTER);