summaryrefslogtreecommitdiffstats
path: root/src/day.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/day.c
parent07954626c6925f22e4d59b6d68f0947d4e54b8b9 (diff)
downloadcalcurse-eaf8f96e065ef30fb78ead5cf1e4007aefd25fbf.tar.gz
calcurse-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/day.c')
-rw-r--r--src/day.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/day.c b/src/day.c
index 3dc8349..2a98706 100644
--- a/src/day.c
+++ b/src/day.c
@@ -66,14 +66,30 @@ void day_free_vector(void)
VECTOR_FREE(&day_items);
}
-static int day_cmp_start(struct day_item **pa, struct day_item **pb)
+static int day_cmp(struct day_item **pa, struct day_item **pb)
{
struct day_item *a = *pa;
struct day_item *b = *pb;
+ int a_state, b_state;
if ((a->type == APPT || a->type == RECUR_APPT) &&
(b->type == APPT || b->type == RECUR_APPT)) {
- return a->start - b->start;
+ if (a->start < b->start)
+ return -1;
+ if (a->start > b->start)
+ return 1;
+
+ a_state = day_item_get_state(a);
+ b_state = day_item_get_state(b);
+ if ((a_state & APOINT_NOTIFY) && !(b_state & APOINT_NOTIFY))
+ return -1;
+ if (!(a_state & APOINT_NOTIFY) && (b_state & APOINT_NOTIFY))
+ return 1;
+
+ return strcmp(day_item_get_mesg(a), day_item_get_mesg(b));
+ } else if ((a->type == EVNT || a->type == RECUR_EVNT) &&
+ (b->type == EVNT || b->type == RECUR_EVNT)) {
+ return strcmp(day_item_get_mesg(a), day_item_get_mesg(b));
}
return a->type - b->type;
@@ -347,7 +363,7 @@ day_store_items(long date, int include_captions)
if (include_captions && events > 0 && apts > 0)
day_add_item(DAY_SEPARATOR, 0, p);
- VECTOR_SORT(&day_items, day_cmp_start);
+ VECTOR_SORT(&day_items, day_cmp);
day_items_nb = events + apts;
}