[gnome-calendar/wip/gbsneto/alarms: 8/12] utils: move utility method to get alarm's minutes
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/gbsneto/alarms: 8/12] utils: move utility method to get alarm's minutes
- Date: Wed, 6 Jul 2016 06:02:11 +0000 (UTC)
commit 19d68573dd5de0354c8bc1393ebd68744ae33bd0
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Jul 6 01:33:59 2016 -0300
utils: move utility method to get alarm's minutes
src/gcal-event.c | 34 ++--------------------------------
src/gcal-utils.c | 32 ++++++++++++++++++++++++++++++++
src/gcal-utils.h | 3 +++
3 files changed, 37 insertions(+), 32 deletions(-)
---
diff --git a/src/gcal-event.c b/src/gcal-event.c
index f2f9623..6e6b27a 100644
--- a/src/gcal-event.c
+++ b/src/gcal-event.c
@@ -190,36 +190,6 @@ gcal_event_update_uid_internal (GcalEvent *self)
g_object_notify (G_OBJECT (self), "uid");
}
-static gint
-get_trigger_minutes (GcalEvent *self,
- ECalComponentAlarm *alarm)
-{
- ECalComponentAlarmTrigger trigger;
- GDateTime *alarm_dt;
- gint diff;
-
- e_cal_component_alarm_get_trigger (alarm, &trigger);
-
- /*
- * We only support alarms relative to the start date, and solely
- * ignore whetever different it may be.
- */
- if (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START)
- return -1;
-
- alarm_dt = g_date_time_add_full (self->dt_start,
- 0,
- 0,
- - (trigger.u.rel_duration.days + trigger.u.rel_duration.weeks * 7),
- - trigger.u.rel_duration.hours,
- - trigger.u.rel_duration.minutes,
- - trigger.u.rel_duration.seconds);
-
- diff = g_date_time_difference (self->dt_start, alarm_dt) / G_TIME_SPAN_MINUTE;
-
- return diff;
-}
-
static void
load_alarms (GcalEvent *self)
{
@@ -233,7 +203,7 @@ load_alarms (GcalEvent *self)
gint trigger_minutes;
alarm = e_cal_component_get_alarm (self->component, l->data);
- trigger_minutes = get_trigger_minutes (self, alarm);
+ trigger_minutes = get_alarm_trigger_minutes (self, alarm);
/* We only support a single alarm for a given time */
if (!g_hash_table_contains (self->alarms, GINT_TO_POINTER (trigger_minutes)))
@@ -940,7 +910,7 @@ gcal_event_get_alarms (GcalEvent *self)
gint trigger_minutes;
alarm = e_cal_component_get_alarm (self->component, l->data);
- trigger_minutes = get_trigger_minutes (self, alarm);
+ trigger_minutes = get_alarm_trigger_minutes (self, alarm);
/* We only support a single alarm for a given time */
if (!g_hash_table_contains (tmp, GINT_TO_POINTER (trigger_minutes)))
diff --git a/src/gcal-utils.c b/src/gcal-utils.c
index 9b66437..47a5ee1 100644
--- a/src/gcal-utils.c
+++ b/src/gcal-utils.c
@@ -809,3 +809,35 @@ format_utc_offset (gint64 offset)
else
return g_strdup_printf ("%s%02i%02i", sign, hours, minutes);
}
+
+gint
+get_alarm_trigger_minutes (GcalEvent *event,
+ ECalComponentAlarm *alarm)
+{
+ ECalComponentAlarmTrigger trigger;
+ GDateTime *alarm_dt;
+ gint diff;
+
+ e_cal_component_alarm_get_trigger (alarm, &trigger);
+
+ /*
+ * We only support alarms relative to the start date, and solely
+ * ignore whetever different it may be.
+ */
+ if (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START)
+ return -1;
+
+ alarm_dt = g_date_time_add_full (gcal_event_get_date_start (event),
+ 0,
+ 0,
+ - (trigger.u.rel_duration.days + trigger.u.rel_duration.weeks * 7),
+ - trigger.u.rel_duration.hours,
+ - trigger.u.rel_duration.minutes,
+ - trigger.u.rel_duration.seconds);
+
+ diff = g_date_time_difference (gcal_event_get_date_start (event), alarm_dt) / G_TIME_SPAN_MINUTE;
+
+ g_clear_pointer (&alarm_dt, g_date_time_unref);
+
+ return diff;
+}
diff --git a/src/gcal-utils.h b/src/gcal-utils.h
index e3c4148..b8be51b 100644
--- a/src/gcal-utils.h
+++ b/src/gcal-utils.h
@@ -120,4 +120,7 @@ void get_source_parent_name_color (GcalManager
gchar* format_utc_offset (gint64 offset);
+gint get_alarm_trigger_minutes (GcalEvent *event,
+ ECalComponentAlarm *alarm);
+
#endif // __GCAL_UTILS_H__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]