[evolution-data-server/gbsneto/gdata-task-position] Expose GData 'parent' and 'position' task fields



commit 2fc68c25eb6c04fd21be801107d6d7727c0f9e37
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Sep 16 14:06:11 2018 -0300

    Expose GData 'parent' and 'position' task fields
    
    The 'parent' property of the GDataTasksTask object is exposed
    through ICAL_RELATEDTO_PROPERTY, which matches the practices
    of GNOME To Do and NextCloud and other ICal-based providers.
    
    The position, however, is exposed through an X ICal property
    named X-EVOLUTION-GTASKS-POSITION. This doesn't affect Evolution
    in any form, but will still allow external consumers of EDS to
    retrieve the position of the task. Since GData tasks themselves
    aren't backed by ICal components, we have some creative freedom
    to use X properties.
    
    Updating the task position and parent requires [1] but a compile
    check was added to not force EDS to bump the libgdata version.
    
    [1] https://gitlab.gnome.org/GNOME/libgdata/merge_requests/4

 .../backends/gtasks/e-cal-backend-gtasks.c         | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
---
diff --git a/src/calendar/backends/gtasks/e-cal-backend-gtasks.c 
b/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
index 5f0e005c9..64b8a6c54 100644
--- a/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
+++ b/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
@@ -32,6 +32,7 @@
 
 #define GTASKS_DEFAULT_TASKLIST_NAME "@default"
 #define X_EVO_GTASKS_SELF_LINK "X-EVOLUTION-GTASKS-SELF-LINK"
+#define X_EVO_GTASKS_POSITION  "X-EVOLUTION-GTASKS-POSITION"
 
 /* Current data version; when doesn't match with the stored,
    then fetches everything again. */
@@ -100,6 +101,8 @@ ecb_gtasks_gdata_to_comp (GDataTasksTask *task)
        GDataLink *data_link;
        ECalComponent *comp;
        icalcomponent *icomp;
+       const gchar *position;
+       const gchar *parent;
        const gchar *text;
        struct icaltimetype tt;
 
@@ -165,6 +168,14 @@ ecb_gtasks_gdata_to_comp (GDataTasksTask *task)
        if (data_link)
                e_cal_util_set_x_property (icomp, X_EVO_GTASKS_SELF_LINK, gdata_link_get_uri (data_link));
 
+       position = gdata_tasks_task_get_position (task);
+       if (position)
+               e_cal_util_set_x_property (icomp, X_EVO_GTASKS_POSITION, position);
+
+       parent = gdata_tasks_task_get_parent (task);
+       if (parent)
+               icalcomponent_add_property (icomp, icalproperty_new_relatedto (parent));
+
        comp = e_cal_component_new_from_icalcomponent (icomp);
        g_warn_if_fail (comp != NULL);
 
@@ -181,6 +192,9 @@ ecb_gtasks_comp_to_gdata (ECalComponent *comp,
        icalcomponent *icomp;
        icalproperty *prop;
        const gchar *text;
+#if GDATA_CHECK_VERSION(0, 17, 10)
+       gchar *position;
+#endif
        gchar *tmp;
        struct icaltimetype tt;
 
@@ -252,6 +266,41 @@ ecb_gtasks_comp_to_gdata (ECalComponent *comp,
 
        g_free (tmp);
 
+#if GDATA_CHECK_VERSION(0, 17, 10)
+       /* Position */
+       position = e_cal_util_dup_x_property (icomp, X_EVO_GTASKS_POSITION);
+       if (!position || !*position) {
+               g_free (position);
+               position = NULL;
+
+               /* If the passed-in component doesn't contain the libgdata position,
+                  then get it from the cached comp */
+               if (cached_comp) {
+                       position = e_cal_util_dup_x_property (
+                               e_cal_component_get_icalcomponent (cached_comp),
+                               X_EVO_GTASKS_POSITION);
+               }
+       }
+
+       if (position && *position)
+               gdata_tasks_task_set_position (task, position);
+
+       g_free (position);
+
+       /* Parent */
+       prop = icalcomponent_get_first_property (icomp, ICAL_RELATEDTO_PROPERTY);
+       if (!prop && cached_comp) {
+               icalcomponent *cached_icomp;
+               cached_icomp = e_cal_component_get_icalcomponent (cached_comp);
+               prop = icalcomponent_get_first_property (
+                       cached_icomp,
+                       ICAL_RELATEDTO_PROPERTY);
+       }
+
+       if (prop)
+               gdata_tasks_task_set_parent (task, icalproperty_get_relatedto (prop));
+#endif
+
        return task;
 }
 


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