[evolution-data-server] Bug 795197 - Add an API to refresh collection backend



commit c495f3db20685a4a473dba6d356d5667ae7a053c
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jun 8 08:45:24 2018 +0200

    Bug 795197 - Add an API to refresh collection backend

 CMakeLists.txt                                     |   2 +-
 src/libebackend/e-collection-backend.c             |  31 +++---
 src/libebackend/e-collection-backend.h             |   2 +
 src/libebackend/e-source-registry-server.c         |  49 +++++++++
 src/libedataserver/e-source-registry.c             | 116 +++++++++++++++++++++
 src/libedataserver/e-source-registry.h             |  15 +++
 ...rg.gnome.evolution.dataserver.SourceManager.xml |  10 ++
 7 files changed, 212 insertions(+), 13 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e85ec73e1..2f7cac309 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,7 +39,7 @@ set(PROJECT_DISTCONFIGURE_PARAMS
 # ******************************
 set(ADDRESS_BOOK_DBUS_SERVICE_NAME     "org.gnome.evolution.dataserver.AddressBook9")
 set(CALENDAR_DBUS_SERVICE_NAME         "org.gnome.evolution.dataserver.Calendar7")
-set(SOURCES_DBUS_SERVICE_NAME          "org.gnome.evolution.dataserver.Sources5")
+set(SOURCES_DBUS_SERVICE_NAME          "org.gnome.evolution.dataserver.Sources6")
 set(USER_PROMPTER_DBUS_SERVICE_NAME    "org.gnome.evolution.dataserver.UserPrompter0")
 
 # ******************************
diff --git a/src/libebackend/e-collection-backend.c b/src/libebackend/e-collection-backend.c
index 1001db90d..d9ed7d43f 100644
--- a/src/libebackend/e-collection-backend.c
+++ b/src/libebackend/e-collection-backend.c
@@ -579,17 +579,6 @@ collection_backend_schedule_populate_idle (ECollectionBackend *backend)
                        (GDestroyNotify) g_object_unref);
 }
 
-static void
-collection_backend_online_cb (EBackend *backend,
-                             GParamSpec *spec,
-                             gpointer user_data)
-{
-       g_return_if_fail (E_IS_COLLECTION_BACKEND (backend));
-
-       if (e_backend_get_online (backend))
-               collection_backend_schedule_populate_idle (E_COLLECTION_BACKEND (backend));
-}
-
 static void
 collection_backend_notify_collection_cb (ESourceCollection *collection_extension,
                                         GParamSpec *param,
@@ -903,7 +892,7 @@ collection_backend_constructed (GObject *object)
        collection_backend_schedule_populate_idle (backend);
 
        backend->priv->notify_online_handler_id = g_signal_connect (backend, "notify::online",
-               G_CALLBACK (collection_backend_online_cb), NULL);
+               G_CALLBACK (e_collection_backend_schedule_populate), NULL);
 }
 
 static void
@@ -1884,3 +1873,21 @@ e_collection_backend_authenticate_children (ECollectionBackend *backend,
        g_clear_object (&credentials_provider);
        g_clear_object (&registry_server);
 }
+
+/**
+ * e_collection_backend_schedule_populate:
+ * @backend: an #ECollectionBackend
+ *
+ * Schedules a call to populate() of the @backend on idle.
+ * The function does nothing in case the @backend is offline.
+ *
+ * Since: 3.30
+ **/
+void
+e_collection_backend_schedule_populate (ECollectionBackend *backend)
+{
+       g_return_if_fail (E_IS_COLLECTION_BACKEND (backend));
+
+       if (e_backend_get_online (E_BACKEND (backend)))
+               collection_backend_schedule_populate_idle (backend);
+}
diff --git a/src/libebackend/e-collection-backend.h b/src/libebackend/e-collection-backend.h
index 410b2a3af..014232e42 100644
--- a/src/libebackend/e-collection-backend.h
+++ b/src/libebackend/e-collection-backend.h
@@ -166,6 +166,8 @@ gboolean    e_collection_backend_delete_resource_finish
 void           e_collection_backend_authenticate_children
                                                (ECollectionBackend *backend,
                                                 const ENamedParameters *credentials);
+void           e_collection_backend_schedule_populate
+                                               (ECollectionBackend *backend);
 
 G_END_DECLS
 
