summaryrefslogtreecommitdiff
path: root/src/apoint.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-02-15 08:35:21 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-02-15 18:25:55 +0100
commiteaf8f96e065ef30fb78ead5cf1e4007aefd25fbf (patch)
tree0d165e8a1ecdb0ec8261cb51a0f2a036a88618f2 /src/apoint.c
parent07954626c6925f22e4d59b6d68f0947d4e54b8b9 (diff)
downloadcalcurse-eaf8f96e065ef30fb78ead5cf1e4007aefd25fbf.zip
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 <lfleischer@calcurse.org>
Diffstat (limited to 'src/apoint.c')
-rw-r--r--src/apoint.c17
1 files changed, 13 insertions, 4 deletions
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())