aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-extensible.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-03-22 10:22:57 +0800
committerMichael Meeks <michael.meeks@novell.com>2010-04-07 19:13:36 +0800
commit13fb16f2793ee91099b1f2960c1875896991f1c4 (patch)
tree9d5832e48bd514baeb24e158db0693f5a1202f7f /e-util/e-extensible.c
parent83e36a49baa491609bda692e36006123a7aa079f (diff)
downloadgsoc2013-evolution-13fb16f2793ee91099b1f2960c1875896991f1c4.tar.gz
gsoc2013-evolution-13fb16f2793ee91099b1f2960c1875896991f1c4.tar.zst
gsoc2013-evolution-13fb16f2793ee91099b1f2960c1875896991f1c4.zip
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.
Diffstat (limited to 'e-util/e-extensible.c')
-rw-r--r--e-util/e-extensible.c46
1 files changed, 45 insertions, 1 deletions
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 <e-util/e-util.h>
#include <e-util/e-extension.h>
+#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);
+}