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:
parent
a47a562322
commit
528368932c
@ -1008,6 +1008,8 @@ void pcal_export_data(FILE *);
|
|||||||
/* recur.c */
|
/* recur.c */
|
||||||
extern llist_ts_t recur_alist_p;
|
extern llist_ts_t recur_alist_p;
|
||||||
extern llist_t recur_elist;
|
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_event *recur_event_dup(struct recur_event *);
|
||||||
struct recur_apoint *recur_apoint_dup(struct recur_apoint *);
|
struct recur_apoint *recur_apoint_dup(struct recur_apoint *);
|
||||||
void recur_event_free_bkp(void);
|
void recur_event_free_bkp(void);
|
||||||
|
51
src/recur.c
51
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)
|
struct recur_event *recur_event_dup(struct recur_event *in)
|
||||||
{
|
{
|
||||||
EXIT_IF(!in, _("null pointer"));
|
EXIT_IF(!in, _("null pointer"));
|
||||||
|
20
src/ui-day.c
20
src/ui-day.c
@ -367,6 +367,22 @@ cleanup:
|
|||||||
mem_free(outstr);
|
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. */
|
/* Edit an already existing item. */
|
||||||
void ui_day_item_edit(void)
|
void ui_day_item_edit(void)
|
||||||
{
|
{
|
||||||
@ -386,7 +402,7 @@ void ui_day_item_edit(void)
|
|||||||
re = p->item.rev;
|
re = p->item.rev;
|
||||||
const char *choice_recur_evnt[2] = {
|
const char *choice_recur_evnt[2] = {
|
||||||
_("Description"),
|
_("Description"),
|
||||||
_("Repetition"),
|
_("Repetition")
|
||||||
};
|
};
|
||||||
switch (status_ask_simplechoice
|
switch (status_ask_simplechoice
|
||||||
(_("Edit: "), choice_recur_evnt, 2)) {
|
(_("Edit: "), choice_recur_evnt, 2)) {
|
||||||
@ -396,6 +412,7 @@ void ui_day_item_edit(void)
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
update_rept(&re->rpt, re->day);
|
update_rept(&re->rpt, re->day);
|
||||||
|
update_exc(&re->exc);
|
||||||
io_set_modified();
|
io_set_modified();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -437,6 +454,7 @@ void ui_day_item_edit(void)
|
|||||||
case 4:
|
case 4:
|
||||||
need_check_notify = 1;
|
need_check_notify = 1;
|
||||||
update_rept(&ra->rpt, ra->start);
|
update_rept(&ra->rpt, ra->start);
|
||||||
|
update_exc(&ra->exc);
|
||||||
io_set_modified();
|
io_set_modified();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user