diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-05-03 03:12:33 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2011-05-03 03:12:55 +0800 |
commit | 74f86383fce61cd6712804f39a1baf011d59729a (patch) | |
tree | 937b63e8282c8363e624a90d7b8db9eb6c9c100c /mail | |
parent | 5fcf41925becbac39447b315097b062de2bfd0a1 (diff) | |
download | gsoc2013-evolution-74f86383fce61cd6712804f39a1baf011d59729a.tar gsoc2013-evolution-74f86383fce61cd6712804f39a1baf011d59729a.tar.gz gsoc2013-evolution-74f86383fce61cd6712804f39a1baf011d59729a.tar.bz2 gsoc2013-evolution-74f86383fce61cd6712804f39a1baf011d59729a.tar.lz gsoc2013-evolution-74f86383fce61cd6712804f39a1baf011d59729a.tar.xz gsoc2013-evolution-74f86383fce61cd6712804f39a1baf011d59729a.tar.zst gsoc2013-evolution-74f86383fce61cd6712804f39a1baf011d59729a.zip |
EMConfig coding style cleanups.
Diffstat (limited to 'mail')
-rw-r--r-- | mail/em-config.c | 150 | ||||
-rw-r--r-- | mail/em-config.h | 28 |
2 files changed, 92 insertions, 86 deletions
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 <e-util/e-util.h> -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; } diff --git a/mail/em-config.h b/mail/em-config.h index b0493cd9cf..bd39a4702c 100644 --- a/mail/em-config.h +++ b/mail/em-config.h @@ -20,8 +20,8 @@ * */ -#ifndef __EM_CONFIG_H__ -#define __EM_CONFIG_H__ +#ifndef EM_CONFIG_H +#define EM_CONFIG_H #include <camel/camel.h> #include <gconf/gconf-client.h> @@ -71,10 +71,8 @@ struct _EMConfigTargetAccount { typedef struct _EConfigItem EMConfigItem; -/* The object */ struct _EMConfig { EConfig config; - EMConfigPrivate *priv; }; @@ -82,14 +80,20 @@ struct _EMConfigClass { EConfigClass config_class; }; -GType em_config_get_type (void); - -EMConfig *em_config_new (gint type, const gchar *menuid); - -EMConfigTargetFolder *em_config_target_new_folder (EMConfig *emp, CamelFolder *folder, const gchar *uri); -EMConfigTargetPrefs *em_config_target_new_prefs (EMConfig *emp, GConfClient *gconf); -EMConfigTargetAccount *em_config_target_new_account (EMConfig *emp, EAccount *account); +GType em_config_get_type (void); +EMConfig * em_config_new (gint type, + const gchar *menuid); +EMConfigTargetFolder * + em_config_target_new_folder (EMConfig *emp, + CamelFolder *folder, + const gchar *uri); +EMConfigTargetPrefs * + em_config_target_new_prefs (EMConfig *emp, + GConfClient *gconf); +EMConfigTargetAccount * + em_config_target_new_account (EMConfig *emp, + EAccount *account); G_END_DECLS -#endif /* __EM_CONFIG_H__ */ +#endif /* EM_CONFIG_H */ |