From 8cbd4566405dfac11d723df5c4bb85a679ef8dbf Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Sun, 15 Jul 2018 10:30:41 +0200 Subject: Fix next recurring appointment Recurring appointments do not show up in the notification bar as next appointment. This was partly corrected by 2084f35 (Fix notification of recurrent appointments, 2017-02-09) and 5aa7a09 (Fix another error in the notification code, 2017-02-11). The search function recur_apoint_starts_before() had a wrong second argument, but is really of no use: the start time of a recurring appointment is the start time of the very first occurrence (in the past). A comparison against the item in the notify_app structure tells nothing of the start time of the current day; at most it eliminates some future recurring appointments. The function can be dropped, and the entire recurring appointment list looked through. The proper start time is found in the main search loop (and called real_recur_start_time) and must be compared against the item in the notify_app structure. But because recur_apoint_find_occurrence() is limited to a particular day (second argument), two searches are necessary to cover 24 hours. Unrelated cleanups: removed function return value; changed long to time_t. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/args.c | 3 +-- src/calcurse.h | 3 +-- src/recur.c | 39 ++++++++++++++++----------------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/args.c b/src/args.c index 52496cd..8443454 100644 --- a/src/args.c +++ b/src/args.c @@ -231,8 +231,7 @@ static void next_arg(void) next_app.got_app = 0; next_app.txt = NULL; - next_app = *recur_apoint_check_next(&next_app, current_time, - get_today()); + recur_apoint_check_next(&next_app, current_time, get_today()); next_app = *apoint_check_next(&next_app, current_time); if (next_app.got_app) { diff --git a/src/calcurse.h b/src/calcurse.h index a026896..4e92808 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -1049,8 +1049,7 @@ void recur_apoint_add_exc(struct recur_apoint *, long); void recur_event_erase(struct recur_event *); void recur_apoint_erase(struct recur_apoint *); void recur_exc_scan(llist_t *, FILE *); -struct notify_app *recur_apoint_check_next(struct notify_app *, long, - long); +void recur_apoint_check_next(struct notify_app *, time_t, time_t); void recur_apoint_switch_notify(struct recur_apoint *); void recur_event_paste_item(struct recur_event *, long); void recur_apoint_paste_item(struct recur_apoint *, long); diff --git a/src/recur.c b/src/recur.c index e481c08..31f84ae 100644 --- a/src/recur.c +++ b/src/recur.c @@ -922,36 +922,31 @@ void recur_exc_scan(llist_t * lexc, FILE * data_file) } } -static int recur_apoint_starts_before(struct recur_apoint *rapt, long *time) -{ - return rapt->start < *time; -} - /* - * Look in the appointment list if we have an item which starts before the item - * stored in the notify_app structure (which is the next item to be notified). + * Look in the appointment list if we have an item which starts after start and + * before the item stored in the notify_app structure (which is the next item + * to be notified). Note, the search may change the notify_app structure. */ -struct notify_app *recur_apoint_check_next(struct notify_app *app, - long start, long day) +void recur_apoint_check_next(struct notify_app *app, time_t start, time_t day) { llist_item_t *i; time_t real_recur_start_time; LLIST_TS_LOCK(&recur_alist_p); - /* - * Iterate over all recurrent items starting before the current "next" - * appointment. We cannot filter by start time because a recurrent item - * can actually start (several days) before the current "next" item and - * still have an occurrence which is the next item to be notified. - */ - LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time, - recur_apoint_starts_before, i) { + LLIST_TS_FOREACH(&recur_alist_p, i) { struct recur_apoint *rapt = LLIST_TS_GET_DATA(i); - /* - * Check whether the recurrent appointment contains an - * occurrence which is the next item to be notified. - */ + /* Tomorrow? */ + if (recur_apoint_find_occurrence + (rapt, day + DAYINSEC, &real_recur_start_time) + && real_recur_start_time > start + && real_recur_start_time < app->time) { + app->time = real_recur_start_time; + app->txt = mem_strdup(rapt->mesg); + app->state = rapt->state; + app->got_app = 1; + } + /* Today? */ if (recur_apoint_find_occurrence (rapt, day, &real_recur_start_time) && real_recur_start_time > start @@ -963,8 +958,6 @@ struct notify_app *recur_apoint_check_next(struct notify_app *app, } } LLIST_TS_UNLOCK(&recur_alist_p); - - return app; } /* Switch recurrent item notification state. */ -- cgit v1.2.3-70-g09d2