[evolution-ews] Extract create and set alarm functions



commit 2e2ed5c8c93f25ee0432de60c327e9091581c55c
Author: Pavel Ocheretny <pocheretny src gnome org>
Date:   Mon Jul 18 16:34:55 2011 +0300

    Extract create and set alarm functions

 src/calendar/e-cal-backend-ews-utils.c |   53 ++++++++++++++++++++++++++++++++
 src/calendar/e-cal-backend-ews-utils.h |    2 +
 src/calendar/e-cal-backend-ews.c       |   28 +---------------
 3 files changed, 57 insertions(+), 26 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews-utils.c b/src/calendar/e-cal-backend-ews-utils.c
index 7489bfd..0bb5044 100644
--- a/src/calendar/e-cal-backend-ews-utils.c
+++ b/src/calendar/e-cal-backend-ews-utils.c
@@ -90,6 +90,59 @@ void e_ews_collect_attendees(icalcomponent *comp, GSList **required, GSList **op
 	}
 }
 
+gint ews_get_alarm (ECalComponent *comp)
+{
+	GList *alarm_uids = e_cal_component_get_alarm_uids (comp);
+	ECalComponentAlarm *alarm = e_cal_component_get_alarm (comp, (const gchar *) (alarm_uids->data));
+	ECalComponentAlarmAction action;
+	ECalComponentAlarmTrigger trigger;
+	gint dur_int = 0;
+
+	e_cal_component_alarm_get_action (alarm, &action);
+	if (action == E_CAL_COMPONENT_ALARM_DISPLAY) {
+		e_cal_component_alarm_get_trigger (alarm, &trigger);
+		switch (trigger.type) {
+		case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START:
+			dur_int = ((icaldurationtype_as_int (trigger.u.rel_duration)) / SECS_IN_MINUTE) * -1;
+			break;
+		default:
+			break;
+		}
+	}
+	e_cal_component_alarm_free (alarm);
+	cal_obj_uid_list_free (alarm_uids);
+	return dur_int;
+}
+
+void ews_set_alarm (ESoapMessage *msg, ECalComponent *comp)
+{
+	/* We know there would be only a single alarm in EWS calendar item */
+	GList *alarm_uids = e_cal_component_get_alarm_uids (comp);
+	ECalComponentAlarm *alarm = e_cal_component_get_alarm (comp, (const gchar *) (alarm_uids->data));
+	ECalComponentAlarmAction action;
+
+	e_ews_message_write_string_parameter (msg, "ReminderIsSet", NULL, "true");
+	e_cal_component_alarm_get_action (alarm, &action);
+	if (action == E_CAL_COMPONENT_ALARM_DISPLAY) {
+		ECalComponentAlarmTrigger trigger;
+		char buf[20];
+		gint dur_int = 0;
+		e_cal_component_alarm_get_trigger (alarm, &trigger);
+		switch (trigger.type) {
+		case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START:
+			dur_int = ((icaldurationtype_as_int (trigger.u.rel_duration)) / SECS_IN_MINUTE) * -1;
+			snprintf (buf, 20, "%d", dur_int);
+			e_ews_message_write_string_parameter (msg, "ReminderMinutesBeforeStart", NULL, buf);
+			break;
+		default:
+			break;
+		}
+	}
+	e_cal_component_alarm_free (alarm);
+	cal_obj_uid_list_free (alarm_uids);
+
+}
+
 void ewscal_set_time (ESoapMessage *msg, const gchar *name, icaltimetype *t)
 {
 	char *str;
diff --git a/src/calendar/e-cal-backend-ews-utils.h b/src/calendar/e-cal-backend-ews-utils.h
index bf914db..e43542d 100644
--- a/src/calendar/e-cal-backend-ews-utils.h
+++ b/src/calendar/e-cal-backend-ews-utils.h
@@ -41,6 +41,8 @@ void ewscal_set_reccurence (ESoapMessage *msg, icalproperty *rrule, icaltimetype
 void ewscal_set_reccurence_exceptions (ESoapMessage *msg, icalcomponent *comp);
 void ewscal_get_attach_differences (const GSList *original, const GSList *modified, GSList **removed, GSList **added);
 gchar *e_ews_extract_attachment_id_from_uri (const gchar *uri);
+void ews_set_alarm (ESoapMessage *msg, ECalComponent *comp);
+gint ews_get_alarm (ECalComponent *comp);
 
 G_END_DECLS
 
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 0d46135..b1b5743 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -1053,32 +1053,8 @@ convert_vevent_calcomp_to_xml(ESoapMessage *msg, gpointer user_data)
 
 	/* set alarms */
 	has_alarms = e_cal_component_has_alarms (comp);
-	if (has_alarms) {
-		/* We know there would be only a single alarm in EWS calendar item */
-		GList *alarm_uids = e_cal_component_get_alarm_uids (comp);
-		ECalComponentAlarm *alarm = e_cal_component_get_alarm (comp, (const gchar *)(alarm_uids->data));
-		ECalComponentAlarmAction action;
-
-		e_ews_message_write_string_parameter(msg, "ReminderIsSet", NULL, "true");
-		e_cal_component_alarm_get_action (alarm, &action);
-		if (action == E_CAL_COMPONENT_ALARM_DISPLAY) {
-			ECalComponentAlarmTrigger trigger;
-			char buf[20];
-			gint dur_int = 0;
-			e_cal_component_alarm_get_trigger (alarm, &trigger);
-			switch (trigger.type) {
-			case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START :
-				dur_int = ((icaldurationtype_as_int (trigger.u.rel_duration)) / SECS_IN_MINUTE) * -1;
-				snprintf (buf, 20, "%d",dur_int);
-				e_ews_message_write_string_parameter(msg, "ReminderMinutesBeforeStart", NULL, buf);
-				break;
-			default :
-				break;
-			}
-		}
-		e_cal_component_alarm_free (alarm);
-		cal_obj_uid_list_free (alarm_uids);
-	}
+	if (has_alarms)
+		ews_set_alarm (msg, comp);
 
 	/* start time, end time and meeting time zone */
 	dtstart = icalcomponent_get_dtstart (icalcomp);



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