Move interaction functions to a separate file
This is a first step to clean up several compilation units and separate the front end from back-end operations. All functions that require user interaction are moved to a new compilation unit "interaction.c". Also, following things are adjusted to the new layout: * Make day_item_get_*() and a few other functions public, so that it can be accessed from the new compilation unit. * Use apoint_hilt(), todo_hilt(), etc. instead of directly accessing static variables. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
136
src/recur.c
136
src/recur.c
@@ -782,142 +782,6 @@ recur_apoint_erase(long start, unsigned num, unsigned delete_whole,
|
||||
LLIST_TS_UNLOCK(&recur_alist_p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ask user for repetition characteristics:
|
||||
* o repetition type: daily, weekly, monthly, yearly
|
||||
* o repetition frequence: every X days, weeks, ...
|
||||
* o repetition end date
|
||||
* and then delete the selected item to recreate it as a recurrent one
|
||||
*/
|
||||
void recur_repeat_item(void)
|
||||
{
|
||||
struct tm *lt;
|
||||
time_t t;
|
||||
int date_entered = 0;
|
||||
int year = 0, month = 0, day = 0;
|
||||
struct date until_date;
|
||||
char outstr[BUFSIZ];
|
||||
char user_input[BUFSIZ] = "";
|
||||
const char *msg_rpt_prefix = _("Enter the repetition type:");
|
||||
const char *msg_rpt_daily = _("(d)aily");
|
||||
const char *msg_rpt_weekly = _("(w)eekly");
|
||||
const char *msg_rpt_monthly = _("(m)onthly");
|
||||
const char *msg_rpt_yearly = _("(y)early");
|
||||
const char *msg_type_choice = _("[dwmy]");
|
||||
const char *mesg_freq_1 = _("Enter the repetition frequence:");
|
||||
const char *mesg_wrong_freq = _("The frequence you entered is not valid.");
|
||||
const char *mesg_until_1 =
|
||||
_("Enter the ending date: [%s] or '0' for an endless repetition");
|
||||
const char *mesg_wrong_1 = _("The entered date is not valid.");
|
||||
const char *mesg_wrong_2 =
|
||||
_("Possible formats are [%s] or '0' for an endless repetition");
|
||||
const char *wrong_type_1 = _("This item is already a repeated one.");
|
||||
const char *wrong_type_2 = _("Press [ENTER] to continue.");
|
||||
const char *mesg_older =
|
||||
_("Sorry, the date you entered is older than the item start time.");
|
||||
|
||||
char msg_asktype[BUFSIZ];
|
||||
snprintf(msg_asktype, BUFSIZ, "%s %s, %s, %s, %s",
|
||||
msg_rpt_prefix,
|
||||
msg_rpt_daily, msg_rpt_weekly, msg_rpt_monthly, msg_rpt_yearly);
|
||||
|
||||
int type = 0, freq = 0;
|
||||
int item_nb;
|
||||
struct day_item *p;
|
||||
struct recur_apoint *ra;
|
||||
long until, date;
|
||||
|
||||
item_nb = apoint_hilt();
|
||||
p = day_get_item(item_nb);
|
||||
if (p->type != APPT && p->type != EVNT) {
|
||||
status_mesg(wrong_type_1, wrong_type_2);
|
||||
wgetch(win[STA].p);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status_ask_choice(msg_asktype, msg_type_choice, 4)) {
|
||||
case 1:
|
||||
type = RECUR_DAILY;
|
||||
break;
|
||||
case 2:
|
||||
type = RECUR_WEEKLY;
|
||||
break;
|
||||
case 3:
|
||||
type = RECUR_MONTHLY;
|
||||
break;
|
||||
case 4:
|
||||
type = RECUR_YEARLY;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
while (freq == 0) {
|
||||
status_mesg(mesg_freq_1, "");
|
||||
if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID) {
|
||||
freq = atoi(user_input);
|
||||
if (freq == 0) {
|
||||
status_mesg(mesg_wrong_freq, wrong_type_2);
|
||||
wgetch(win[STA].p);
|
||||
}
|
||||
user_input[0] = '\0';
|
||||
} else
|
||||
return;
|
||||
}
|
||||
|
||||
while (!date_entered) {
|
||||
snprintf(outstr, BUFSIZ, mesg_until_1, DATEFMT_DESC(conf.input_datefmt));
|
||||
status_mesg(outstr, "");
|
||||
if (getstring(win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID) {
|
||||
if (strlen(user_input) == 1 && strcmp(user_input, "0") == 0) {
|
||||
until = 0;
|
||||
date_entered = 1;
|
||||
} else {
|
||||
if (parse_date(user_input, conf.input_datefmt,
|
||||
&year, &month, &day, calendar_get_slctd_day())) {
|
||||
t = p->start;
|
||||
lt = localtime(&t);
|
||||
until_date.dd = day;
|
||||
until_date.mm = month;
|
||||
until_date.yyyy = year;
|
||||
until = date2sec(until_date, lt->tm_hour, lt->tm_min);
|
||||
if (until < p->start) {
|
||||
status_mesg(mesg_older, wrong_type_2);
|
||||
wgetch(win[STA].p);
|
||||
date_entered = 0;
|
||||
} else {
|
||||
date_entered = 1;
|
||||
}
|
||||
} else {
|
||||
snprintf(outstr, BUFSIZ, mesg_wrong_2,
|
||||
DATEFMT_DESC(conf.input_datefmt));
|
||||
status_mesg(mesg_wrong_1, outstr);
|
||||
wgetch(win[STA].p);
|
||||
date_entered = 0;
|
||||
}
|
||||
}
|
||||
} else
|
||||
return;
|
||||
}
|
||||
|
||||
date = calendar_get_slctd_day_sec();
|
||||
if (p->type == EVNT) {
|
||||
struct event *ev = p->item.ev;
|
||||
recur_event_new(ev->mesg, ev->note, ev->day, ev->id, type, freq, until,
|
||||
NULL);
|
||||
} else if (p->type == APPT) {
|
||||
struct apoint *apt = p->item.apt;
|
||||
ra = recur_apoint_new(apt->mesg, apt->note, apt->start, apt->dur,
|
||||
apt->state, type, freq, until, NULL);
|
||||
if (notify_bar())
|
||||
notify_check_repeated(ra);
|
||||
} else {
|
||||
EXIT(_("wrong item type"));
|
||||
/* NOTREACHED */
|
||||
}
|
||||
day_erase_item(date, item_nb, ERASE_FORCE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read days for which recurrent items must not be repeated
|
||||
* (such days are called exceptions).
|
||||
|
||||
Reference in New Issue
Block a user