From 906f93a130d8d670c4b5213c2c2bf03c47c02337 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 21 Mar 2010 22:22:57 -0400 Subject: Demonstrate extending the EExtension API. Introduce e_extensible_list_extensions(), which provides extensible objects access to their own extensions, or a subset of them. Convert EShellBackend to an abstract EExtension subtype. EShell will load its extensions with e_extensible_load_extensions(), and then obtain a list of EShellBackend extensions as follows: shell_backends = e_extensible_list_extensions ( E_EXTENSIBLE (shell), E_TYPE_SHELL_BACKEND); Because EShellBackend is abstract, its GType is skipped while traversing the GType hierarchy to find EShell extensions. --- e-util/e-extensible.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'e-util/e-extensible.c') diff --git a/e-util/e-extensible.c b/e-util/e-extensible.c index a5e87c4280..b718fc59bf 100644 --- a/e-util/e-extensible.c +++ b/e-util/e-extensible.c @@ -61,6 +61,9 @@ #include #include +#define IS_AN_EXTENSION_TYPE(type) \ + (g_type_is_a ((type), E_TYPE_EXTENSION)) + static GQuark extensible_quark; static GPtrArray * @@ -133,7 +136,7 @@ e_extensible_get_type (void) * e_extensible_load_extensions: * @extensible: an #EExtensible * - * Creates an instance of all registered subtypes of #EExtension which + * Creates an instance of all instantiable subtypes of #EExtension which * target the class of @extensible. The lifetimes of these newly created * #EExtension objects are bound to @extensible such that they are finalized * when @extensible is finalized. @@ -159,3 +162,44 @@ e_extensible_load_extensions (EExtensible *extensible) E_TYPE_EXTENSION, (ETypeFunc) extensible_load_extension, extensible); } + +/** + * e_extensible_list_extensions: + * @extensible: an #EExtensible + * @extension_type: the type of extensions to list + * + * Returns a list of #EExtension objects bound to @extensible whose + * types are ancestors of @extension_type. For a complete list of + * extension objects bound to @extensible, pass %E_TYPE_EXTENSION. + * + * The list itself should be freed with g_list_free(). The extension + * objects are owned by @extensible and should not be unreferenced. + * + * Returns: a list of extension objects derived from @extension_type + **/ +GList * +e_extensible_list_extensions (EExtensible *extensible, + GType extension_type) +{ + GPtrArray *extensions; + GList *list = NULL; + guint ii; + + g_return_val_if_fail (E_IS_EXTENSIBLE (extensible), NULL); + g_return_val_if_fail (IS_AN_EXTENSION_TYPE (extension_type), NULL); + + e_extensible_load_extensions (extensible); + + extensions = extensible_get_extensions (extensible); + g_return_val_if_fail (extensions != NULL, NULL); + + for (ii = 0; ii < extensions->len; ii++) { + GObject *object; + + object = g_ptr_array_index (extensions, ii); + if (g_type_is_a (G_OBJECT_TYPE (object), extension_type)) + list = g_list_prepend (list, object); + } + + return g_list_reverse (list); +} -- cgit v1.2.3