week-header: sort events before placing them

Sort the events based on multiday/single day, start date and duration.
This commit is contained in:
pandusonu2
2016-12-01 23:48:53 -02:00
committed by Georges Basile Stavracas Neto
parent 175d22e9ef
commit 4544b39b47
+26
View File
@@ -59,6 +59,9 @@ struct _GcalWeekHeader
static GDateTime* get_start_of_week (GcalWeekHeader *self);
static gint events_compare_func (GcalEvent *first,
GcalEvent *second);
static void update_headers (GcalWeekHeader *self);
static void place_events (GcalWeekHeader *self);
@@ -112,6 +115,27 @@ get_start_of_week (GcalWeekHeader *self)
return icaltime_to_datetime (new_date);
}
static gint
events_compare_func (GcalEvent *first,
GcalEvent *second)
{
gint retval;
/* Multiday events should come before single day events */
if (gcal_event_is_multiday (first) != gcal_event_is_multiday (second))
return gcal_event_is_multiday (second) - gcal_event_is_multiday (first);
/* Compare with respect to start day */
retval = g_date_time_compare (gcal_event_get_date_start (first),
gcal_event_get_date_start (second));
if (retval != 0)
return retval;
/* Compare with respect to end day effectively comparing with respect to duration */
return g_date_time_compare (gcal_event_get_date_end (second), gcal_event_get_date_end (first));
}
static void
update_headers (GcalWeekHeader *self)
{
@@ -173,6 +197,8 @@ place_events (GcalWeekHeader *self)
week_start = get_start_of_week (self);
iter = g_list_copy (self->events);
iter = g_list_sort (iter, (GCompareFunc) events_compare_func);
for (l = iter; l != NULL; l = l->next)
{
GcalEvent *event;