aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-07-06 00:22:35 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-06 04:40:50 +0800
commitd629e6850a64b826fad60857a6b6945149ca8214 (patch)
tree61c62776a88f194e68d6c7179d3219ee2641306f /e-util
parentda9673c4213668d49700d2a39183a41ad0373f47 (diff)
downloadgsoc2013-evolution-d629e6850a64b826fad60857a6b6945149ca8214.tar
gsoc2013-evolution-d629e6850a64b826fad60857a6b6945149ca8214.tar.gz
gsoc2013-evolution-d629e6850a64b826fad60857a6b6945149ca8214.tar.bz2
gsoc2013-evolution-d629e6850a64b826fad60857a6b6945149ca8214.tar.lz
gsoc2013-evolution-d629e6850a64b826fad60857a6b6945149ca8214.tar.xz
gsoc2013-evolution-d629e6850a64b826fad60857a6b6945149ca8214.tar.zst
gsoc2013-evolution-d629e6850a64b826fad60857a6b6945149ca8214.zip
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.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/gal-view-collection.c52
1 files changed, 37 insertions, 15 deletions
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 <libxml/parser.h>
#include <libedataserver/libedataserver.h>
+#include <libebackend/libebackend.h>
+
#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 *