[evolution-data-server/wip/offline-cache] Minor ECalMetaBackend tweaks



commit 3f26bc5d8fe4250e971c00d351281ea67f3e6a64
Author: Milan Crha <mcrha redhat com>
Date:   Fri Mar 10 08:55:30 2017 +0100

    Minor ECalMetaBackend tweaks

 src/calendar/libedata-cal/e-cal-meta-backend.c |  134 ++++++++++++++---------
 src/calendar/libedata-cal/e-cal-meta-backend.h |   30 +++---
 2 files changed, 97 insertions(+), 67 deletions(-)
---
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.c b/src/calendar/libedata-cal/e-cal-meta-backend.c
index de167dc..ac8af44 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.c
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.c
@@ -70,6 +70,7 @@ enum {
 
 enum {
        REFRESH_COMPLETED,
+       SOURCE_CHANGED,
        LAST_SIGNAL
 };
 
@@ -655,7 +656,7 @@ ecmb_refresh_thread_func (ECalBackend *cal_backend,
 
        g_mutex_unlock (&meta_backend->priv->property_lock);
 
-       g_signal_emit (cal_backend, signals[REFRESH_COMPLETED], 0, NULL);
+       g_signal_emit (meta_backend, signals[REFRESH_COMPLETED], 0, NULL);
 }
 
 static void
@@ -700,6 +701,8 @@ ecmb_source_changed_thread_func (ECalBackend *cal_backend,
        }
        g_mutex_unlock (&meta_backend->priv->property_lock);
 
+       g_signal_emit (meta_backend, signals[SOURCE_CHANGED], 0, NULL);
+
        if (e_backend_get_online (E_BACKEND (meta_backend)) &&
            e_cal_meta_backend_disconnect_sync (meta_backend, cancellable, error)) {
                ecmb_schedule_refresh (meta_backend);
@@ -2901,8 +2904,25 @@ e_cal_meta_backend_class_init (ECalMetaBackendClass *klass)
                G_OBJECT_CLASS_TYPE (klass),
                G_SIGNAL_RUN_LAST,
                0,
-               NULL, NULL,
-               NULL,
+               NULL, NULL, NULL,
+               G_TYPE_NONE, 0, G_TYPE_NONE);
+
+       /**
+        * ECalMetaBackend::source-changed
+        *
+        * This signal is emitted whenever the underlying backend #ESource
+        * changes. Unlike the #ESource's 'changed' signal this one is
+        * tight to the #ECalMetaBackend itself and is emitted from
+        * a dedicated thread, thus it doesn't block the main thread.
+        *
+        * Since: 3.26
+        **/
+       signals[SOURCE_CHANGED] = g_signal_new (
+               "source-changed",
+               G_OBJECT_CLASS_TYPE (klass),
+               G_SIGNAL_RUN_LAST,
+               G_STRUCT_OFFSET (ECalMetaBackendClass, source_changed),
+               NULL, NULL, NULL,
                G_TYPE_NONE, 0, G_TYPE_NONE);
 }
 
