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>
This commit is contained in:
Lars Henriksen 2019-02-05 21:56:13 +01:00 committed by Lukas Fleischer
parent a47a562322
commit 528368932c
3 changed files with 72 additions and 1 deletions

View File

@ -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);

View File

@ -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"));

View File

@ -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: