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/apoint.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/apoint.c') diff --git a/src/apoint.c b/src/apoint.c index 1c9aa23..cb23ead 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -84,9 +84,18 @@ void apoint_llist_free(void) LLIST_TS_FREE(&alist_p); } -static int apoint_cmp_start(struct apoint *a, struct apoint *b) +static int apoint_cmp(struct apoint *a, struct 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); } struct apoint *apoint_new(char *mesg, char *note, long start, long dur, @@ -102,7 +111,7 @@ struct apoint *apoint_new(char *mesg, char *note, long start, long dur, apt->dur = dur; LLIST_TS_LOCK(&alist_p); - LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp_start); + LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp); LLIST_TS_UNLOCK(&alist_p); return apt; @@ -319,7 +328,7 @@ void apoint_paste_item(struct apoint *apt, long date) apt->start = date + get_item_time(apt->start); LLIST_TS_LOCK(&alist_p); - LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp_start); + LLIST_TS_ADD_SORTED(&alist_p, apt, apoint_cmp); LLIST_TS_UNLOCK(&alist_p); if (notify_bar()) -- cgit v1.2.3-54-g00ecf