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
update_rept (struct rpt **rpt, const long start)
{
const int SINGLECHAR = 2;
int ch, newfreq, date_entered;
int newtype, newfreq, date_entered;
long newuntil;
char outstr[BUFSIZ];
char *typstr, *freqstr, *timstr;
const char *msg_rpt_type = _("Enter the new repetition type: (D)aily, (W)eekly, "
"(M)onthly, (Y)early");
const char *msg_rpt_ans = _("[D/W/M/Y] ");
char *freqstr, *timstr;
const char *msg_rpt_prefix = _("Enter the new 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");
/* 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_time = _("Invalid time: start time must be before end time!");
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";
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);
typstr = mem_calloc (SINGLECHAR, sizeof (char));
snprintf (typstr, SINGLECHAR, "%c", recur_def2char ((*rpt)->type));
if (updatestring (win[STA].p, &typstr, 0, 1) == GETSTRING_VALID)
{
ch = toupper (*typstr);
mem_free (typstr);
}
else
{
mem_free (typstr);
return;
}
case 1:
newtype = 'D';
break;
case 2:
newtype = 'W';
break;
case 3:
newtype = 'M';
break;
case 4:
newtype = 'Y';
break;
default:
return;
}
while ((ch != 'D') && (ch != 'W') && (ch != 'M') && (ch != 'Y'));
do
{
@ -805,7 +841,7 @@ update_rept (struct rpt **rpt, const long start)
while (date_entered == 0);
mem_free (timstr);
(*rpt)->type = recur_char2def (ch);
(*rpt)->type = recur_char2def (newtype);
(*rpt)->freq = newfreq;
(*rpt)->until = newuntil;
}

View File

@ -868,15 +868,17 @@ recur_repeat_item (void)
{
struct tm *lt;
time_t t;
int ch = 0;
int date_entered = 0;
int year = 0, month = 0, day = 0;
struct date until_date;
char outstr[BUFSIZ];
char user_input[BUFSIZ] = "";
const char *mesg_type_1 =
_("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early");
const char *mesg_type_2 = _("[D/W/M/Y] ");
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 =
@ -888,6 +890,15 @@ recur_repeat_item (void)
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;
@ -903,21 +914,23 @@ recur_repeat_item (void)
return;
}
while ((ch != 'D') && (ch != 'W') && (ch != 'M')
&& (ch != 'Y') && (ch != ESCAPE))
{
status_mesg (mesg_type_1, mesg_type_2);
ch = wgetch (win[STA].p);
ch = toupper (ch);
}
if (ch == ESCAPE)
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;
}
else
{
type = recur_char2def (ch);
}
while (freq == 0)
{