From 660eef88e4a0add913e8a147d97b9549162a921e Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 24 Nov 2012 23:36:51 +0100 Subject: Add configuration option to set a default panel This allows for customizing the panel that is selected by default when calcurse is started. Note that this patch doesn't add any documentation. Also, this configuration option currently cannot be configured using the configuration menu. Implements FR#19. Signed-off-by: Lukas Fleischer --- src/calcurse.c | 3 ++- src/calcurse.h | 19 ++++++++++--------- src/config.c | 30 ++++++++++++++++++++++++++++++ src/vars.c | 1 + 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/calcurse.c b/src/calcurse.c index 0c8bfa4..c55db55 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -549,6 +549,7 @@ int main(int argc, char **argv) vars_init(); wins_init(); + /* Default to the calendar panel -- this is overridden later. */ wins_slctd_set(CAL); notify_init_bar(); wins_reset_status_page(); @@ -569,7 +570,7 @@ int main(int argc, char **argv) io_startup_screen(no_data_file); } inday = *day_process_storage(0, 0, &inday); - wins_slctd_set(CAL); + wins_slctd_set(conf.default_panel); wins_update(FLAG_ALL); /* Start miscellaneous threads. */ diff --git a/src/calcurse.h b/src/calcurse.h index be18739..310b28d 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -233,6 +233,15 @@ #define MAX(x,y) ((x)>(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y)) +enum win { + CAL, + APP, + TOD, + NOT, + STA, + NBWINS +}; + /* General configuration variables. */ struct conf { unsigned auto_save; @@ -240,6 +249,7 @@ struct conf { unsigned periodic_save; unsigned confirm_quit; unsigned confirm_delete; + enum win default_panel; unsigned system_dialogs; unsigned progress_bar; const char *editor; @@ -449,15 +459,6 @@ struct binding { enum key action; }; -enum win { - CAL, - APP, - TOD, - NOT, - STA, - NBWINS -}; - #define FLAG_CAL (1 << CAL) #define FLAG_APP (1 << APP) #define FLAG_TOD (1 << TOD) diff --git a/src/config.c b/src/config.c index 06a8124..c601336 100644 --- a/src/config.c +++ b/src/config.c @@ -59,6 +59,8 @@ static int config_parse_str(char *, const char *); static int config_serialize_str(char *, const char *); static int config_parse_calendar_view(void *, const char *); static int config_serialize_calendar_view(char *, void *); +static int config_parse_default_panel(void *, const char *); +static int config_serialize_default_panel(char *, void *); static int config_parse_first_day_of_week(void *, const char *); static int config_serialize_first_day_of_week(char *, void *); static int config_parse_color_theme(void *, const char *); @@ -84,6 +86,8 @@ static int config_serialize_input_datefmt(char *, void *); static const struct confvar confmap[] = { {"appearance.calendarview", config_parse_calendar_view, config_serialize_calendar_view, NULL}, + {"appearance.defaultpanel", config_parse_default_panel, + config_serialize_default_panel, NULL}, {"appearance.layout", config_parse_layout, config_serialize_layout, NULL}, {"appearance.notifybar", CONFIG_HANDLER_BOOL(nbar.show)}, {"appearance.sidebarwidth", config_parse_sidebar_width, @@ -206,6 +210,20 @@ static int config_parse_calendar_view(void *dummy, const char *val) return 1; } +static int config_parse_default_panel(void *dummy, const char *val) +{ + if (!strcmp(val, "calendar")) + conf.default_panel = CAL; + else if (!strcmp(val, "appointments")) + conf.default_panel = APP; + else if (!strcmp(val, "todo")) + conf.default_panel = TOD; + else + return 0; + + return 1; +} + static int config_parse_first_day_of_week(void *dummy, const char *val) { if (!strcmp(val, "monday")) @@ -368,6 +386,18 @@ static int config_serialize_calendar_view(char *buf, void *dummy) return 1; } +static int config_serialize_default_panel(char *buf, void *dummy) +{ + if (conf.default_panel == CAL) + strcpy(buf, "calendar"); + else if (conf.default_panel == APP) + strcpy(buf, "appointments"); + else + strcpy(buf, "todo"); + + return 1; +} + static int config_serialize_first_day_of_week(char *buf, void *dummy) { if (calendar_week_begins_on_monday()) diff --git a/src/vars.c b/src/vars.c index b6bddcb..9192c5c 100644 --- a/src/vars.c +++ b/src/vars.c @@ -134,6 +134,7 @@ void vars_init(void) conf.auto_save = 1; conf.auto_gc = 0; conf.periodic_save = 0; + conf.default_panel = CAL; conf.system_dialogs = 1; conf.progress_bar = 1; strncpy(conf.output_datefmt, "%D", 3); -- cgit v1.2.3-70-g09d2