@@ -3554,6 +3574,52 @@ e_cal_meta_backend_list_existing_sync (ECalMetaBackend *meta_backend,
 }
 
 /**
+ * e_cal_meta_backend_load_component_sync:
+ * @meta_backend: an #ECalMetaBackend
+ * @uid: a component UID
+ * @out_component: (out) (transfer full): a loaded component, as icalcomponent
+ * @out_extra: (out) (transfer full): an extra data to store to #ECalCache with this component
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Loads a component from the remote side. Any detached instances should be
+ * returned together with the master object. The @out_component can be either
+ * a VCALENDAR component, which would contain the master object and all of
+ * its detached instances, eventually also used time zones, or the requested
+ * component of type VEVENT, VJOURNAL or VTODO.
+ *
+ * It is mandatory to implement this virtual method by the descendant.
+ *
+ * The returned @out_component should be freed with icalcomponent_free()
+ * when no longer needed.
+ *
+ * Returns: Whether succeeded.
+ *
+ * Since: 3.26
+ **/
+gboolean
+e_cal_meta_backend_load_component_sync (ECalMetaBackend *meta_backend,
+                                       const gchar *uid,
+                                       icalcomponent **out_component,
+                                       gchar **out_extra,
+                                       GCancellable *cancellable,
+                                       GError **error)
+{
+       ECalMetaBackendClass *klass;
+
+       g_return_val_if_fail (E_IS_CAL_META_BACKEND (meta_backend), FALSE);
+       g_return_val_if_fail (uid != NULL, FALSE);
+       g_return_val_if_fail (out_component != NULL, FALSE);
+       g_return_val_if_fail (out_extra != NULL, FALSE);
+
+       klass = E_CAL_META_BACKEND_GET_CLASS (meta_backend);
+       g_return_val_if_fail (klass != NULL, FALSE);
+       g_return_val_if_fail (klass->load_component_sync != NULL, FALSE);
+
+       return klass->load_component_sync (meta_backend, uid, out_component, out_extra, cancellable, error);
+}
+
+/**
  * e_cal_meta_backend_save_component_sync:
  * @meta_backend: an #ECalMetaBackend
  * @overwrite_existing: %TRUE when can overwrite existing components, %FALSE otherwise
@@ -3589,7 +3655,7 @@ e_cal_meta_backend_list_existing_sync (ECalMetaBackend *meta_backend,
  * The #E_CLIENT_ERROR_OUT_OF_SYNC error should not be used when the descendant
  * is able to resolve the conflicts itself.
  *
- * It is mandatory to implement this virtual method by the descendant.
+ * It is mandatory to implement this virtual method by the writable descendant.
  *
  * Returns: Whether succeeded.
  *
@@ -3613,55 +3679,13 @@ e_cal_meta_backend_save_component_sync (ECalMetaBackend *meta_backend,
 
        klass = E_CAL_META_BACKEND_GET_CLASS (meta_backend);
        g_return_val_if_fail (klass != NULL, FALSE);
-       g_return_val_if_fail (klass->save_component_sync != NULL, FALSE);
-
-       return klass->save_component_sync (meta_backend, overwrite_existing, conflict_resolution, instances, 
extra, out_new_uid, cancellable, error);
-}
-
-/**
- * e_cal_meta_backend_load_component_sync:
- * @meta_backend: an #ECalMetaBackend
- * @uid: a component UID
- * @out_component: (out) (transfer full): a loaded component, as icalcomponent
- * @out_extra: (out) (transfer full): an extra data to store to #ECalCache with this component
- * @cancellable: optional #GCancellable object, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Loads a component from the remote side. Any detached instances should be
- * returned together with the master object. The @out_component can be either
- * a VCALENDAR component, which would contain the master object and all of
- * its detached instances, eventually also used time zones, or the requested
- * component of type VEVENT, VJOURNAL or VTODO.
- *
- * It is mandatory to implement this virtual method by the descendant.
- *
- * The returned @out_component should be freed with icalcomponent_free()
- * when no longer needed.
- *
- * Returns: Whether succeeded.
- *
- * Since: 3.26
- **/
-gboolean
-e_cal_meta_backend_load_component_sync (ECalMetaBackend *meta_backend,
-                                       const gchar *uid,
-                                       icalcomponent **out_component,
-                                       gchar **out_extra,
-                                       GCancellable *cancellable,
-                                       GError **error)
-{
-       ECalMetaBackendClass *klass;
 
-       g_return_val_if_fail (E_IS_CAL_META_BACKEND (meta_backend), FALSE);
-       g_return_val_if_fail (uid != NULL, FALSE);
-       g_return_val_if_fail (out_component != NULL, FALSE);
-       g_return_val_if_fail (out_extra != NULL, FALSE);
-
-       klass = E_CAL_META_BACKEND_GET_CLASS (meta_backend);
-       g_return_val_if_fail (klass != NULL, FALSE);
-       g_return_val_if_fail (klass->load_component_sync != NULL, FALSE);
+       if (!klass->save_component_sync) {
+               g_propagate_error (error, e_data_cal_create_error (NotSupported, NULL));
+               return FALSE;
+       }
 
-       return klass->load_component_sync (meta_backend, uid, out_component, out_extra, cancellable, error);
+       return klass->save_component_sync (meta_backend, overwrite_existing, conflict_resolution, instances, 
extra, out_new_uid, cancellable, error);
 }
 
 /**
@@ -3675,7 +3699,7 @@ e_cal_meta_backend_load_component_sync (ECalMetaBackend *meta_backend,
  *
  * Removes a component from the remote side, with all its detached instances.
  *
- * It is mandatory to implement this virtual method by the descendant.
+ * It is mandatory to implement this virtual method by the writable descendant.
  *
  * Returns: Whether succeeded.
  *
@@ -3696,7 +3720,11 @@ e_cal_meta_backend_remove_component_sync (ECalMetaBackend *meta_backend,
 
        klass = E_CAL_META_BACKEND_GET_CLASS (meta_backend);
        g_return_val_if_fail (klass != NULL, FALSE);
-       g_return_val_if_fail (klass->remove_component_sync != NULL, FALSE);
+
+       if (!klass->remove_component_sync) {
+               g_propagate_error (error, e_data_cal_create_error (NotSupported, NULL));
+               return FALSE;
+       }
 
        return klass->remove_component_sync (meta_backend, conflict_resolution, uid, extra, cancellable, 
error);
 }
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.h b/src/calendar/libedata-cal/e-cal-meta-backend.h
index b12d5f0..e516a00 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.h
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.h
@@ -121,7 +121,12 @@ struct _ECalMetaBackendClass {
                                                 GSList **out_existing_objects, /* ECalMetaBackendInfo * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-
+       gboolean        (* load_component_sync) (ECalMetaBackend *meta_backend,
+                                                const gchar *uid,
+                                                icalcomponent **out_instances,
+                                                gchar **out_extra,
+                                                GCancellable *cancellable,
+                                                GError **error);
        gboolean        (* save_component_sync) (ECalMetaBackend *meta_backend,
                                                 gboolean overwrite_existing,
                                                 EConflictResolution conflict_resolution,
@@ -130,12 +135,6 @@ struct _ECalMetaBackendClass {
                                                 gchar **out_new_uid,
                                                 GCancellable *cancellable,
                                                 GError **error);
-       gboolean        (* load_component_sync) (ECalMetaBackend *meta_backend,
-                                                const gchar *uid,
-                                                icalcomponent **out_instances,
-                                                gchar **out_extra,
-                                                GCancellable *cancellable,
-                                                GError **error);
        gboolean        (* remove_component_sync)
                                                (ECalMetaBackend *meta_backend,
                                                 EConflictResolution conflict_resolution,
@@ -144,6 +143,9 @@ struct _ECalMetaBackendClass {
                                                 GCancellable *cancellable,
                                                 GError **error);
 
+       /* Signals */
+       void            (* source_changed)      (ECalMetaBackend *meta_backend);
+
        /* Padding for future expansion */
        gpointer reserved[10];
 };
