From 73d64a9fed447ea022adcf267d16a4107703cc13 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Thu, 17 Nov 2005 11:38:48 +0000 Subject: [PATCH] Use G_DEFINE_TYPE and add some more const keywords. --- ChangeLog | 15 ++++++++++++ libedataserver/e-account-list.c | 40 ++++++------------------------- libedataserver/e-account.c | 36 +++++----------------------- libedataserver/e-component-listener.c | 33 ++++--------------------- libedataserver/e-file-cache.c | 37 ++-------------------------- libedataserver/e-iterator.c | 39 +----------------------------- libedataserver/e-list-iterator.c | 45 +++-------------------------------- libedataserver/e-list.c | 39 ++---------------------------- libedataserver/e-sexp.c | 4 ++-- libedataserver/e-source-group.c | 32 ++++--------------------- libedataserver/e-source-list.c | 36 +++++----------------------- libedataserver/e-source.c | 32 ++++--------------------- 12 files changed, 56 insertions(+), 332 deletions(-) diff --git a/ChangeLog b/ChangeLog index 467bb9d..a21b642 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-11-17 Ross Burton + + * libedataserver/e-account-list.c: + * libedataserver/e-account.c: + * libedataserver/e-component-listener.c: + * libedataserver/e-file-cache.c: + * libedataserver/e-iterator.c: + * libedataserver/e-list-iterator.c: + * libedataserver/e-list.c: + * libedataserver/e-sexp.c: + * libedataserver/e-source-group.c: + * libedataserver/e-source-list.c: + * libedataserver/e-source.c: + Use G_DEFINE_TYPE and add some more const keywords. + 2005-11-15 Ross Burton * libedataserver/e-data-server-module.c diff --git a/libedataserver/e-account-list.c b/libedataserver/e-account-list.c index 41af368..f70eec7 100644 --- a/libedataserver/e-account-list.c +++ b/libedataserver/e-account-list.c @@ -41,16 +41,15 @@ enum { static guint signals [LAST_SIGNAL] = { 0 }; -#define PARENT_TYPE E_TYPE_LIST -static EListClass *parent_class = NULL; - static void dispose (GObject *); static void finalize (GObject *); +G_DEFINE_TYPE (EAccountList, e_account_list, E_TYPE_LIST); + static void -class_init (GObjectClass *object_class) +e_account_list_class_init (EAccountListClass *klass) { - parent_class = g_type_class_ref (PARENT_TYPE); + GObjectClass *object_class = G_OBJECT_CLASS (klass); /* virtual method override */ object_class->dispose = dispose; @@ -87,10 +86,8 @@ class_init (GObjectClass *object_class) } static void -init (GObject *object) +e_account_list_init (EAccountList *account_list) { - EAccountList *account_list = E_ACCOUNT_LIST (object); - account_list->priv = g_new0 (EAccountListPrivate, 1); } @@ -108,7 +105,7 @@ dispose (GObject *object) account_list->priv->gconf = NULL; } - G_OBJECT_CLASS (parent_class)->dispose (object); + G_OBJECT_CLASS (e_account_list_parent_class)->dispose (object); } static void @@ -118,30 +115,7 @@ finalize (GObject *object) g_free (account_list->priv); - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -GType -e_account_list_get_type (void) -{ - static GType type = 0; - - if (!type) { - static GTypeInfo const object_info = { - sizeof (EAccountListClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (EAccountList), - 0, - (GInstanceInitFunc) init - }; - type = g_type_register_static (PARENT_TYPE, "EAccountList", &object_info, 0); - } - - return type; + G_OBJECT_CLASS (e_account_list_parent_class)->finalize (object); } static void diff --git a/libedataserver/e-account.c b/libedataserver/e-account.c index 9f3ae85..efdbfe6 100644 --- a/libedataserver/e-account.c +++ b/libedataserver/e-account.c @@ -31,22 +31,21 @@ #include #include -#define PARENT_TYPE G_TYPE_OBJECT -static GObjectClass *parent_class = NULL; - static void finalize (GObject *); +G_DEFINE_TYPE (EAccount, e_account, G_TYPE_OBJECT); + static void -class_init (GObjectClass *object_class) +e_account_class_init (EAccountClass *account_class) { - parent_class = g_type_class_ref (PARENT_TYPE); + GObjectClass *object_class = G_OBJECT_CLASS (account_class); /* virtual method override */ object_class->finalize = finalize; } static void -init (EAccount *account) +e_account_init (EAccount *account) { account->id = g_new0 (EAccountIdentity, 1); account->source = g_new0 (EAccountService, 1); @@ -100,30 +99,7 @@ finalize (GObject *object) g_free (account->smime_sign_key); g_free (account->smime_encrypt_key); - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -GType -e_account_get_type (void) -{ - static GType type = 0; - - if (!type) { - static GTypeInfo const object_info = { - sizeof (EAccountClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (EAccount), - 0, - (GInstanceInitFunc) init - }; - type = g_type_register_static (PARENT_TYPE, "EAccount", &object_info, 0); - } - - return type; + G_OBJECT_CLASS (e_account_parent_class)->finalize (object); } /** diff --git a/libedataserver/e-component-listener.c b/libedataserver/e-component-listener.c index 4518fb8..a9696ed 100644 --- a/libedataserver/e-component-listener.c +++ b/libedataserver/e-component-listener.c @@ -17,8 +17,6 @@ #include #include "e-component-listener.h" -#define PARENT_TYPE GTK_TYPE_OBJECT - struct _EComponentListenerPrivate { Bonobo_Unknown component; }; @@ -27,7 +25,6 @@ static void e_component_listener_class_init (EComponentListenerClass *klass); static void e_component_listener_init (EComponentListener *cl, EComponentListenerClass *klass); static void e_component_listener_finalize (GObject *object); -static GObjectClass *parent_class = NULL; static GList *watched_connections = NULL; enum { @@ -62,13 +59,13 @@ connection_listen_cb (gpointer object, gpointer user_data) } } +G_DEFINE_TYPE (EComponentListener, e_component_listener, G_TYPE_OBJECT); + static void e_component_listener_class_init (EComponentListenerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); - object_class->finalize = e_component_listener_finalize; klass->component_died = NULL; @@ -106,30 +103,8 @@ e_component_listener_finalize (GObject *object) g_free (cl->priv); cl->priv = NULL; - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -GType -e_component_listener_get_type (void) -{ - static GType type = 0; - - if (!type) { - static GTypeInfo info = { - sizeof (EComponentListenerClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) e_component_listener_class_init, - NULL, NULL, - sizeof (EComponentListener), - 0, - (GInstanceInitFunc) e_component_listener_init - }; - type = g_type_register_static (G_TYPE_OBJECT, "EComponentListener", &info, 0); - } - - return type; + if (G_OBJECT_CLASS (e_component_listener_parent_class)->finalize) + (* G_OBJECT_CLASS (e_component_listener_parent_class)->finalize) (object); } /** diff --git a/libedataserver/e-file-cache.c b/libedataserver/e-file-cache.c index 9dd4291..6c6c098 100644 --- a/libedataserver/e-file-cache.c +++ b/libedataserver/e-file-cache.c @@ -39,7 +39,7 @@ enum { PROP_FILENAME }; -static GObjectClass *parent_class = NULL; +G_DEFINE_TYPE (EFileCache, e_file_cache, G_TYPE_OBJECT); static void e_file_cache_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) @@ -123,7 +123,7 @@ e_file_cache_finalize (GObject *object) cache->priv = NULL; } - parent_class->finalize (object); + G_OBJECT_CLASS (e_file_cache_parent_class)->finalize (object); } static void @@ -131,8 +131,6 @@ e_file_cache_class_init (EFileCacheClass *klass) { GObjectClass *object_class; - parent_class = g_type_class_peek_parent (klass); - object_class = G_OBJECT_CLASS (klass); object_class->finalize = e_file_cache_finalize; object_class->set_property = e_file_cache_set_property; @@ -156,37 +154,6 @@ e_file_cache_init (EFileCache *cache) } /** - * e_file_cache_get_type: - * @void: - * - * Registers the #EFileCache class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #EFileCache class. - **/ -GType -e_file_cache_get_type (void) -{ - static GType type = 0; - - if (!type) { - static GTypeInfo info = { - sizeof (EFileCacheClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) e_file_cache_class_init, - NULL, NULL, - sizeof (EFileCache), - 0, - (GInstanceInitFunc) e_file_cache_init, - }; - type = g_type_register_static (G_TYPE_OBJECT, "EFileCache", &info, 0); - } - - return type; -} - -/** * e_file_cache_new * @filename: filename where the cache is kept. * diff --git a/libedataserver/e-iterator.c b/libedataserver/e-iterator.c index f9aa0b6..efa6167 100644 --- a/libedataserver/e-iterator.c +++ b/libedataserver/e-iterator.c @@ -14,10 +14,6 @@ static void e_iterator_init (EIterator *card); static void e_iterator_class_init (EIteratorClass *klass); -#define PARENT_TYPE G_TYPE_OBJECT - -static GObjectClass *parent_class; - enum { INVALIDATE, LAST_SIGNAL @@ -25,38 +21,7 @@ enum { static guint e_iterator_signals [LAST_SIGNAL] = { 0, }; -/** - * e_iterator_get_type: - * @void: - * - * Registers the &EIterator class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EIterator class. - **/ -GType -e_iterator_get_type (void) -{ - static GType type = 0; - - if (! type) { - GTypeInfo info = { - sizeof (EIteratorClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) e_iterator_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EIterator), - 0, /* n_preallocs */ - (GInstanceInitFunc) e_iterator_init - }; - - type = g_type_register_static (PARENT_TYPE, "EIterator", &info, 0); - } - - return type; -} +G_DEFINE_TYPE (EIterator, e_iterator, G_TYPE_OBJECT); static void e_iterator_class_init (EIteratorClass *klass) @@ -65,8 +30,6 @@ e_iterator_class_init (EIteratorClass *klass) object_class = G_OBJECT_CLASS(klass); - parent_class = g_type_class_ref (PARENT_TYPE); - e_iterator_signals [INVALIDATE] = g_signal_new ("invalidate", G_OBJECT_CLASS_TYPE (object_class), diff --git a/libedataserver/e-list-iterator.c b/libedataserver/e-list-iterator.c index 7404279..b0b82b2 100644 --- a/libedataserver/e-list-iterator.c +++ b/libedataserver/e-list-iterator.c @@ -30,42 +30,7 @@ static void e_list_iterator_last (EIterator *iterator); static const void *e_list_iterator_get (EIterator *iterator); static void e_list_iterator_dispose (GObject *object); -#define PARENT_TYPE E_TYPE_ITERATOR - -static EIteratorClass *parent_class; - -/** - * e_list_iterator_get_type: - * @void: - * - * Registers the &EListIterator class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EListIterator class. - **/ -GType -e_list_iterator_get_type (void) -{ - static GType type = 0; - - if (! type) { - GTypeInfo info = { - sizeof (EListIteratorClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) e_list_iterator_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EListIterator), - 0, /* n_preallocs */ - (GInstanceInitFunc) e_list_iterator_init - }; - - type = g_type_register_static (PARENT_TYPE, "EListIterator", &info, 0); - } - - return type; -} +G_DEFINE_TYPE(EListIterator, e_list_iterator, E_TYPE_ITERATOR); static void e_list_iterator_class_init (EListIteratorClass *klass) @@ -76,8 +41,6 @@ e_list_iterator_class_init (EListIteratorClass *klass) object_class = G_OBJECT_CLASS(klass); iterator_class = E_ITERATOR_CLASS(klass); - parent_class = g_type_class_ref (PARENT_TYPE); - object_class->dispose = e_list_iterator_dispose; iterator_class->invalidate = e_list_iterator_invalidate; @@ -92,8 +55,6 @@ e_list_iterator_class_init (EListIteratorClass *klass) iterator_class->is_valid = e_list_iterator_is_valid; } - - /** * e_list_iterator_init: */ @@ -127,8 +88,8 @@ e_list_iterator_dispose (GObject *object) e_list_remove_iterator(iterator->list, E_ITERATOR(iterator)); g_object_unref(iterator->list); - if (G_OBJECT_CLASS (parent_class)->dispose) - (* G_OBJECT_CLASS (parent_class)->dispose) (object); + if (G_OBJECT_CLASS (e_list_iterator_parent_class)->dispose) + (* G_OBJECT_CLASS (e_list_iterator_parent_class)->dispose) (object); } static const void * diff --git a/libedataserver/e-list.c b/libedataserver/e-list.c index 0a39b6d..d921a64 100644 --- a/libedataserver/e-list.c +++ b/libedataserver/e-list.c @@ -15,40 +15,7 @@ static void e_list_init (EList *list); static void e_list_class_init (EListClass *klass); static void e_list_dispose (GObject *object); -static GObjectClass *parent_class; - -/** - * e_list_get_type: - * @void: - * - * Registers the &EList class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EList class. - **/ -GType -e_list_get_type (void) -{ - static GType type = 0; - - if (! type) { - GTypeInfo info = { - sizeof (EListClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) e_list_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EList), - 0, /* n_preallocs */ - (GInstanceInitFunc) e_list_init - }; - - type = g_type_register_static (G_TYPE_OBJECT, "EList", &info, 0); - } - - return type; -} +G_DEFINE_TYPE (EList, e_list, G_TYPE_OBJECT); static void e_list_class_init (EListClass *klass) @@ -57,8 +24,6 @@ e_list_class_init (EListClass *klass) object_class = G_OBJECT_CLASS(klass); - parent_class = g_type_class_ref (G_TYPE_OBJECT); - object_class->dispose = e_list_dispose; } @@ -187,6 +152,6 @@ e_list_dispose (GObject *object) g_list_foreach(list->list, (GFunc) list->free, list->closure); g_list_free(list->list); - (* G_OBJECT_CLASS (parent_class)->dispose) (object); + (* G_OBJECT_CLASS (e_list_parent_class)->dispose) (object); } diff --git a/libedataserver/e-sexp.c b/libedataserver/e-sexp.c index bd4ce59..24a89d7 100644 --- a/libedataserver/e-sexp.c +++ b/libedataserver/e-sexp.c @@ -109,7 +109,7 @@ static void parse_dump_term(struct _ESExpTerm *t, int depth); static GObjectClass *parent_class; #endif -static GScannerConfig scanner_config = +static const GScannerConfig scanner_config = { ( " \t\r\n") /* cset_skip_characters */, ( G_CSET_a_2_z @@ -1045,7 +1045,7 @@ e_sexp_class_init (ESExpClass *klass) #endif /* 'builtin' functions */ -static struct { +static const struct { char *name; ESExpFunc *func; int type; /* set to 1 if a function can perform shortcut evaluation, or diff --git a/libedataserver/e-source-group.c b/libedataserver/e-source-group.c index 0e30a33..49865e1 100644 --- a/libedataserver/e-source-group.c +++ b/libedataserver/e-source-group.c @@ -29,8 +29,6 @@ #include "e-uid.h" #include "e-source-group.h" -static GObjectClass *parent_class = NULL; - /* Private members. */ struct _ESourceGroupPrivate { @@ -69,6 +67,8 @@ source_changed_callback (ESource *source, /* GObject methods. */ +G_DEFINE_TYPE (ESourceGroup, e_source_group, G_TYPE_OBJECT); + static void impl_dispose (GObject *object) { @@ -90,7 +90,7 @@ impl_dispose (GObject *object) priv->sources = NULL; } - (* G_OBJECT_CLASS (parent_class)->dispose) (object); + (* G_OBJECT_CLASS (e_source_group_parent_class)->dispose) (object); } static void @@ -103,7 +103,7 @@ impl_finalize (GObject *object) g_free (priv->base_uri); g_free (priv); - (* G_OBJECT_CLASS (parent_class)->finalize) (object); + (* G_OBJECT_CLASS (e_source_group_parent_class)->finalize) (object); } @@ -117,8 +117,6 @@ e_source_group_class_init (ESourceGroupClass *class) object_class->dispose = impl_dispose; object_class->finalize = impl_finalize; - parent_class = g_type_class_peek_parent (class); - signals[CHANGED] = g_signal_new ("changed", G_OBJECT_CLASS_TYPE (object_class), @@ -157,28 +155,6 @@ e_source_group_init (ESourceGroup *source_group) source_group->priv = priv; } -GType -e_source_group_get_type (void) -{ - static GType e_source_group_type = 0; - - if (!e_source_group_type) { - static GTypeInfo info = { - sizeof (ESourceGroupClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) e_source_group_class_init, - NULL, NULL, - sizeof (ESourceGroup), - 0, - (GInstanceInitFunc) e_source_group_init - }; - e_source_group_type = g_type_register_static (G_TYPE_OBJECT, "ESourceGroup", &info, 0); - } - - return e_source_group_type; -} - /* Public methods. */ ESourceGroup * diff --git a/libedataserver/e-source-list.c b/libedataserver/e-source-list.c index 86f5c15..f591796 100644 --- a/libedataserver/e-source-list.c +++ b/libedataserver/e-source-list.c @@ -28,8 +28,6 @@ #include "e-data-server-marshal.h" #include "e-source-list.h" -static GObjectClass *parent_class = NULL; - struct _ESourceListPrivate { GConfClient *gconf_client; char *gconf_path; @@ -84,12 +82,12 @@ load_from_gconf (ESourceList *list) new_groups_hash = g_hash_table_new (g_direct_hash, g_direct_equal); for (p = conf_list, pos = 0; p != NULL; p = p->next, pos++) { - const char *xml = p->data; + const xmlChar *xml = p->data; xmlDocPtr xmldoc; char *group_uid; ESourceGroup *existing_group; - xmldoc = xmlParseDoc ((char *) xml); + xmldoc = xmlParseDoc (xml); if (xmldoc == NULL) continue; @@ -231,6 +229,8 @@ conf_changed_callback (GConfClient *client, /* GObject methods. */ +G_DEFINE_TYPE (ESourceList, e_source_list, G_TYPE_OBJECT); + static void impl_dispose (GObject *object) { @@ -268,7 +268,7 @@ impl_dispose (GObject *object) priv->gconf_client = NULL; } - (* G_OBJECT_CLASS (parent_class)->dispose) (object); + (* G_OBJECT_CLASS (e_source_list_parent_class)->dispose) (object); } static void @@ -285,7 +285,7 @@ impl_finalize (GObject *object) g_free (priv->gconf_path); g_free (priv); - (* G_OBJECT_CLASS (parent_class)->finalize) (object); + (* G_OBJECT_CLASS (e_source_list_parent_class)->finalize) (object); } @@ -299,8 +299,6 @@ e_source_list_class_init (ESourceListClass *class) object_class->dispose = impl_dispose; object_class->finalize = impl_finalize; - parent_class = g_type_class_peek_parent (class); - signals[CHANGED] = g_signal_new ("changed", G_OBJECT_CLASS_TYPE (object_class), @@ -341,28 +339,6 @@ e_source_list_init (ESourceList *source_list) source_list->priv = priv; } -GType -e_source_list_get_type (void) -{ - static GType e_source_list_type = 0; - - if (!e_source_list_type) { - static GTypeInfo info = { - sizeof (ESourceListClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) e_source_list_class_init, - NULL, NULL, - sizeof (ESourceList), - 0, - (GInstanceInitFunc) e_source_list_init - }; - e_source_list_type = g_type_register_static (G_TYPE_OBJECT, "ESourceList", &info, 0); - } - - return e_source_list_type; -} - /* Public methods. */ ESourceList * diff --git a/libedataserver/e-source.c b/libedataserver/e-source.c index eaf9936..84d4ae1 100644 --- a/libedataserver/e-source.c +++ b/libedataserver/e-source.c @@ -29,8 +29,6 @@ #include "e-uid.h" #include "e-source.h" -static GObjectClass *parent_class = NULL; - #define ES_CLASS(obj) E_SOURCE_CLASS (G_OBJECT_GET_CLASS (obj)) @@ -80,6 +78,8 @@ group_weak_notify (ESource *source, /* GObject methods. */ +G_DEFINE_TYPE (ESource, e_source, G_TYPE_OBJECT); + static void impl_finalize (GObject *object) { @@ -94,7 +94,7 @@ impl_finalize (GObject *object) g_free (priv); - (* G_OBJECT_CLASS (parent_class)->finalize) (object); + (* G_OBJECT_CLASS (e_source_parent_class)->finalize) (object); } static void @@ -107,7 +107,7 @@ impl_dispose (GObject *object) priv->group = NULL; } - (* G_OBJECT_CLASS (parent_class)->dispose) (object); + (* G_OBJECT_CLASS (e_source_parent_class)->dispose) (object); } @@ -121,8 +121,6 @@ e_source_class_init (ESourceClass *class) object_class->dispose = impl_dispose; object_class->finalize = impl_finalize; - parent_class = g_type_class_peek_parent (class); - signals[CHANGED] = g_signal_new ("changed", G_OBJECT_CLASS_TYPE (object_class), @@ -145,28 +143,6 @@ e_source_init (ESource *source) g_free, g_free); } -GType -e_source_get_type (void) -{ - static GType e_source_type = 0; - - if (!e_source_type) { - static GTypeInfo info = { - sizeof (ESourceClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) e_source_class_init, - NULL, NULL, - sizeof (ESource), - 0, - (GInstanceInitFunc) e_source_init - }; - e_source_type = g_type_register_static (G_TYPE_OBJECT, "ESource", &info, 0); - } - - return e_source_type; -} - /* Public methods. */ ESource * -- 2.7.4