diff --git a/src/libebackend/e-source-registry-server.c b/src/libebackend/e-source-registry-server.c
index db861308a..70ab710c8 100644
--- a/src/libebackend/e-source-registry-server.c
+++ b/src/libebackend/e-source-registry-server.c
@@ -421,6 +421,50 @@ source_registry_server_reload_cb (EDBusSourceManager *dbus_interface,
        return TRUE;
 }
 
+static gboolean
+source_registry_server_refresh_backend_cb (EDBusSourceManager *dbus_interface,
+                                          GDBusMethodInvocation *invocation,
+                                          const gchar *source_uid,
+                                          ESourceRegistryServer *server)
+{
+       ESource *source;
+       GError *error = NULL;
+
+       g_return_val_if_fail (E_IS_SOURCE_REGISTRY_SERVER (server), FALSE);
+       g_return_val_if_fail (source_uid != NULL, FALSE);
+
+       source = e_source_registry_server_ref_source (server, source_uid);
+       if (source) {
+               if (e_source_has_extension (source, E_SOURCE_EXTENSION_COLLECTION)) {
+                       ECollectionBackend *backend;
+
+                       backend = e_source_registry_server_ref_backend (server, source);
+                       if (backend) {
+                               e_collection_backend_schedule_populate (backend);
+                               g_object_unref (backend);
+                       } else {
+                               error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                                       _("Cannot find corresponding collection backend for source “%s”"), 
source_uid);
+                       }
+               } else {
+                       error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+                               _("Source “%s” is not a collection source"), source_uid);
+               }
+
+               g_object_unref (source);
+       } else {
+               error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                       _("Cannot find source “%s”"), source_uid);
+       }
+
+       if (error)
+               g_dbus_method_invocation_take_error (invocation, error);
+       else
+               e_dbus_source_manager_complete_refresh_backend (dbus_interface, invocation);
+
+       return TRUE;
+}
+
 typedef struct _FileEventData {
        GFile *file;
        GFileMonitorEvent event_type;
@@ -1142,6 +1186,11 @@ e_source_registry_server_init (ESourceRegistryServer *server)
                source_manager, "handle-reload",
                G_CALLBACK (source_registry_server_reload_cb),
                server);