@@ -196,6 +198,13 @@ gboolean   e_cal_meta_backend_list_existing_sync
                                                 GSList **out_existing_objects, /* ECalMetaBackendInfo * */
                                                 GCancellable *cancellable,
                                                 GError **error);
+gboolean       e_cal_meta_backend_load_component_sync
+                                               (ECalMetaBackend *meta_backend,
+                                                const gchar *uid,
+                                                icalcomponent **out_component,
+                                                gchar **out_extra,
+                                                GCancellable *cancellable,
+                                                GError **error);
 gboolean       e_cal_meta_backend_save_component_sync
                                                (ECalMetaBackend *meta_backend,
                                                 gboolean overwrite_existing,
@@ -205,13 +214,6 @@ gboolean   e_cal_meta_backend_save_component_sync
                                                 gchar **out_new_uid,
                                                 GCancellable *cancellable,
                                                 GError **error);
-gboolean       e_cal_meta_backend_load_component_sync
-                                               (ECalMetaBackend *meta_backend,
-                                                const gchar *uid,
-                                                icalcomponent **out_component,
-                                                gchar **out_extra,
-                                                GCancellable *cancellable,
-                                                GError **error);
 gboolean       e_cal_meta_backend_remove_component_sync
                                                (ECalMetaBackend *meta_backend,
                                                 EConflictResolution conflict_resolution,


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