From eaf8f96e065ef30fb78ead5cf1e4007aefd25fbf Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 15 Feb 2016 08:35:21 +0100 Subject: Improve ordering of appointments/events * Order by start time first. * Order items with the same start time by priority. * Order items with the same start and priority by description. Signed-off-by: Lukas Fleischer --- src/recur.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/recur.c') diff --git a/src/recur.c b/src/recur.c index 55f9a12..186acbe 100644 --- a/src/recur.c +++ b/src/recur.c @@ -181,15 +181,28 @@ void recur_event_llist_free(void) } static int -recur_apoint_cmp_start(struct recur_apoint *a, struct recur_apoint *b) +recur_apoint_cmp(struct recur_apoint *a, struct recur_apoint *b) { - return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1); + if (a->start < b->start) + return -1; + if (a->start > b->start) + return 1; + if ((a->state & APOINT_NOTIFY) && !(b->state & APOINT_NOTIFY)) + return -1; + if (!(a->state & APOINT_NOTIFY) && (b->state & APOINT_NOTIFY)) + return 1; + + return strcmp(a->mesg, b->mesg); } -static int recur_event_cmp_day(struct recur_event *a, - struct recur_event *b) +static int recur_event_cmp(struct recur_event *a, struct recur_event *b) { - return a->day < b->day ? -1 : (a->day == b->day ? 0 : 1); + if (a->day < b->day) + return -1; + if (a->day > b->day) + return 1; + + return strcmp(a->mesg, b->mesg); } /* Insert a new recursive appointment in the general linked list */ @@ -218,7 +231,7 @@ struct recur_apoint *recur_apoint_new(char *mesg, char *note, long start, } LLIST_TS_LOCK(&recur_alist_p); - LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start); + LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp); LLIST_TS_UNLOCK(&recur_alist_p); return rapt; @@ -246,7 +259,7 @@ struct recur_event *recur_event_new(char *mesg, char *note, long day, LLIST_INIT(&rev->exc); } - LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day); + LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp); return rev; } @@ -966,7 +979,7 @@ void recur_event_paste_item(struct recur_event *rev, long date) exc->st += time_shift; } - LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day); + LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp); } void recur_apoint_paste_item(struct recur_apoint *rapt, long date) @@ -986,7 +999,7 @@ void recur_apoint_paste_item(struct recur_apoint *rapt, long date) } LLIST_TS_LOCK(&recur_alist_p); - LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start); + LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp); LLIST_TS_UNLOCK(&recur_alist_p); if (notify_bar()) -- cgit v1.2.3-54-g00ecf