+
+       g_signal_connect (
+               source_manager, "handle-refresh-backend",
+               G_CALLBACK (source_registry_server_refresh_backend_cb),
+               server);
 }
 
 /**
diff --git a/src/libedataserver/e-source-registry.c b/src/libedataserver/e-source-registry.c
index 63970ffb0..b7c975abc 100644
--- a/src/libedataserver/e-source-registry.c
+++ b/src/libedataserver/e-source-registry.c
@@ -2311,6 +2311,122 @@ e_source_registry_create_sources_finish (ESourceRegistry *registry,
        return !g_simple_async_result_propagate_error (simple, error);
 }
 
+/**
+ * e_source_registry_refresh_backend_sync:
+ * @registry: an #ESourceRegistry
+ * @source_uid: UID of a collection #ESource whose backend to refresh
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Requests the D-Bus service to refresh collection backend for an #ESource
+ * with UID @source_uid. The result means that the refresh had been scheduled
+ * not whether the refresh itself succeeded. The refresh is not initiated
+ * when the collection backend is offline.
+ *
+ * If an error occurs, the function will set @error and return %FALSE.
+ *
+ * Returns: Whether succeeded
+ *
+ * Since: 3.30
+ **/
+gboolean
+e_source_registry_refresh_backend_sync (ESourceRegistry *registry,
+                                       const gchar *source_uid,
+                                       GCancellable *cancellable,
+                                       GError **error)
+{
+       g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
+       g_return_val_if_fail (source_uid != NULL, FALSE);
+
+       return e_dbus_source_manager_call_refresh_backend_sync (
+               registry->priv->dbus_source_manager,
+               source_uid, cancellable, error);
+}
+
+static void
+e_source_registry_refresh_backend_thread (GTask *task,
+                                         gpointer source_object,
+                                         gpointer task_data,
+                                         GCancellable *cancellable)
+{
+       gboolean success;
+       GError *local_error = NULL;
+
+       success = e_source_registry_refresh_backend_sync (source_object, task_data, cancellable, 
&local_error);
+
+       if (local_error)
+               g_task_return_error (task, local_error);
+       else
+               g_task_return_boolean (task, success);
+}
+
+/**
+ * e_source_registry_refresh_backend:
+ * @registry: an #ESourceRegistry
+ * @source_uid: UID of a collection #ESource whose backend to refresh
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request
+ *            is satisfied
+ * @user_data: (closure): data to pass to the callback function
+ *
+ * Asynchronously requests the D-Bus service to refresh collection backend
+ * for an #ESource with UID @source_uid. The result means that the refresh
+ * had been scheduled not whether the refresh itself succeeded. The refresh
+ * is not initiated when the collection backend is offline.
+ *
+ * When the operation is finished, @callback will be called. You can then
+ * call e_source_registry_refresh_backend_finish() to get the result of
+ * the operation.
+ *
+ * Since: 3.30
+ **/
+void
+e_source_registry_refresh_backend (ESourceRegistry *registry,
+                                  const gchar *source_uid,
+                                  GCancellable *cancellable,
+                                  GAsyncReadyCallback callback,
+                                  gpointer user_data)
+{
+       GTask *task;
+
+       g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+       g_return_if_fail (source_uid != NULL);
+
+       task = g_task_new (registry, cancellable, callback, user_data);
+       g_task_set_source_tag (task, e_source_registry_refresh_backend);
+       g_task_set_task_data (task, g_strdup (source_uid), g_free);
+
+       g_task_run_in_thread (task, e_source_registry_refresh_backend_thread);
+
+       g_object_unref (task);
+}
+
+/**
+ * e_source_registry_refresh_backend_finish:
+ * @registry: an #ESourceRegistry
+ * @result: a #GAsyncResult
+ * @error: return location for a #GError, or %NULL
+ *
+ * Finishes the operation started with e_source_registry_refresh_backend().
+ *
+ * If an error occurred, the function will set @error and return %FALSE.
+ *
+ * Returns: Whether succeeded
+ *
+ * Since: 3.30
+ **/
+gboolean
+e_source_registry_refresh_backend_finish (ESourceRegistry *registry,
+                                         GAsyncResult *result,
+                                         GError **error)
+{
+       g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
+       g_return_val_if_fail (g_task_is_valid (result, registry), FALSE);
+       g_return_val_if_fail (g_async_result_is_tagged (result, e_source_registry_refresh_backend), FALSE);
+
+       return g_task_propagate_boolean (G_TASK (result), error);
+}
+
 /**
  * e_source_registry_ref_source:
  * @registry: an #ESourceRegistry
diff --git a/src/libedataserver/e-source-registry.h b/src/libedataserver/e-source-registry.h
index 66c57590b..0141acc6d 100644
--- a/src/libedataserver/e-source-registry.h
+++ b/src/libedataserver/e-source-registry.h
@@ -128,6 +128,21 @@ gboolean   e_source_registry_create_sources_finish
                                                (ESourceRegistry *registry,
                                                 GAsyncResult *result,
                                                 GError **error);
+gboolean       e_source_registry_refresh_backend_sync
+                                               (ESourceRegistry *registry,
+                                                const gchar *source_uid,
+                                                GCancellable *cancellable,
+                                                GError **error);
+void           e_source_registry_refresh_backend
+                                               (ESourceRegistry *registry,
+                                                const gchar *source_uid,
+                                                GCancellable *cancellable,
+                                                GAsyncReadyCallback callback,
+                                                gpointer user_data);
+gboolean       e_source_registry_refresh_backend_finish
+                                               (ESourceRegistry *registry,
+                                                GAsyncResult *result,
+                                                GError **error);
 ESource *      e_source_registry_ref_source    (ESourceRegistry *registry,
                                                 const gchar *uid);
 GList *                e_source_registry_list_sources  (ESourceRegistry *registry,
diff --git a/src/private/org.gnome.evolution.dataserver.SourceManager.xml 
b/src/private/org.gnome.evolution.dataserver.SourceManager.xml
index 3c5fad89f..482b55d3d 100644
--- a/src/private/org.gnome.evolution.dataserver.SourceManager.xml
+++ b/src/private/org.gnome.evolution.dataserver.SourceManager.xml
@@ -37,5 +37,15 @@
       a SIGHUP on platforms that support it.
   -->
   <method name="Reload"/>
+
+  <!--
+      RefreshBackend:
+      @source_uid: A UID of a collection ESource
+
+      Initiates refresh of a backend for a collection ESource with the given source_uid.
+  -->
+  <method name="RefreshBackend">
+    <arg name="source_uid" direction="in" type="s"/>
+  </method>
 </interface>
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]