From 70978d2f7f5d9ce0f049fd200d960d1c140719a9 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 2 May 2011 15:12:33 -0400 Subject: EMConfig coding style cleanups. --- mail/em-config.c | 150 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 76 insertions(+), 74 deletions(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index 2ac286b85a..bc1c0e50d0 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -38,38 +38,39 @@ #include -static GObjectClass *emp_parent; +G_DEFINE_TYPE (EMConfig, em_config, E_TYPE_CONFIG) struct _EMConfigPrivate { gint account_changed_id; }; static void -emp_init (GObject *o) +emp_account_changed (struct _EAccount *ea, gint id, EMConfig *emc) { - EMConfig *emp = (EMConfig *)o; - - emp->priv = g_malloc0 (sizeof (*emp->priv)); + e_config_target_changed ((EConfig *)emc, E_CONFIG_TARGET_CHANGED_STATE); } static void -emp_finalise (GObject *o) +em_config_finalize (GObject *object) { - struct _EMConfigPrivate *p = ((EMConfig *)o)->priv; - /* Note we can't be unreffed if a target exists, so the target * will need to be freed first which will clean up any * listeners */ - g_free (p); + g_free (((EMConfig *) object)->priv); - ((GObjectClass *)emp_parent)->finalize (o); + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (em_config_parent_class)->finalize (object); } static void -emp_target_free (EConfig *ep, EConfigTarget *t) +em_config_set_target (EConfig *ep, + EConfigTarget *t) { - if (ep->target == t) { + /* Chain up to parent's set_target() method. */ + E_CONFIG_CLASS (em_config_parent_class)->set_target (ep, t); + + if (t) { switch (t->type) { case EM_CONFIG_TARGET_FOLDER: { /*EMConfigTargetFolder *s = (EMConfigTargetFolder *)t;*/ @@ -79,10 +80,35 @@ emp_target_free (EConfig *ep, EConfigTarget *t) break; } case EM_CONFIG_TARGET_ACCOUNT: { EMConfigTargetAccount *s = (EMConfigTargetAccount *)t; + EMConfig *config = (EMConfig *) ep; + + config->priv->account_changed_id = g_signal_connect ( + s->account, "changed", + G_CALLBACK(emp_account_changed), ep); + break; } + } + } +} + +static void +em_config_target_free (EConfig *ep, + EConfigTarget *t) +{ + if (ep->target == t) { + switch (t->type) { + case EM_CONFIG_TARGET_FOLDER: + break; + case EM_CONFIG_TARGET_PREFS: + break; + case EM_CONFIG_TARGET_ACCOUNT: { + EMConfigTargetAccount *s = (EMConfigTargetAccount *)t; + EMConfig *config = (EMConfig *) ep; - if (((EMConfig *)ep)->priv->account_changed_id) { - g_signal_handler_disconnect (s->account, ((EMConfig *)ep)->priv->account_changed_id); - ((EMConfig *)ep)->priv->account_changed_id = 0; + if (config->priv->account_changed_id > 0) { + g_signal_handler_disconnect ( + s->account, + config->priv->account_changed_id); + config->priv->account_changed_id = 0; } break; } } @@ -108,95 +134,71 @@ emp_target_free (EConfig *ep, EConfigTarget *t) break; } } - ((EConfigClass *)emp_parent)->target_free (ep, t); + /* Chain up to parent's target_free() method. */ + E_CONFIG_CLASS (em_config_parent_class)->target_free (ep, t); } static void -emp_account_changed (struct _EAccount *ea, gint id, EMConfig *emc) +em_config_class_init (EMConfigClass *class) { - e_config_target_changed ((EConfig *)emc, E_CONFIG_TARGET_CHANGED_STATE); -} + GObjectClass *object_class; + EConfigClass *config_class; -static void -emp_set_target (EConfig *ep, EConfigTarget *t) -{ - ((EConfigClass *)emp_parent)->set_target (ep, t); - - if (t) { - switch (t->type) { - case EM_CONFIG_TARGET_FOLDER: { - /*EMConfigTargetFolder *s = (EMConfigTargetFolder *)t;*/ - break; } - case EM_CONFIG_TARGET_PREFS: { - /*EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t;*/ - break; } - case EM_CONFIG_TARGET_ACCOUNT: { - EMConfigTargetAccount *s = (EMConfigTargetAccount *)t; + object_class = G_OBJECT_CLASS (class); + object_class->finalize = em_config_finalize; - ((EMConfig *)ep)->priv->account_changed_id = g_signal_connect(s->account, "changed", G_CALLBACK(emp_account_changed), ep); - break; } - } - } + config_class = E_CONFIG_CLASS (class); + config_class->set_target = em_config_set_target; + config_class->target_free = em_config_target_free; } static void -emp_class_init (GObjectClass *klass) -{ - klass->finalize = emp_finalise; - ((EConfigClass *)klass)->set_target = emp_set_target; - ((EConfigClass *)klass)->target_free = emp_target_free; -} - -GType -em_config_get_type (void) +em_config_init (EMConfig *emp) { - static GType type = 0; - - if (type == 0) { - static const GTypeInfo info = { - sizeof (EMConfigClass), - NULL, NULL, - (GClassInitFunc)emp_class_init, - NULL, NULL, - sizeof (EMConfig), 0, - (GInstanceInitFunc)emp_init - }; - emp_parent = g_type_class_ref (e_config_get_type ()); - type = g_type_register_static(e_config_get_type(), "EMConfig", &info, 0); - } - - return type; + emp->priv = g_malloc0 (sizeof (*emp->priv)); } -EMConfig *em_config_new (gint type, const gchar *menuid) +EMConfig * +em_config_new (gint type, + const gchar *menuid) { - EMConfig *emp = g_object_new (em_config_get_type (), NULL); + EMConfig *emp; + emp = g_object_new (em_config_get_type (), NULL); e_config_construct (&emp->config, type, menuid); return emp; } EMConfigTargetFolder * -em_config_target_new_folder (EMConfig *emp, CamelFolder *folder, const gchar *uri) +em_config_target_new_folder (EMConfig *emp, + CamelFolder *folder, + const gchar *uri) { - EMConfigTargetFolder *t = e_config_target_new (&emp->config, EM_CONFIG_TARGET_FOLDER, sizeof (*t)); + EMConfigTargetFolder *t; + + t = e_config_target_new ( + &emp->config, EM_CONFIG_TARGET_FOLDER, sizeof (*t)); t->uri = g_strdup (uri); - t->folder = folder; - g_object_ref (folder); + t->folder = g_object_ref (folder); return t; } EMConfigTargetPrefs * -em_config_target_new_prefs (EMConfig *emp, struct _GConfClient *gconf) +em_config_target_new_prefs (EMConfig *emp, + GConfClient *gconf) { - EMConfigTargetPrefs *t = e_config_target_new (&emp->config, EM_CONFIG_TARGET_PREFS, sizeof (*t)); + EMConfigTargetPrefs *t; + + t = e_config_target_new ( + &emp->config, EM_CONFIG_TARGET_PREFS, sizeof (*t)); - t->gconf = gconf; - if (gconf) - g_object_ref (gconf); + if (GCONF_IS_CLIENT (gconf)) + t->gconf = g_object_ref (gconf); + else + t->gconf = NULL; return t; } -- cgit v1.2.3 From 9a149f3ab61a08a5943d57045fad59cd894ba7a5 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 2 May 2011 15:34:56 -0400 Subject: EMConfigTargetAccount: Add original_account member. Rename the existing 'account' member to 'modified_account' and add an 'original_account' member so plugins have direct access to both. Mostly of benefit to the imap-features plugin. --- mail/em-config.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index bc1c0e50d0..e6ed1d5b3b 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -83,7 +83,7 @@ em_config_set_target (EConfig *ep, EMConfig *config = (EMConfig *) ep; config->priv->account_changed_id = g_signal_connect ( - s->account, "changed", + s->modified_account, "changed", G_CALLBACK(emp_account_changed), ep); break; } } @@ -106,7 +106,7 @@ em_config_target_free (EConfig *ep, if (config->priv->account_changed_id > 0) { g_signal_handler_disconnect ( - s->account, + s->modified_account, config->priv->account_changed_id); config->priv->account_changed_id = 0; } @@ -130,7 +130,10 @@ em_config_target_free (EConfig *ep, case EM_CONFIG_TARGET_ACCOUNT: { EMConfigTargetAccount *s = (EMConfigTargetAccount *)t; - g_object_unref (s->account); + if (s->original_account != NULL) + g_object_unref (s->original_account); + if (s->modified_account != NULL) + g_object_unref (s->modified_account); break; } } @@ -204,12 +207,24 @@ em_config_target_new_prefs (EMConfig *emp, } EMConfigTargetAccount * -em_config_target_new_account (EMConfig *emp, struct _EAccount *account) +em_config_target_new_account (EMConfig *emp, + EAccount *original_account, + EAccount *modified_account) { - EMConfigTargetAccount *t = e_config_target_new (&emp->config, EM_CONFIG_TARGET_ACCOUNT, sizeof (*t)); + EMConfigTargetAccount *t; - t->account = account; - g_object_ref (account); + t = e_config_target_new ( + &emp->config, EM_CONFIG_TARGET_ACCOUNT, sizeof (*t)); + + if (original_account != NULL) + t->original_account = g_object_ref (original_account); + else + t->original_account = NULL; + + if (modified_account != NULL) + t->modified_account = g_object_ref (modified_account); + else + t->modified_account = NULL; return t; } -- cgit v1.2.3 From 578214584caa7805edca09b27e2306dc31d80fb6 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 7 May 2011 12:22:36 -0400 Subject: Whitespace and coding style cleanups. --- mail/em-config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index e6ed1d5b3b..53728b8e66 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -84,7 +84,7 @@ em_config_set_target (EConfig *ep, config->priv->account_changed_id = g_signal_connect ( s->modified_account, "changed", - G_CALLBACK(emp_account_changed), ep); + G_CALLBACK (emp_account_changed), ep); break; } } } -- cgit v1.2.3 From 54da4fc09cf226fdb59b9f0c70555e2e57dc1f91 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 8 May 2011 13:24:42 -0400 Subject: Coding style cleanups. --- mail/em-config.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index 53728b8e66..a5ddb7a702 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -47,7 +47,7 @@ struct _EMConfigPrivate { static void emp_account_changed (struct _EAccount *ea, gint id, EMConfig *emc) { - e_config_target_changed ((EConfig *)emc, E_CONFIG_TARGET_CHANGED_STATE); + e_config_target_changed ((EConfig *) emc, E_CONFIG_TARGET_CHANGED_STATE); } static void @@ -79,7 +79,7 @@ em_config_set_target (EConfig *ep, /*EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t;*/ break; } case EM_CONFIG_TARGET_ACCOUNT: { - EMConfigTargetAccount *s = (EMConfigTargetAccount *)t; + EMConfigTargetAccount *s = (EMConfigTargetAccount *) t; EMConfig *config = (EMConfig *) ep; config->priv->account_changed_id = g_signal_connect ( @@ -101,7 +101,7 @@ em_config_target_free (EConfig *ep, case EM_CONFIG_TARGET_PREFS: break; case EM_CONFIG_TARGET_ACCOUNT: { - EMConfigTargetAccount *s = (EMConfigTargetAccount *)t; + EMConfigTargetAccount *s = (EMConfigTargetAccount *) t; EMConfig *config = (EMConfig *) ep; if (config->priv->account_changed_id > 0) { @@ -116,19 +116,19 @@ em_config_target_free (EConfig *ep, switch (t->type) { case EM_CONFIG_TARGET_FOLDER: { - EMConfigTargetFolder *s = (EMConfigTargetFolder *)t; + EMConfigTargetFolder *s = (EMConfigTargetFolder *) t; g_free (s->uri); g_object_unref (s->folder); break; } case EM_CONFIG_TARGET_PREFS: { - EMConfigTargetPrefs *s = (EMConfigTargetPrefs *)t; + EMConfigTargetPrefs *s = (EMConfigTargetPrefs *) t; if (s->gconf) g_object_unref (s->gconf); break; } case EM_CONFIG_TARGET_ACCOUNT: { - EMConfigTargetAccount *s = (EMConfigTargetAccount *)t; + EMConfigTargetAccount *s = (EMConfigTargetAccount *) t; if (s->original_account != NULL) g_object_unref (s->original_account); -- cgit v1.2.3 From d85a92dba12565da3609bb2f72842df1d02fe0b9 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 12 May 2011 13:21:54 -0400 Subject: EMConfigTargetFolder: Remove URI member. Use e_mail_folder_uri_from_folder() if you really need a folder URI for the target's CamelFolder. --- mail/em-config.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index a5ddb7a702..bad3d92c47 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -118,7 +118,6 @@ em_config_target_free (EConfig *ep, case EM_CONFIG_TARGET_FOLDER: { EMConfigTargetFolder *s = (EMConfigTargetFolder *) t; - g_free (s->uri); g_object_unref (s->folder); break; } case EM_CONFIG_TARGET_PREFS: { @@ -175,15 +174,13 @@ em_config_new (gint type, EMConfigTargetFolder * em_config_target_new_folder (EMConfig *emp, - CamelFolder *folder, - const gchar *uri) + CamelFolder *folder) { EMConfigTargetFolder *t; t = e_config_target_new ( &emp->config, EM_CONFIG_TARGET_FOLDER, sizeof (*t)); - t->uri = g_strdup (uri); t->folder = g_object_ref (folder); return t; -- cgit v1.2.3 From df7755eff8326759db2afc7ab7cee52863cfb8df Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 15 Aug 2011 10:42:11 -0400 Subject: EMConfigTargetAccount: Add CamelSettings member. Allows plugins to manipulate a CamelSettings instance directly. The settings are written back to the URL string (for now) when the user clicks Apply in the mail account editor. --- mail/em-config.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index bad3d92c47..fbde5d5430 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -133,6 +133,8 @@ em_config_target_free (EConfig *ep, g_object_unref (s->original_account); if (s->modified_account != NULL) g_object_unref (s->modified_account); + if (s->settings != NULL) + g_object_unref (s->settings); break; } } @@ -206,7 +208,8 @@ em_config_target_new_prefs (EMConfig *emp, EMConfigTargetAccount * em_config_target_new_account (EMConfig *emp, EAccount *original_account, - EAccount *modified_account) + EAccount *modified_account, + CamelSettings *settings) { EMConfigTargetAccount *t; @@ -223,5 +226,10 @@ em_config_target_new_account (EMConfig *emp, else t->modified_account = NULL; + if (settings != NULL) + t->settings = g_object_ref (settings); + else + t->settings = NULL; + return t; } -- cgit v1.2.3 From c4247dda8f228360592c9a527f5df71f4aba9221 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 16 Aug 2011 08:52:13 +0200 Subject: Bug #656620 - Account editor doesn't update on settings change --- mail/em-config.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index fbde5d5430..3f649bacb3 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -85,6 +85,8 @@ em_config_set_target (EConfig *ep, config->priv->account_changed_id = g_signal_connect ( s->modified_account, "changed", G_CALLBACK (emp_account_changed), ep); + + em_config_target_new_account_update_settings (ep, s, s->settings); break; } } } @@ -110,6 +112,8 @@ em_config_target_free (EConfig *ep, config->priv->account_changed_id); config->priv->account_changed_id = 0; } + + em_config_target_new_account_update_settings (ep, s, NULL); break; } } } @@ -233,3 +237,37 @@ em_config_target_new_account (EMConfig *emp, return t; } + +void +em_config_target_new_account_update_settings (EConfig *ep, EMConfigTargetAccount *target, CamelSettings *settings) +{ + g_return_if_fail (ep != NULL); + g_return_if_fail (target != NULL); + + if (settings) + g_object_ref (settings); + + if (target->settings != NULL) { + g_signal_handlers_disconnect_by_func (target->settings, G_CALLBACK (emp_account_changed), ep); + g_object_unref (target->settings); + } + + target->settings = settings; + + if (target->settings != NULL) { + GParamSpec **params; + guint n_params = 0; + + params = camel_settings_class_list_settings (CAMEL_SETTINGS_GET_CLASS (target->settings), &n_params); + if (params) { + guint ii; + gchar *sig_name; + + for (ii = 0; ii < n_params; ii++) { + sig_name = g_strconcat ("notify::", params[ii]->name, NULL); + g_signal_connect (target->settings, sig_name, G_CALLBACK (emp_account_changed), ep); + g_free (sig_name); + } + } + } +} -- cgit v1.2.3 From 1b4f38f6dd6ceabca8518bee5d51ed801b2a79f2 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 16 Aug 2011 11:34:08 -0400 Subject: Simplify em_config_target_new_account_update_settings(). Just connect to the "notify" signal, without the detail. That will trigger the callback when any property changes, which seems to be the intent there. --- mail/em-config.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index 3f649bacb3..464c9d814b 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -254,20 +254,8 @@ em_config_target_new_account_update_settings (EConfig *ep, EMConfigTargetAccount target->settings = settings; - if (target->settings != NULL) { - GParamSpec **params; - guint n_params = 0; - - params = camel_settings_class_list_settings (CAMEL_SETTINGS_GET_CLASS (target->settings), &n_params); - if (params) { - guint ii; - gchar *sig_name; - - for (ii = 0; ii < n_params; ii++) { - sig_name = g_strconcat ("notify::", params[ii]->name, NULL); - g_signal_connect (target->settings, sig_name, G_CALLBACK (emp_account_changed), ep); - g_free (sig_name); - } - } - } + if (target->settings != NULL) + g_signal_connect ( + target->settings, "notify", + G_CALLBACK (emp_account_changed), ep); } -- cgit v1.2.3 From 777c1cbd40eb63365f2c28e38f6a93beb2d1c9d1 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 16 Aug 2011 11:25:56 -0400 Subject: Coding style and whitespace cleanup. --- mail/em-config.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index 464c9d814b..c9bcf0a7a4 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -45,7 +45,9 @@ struct _EMConfigPrivate { }; static void -emp_account_changed (struct _EAccount *ea, gint id, EMConfig *emc) +emp_account_changed (EAccount *ea, + gint id, + EMConfig *emc) { e_config_target_changed ((EConfig *) emc, E_CONFIG_TARGET_CHANGED_STATE); } @@ -86,7 +88,8 @@ em_config_set_target (EConfig *ep, s->modified_account, "changed", G_CALLBACK (emp_account_changed), ep); - em_config_target_new_account_update_settings (ep, s, s->settings); + em_config_target_new_account_update_settings ( + ep, s, s->settings); break; } } } @@ -239,7 +242,9 @@ em_config_target_new_account (EMConfig *emp, } void -em_config_target_new_account_update_settings (EConfig *ep, EMConfigTargetAccount *target, CamelSettings *settings) +em_config_target_new_account_update_settings (EConfig *ep, + EMConfigTargetAccount *target, + CamelSettings *settings) { g_return_if_fail (ep != NULL); g_return_if_fail (target != NULL); @@ -248,7 +253,8 @@ em_config_target_new_account_update_settings (EConfig *ep, EMConfigTargetAccount g_object_ref (settings); if (target->settings != NULL) { - g_signal_handlers_disconnect_by_func (target->settings, G_CALLBACK (emp_account_changed), ep); + g_signal_handlers_disconnect_by_func ( + target->settings, emp_account_changed, ep); g_object_unref (target->settings); } -- cgit v1.2.3 From e64d6fe05c30c2cc1d7625a202afba3ba2da07cd Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 22 Nov 2011 18:22:14 -0500 Subject: Miscellaneous cleanups. --- mail/em-config.c | 1 - 1 file changed, 1 deletion(-) (limited to 'mail/em-config.c') diff --git a/mail/em-config.c b/mail/em-config.c index 6a133f1c56..352e16b4b1 100644 --- a/mail/em-config.c +++ b/mail/em-config.c @@ -121,7 +121,6 @@ em_config_class_init (EMConfigClass *class) { EConfigClass *config_class; - config_class = E_CONFIG_CLASS (class); config_class->set_target = em_config_set_target; config_class->target_free = em_config_target_free; -- cgit v1.2.3