Use status_ask_choice() on more difficult cases

These cases are also candidates for the factorisation process, but
they are somewhat more tricky to get right.

Since we use a completely different approach, the result (from a user
perspective) looks different.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Baptiste Jonglez 2012-05-13 14:09:20 +02:00 committed by Lukas Fleischer
parent 1d9c90bb18
commit 7d4ef08345
2 changed files with 87 additions and 38 deletions

View File

@ -694,14 +694,50 @@ update_desc (char **desc)
static void static void
update_rept (struct rpt **rpt, const long start) update_rept (struct rpt **rpt, const long start)
{ {
const int SINGLECHAR = 2; int newtype, newfreq, date_entered;
int ch, newfreq, date_entered;
long newuntil; long newuntil;
char outstr[BUFSIZ]; char outstr[BUFSIZ];
char *typstr, *freqstr, *timstr; char *freqstr, *timstr;
const char *msg_rpt_type = _("Enter the new repetition type: (D)aily, (W)eekly, " const char *msg_rpt_prefix = _("Enter the new repetition type:");
"(M)onthly, (Y)early"); const char *msg_rpt_daily = _("(d)aily");
const char *msg_rpt_ans = _("[D/W/M/Y] "); const char *msg_rpt_weekly = _("(w)eekly");
const char *msg_rpt_monthly = _("(m)onthly");
const char *msg_rpt_yearly = _("(y)early");
/* Find the current repetition type. */
const char *rpt_current;
char msg_rpt_current[BUFSIZ];
switch (recur_def2char ((*rpt)->type))
{
case 'D':
rpt_current = msg_rpt_daily;
break;
case 'W':
rpt_current = msg_rpt_weekly;
break;
case 'M':
rpt_current = msg_rpt_monthly;
break;
case 'Y':
rpt_current = msg_rpt_yearly;
break;
default:
/* NOTREACHED, but makes the compiler happier. */
rpt_current = msg_rpt_daily;
}
snprintf (msg_rpt_current, BUFSIZ, _("(currently using %s)"), rpt_current);
char msg_rpt_asktype[BUFSIZ];
snprintf (msg_rpt_asktype, BUFSIZ, "%s %s, %s, %s, %s ? %s",
msg_rpt_prefix,
msg_rpt_daily,
msg_rpt_weekly,
msg_rpt_monthly,
msg_rpt_yearly,
msg_rpt_current);
const char *msg_rpt_choice = _("[dwmy]");
const char *msg_wrong_freq = _("The frequence you entered is not valid."); const char *msg_wrong_freq = _("The frequence you entered is not valid.");
const char *msg_wrong_time = _("Invalid time: start time must be before end time!"); const char *msg_wrong_time = _("Invalid time: start time must be before end time!");
const char *msg_wrong_date = _("The entered date is not valid."); const char *msg_wrong_date = _("The entered date is not valid.");
@ -709,23 +745,23 @@ update_rept (struct rpt **rpt, const long start)
"Possible formats are [%s] or '0' for an endless repetetition"; "Possible formats are [%s] or '0' for an endless repetetition";
const char *msg_enter = _("Press [Enter] to continue"); const char *msg_enter = _("Press [Enter] to continue");
do switch (status_ask_choice (msg_rpt_asktype, msg_rpt_choice, 4))
{ {
status_mesg (msg_rpt_type, msg_rpt_ans); case 1:
typstr = mem_calloc (SINGLECHAR, sizeof (char)); newtype = 'D';
snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type)); break;
if (updatestring (win[STA].p, &typstr, 0, 1) == GETSTRING_VALID) case 2:
{ newtype = 'W';
ch = toupper (*typstr); break;
mem_free (typstr); case 3:
} newtype = 'M';
else break;
{ case 4:
mem_free (typstr); newtype = 'Y';
return; break;
} default:
return;
} }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y'));
do do
{ {
@ -805,7 +841,7 @@ update_rept (struct rpt **rpt, const long start)
while (date_entered == 0); while (date_entered == 0);
mem_free (timstr); mem_free (timstr);
(*rpt)->type = recur_char2def (ch); (*rpt)->type = recur_char2def (newtype);
(*rpt)->freq = newfreq; (*rpt)->freq = newfreq;
(*rpt)->until = newuntil; (*rpt)->until = newuntil;
} }

View File

@ -868,15 +868,17 @@ recur_repeat_item (void)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
int ch = 0;
int date_entered = 0; int date_entered = 0;
int year = 0, month = 0, day = 0; int year = 0, month = 0, day = 0;
struct date until_date; struct date until_date;
char outstr[BUFSIZ]; char outstr[BUFSIZ];
char user_input[BUFSIZ] = ""; char user_input[BUFSIZ] = "";
const char *mesg_type_1 = const char *msg_rpt_prefix = _("Enter the repetition type:");
_("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early"); const char *msg_rpt_daily = _("(d)aily");
const char *mesg_type_2 = _("[D/W/M/Y] "); 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_freq_1 = _("Enter the repetition frequence:");
const char *mesg_wrong_freq = _("The frequence you entered is not valid."); const char *mesg_wrong_freq = _("The frequence you entered is not valid.");
const char *mesg_until_1 = const char *mesg_until_1 =
@ -888,6 +890,15 @@ recur_repeat_item (void)
const char *wrong_type_2 = _("Press [ENTER] to continue."); const char *wrong_type_2 = _("Press [ENTER] to continue.");
const char *mesg_older = const char *mesg_older =
_("Sorry, the date you entered is older than the item start time."); _("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 type = 0, freq = 0;
int item_nb; int item_nb;
struct day_item *p; struct day_item *p;
@ -903,21 +914,23 @@ recur_repeat_item (void)
return; return;
} }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') switch (status_ask_choice (msg_asktype, msg_type_choice, 4))
&& (ch != 'Y') && (ch != ESCAPE))
{
status_mesg (mesg_type_1, mesg_type_2);
ch = wgetch (win[STA].p);
ch = toupper (ch);
}
if (ch == ESCAPE)
{ {
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; return;
} }
else
{
type = recur_char2def (ch);
}
while (freq == 0) while (freq == 0)
{ {