From d53a3570bfa01cd43c31f620c3c8b7ebf4e91ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erick=20P=C3=A9rez=20Castellanos?= Date: Mon, 19 Jan 2015 01:39:44 -0500 Subject: [PATCH] event-widget: added compare function This compare function is made to sort using the same two methods used before but together, giving priority to the longer events. The idea is sort event properly on year-view's sidebar. This function will probably change later. --- src/gcal-event-widget.c | 39 +++++++++++++++++++++++++++++++++++++++ src/gcal-event-widget.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c index 8ee05097..094a7c97 100644 --- a/src/gcal-event-widget.c +++ b/src/gcal-event-widget.c @@ -1164,3 +1164,42 @@ gcal_event_widget_compare_by_start_date (GcalEventWidget *widget1, return icaltime_compare (*(priv1->dt_start), *(priv2->dt_start)); } + +/** + * gcal_event_widget_compare_for_single_day: + * @widget1: + * @widget2: + * + * Compare widgets by putting those that span over a day before the rest, and between those + * who last less than a day by its start time/date + * + * Returns: + **/ +gint +gcal_event_widget_compare_for_single_day (GcalEventWidget *widget1, + GcalEventWidget *widget2) +{ + GcalEventWidgetPrivate *priv1; + GcalEventWidgetPrivate *priv2; + + time_t time_s1, time_s2; + time_t time_e1, time_e2; + time_t result; + + priv1 = gcal_event_widget_get_instance_private (widget1); + priv2 = gcal_event_widget_get_instance_private (widget2); + + time_e1 = time_s1 = icaltime_as_timet (*(priv1->dt_start)); + time_e2 = time_s2 = icaltime_as_timet (*(priv2->dt_start)); + + if (priv1->dt_end != NULL) + time_e1 = icaltime_as_timet (*(priv1->dt_end)); + if (priv2->dt_end) + time_e2 = icaltime_as_timet (*(priv2->dt_end)); + + result = (time_e2 - time_s2) - (time_e1 - time_s1); + if (result != 0) + return result; + else + return icaltime_compare (*(priv1->dt_start), *(priv2->dt_start)); +} diff --git a/src/gcal-event-widget.h b/src/gcal-event-widget.h index c1c2ce66..12036ba4 100644 --- a/src/gcal-event-widget.h +++ b/src/gcal-event-widget.h @@ -117,6 +117,9 @@ gint gcal_event_widget_compare_by_length (GcalEventWidget * gint gcal_event_widget_compare_by_start_date (GcalEventWidget *widget1, GcalEventWidget *widget2); +gint gcal_event_widget_compare_for_single_day (GcalEventWidget *widget1, + GcalEventWidget *widget2); + G_END_DECLS #endif /* __GCAL_EVENT_WIDGET_H__ */