e_source_registry_commit_source_sync(): Handle collection members.
authorMatthew Barnes <mbarnes@redhat.com>
Wed, 25 Jul 2012 18:47:57 +0000 (14:47 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Fri, 3 Aug 2012 15:39:50 +0000 (11:39 -0400)
If a scratch source (with no GDBusObject) references a collection source
as an ancestor call e_source_remote_create_sync() on the collection source
instead of e_source_registry_create_sources_sync().

libedataserver/e-source-registry.c

index cdd1c7d..c9783d6 100644 (file)
@@ -1824,7 +1824,9 @@ source_registry_commit_source_thread (GSimpleAsyncResult *simple,
  *
  * If @source does NOT have a #GDBusObject (implying it's a scratch
  * #ESource), its contents are submitted to the D-Bus service through
- * e_source_registry_create_sources_sync().
+ * either e_source_remote_create_sync() if @source is to be a collection
+ * member, or e_source_registry_create_sources_sync() if @source to be an
+ * independent data source.
  *
  * If an error occurs, the function will set @error and return %FALSE.
  *
@@ -1839,6 +1841,8 @@ e_source_registry_commit_source_sync (ESourceRegistry *registry,
                                       GError **error)
 {
        GDBusObject *dbus_object;
+       ESource *collection_source;
+       gboolean collection_member;
        gboolean success;
 
        g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
@@ -1846,9 +1850,21 @@ e_source_registry_commit_source_sync (ESourceRegistry *registry,
 
        dbus_object = e_source_ref_dbus_object (source);
 
+       collection_source = e_source_registry_find_extension (
+               registry, source, E_SOURCE_EXTENSION_COLLECTION);
+
+       collection_member =
+               (collection_source != NULL) &&
+               (collection_source != source);
+
        if (dbus_object != NULL) {
                success = e_source_write_sync (source, cancellable, error);
                g_object_unref (dbus_object);
+
+       } else if (collection_member) {
+               success = e_source_remote_create_sync (
+                       collection_source, source, cancellable, error);
+
        } else {
                GList *list = g_list_prepend (NULL, source);
                success = e_source_registry_create_sources_sync (
@@ -1856,6 +1872,9 @@ e_source_registry_commit_source_sync (ESourceRegistry *registry,
                g_list_free (list);
        }
 
+       if (collection_source != NULL)
+               g_object_unref (collection_source);
+
        return success;
 }