diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2019-02-05 21:56:13 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2019-02-28 08:03:53 +0100 |
commit | 528368932ceb05fec10638062ca56d6772f21040 (patch) | |
tree | 3124e3805f923ef3461c67cf3cab576f4b378634 | |
parent | a47a562322d52275b0bae7181a5077cf95b24ffb (diff) | |
download | calcurse-528368932ceb05fec10638062ca56d6772f21040.tar.gz calcurse-528368932ceb05fec10638062ca56d6772f21040.zip |
View or edit exception days of a recurrent item
The exception days are presented for viewing/editing as a string of
space-separated dates (in the user-preferred input format). After
editing the string is checked for valid dates, but there is no check
that a date is meaningful (an occurrence day of the item between start
day and until day). Although possible, it is best to add exception days
in the usual way by deletion of occurrences.
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r-- | src/calcurse.h | 2 | ||||
-rw-r--r-- | src/recur.c | 51 | ||||
-rw-r--r-- | src/ui-day.c | 20 |
3 files changed, 72 insertions, 1 deletions
diff --git a/src/calcurse.h b/src/calcurse.h index 5e14b80..afa9046 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -1008,6 +1008,8 @@ void pcal_export_data(FILE *); /* recur.c */ extern llist_ts_t recur_alist_p; extern llist_t recur_elist; +void recur_update_exc(llist_t *, char *); +char *recur_exc2str(llist_t *); struct recur_event *recur_event_dup(struct recur_event *); struct recur_apoint *recur_apoint_dup(struct recur_apoint *); void recur_event_free_bkp(void); diff --git a/src/recur.c b/src/recur.c index 2a0a9f7..4e8bd09 100644 --- a/src/recur.c +++ b/src/recur.c @@ -84,6 +84,57 @@ static void exc_dup(llist_t * in, llist_t * exc) } } +/* Return a string containing the exception days. */ +char *recur_exc2str(llist_t *exc) +{ + llist_item_t *i; + struct excp *p; + struct string s; + struct tm tm; + + string_init(&s); + LLIST_FOREACH(exc, i) { + p = LLIST_GET_DATA(i); + localtime_r(&p->st, &tm); + string_catftime(&s, DATEFMT(conf.input_datefmt), &tm); + string_catf(&s, "%c", ' '); + } + return string_buf(&s); +} + +/* + * Update the list of exceptions from a string of days. Any positive number of + * spaces are allowed before, between and after the days. + */ +void recur_update_exc(llist_t *exc, char *days) +{ + char *d; + time_t t = get_today(); + llist_t nexc; + LLIST_INIT(&nexc); + + while (1) { + while (*days == ' ') + days++; + if ((d = strchr(days, ' '))) + *d = '\0'; + else if (!strlen(days)) + break; + if (parse_datetime(days, &t, 0)) + recur_add_exc(&nexc, t); + else + goto cleanup; + if (d) + days = d + 1; + else + break; + } + free_exc_list(exc); + exc_dup(exc, &nexc); +cleanup: + free_exc_list(&nexc); +} + struct recur_event *recur_event_dup(struct recur_event *in) { EXIT_IF(!in, _("null pointer")); diff --git a/src/ui-day.c b/src/ui-day.c index 626cf5a..2df9cef 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -367,6 +367,22 @@ cleanup: mem_free(outstr); } +/* Edit the list of exception days for a recurrent item. */ +static void update_exc(llist_t *exc) +{ + if (!exc->head) + return; + char *days; + enum getstr ret; + + status_mesg(_("Exception days:"), ""); + days = recur_exc2str(exc); + ret = updatestring(win[STA].p, &days, 0, 1); + if (ret == GETSTRING_VALID || ret == GETSTRING_RET) + recur_update_exc(exc, days); + mem_free(days); +} + /* Edit an already existing item. */ void ui_day_item_edit(void) { @@ -386,7 +402,7 @@ void ui_day_item_edit(void) re = p->item.rev; const char *choice_recur_evnt[2] = { _("Description"), - _("Repetition"), + _("Repetition") }; switch (status_ask_simplechoice (_("Edit: "), choice_recur_evnt, 2)) { @@ -396,6 +412,7 @@ void ui_day_item_edit(void) break; case 2: update_rept(&re->rpt, re->day); + update_exc(&re->exc); io_set_modified(); break; default: @@ -437,6 +454,7 @@ void ui_day_item_edit(void) case 4: need_check_notify = 1; update_rept(&ra->rpt, ra->start); + update_exc(&ra->exc); io_set_modified(); break; case 5: |