[evolution-data-server/wip/offline-cache] Make GTasks backend work in offline (writable) + ECalMetaBackend test fixes



commit 5211900444ef9d40b535aff3e6d47532038dee13
Author: Milan Crha <mcrha redhat com>
Date:   Wed Mar 22 19:02:17 2017 +0100

    Make GTasks backend work in offline (writable) + ECalMetaBackend test fixes

 .../backends/gtasks/e-cal-backend-gtasks.c         |   20 ++++++++++++++------
 src/calendar/libedata-cal/e-cal-meta-backend.c     |   13 +++++++++----
 src/calendar/libedata-cal/e-cal-meta-backend.h     |    2 ++
 tests/libedata-cal/components/.gitattributes       |    1 +
 tests/libedata-cal/test-cal-meta-backend.c         |    7 ++++---
 5 files changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/src/calendar/backends/gtasks/e-cal-backend-gtasks.c 
b/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
index 2d5dc2f..e74f3ba 100644
--- a/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
+++ b/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
@@ -434,11 +434,7 @@ ecb_gtasks_connect_sync (ECalMetaBackend *meta_backend,
        if (success)
                success = ecb_gtasks_prepare_tasklist (cbgtasks, cancellable, &local_error);
 
-       if (success) {
-               e_cal_backend_set_writable (E_CAL_BACKEND (cbgtasks), TRUE);
-       } else {
-               e_cal_backend_set_writable (E_CAL_BACKEND (cbgtasks), FALSE);
-
+       if (!success) {
                if (g_error_matches (local_error, GDATA_SERVICE_ERROR, 
GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED)) {
                        if (!e_named_parameters_exists (credentials, E_SOURCE_CREDENTIAL_PASSWORD))
                                *out_auth_result = E_SOURCE_AUTHENTICATION_REQUIRED;
@@ -845,6 +841,7 @@ ecb_gtasks_remove_component_sync (ECalMetaBackend *meta_backend,
                                  EConflictResolution conflict_resolution,
                                  const gchar *uid,
                                  const gchar *extra,
+                                 const gchar *object,
                                  GCancellable *cancellable,
                                  GError **error)
 {
@@ -859,7 +856,15 @@ ecb_gtasks_remove_component_sync (ECalMetaBackend *meta_backend,
        cal_cache = e_cal_meta_backend_ref_cache (meta_backend);
        g_return_val_if_fail (cal_cache != NULL, FALSE);
 
-       if (!e_cal_cache_get_component (cal_cache, uid, NULL, &cached_comp, cancellable, &local_error)) {
+       if (object) {
+               cached_comp = e_cal_component_new_from_string (object);
+               if (!cached_comp) {
+                       g_propagate_error (error, EDC_ERROR (InvalidObject));
+                       g_object_unref (cal_cache);
+
+                       return FALSE;
+               }
+       } else if (!e_cal_cache_get_component (cal_cache, uid, NULL, &cached_comp, cancellable, 
&local_error)) {
                if (g_error_matches (local_error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND)) {
                        g_clear_error (&local_error);
                        g_propagate_error (error, EDC_ERROR (ObjectNotFound));
@@ -979,6 +984,9 @@ ecb_gtasks_constructed (GObject *object)
        g_signal_connect (cal_cache, "dup-component-revision", G_CALLBACK 
(ecb_gtasks_dup_component_revision), NULL);
 
        g_clear_object (&cal_cache);
+
+       /* Set it as always writable, regardless online/offline state */
+       e_cal_backend_set_writable (E_CAL_BACKEND (cbgtasks), TRUE);
 }
 
 static void
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.c b/src/calendar/libedata-cal/e-cal-meta-backend.c
index aa06272..80dcd16 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.c
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.c
@@ -619,7 +619,7 @@ ecmb_upload_local_changes_sync (ECalMetaBackend *meta_backend,
                        GError *local_error = NULL;
 
                        success = e_cal_meta_backend_remove_component_sync (meta_backend, conflict_resolution,
-                               change->uid, extra, cancellable, &local_error);
+                               change->uid, extra, change->object, cancellable, &local_error);
 
                        if (!success) {
                                if (g_error_matches (local_error, E_DATA_CAL_ERROR, ObjectNotFound)) {
@@ -1891,7 +1891,7 @@ ecmb_modify_object_sync (ECalMetaBackend *meta_backend,
                *out_old_comp = old_comp;
        if (out_new_comp) {
                if (new_uid) {
-                       if (!e_cal_cache_get_component (cal_cache, new_uid, NULL, out_new_comp, cancellable, 
NULL))
+                       if (!e_cal_cache_get_component (cal_cache, new_uid, id->rid, out_new_comp, 
cancellable, NULL))
                                *out_new_comp = NULL;
                } else {
                        *out_new_comp = new_comp ? g_object_ref (new_comp) : NULL;
@@ -2151,7 +2151,7 @@ ecmb_remove_object_sync (ECalMetaBackend *meta_backend,
 
                if (mod == E_CAL_OBJ_MOD_ALL) {
                        if (*offline_flag == E_CACHE_IS_ONLINE) {
-                               success = e_cal_meta_backend_remove_component_sync (meta_backend, 
conflict_resolution, uid, extra, cancellable, error);
+                               success = e_cal_meta_backend_remove_component_sync (meta_backend, 
conflict_resolution, uid, extra, NULL, cancellable, error);
                        }
 
                        success = success && ecmb_maybe_remove_from_cache (meta_backend, cal_cache, 
*offline_flag, uid, cancellable, error);
@@ -4050,10 +4050,14 @@ e_cal_meta_backend_save_component_sync (ECalMetaBackend *meta_backend,
  * @conflict_resolution: an #EConflictResolution to use
  * @uid: a component UID
  * @extra: (nullable): extra data being saved with the component in the local cache, or %NULL
+ * @object: (nullable): corresponding iCalendar object, as stored in the local cache, or %NULL
  * @cancellable: optional #GCancellable object, or %NULL
  * @error: return location for a #GError, or %NULL
  *
  * Removes a component from the remote side, with all its detached instances.
+ * The @object is not %NULL when it's removing locally deleted object
+ * in offline mode. Being it %NULL, the descendant can obtain the object
+ * from the #ECalCache.
  *
  * It is mandatory to implement this virtual method by the writable descendant.
  *
@@ -4066,6 +4070,7 @@ e_cal_meta_backend_remove_component_sync (ECalMetaBackend *meta_backend,
                                          EConflictResolution conflict_resolution,
                                          const gchar *uid,
                                          const gchar *extra,
+                                         const gchar *object,
                                          GCancellable *cancellable,
                                          GError **error)
 {
@@ -4082,7 +4087,7 @@ e_cal_meta_backend_remove_component_sync (ECalMetaBackend *meta_backend,
                return FALSE;
        }
 
-       return klass->remove_component_sync (meta_backend, conflict_resolution, uid, extra, cancellable, 
error);
+       return klass->remove_component_sync (meta_backend, conflict_resolution, uid, extra, object, 
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 463d268..accdcfc 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.h
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.h
@@ -142,6 +142,7 @@ struct _ECalMetaBackendClass {
                                                 EConflictResolution conflict_resolution,
                                                 const gchar *uid,
                                                 const gchar *extra,
+                                                const gchar *object,
                                                 GCancellable *cancellable,
                                                 GError **error);
        gboolean        (* requires_reconnect)  (ECalMetaBackend *meta_backend);
@@ -232,6 +233,7 @@ gboolean    e_cal_meta_backend_remove_component_sync
                                                 EConflictResolution conflict_resolution,
                                                 const gchar *uid,
                                                 const gchar *extra,
+                                                const gchar *object,
                                                 GCancellable *cancellable,
                                                 GError **error);
 gboolean       e_cal_meta_backend_requires_reconnect
diff --git a/tests/libedata-cal/components/.gitattributes b/tests/libedata-cal/components/.gitattributes
new file mode 100644
index 0000000..11bcb63
--- /dev/null
+++ b/tests/libedata-cal/components/.gitattributes
@@ -0,0 +1 @@
+*.ics eol=crlf
diff --git a/tests/libedata-cal/test-cal-meta-backend.c b/tests/libedata-cal/test-cal-meta-backend.c
index d7fb6fc..8524c60 100644
--- a/tests/libedata-cal/test-cal-meta-backend.c
+++ b/tests/libedata-cal/test-cal-meta-backend.c
@@ -527,6 +527,7 @@ e_cal_meta_backend_test_remove_component_sync (ECalMetaBackend *meta_backend,
                                               EConflictResolution conflict_resolution,
                                               const gchar *uid,
                                               const gchar *extra,
+                                              const gchar *object,
                                               GCancellable *cancellable,
                                               GError **error)
 {
@@ -1870,13 +1871,13 @@ test_modify_objects (ECalMetaBackend *meta_backend)
 
        icalcomp = e_cal_component_get_icalcomponent (old_components->data);
        old_sequence = icalcomponent_get_sequence (icalcomp);
-       g_assert_cmpstr (icalcomponent_get_summary (icalcomp), !=, MODIFIED_SUMMARY_STR);
        g_assert_cmpstr (icalcomponent_get_uid (icalcomp), ==, "event-6");
+       g_assert_cmpstr (icalcomponent_get_summary (icalcomp), !=, MODIFIED_SUMMARY_STR);
 
        icalcomp = e_cal_component_get_icalcomponent (new_components->data);
-       g_assert_cmpint (old_sequence + 1, ==, icalcomponent_get_sequence (icalcomp));
-       g_assert_cmpstr (icalcomponent_get_summary (icalcomp), ==, MODIFIED_SUMMARY_STR);
        g_assert_cmpstr (icalcomponent_get_uid (icalcomp), ==, "event-6");
+       g_assert_cmpstr (icalcomponent_get_summary (icalcomp), ==, MODIFIED_SUMMARY_STR);
+       g_assert_cmpint (old_sequence + 1, ==, icalcomponent_get_sequence (icalcomp));
 
        g_slist_free_full (old_components, g_object_unref);
        g_slist_free_full (new_components, g_object_unref);


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