aboutsummaryrefslogtreecommitdiffstats
path: root/src/day.c
diff options
context:
space:
mode:
authorBaptiste Jonglez <baptiste--git@jonglez.org>2012-05-13 14:09:20 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-05-14 19:31:13 +0200
commit7d4ef08345d51e59b045c3d8415a4f15bd758d3c (patch)
treea21f887648a81521c8803feab8a859b1d2dc6731 /src/day.c
parent1d9c90bb18969faed7dc2e833c4b21949bd31bbb (diff)
downloadcalcurse-7d4ef08345d51e59b045c3d8415a4f15bd758d3c.tar.gz
calcurse-7d4ef08345d51e59b045c3d8415a4f15bd758d3c.zip
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>
Diffstat (limited to 'src/day.c')
-rw-r--r--src/day.c80
1 files changed, 58 insertions, 22 deletions
diff --git a/src/day.c b/src/day.c
index 8b7e87d..d74283f 100644
--- a/src/day.c
+++ b/src/day.c
@@ -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;
}