From d629e6850a64b826fad60857a6b6945149ca8214 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 5 Jul 2013 12:22:35 -0400 Subject: GalViewCollection: We don't need no stinkin' factories! Given a type code string from an XML file, find the appropriate GType by traversing the GType hierarchy from GAL_TYPE_VIEW and checking the class structures for a matching type code string. This completely eliminates the need for what's left of GalViewFactory. Now it's just a matter of cleaning up the remains. --- e-util/gal-view-collection.c | 52 +++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'e-util') diff --git a/e-util/gal-view-collection.c b/e-util/gal-view-collection.c index 7c7e997a34..617eaad2ad 100644 --- a/e-util/gal-view-collection.c +++ b/e-util/gal-view-collection.c @@ -25,6 +25,8 @@ #include #include +#include + #include "e-unicode.h" #include "e-xml-utils.h" @@ -371,6 +373,26 @@ view_changed (GalView *view, g_signal_handler_unblock (item->view, item->view_changed_id); } +static void +view_collection_check_type (GType type, + gpointer user_data) +{ + GalViewClass *class; + + struct { + const gchar *type_code; + GType type; + } *closure = user_data; + + class = g_type_class_ref (type); + g_return_if_fail (class != NULL); + + if (g_strcmp0 (class->type_code, closure->type_code) == 0) + closure->type = type; + + g_type_class_unref (class); +} + /* Use factory list to load a GalView file. */ static GalView * gal_view_collection_real_load_view_from_file (GalViewCollection *collection, @@ -379,25 +401,25 @@ gal_view_collection_real_load_view_from_file (GalViewCollection *collection, const gchar *dir, const gchar *filename) { - GalViewFactory *factory; - GList *factories; + GalView *view = NULL; - factory = NULL; - for (factories = collection->priv->factory_list; factories; factories = factories->next) { - if (type && !strcmp (gal_view_factory_get_type_code (factories->data), type)) { - factory = factories->data; - break; - } - } - if (factory) { - GalView *view; + struct { + const gchar *type_code; + GType type; + } closure; - view = gal_view_factory_new_view (factory, title); - gal_view_set_title (view, title); + closure.type_code = type; + closure.type = G_TYPE_INVALID; + + /* Find the appropriate GalView subtype for the "type_code" string. */ + e_type_traverse (GAL_TYPE_VIEW, view_collection_check_type, &closure); + + if (g_type_is_a (closure.type, GAL_TYPE_VIEW)) { + view = g_object_new (closure.type, "title", title, NULL); gal_view_load (view, filename); - return view; } - return NULL; + + return view; } GalView * -- cgit v1.2.3