Automate the calculation of number of days to load

Instead of having the user tell how many days to load, calcurse can
calculate an overestimation from the running configuration (panel size,
appearance of headers and separators etc.)

The configuration variable conf.multiple_days is turned into a Boolean
that switches the feature on and off.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2019-05-14 07:10:33 +02:00 committed by Lukas Fleischer
parent 4db9677119
commit d15f1e9242
4 changed files with 20 additions and 13 deletions

View File

@ -115,7 +115,7 @@ static const struct confvar confmap[] = {
{"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)}, {"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)},
{"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)}, {"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)},
{"general.firstdayofweek", config_parse_first_day_of_week, config_serialize_first_day_of_week, NULL}, {"general.firstdayofweek", config_parse_first_day_of_week, config_serialize_first_day_of_week, NULL},
{"general.multipledays", CONFIG_HANDLER_UNSIGNED(conf.multiple_days)}, {"general.multipledays", CONFIG_HANDLER_BOOL(conf.multiple_days)},
{"general.periodicsave", CONFIG_HANDLER_UNSIGNED(conf.periodic_save)}, {"general.periodicsave", CONFIG_HANDLER_UNSIGNED(conf.periodic_save)},
{"general.systemevents", CONFIG_HANDLER_BOOL(conf.systemevents)}, {"general.systemevents", CONFIG_HANDLER_BOOL(conf.systemevents)},
{"general.systemdialogs", CONFIG_HANDLER_BOOL(conf.system_dialogs)}, {"general.systemdialogs", CONFIG_HANDLER_BOOL(conf.system_dialogs)},

View File

@ -643,13 +643,10 @@ static void print_general_option(int i, WINDOW *win, int y, int hilt, void *cb_d
_("(insert an empty line after each appointment)")); _("(insert an empty line after each appointment)"));
break; break;
case MULTIPLE_DAYS: case MULTIPLE_DAYS:
custom_apply_attr(win, ATTR_HIGHEST); print_bool_option_incolor(win, conf.multiple_days, y,
mvwprintw(win, y, XPOS + strlen(opt[MULTIPLE_DAYS]), "%d", XPOS + strlen(opt[MULTIPLE_DAYS]));
conf.multiple_days);
custom_remove_attr(win, ATTR_HIGHEST);
mvwaddstr(win, y + 1, XPOS, mvwaddstr(win, y + 1, XPOS,
_("(number of days (1..21) to display in the appointments " _("(display more than one day in the appointments panel)"));
"panel)"));
break; break;
case AUTO_SAVE: case AUTO_SAVE:
print_bool_option_incolor(win, conf.auto_save, y, print_bool_option_incolor(win, conf.auto_save, y,
@ -807,10 +804,7 @@ static void general_option_edit(int i)
ui_todo_load_items(); ui_todo_load_items();
break; break;
case MULTIPLE_DAYS: case MULTIPLE_DAYS:
if (conf.multiple_days == 21) conf.multiple_days = !conf.multiple_days;
conf.multiple_days = 1;
else
conf.multiple_days++;
break; break;
case HEADER_LINE: case HEADER_LINE:
conf.header_line = !conf.header_line; conf.header_line = !conf.header_line;

View File

@ -106,9 +106,22 @@ int day_sel_index(void)
return -1; return -1;
} }
/*
* Return the number of days to load in the appointments panel.
*/
int day_get_days(void) int day_get_days(void)
{ {
return conf.multiple_days; int panel, day;
if (!conf.multiple_days)
return 1;
panel = win[APP].h - (conf.compact_panels ? 2 : 4);
/* Assume one event per day (no event separator). */
day = 2 + conf.header_line + conf.day_separator + conf.empty_appt_line;
/* Round up. */
return panel / day + (panel % day != 0);
} }
static void day_free(struct day_item *day) static void day_free(struct day_item *day)

View File

@ -122,7 +122,7 @@ void vars_init(void)
/* Variables for user configuration */ /* Variables for user configuration */
conf.cal_view = CAL_MONTH_VIEW; conf.cal_view = CAL_MONTH_VIEW;
conf.todo_view = TODO_HIDE_COMPLETED_VIEW; conf.todo_view = TODO_HIDE_COMPLETED_VIEW;
conf.multiple_days = 7; conf.multiple_days = 1;
conf.header_line = 1; conf.header_line = 1;
conf.event_separator = 1; conf.event_separator = 1;
conf.day_separator = 1; conf.day_separator = 1;