[evolution-data-server/wip/mcrha/libical-glib] Add e_cal_util_component_get_recurid_as_string()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/mcrha/libical-glib] Add e_cal_util_component_get_recurid_as_string()
- Date: Thu, 21 Mar 2019 13:30:31 +0000 (UTC)
commit b077c64508bca6a7675607494de5fc45328e2c2d
Author: Milan Crha <mcrha redhat com>
Date: Thu Mar 21 14:31:43 2019 +0100
Add e_cal_util_component_get_recurid_as_string()
src/calendar/libecal/e-cal-component.c | 28 +------------------------
src/calendar/libecal/e-cal-util.c | 38 ++++++++++++++++++++++++++++++++++
src/calendar/libecal/e-cal-util.h | 2 ++
3 files changed, 41 insertions(+), 27 deletions(-)
---
diff --git a/src/calendar/libecal/e-cal-component.c b/src/calendar/libecal/e-cal-component.c
index 5f6c1ccf5..aaca507ba 100644
--- a/src/calendar/libecal/e-cal-component.c
+++ b/src/calendar/libecal/e-cal-component.c
@@ -2814,33 +2814,7 @@ e_cal_component_get_recurid (ECalComponent *comp)
gchar *
e_cal_component_get_recurid_as_string (ECalComponent *comp)
{
- ECalComponentRange *range;
- ECalComponentDateTime *dt = NULL; /* owned by the 'range' */
- ICalTimetype *tt = NULL; /* owned by the 'range' */
- gchar *rid;
-
- if (!e_cal_component_is_instance (comp))
- return NULL;
-
- range = e_cal_component_get_recurid (comp);
- if (range)
- dt = e_cal_component_range_get_datetime (range);
- if (dt)
- tt = e_cal_component_datetime_get_value (dt);
-
- if (!range || !dt || !tt) {
- e_cal_component_range_free (range);
- return g_strdup ("0");
- }
-
- if (i_cal_time_is_valid_time (tt) && !i_cal_time_is_null_time (tt))
- rid = i_cal_time_as_ical_string_r (tt);
- else
- rid = g_strdup ("0");
-
- e_cal_component_range_free (range);
-
- return rid;
+ return e_cal_util_component_get_recurid_as_string (comp->priv->icalcomp);
}
/**
diff --git a/src/calendar/libecal/e-cal-util.c b/src/calendar/libecal/e-cal-util.c
index bd9e6b033..5a95f37f2 100644
--- a/src/calendar/libecal/e-cal-util.c
+++ b/src/calendar/libecal/e-cal-util.c
@@ -1103,6 +1103,44 @@ e_cal_util_component_has_attendee (ICalComponent *icalcomp)
return e_cal_util_component_has_property (icalcomp, I_CAL_ATTENDEE_PROPERTY);
}
+/**
+ * e_cal_util_component_get_recurid_as_string:
+ * @icalcomp: an #ICalComponent
+ *
+ * Returns: (transfer full) (nullable): a RECURRENCEID property as string,
+ * or %NULL, when the @icalcomp is not an instance. Free the returned
+ * string with g_free(), when no longer needed.
+ *
+ * Since: 3.36
+ **/
+gchar *
+e_cal_util_component_get_recurid_as_string (ICalComponent *icalcomp)
+{
+ ICalProperty *prop;
+ ICalTimetype *recurid;
+ gchar *rid;
+
+ g_return_val_if_fail (icalcomp != NULL, NULL);
+
+ prop = i_cal_component_get_first_property (icalcomp, I_CAL_RECURRENCEID_PROPERTY);
+ if (!prop)
+ return NULL;
+
+ recurid = i_cal_property_get_recurrenceid (prop);
+ if (!recurid ||
+ !i_cal_time_is_valid_time (recurid) ||
+ i_cal_time_is_null_time (recurid)) {
+ rid = g_strdup ("0");
+ } else {
+ rid = i_cal_time_as_ical_string_r (recurid);
+ }
+
+ g_clear_object (&recurid);
+ g_object_unref (prop);
+
+ return rid;
+}
+
/**
* e_cal_util_component_has_recurrences:
* @icalcomp: An #ICalComponent.
diff --git a/src/calendar/libecal/e-cal-util.h b/src/calendar/libecal/e-cal-util.h
index 93a5bef5a..67be4b8ef 100644
--- a/src/calendar/libecal/e-cal-util.h
+++ b/src/calendar/libecal/e-cal-util.h
@@ -253,6 +253,8 @@ gboolean e_cal_util_component_has_rdates (ICalComponent *icalcomp);
gboolean e_cal_util_component_has_rrules (ICalComponent *icalcomp);
gboolean e_cal_util_component_has_attendee
(ICalComponent *icalcomp);
+gchar * e_cal_util_component_get_recurid_as_string
+ (ICalComponent *icalcomp);
ICalComponent * e_cal_util_construct_instance (ICalComponent *icalcomp,
const ICalTimetype *rid);
void e_cal_util_remove_instances (ICalComponent *icalcomp,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]