summaryrefslogtreecommitdiff
path: root/libebackend/e-source-registry-server.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-12-31 09:02:00 -0500
committerMatthew Barnes <mbarnes@redhat.com>2012-12-31 09:05:31 -0500
commita86d3aa8f8d26c3c0363447c379ad660cfc0726d (patch)
tree51bb621f9b4729102a9e5103cb61d8aa43992933 /libebackend/e-source-registry-server.c
parentac38601da7dde8be0cafe16a8f5d57cd1d78d537 (diff)
downloadevolution-data-server-a86d3aa8f8d26c3c0363447c379ad660cfc0726d.tar.gz
Add e_source_registry_server_find_extension().
Server-side equivalent of e_source_registry_find_extension(). Use it in e_source_registry_server_ref_backend().
Diffstat (limited to 'libebackend/e-source-registry-server.c')
-rw-r--r--libebackend/e-source-registry-server.c85
1 files changed, 61 insertions, 24 deletions
diff --git a/libebackend/e-source-registry-server.c b/libebackend/e-source-registry-server.c
index 6b1ec6994..753a7f0bc 100644
--- a/libebackend/e-source-registry-server.c
+++ b/libebackend/e-source-registry-server.c
@@ -2054,41 +2054,43 @@ e_source_registry_server_list_sources (ESourceRegistryServer *server,
}
/**
- * e_source_registry_server_ref_backend:
+ * e_source_registry_server_find_extension:
* @server: an #ESourceRegistryServer
* @source: an #ESource
+ * @extension_name: the extension name to find
*
- * Returns the #ECollectionBackend associated with @source, or %NULL if
- * there is no #ECollectionBackend associated with @source.
+ * Examines @source and its ancestors and returns the "deepest" #ESource
+ * having an #ESourceExtension with the given @extension_name. If neither
+ * @source nor any of its ancestors have such an extension, the function
+ * returns %NULL.
*
- * An #ESource is associated with an #ECollectionBackend if the #ESource has
- * an #ESourceCollection extension, or if it is a hierarchical descendant of
- * another #ESource which has an #ESourceCollection extension.
+ * This function is useful in cases when an #ESourceExtension is meant to
+ * apply to both the #ESource it belongs to and the #ESource's descendants.
*
- * The returned #ECollectionBackend is referenced for thread-safety.
- * Unreference the #ECollectionBackend with g_object_unref() when finished
- * with it.
+ * A common example is the #ESourceCollection extension, where descendants
+ * of an #ESource having an #ESourceCollection extension are implied to be
+ * members of that collection. In that example, this function can be used
+ * to test whether @source is a member of a collection.
*
- * Returns: the #ECollectionBackend for @source, or %NULL
+ * The returned #ESource is referenced for thread-safety and must be
+ * unreferenced with g_object_unref() when finished with it.
*
- * Since: 3.6
+ * Note the function returns the #ESource containing the #ESourceExtension
+ * instead of the #ESourceExtension itself because extension instances are
+ * not to be referenced directly (see e_source_get_extension()).
+ *
+ * Returns: an #ESource, or %NULL if no match was found
+ *
+ * Since: 3.8
**/
-ECollectionBackend *
-e_source_registry_server_ref_backend (ESourceRegistryServer *server,
- ESource *source)
+ESource *
+e_source_registry_server_find_extension (ESourceRegistryServer *server,
+ ESource *source,
+ const gchar *extension_name)
{
- ECollectionBackend *backend = NULL;
- const gchar *extension_name;
-
g_return_val_if_fail (E_IS_SOURCE_REGISTRY_SERVER (server), NULL);
g_return_val_if_fail (E_IS_SOURCE (source), NULL);
-
- /* XXX If ESourceRegistryServer ever grows a function similar to
- * e_source_registry_find_extension() then we could just use
- * that, but despite this use case I think the need for such
- * a function is not sufficiently strong yet. */
-
- extension_name = E_SOURCE_EXTENSION_COLLECTION;
+ g_return_val_if_fail (extension_name != NULL, NULL);
g_object_ref (source);
@@ -2110,6 +2112,41 @@ e_source_registry_server_ref_backend (ESourceRegistryServer *server,
break;
}
+ return source;
+}
+
+/**
+ * e_source_registry_server_ref_backend:
+ * @server: an #ESourceRegistryServer
+ * @source: an #ESource
+ *
+ * Returns the #ECollectionBackend associated with @source, or %NULL if
+ * there is no #ECollectionBackend associated with @source.
+ *
+ * An #ESource is associated with an #ECollectionBackend if the #ESource has
+ * an #ESourceCollection extension, or if it is a hierarchical descendant of
+ * another #ESource which has an #ESourceCollection extension.
+ *
+ * The returned #ECollectionBackend is referenced for thread-safety.
+ * Unreference the #ECollectionBackend with g_object_unref() when finished
+ * with it.
+ *
+ * Returns: the #ECollectionBackend for @source, or %NULL
+ *
+ * Since: 3.6
+ **/
+ECollectionBackend *
+e_source_registry_server_ref_backend (ESourceRegistryServer *server,
+ ESource *source)
+{
+ ECollectionBackend *backend = NULL;
+
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY_SERVER (server), NULL);
+ g_return_val_if_fail (E_IS_SOURCE (source), NULL);
+
+ source = e_source_registry_server_find_extension (
+ server, source, E_SOURCE_EXTENSION_COLLECTION);
+
if (source != NULL) {
backend = g_object_get_data (
G_OBJECT (source), BACKEND_DATA_KEY);