[evolution-data-server] Correct ECalMetaBackend::get_object_sync() implementation
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Correct ECalMetaBackend::get_object_sync() implementation
- Date: Tue, 6 Jun 2017 17:20:39 +0000 (UTC)
commit 387bbffe0a17f169b6c83340ab9dcd59aeb154f0
Author: Milan Crha <mcrha redhat com>
Date: Tue Jun 6 19:16:58 2017 +0200
Correct ECalMetaBackend::get_object_sync() implementation
When no 'rid' is provided the function should return the master
object and all of its detached instances, not only the master
object itself.
src/calendar/libedata-cal/e-cal-meta-backend.c | 26 +++++++++++++++++++++++-
tests/libedata-cal/test-cal-meta-backend.c | 20 +++++++++++++++--
2 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.c b/src/calendar/libedata-cal/e-cal-meta-backend.c
index b87c9f5..1bf475a 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.c
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.c
@@ -1235,6 +1235,7 @@ ecmb_get_object_sync (ECalBackendSync *sync_backend,
{
ECalMetaBackend *meta_backend;
ECalCache *cal_cache;
+ gboolean success;
GError *local_error = NULL;
g_return_if_fail (E_IS_CAL_META_BACKEND (sync_backend));
@@ -1246,7 +1247,30 @@ ecmb_get_object_sync (ECalBackendSync *sync_backend,
g_return_if_fail (cal_cache != NULL);
- if (!e_cal_cache_get_component_as_string (cal_cache, uid, rid, calobj, cancellable, &local_error) &&
+ if (rid && *rid) {
+ success = e_cal_cache_get_component_as_string (cal_cache, uid, rid, calobj, cancellable,
&local_error);
+ } else {
+ GSList *components = NULL;
+
+ success = e_cal_cache_get_components_by_uid (cal_cache, uid, &components, cancellable,
&local_error);
+ if (success) {
+ icalcomponent *icalcomp;
+
+ icalcomp = e_cal_meta_backend_merge_instances (meta_backend, components, FALSE);
+ if (icalcomp) {
+ *calobj = icalcomponent_as_ical_string_r (icalcomp);
+
+ icalcomponent_free (icalcomp);
+ } else {
+ g_set_error (&local_error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND, _("Object
ā%sā not found"), uid);
+ success = FALSE;
+ }
+ }
+
+ g_slist_free_full (components, g_object_unref);
+ }
+
+ if (!success &&
g_error_matches (local_error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND)) {
gchar *loaded_uid = NULL;
gboolean found = FALSE;
diff --git a/tests/libedata-cal/test-cal-meta-backend.c b/tests/libedata-cal/test-cal-meta-backend.c
index c931f01..7536c14 100644
--- a/tests/libedata-cal/test-cal-meta-backend.c
+++ b/tests/libedata-cal/test-cal-meta-backend.c
@@ -2261,6 +2261,7 @@ test_get_object (ECalMetaBackend *meta_backend)
{
ECalMetaBackendTest *test_backend;
ECalCache *cal_cache;
+ icalcomponent *icalcomp;
gchar *calobj = NULL;
GError *error = NULL;
@@ -2277,18 +2278,25 @@ test_get_object (ECalMetaBackend *meta_backend)
e_cal_cache_remove_component (cal_cache, "event-9", NULL, E_CACHE_IS_ONLINE, NULL, &error);
g_assert_no_error (error);
- /* Master object */
+ /* Master object with its detached instances */
E_CAL_BACKEND_SYNC_GET_CLASS (meta_backend)->get_object_sync (E_CAL_BACKEND_SYNC (meta_backend),
NULL, NULL, "event-6", NULL, &calobj, &error);
g_assert_no_error (error);
g_assert_nonnull (calobj);
g_assert (strstr (calobj, "UID:event-6"));
- g_assert (!strstr (calobj, "RECURRENCE-ID;TZID=America/New_York:20170225T134900"));
+ g_assert (strstr (calobj, "RECURRENCE-ID;TZID=America/New_York:20170225T134900"));
+
+ icalcomp = icalcomponent_new_from_string (calobj);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VCALENDAR_COMPONENT);
+ g_assert_cmpint (icalcomponent_count_components (icalcomp, ICAL_VEVENT_COMPONENT), ==, 2);
+ icalcomponent_free (icalcomp);
+
g_free (calobj);
calobj = NULL;
- /* Detached instance */
+ /* Only the detached instance */
E_CAL_BACKEND_SYNC_GET_CLASS (meta_backend)->get_object_sync (E_CAL_BACKEND_SYNC (meta_backend),
NULL, NULL, "event-6", "20170225T134900", &calobj, &error);
@@ -2296,6 +2304,12 @@ test_get_object (ECalMetaBackend *meta_backend)
g_assert_nonnull (calobj);
g_assert (strstr (calobj, "UID:event-6"));
g_assert (strstr (calobj, "RECURRENCE-ID;TZID=America/New_York:20170225T134900"));
+
+ icalcomp = icalcomponent_new_from_string (calobj);
+ g_assert_nonnull (icalcomp);
+ g_assert_cmpint (icalcomponent_isa (icalcomp), ==, ICAL_VEVENT_COMPONENT);
+ icalcomponent_free (icalcomp);
+
g_free (calobj);
calobj = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]