aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-03-22 10:22:57 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-03-22 11:30:44 +0800
commit906f93a130d8d670c4b5213c2c2bf03c47c02337 (patch)
tree049d65401eae28e21b98c27bd9e73a8275f94bcb /e-util
parent5368aec9721e9ccd97280d05e6916e1197fa14a1 (diff)
downloadgsoc2013-evolution-906f93a130d8d670c4b5213c2c2bf03c47c02337.tar
gsoc2013-evolution-906f93a130d8d670c4b5213c2c2bf03c47c02337.tar.gz
gsoc2013-evolution-906f93a130d8d670c4b5213c2c2bf03c47c02337.tar.bz2
gsoc2013-evolution-906f93a130d8d670c4b5213c2c2bf03c47c02337.tar.lz
gsoc2013-evolution-906f93a130d8d670c4b5213c2c2bf03c47c02337.tar.xz
gsoc2013-evolution-906f93a130d8d670c4b5213c2c2bf03c47c02337.tar.zst
gsoc2013-evolution-906f93a130d8d670c4b5213c2c2bf03c47c02337.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')
-rw-r--r--e-util/e-extensible.c46
-rw-r--r--e-util/e-extensible.h2
2 files changed, 47 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);
+}
diff --git a/e-util/e-extensible.h b/e-util/e-extensible.h
index a72ea71611..6dd6294212 100644
--- a/e-util/e-extensible.h
+++ b/e-util/e-extensible.h
@@ -51,6 +51,8 @@ struct _EExtensibleInterface {
GType e_extensible_get_type (void);
void e_extensible_load_extensions (EExtensible *extensible);
+GList * e_extensible_list_extensions (EExtensible *extensible,
+ GType extension_type);
G_END_DECLS