summaryrefslogtreecommitdiff
path: root/src/recur.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/recur.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/recur.c')
-rw-r--r--src/recur.c31
1 files changed, 22 insertions, 9 deletions
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())