[evolution-data-server/wip/mcrha/libical-glib] Add ECalComponentAlarm::summary



commit 2bbd71a4165b3a3b4e83934e56159ca8e60db31f
Author: Milan Crha <mcrha redhat com>
Date:   Thu Mar 7 13:41:36 2019 +0100

    Add ECalComponentAlarm::summary
    
    Needed for email alarms, thus provide direct access for it.

 src/calendar/libecal/e-cal-component-alarm.c | 105 ++++++++++++++++++++++++++-
 src/calendar/libecal/e-cal-component-alarm.h |   9 +++
 tests/libecal/test-cal-component.c           |  37 +++++++---
 3 files changed, 140 insertions(+), 11 deletions(-)
---
diff --git a/src/calendar/libecal/e-cal-component-alarm.c b/src/calendar/libecal/e-cal-component-alarm.c
index e52195c19..ee086fbb1 100644
--- a/src/calendar/libecal/e-cal-component-alarm.c
+++ b/src/calendar/libecal/e-cal-component-alarm.c
@@ -42,6 +42,7 @@ G_DEFINE_BOXED_TYPE (ECalComponentAlarm, e_cal_component_alarm, e_cal_component_
 struct _ECalComponentAlarm {
        gchar *uid;
        ECalComponentAlarmAction action;
+       ECalComponentText *summary;
        ECalComponentText *description;
        ECalComponentAlarmRepeat *repeat;
        ECalComponentAlarmTrigger *trigger;
@@ -127,6 +128,9 @@ e_cal_component_alarm_copy (const ECalComponentAlarm *alarm)
        alrm->uid = g_strdup (alarm->uid);
        alrm->action = alarm->action;
 
+       if (alarm->summary)
+               alrm->summary = e_cal_component_text_copy (alarm->summary);
+
        if (alarm->description)
                alrm->description = e_cal_component_text_copy (alarm->description);
 
@@ -204,6 +208,7 @@ e_cal_component_alarm_free (gpointer alarm)
 
        if (alrm) {
                g_free (alrm->uid);
+               e_cal_component_text_free (alrm->summary);
                e_cal_component_text_free (alrm->description);
                e_cal_component_alarm_repeat_free (alrm->repeat);
                e_cal_component_alarm_trigger_free (alrm->trigger);
@@ -237,6 +242,7 @@ e_cal_component_alarm_set_from_component (ECalComponentAlarm *alarm,
        g_return_if_fail (i_cal_component_isa ((ICalComponent *) component) == I_CAL_VALARM_COMPONENT);
 
        g_free (alarm->uid);
+       e_cal_component_text_free (alarm->summary);
        e_cal_component_text_free (alarm->description);
        e_cal_component_alarm_repeat_free (alarm->repeat);
        e_cal_component_alarm_trigger_free (alarm->trigger);
@@ -245,6 +251,7 @@ e_cal_component_alarm_set_from_component (ECalComponentAlarm *alarm,
 
        alarm->uid = NULL;
        alarm->action = E_CAL_COMPONENT_ALARM_NONE;
+       alarm->summary = NULL;
        alarm->description = NULL;
        alarm->repeat = NULL;
        alarm->trigger = NULL;
@@ -295,13 +302,26 @@ e_cal_component_alarm_set_from_component (ECalComponentAlarm *alarm,
                                alarm->attachments = g_slist_prepend (alarm->attachments, attach);
                        break;
 
+               case I_CAL_SUMMARY_PROPERTY:
+                       if (i_cal_property_get_summary (prop)) {
+                               ICalParameter *param;
+
+                               param = i_cal_property_get_first_parameter (prop, I_CAL_ALTREP_PARAMETER);
+                               e_cal_component_alarm_take_summary (alarm,
+                                       e_cal_component_text_new (i_cal_property_get_summary (prop),
+                                       param ? i_cal_parameter_get_altrep (param) : NULL));
+                               g_clear_object (&param);
+                       }
+                       break;
+
                case I_CAL_DESCRIPTION_PROPERTY:
                        if (i_cal_property_get_description (prop)) {
                                ICalParameter *param;
 
                                param = i_cal_property_get_first_parameter (prop, I_CAL_ALTREP_PARAMETER);
-                               alarm->description = e_cal_component_text_new (i_cal_property_get_description 
(prop),
-                                       param ? i_cal_parameter_get_altrep (param) : NULL);
+                               e_cal_component_alarm_take_description (alarm,
+                                       e_cal_component_text_new (i_cal_property_get_description (prop),
+                                       param ? i_cal_parameter_get_altrep (param) : NULL));
                                g_clear_object (&param);
                        }
                        break;
@@ -406,6 +426,7 @@ e_cal_component_alarm_fill_component (ECalComponentAlarm *alarm,
        ICalPropertyKind remove_props[] = {
                I_CAL_ACTION_PROPERTY,
                I_CAL_ATTACH_PROPERTY,
+               I_CAL_SUMMARY_PROPERTY,
                I_CAL_DESCRIPTION_PROPERTY,
                I_CAL_DURATION_PROPERTY,
                I_CAL_REPEAT_PROPERTY,
@@ -488,6 +509,24 @@ e_cal_component_alarm_fill_component (ECalComponentAlarm *alarm,
        if (prop)
                i_cal_component_take_property (component, prop);
 
+       if (alarm->summary && e_cal_component_text_get_value (alarm->summary)) {
+               prop = i_cal_property_new_summary (e_cal_component_text_get_value (alarm->summary));
+
+               if (prop) {
+                       const gchar *altrep = e_cal_component_text_get_altrep (alarm->summary);
+
+                       if (altrep && *altrep) {
+                               ICalParameter *param;
+
+                               param = i_cal_parameter_new_altrep (altrep);
+                               if (param)
+                                       i_cal_property_take_parameter (prop, param);
+                       }
+
+                       i_cal_component_take_property (component, prop);
+               }
+       }
+
        if (alarm->description && e_cal_component_text_get_value (alarm->description)) {
                prop = i_cal_property_new_description (e_cal_component_text_get_value (alarm->description));
 
@@ -628,6 +667,68 @@ e_cal_component_alarm_set_action (ECalComponentAlarm *alarm,
        alarm->action = action;
 }
 
+/**
+ * e_cal_component_alarm_get_summary:
+ * @alarm: an #ECalComponentAlarm
+ *
+ * Get the @alarm summary, as an #ECalComponentText.
+ *
+ * Returns: (transfer none) (nullable): the @alarm summary, or %NULL, when none is set
+ *
+ * Since: 3.36
+ **/
+ECalComponentText *
+e_cal_component_alarm_get_summary (const ECalComponentAlarm *alarm)
+{
+       g_return_val_if_fail (alarm != NULL, NULL);
+
+       return alarm->summary;
+}
+
+/**
+ * e_cal_component_alarm_set_summary:
+ * @alarm: an #ECalComponentAlarm
+ * @summary: (transfer none) (nullable): a summary to set, or %NULL to unset
+ *
+ * Set the @alarm summary, as an #ECalComponentText.
+ *
+ * Since: 3.36
+ **/
+void
+e_cal_component_alarm_set_summary (ECalComponentAlarm *alarm,
+                                  const ECalComponentText *summary)
+{
+       g_return_if_fail (alarm != NULL);
+
+       if (summary != alarm->summary) {
+               e_cal_component_text_free (alarm->summary);
+
+               alarm->summary = summary ? e_cal_component_text_copy (summary) : NULL;
+       }
+}
+
+/**
+ * e_cal_component_alarm_take_summary: (skip)
+ * @alarm: an #ECalComponentAlarm
+ * @summary: (transfer full) (nullable): a summary to set, or %NULL to unset
+ *
+ * Set the @alarm summary, as an #ECalComponentText, and assumes
+ * ownership of the @summary.
+ *
+ * Since: 3.36
+ **/
+void
+e_cal_component_alarm_take_summary (ECalComponentAlarm *alarm,
+                                   ECalComponentText *summary)
+{
+       g_return_if_fail (alarm != NULL);
+
+       if (summary != alarm->summary) {
+               e_cal_component_text_free (alarm->summary);
+               alarm->summary = summary;
+       }
+}
+
 /**
  * e_cal_component_alarm_get_description:
  * @alarm: an #ECalComponentAlarm
diff --git a/src/calendar/libecal/e-cal-component-alarm.h b/src/calendar/libecal/e-cal-component-alarm.h
index f65c1f7b9..696ee38d8 100644
--- a/src/calendar/libecal/e-cal-component-alarm.h
+++ b/src/calendar/libecal/e-cal-component-alarm.h
@@ -76,6 +76,15 @@ ECalComponentAlarmAction
                e_cal_component_alarm_get_action(const ECalComponentAlarm *alarm);
 void           e_cal_component_alarm_set_action(ECalComponentAlarm *alarm,
                                                 ECalComponentAlarmAction action);
+ECalComponentText *
+               e_cal_component_alarm_get_summary
+                                               (const ECalComponentAlarm *alarm);
+void           e_cal_component_alarm_set_summary
+                                               (ECalComponentAlarm *alarm,
+                                                const ECalComponentText *summary);
+void           e_cal_component_alarm_take_summary
+                                               (ECalComponentAlarm *alarm,
+                                                ECalComponentText *summary);
 ECalComponentText *
                e_cal_component_alarm_get_description
                                                (const ECalComponentAlarm *alarm);
diff --git a/tests/libecal/test-cal-component.c b/tests/libecal/test-cal-component.c
index 6f4fed116..8b1b15e31 100644
--- a/tests/libecal/test-cal-component.c
+++ b/tests/libecal/test-cal-component.c
@@ -418,6 +418,9 @@ verify_struct_alarm_equal (const ECalComponentAlarm *expected,
        g_assert_cmpstr (e_cal_component_alarm_get_uid (expected), ==, e_cal_component_alarm_get_uid 
(received));
        g_assert_cmpint (e_cal_component_alarm_get_action (expected), ==, e_cal_component_alarm_get_action 
(received));
 
+       verify_struct_text_equal (e_cal_component_alarm_get_summary (expected),
+                                 e_cal_component_alarm_get_summary (received));
+
        verify_struct_text_equal (e_cal_component_alarm_get_description (expected),
                                  e_cal_component_alarm_get_description (received));
 
@@ -501,6 +504,7 @@ test_component_struct_alarm (void)
        struct _values {
                const gchar *uid;
                ECalComponentAlarmAction action;
+               const gchar *summary;
                const gchar *description;
                gboolean with_repeat;
                gboolean with_trigger;
@@ -508,16 +512,16 @@ test_component_struct_alarm (void)
                gboolean with_attachments;
                gboolean with_properties;
        } values[] = {
-               { "1", E_CAL_COMPONENT_ALARM_AUDIO, NULL, FALSE, FALSE, FALSE, FALSE, FALSE },
-               { "2", E_CAL_COMPONENT_ALARM_DISPLAY, "display text", FALSE, FALSE, FALSE, FALSE, FALSE },
-               { "3", E_CAL_COMPONENT_ALARM_EMAIL, NULL, TRUE, FALSE, FALSE, FALSE, FALSE },
-               { "4", E_CAL_COMPONENT_ALARM_PROCEDURE, "procedure", FALSE, TRUE, FALSE, FALSE, TRUE },
-               { "5", E_CAL_COMPONENT_ALARM_AUDIO, NULL, FALSE, FALSE, TRUE, FALSE, TRUE },
-               { "6", E_CAL_COMPONENT_ALARM_DISPLAY, "display text", FALSE, FALSE, FALSE, TRUE, TRUE },
-               { "7", E_CAL_COMPONENT_ALARM_EMAIL, NULL, TRUE, FALSE, TRUE, FALSE, TRUE },
-               { "8", E_CAL_COMPONENT_ALARM_PROCEDURE, "procedure", TRUE, TRUE, TRUE, TRUE, TRUE }
+               { "1", E_CAL_COMPONENT_ALARM_AUDIO, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE },
+               { "2", E_CAL_COMPONENT_ALARM_DISPLAY, NULL, "display text", FALSE, FALSE, FALSE, FALSE, FALSE 
},
+               { "3", E_CAL_COMPONENT_ALARM_EMAIL, "summary text", NULL, TRUE, FALSE, FALSE, FALSE, FALSE },
+               { "4", E_CAL_COMPONENT_ALARM_PROCEDURE, NULL, "procedure", FALSE, TRUE, FALSE, FALSE, TRUE },
+               { "5", E_CAL_COMPONENT_ALARM_AUDIO, NULL, NULL, FALSE, FALSE, TRUE, FALSE, TRUE },
+               { "6", E_CAL_COMPONENT_ALARM_DISPLAY, NULL, "display text", FALSE, FALSE, FALSE, TRUE, TRUE },
+               { "7", E_CAL_COMPONENT_ALARM_EMAIL, "summary", "description", TRUE, FALSE, TRUE, FALSE, TRUE 
},
+               { "8", E_CAL_COMPONENT_ALARM_PROCEDURE, NULL, "procedure", TRUE, TRUE, TRUE, TRUE, TRUE }
        };
-       gint ii, nth_description = 0, nth_repeat = 0, nth_trigger = 0, nth_attendees = 0, nth_attachments = 
0, nth_properties = 0;
+       gint ii, nth_summary = 0, nth_description = 0, nth_repeat = 0, nth_trigger = 0, nth_attendees = 0, 
nth_attachments = 0, nth_properties = 0;
 
        for (ii = 0; ii < G_N_ELEMENTS (values); ii++) {
                ECalComponentAlarm *expected, *received;
@@ -527,6 +531,20 @@ test_component_struct_alarm (void)
                e_cal_component_alarm_set_uid (expected, values[ii].uid);
                e_cal_component_alarm_set_action (expected, values[ii].action);
 
+               if (values[ii].summary) {
+                       nth_summary++;
+
+                       if ((nth_summary & 1) != 0) {
+                               ECalComponentText *txt;
+
+                               txt = e_cal_component_text_new (values[ii].summary, "alt-representation");
+                               e_cal_component_alarm_set_summary (expected, txt);
+                               e_cal_component_text_free (txt);
+                       } else {
+                               e_cal_component_alarm_take_summary (expected, e_cal_component_text_new 
(values[ii].summary, NULL));
+                       }
+               }
+
                if (values[ii].description) {
                        nth_description++;
 
@@ -698,6 +716,7 @@ test_component_struct_alarm (void)
                e_cal_component_alarm_free (expected);
        }
 
+       g_assert_cmpint (nth_summary, >, 1);
        g_assert_cmpint (nth_description, >, 1);
        g_assert_cmpint (nth_repeat, >, 1);
        g_assert_cmpint (nth_trigger, >, 1);


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