From 78bced937e3088c2105a352f80a930e335d33cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erick=20P=C3=A9rez=20Castellanos?= Date: Thu, 4 Dec 2014 15:41:00 -0500 Subject: [PATCH] utils: add helper method for component construction --- src/gcal-utils.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gcal-utils.h | 4 ++++ 2 files changed, 54 insertions(+) diff --git a/src/gcal-utils.c b/src/gcal-utils.c index 5a3c1306..3bc65fb0 100644 --- a/src/gcal-utils.c +++ b/src/gcal-utils.c @@ -397,6 +397,56 @@ get_first_weekday (void) return 0; } +/** + * build_component_from_details: + * @summary: + * @initial_date: + * @final_date: + * + * Create a component with the provided details + * + * Returns: (Transfer full): an {@link ECalComponent} object + **/ +ECalComponent* +build_component_from_details (const gchar *summary, + const icaltimetype *initial_date, + const icaltimetype *final_date) +{ + ECalComponent *event; + + ECalComponentDateTime dt; + ECalComponentText summ; + icaltimetype *dt_start; + + event = e_cal_component_new (); + e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT); + + dt_start = gcal_dup_icaltime (initial_date); + dt.value = dt_start; + dt.tzid = NULL; + e_cal_component_set_dtstart (event, &dt); + + if (final_date != NULL) + { + *dt.value = *final_date; + e_cal_component_set_dtend (event, &dt); + } + else + { + icaltime_adjust (dt_start, 1, 0, 0, 0); + *dt.value = *dt_start; + e_cal_component_set_dtend (event, &dt); + } + + summ.altrep = NULL; + summ.value = summary; + e_cal_component_set_summary (event, &summ); + + e_cal_component_commit_sequence (event); + + return event; +} + /* Function to do a last minute fixup of the AM/PM stuff if the locale * and gettext haven't done it right. Most English speaking countries * except the USA use the 24 hour clock (UK, Australia etc). However diff --git a/src/gcal-utils.h b/src/gcal-utils.h index 25ecccf9..dad6c803 100644 --- a/src/gcal-utils.h +++ b/src/gcal-utils.h @@ -86,6 +86,10 @@ gchar* get_uuid_from_component (ESource gint get_first_weekday (void); +ECalComponent* build_component_from_details (const gchar *summary, + const icaltimetype *initial_date, + const icaltimetype *final_date); + /* code brought from evolution */ gsize e_strftime_fix_am_pm (gchar *str, gsize max,