diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-10-25 09:19:35 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-11-14 13:23:52 +1100 |
commit | bdcb1f9712f9e99ff1f72497387b34e68585523c (patch) | |
tree | 6b065e8711b655c0e26461b448d909e33a1b338b /ui/ncurses | |
parent | 9df37efcae13a272b25cc5b4e0ba441948fea886 (diff) | |
download | talos-petitboot-bdcb1f9712f9e99ff1f72497387b34e68585523c.tar.gz talos-petitboot-bdcb1f9712f9e99ff1f72497387b34e68585523c.zip |
nui/ncurses: Allow config screen updates
We may receive configuration (or sysinfo) data after the configuration
screen has been displayed. Implement config_screen_update and redraw the
widgetset when new config data arrives.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui/ncurses')
-rw-r--r-- | ui/ncurses/nc-config.c | 49 | ||||
-rw-r--r-- | ui/ncurses/nc-config.h | 3 | ||||
-rw-r--r-- | ui/ncurses/nc-cui.c | 7 |
3 files changed, 50 insertions, 9 deletions
diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c index 00fe72c..49f2e2f 100644 --- a/ui/ncurses/nc-config.c +++ b/ui/ncurses/nc-config.c @@ -378,6 +378,15 @@ static enum net_conf_type find_net_conf_type(const struct config *config) return NET_CONF_TYPE_DHCP_ALL; } +static void config_screen_setup_empty(struct config_screen *screen) +{ + widget_new_label(screen->widgetset, 2, screen->field_x, + "Waiting for configuration data..."); + screen->widgets.cancel_b = widget_new_button(screen->widgetset, + 4, screen->field_x, 6, "Cancel", cancel_click, screen); +} + + static void config_screen_setup_widgets(struct config_screen *screen, const struct config *config, const struct system_info *sysinfo) @@ -477,6 +486,36 @@ static void config_screen_setup_widgets(struct config_screen *screen, cancel_click, screen); } +void config_screen_update(struct config_screen *screen, + const struct config *config, + const struct system_info *sysinfo) +{ + bool repost = false; + + if (screen->widgetset) { + widgetset_unpost(screen->widgetset); + talloc_free(screen->widgetset); + repost = true; + } + + screen->widgetset = widgetset_create(screen, screen->scr.main_ncw, + screen->scr.sub_ncw); + + if (!config || !sysinfo) { + config_screen_setup_empty(screen); + } else { + screen->net_conf_type = find_net_conf_type(config); + + config_screen_setup_widgets(screen, config, sysinfo); + config_screen_layout_widgets(screen, screen->net_conf_type); + } + + if (repost) + widgetset_post(screen->widgetset); + + wrefresh(screen->scr.main_ncw); +} + struct config_screen *config_screen_init(struct cui *cui, const struct config *config, const struct system_info *sysinfo, @@ -502,15 +541,9 @@ struct config_screen *config_screen_init(struct cui *cui, "tab=next, shift+tab=previous"); nc_scr_frame_draw(&screen->scr); - screen->widgetset = widgetset_create(screen, screen->scr.main_ncw, - screen->scr.sub_ncw); - screen->net_conf_type = find_net_conf_type(config); - - config_screen_setup_widgets(screen, config, sysinfo); - config_screen_layout_widgets(screen, screen->net_conf_type); - - wrefresh(screen->scr.main_ncw); scrollok(screen->scr.sub_ncw, true); + config_screen_update(screen, config, sysinfo); + return screen; } diff --git a/ui/ncurses/nc-config.h b/ui/ncurses/nc-config.h index 71e0ea4..dd5fd11 100644 --- a/ui/ncurses/nc-config.h +++ b/ui/ncurses/nc-config.h @@ -30,6 +30,7 @@ struct config_screen *config_screen_init(struct cui *cui, struct nc_scr *config_screen_scr(struct config_screen *screen); void config_screen_update(struct config_screen *screen, - const struct config *config); + const struct config *config, + const struct system_info *sysinfo); #endif /* defined _NC_CONFIG_H */ diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 93377bb..268060c 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -542,6 +542,10 @@ static void cui_update_sysinfo(struct system_info *sysinfo, void *arg) if (cui->sysinfo_screen) sysinfo_screen_update(cui->sysinfo_screen, sysinfo); + /* ... and do the same with the config screen */ + if (cui->config_screen) + config_screen_update(cui->config_screen, cui->config, sysinfo); + cui_update_mm_title(cui); } @@ -549,6 +553,9 @@ static void cui_update_config(struct config *config, void *arg) { struct cui *cui = cui_from_arg(arg); cui->config = talloc_steal(cui, config); + + if (cui->config_screen) + config_screen_update(cui->config_screen, config, cui->sysinfo); } int cui_send_config(struct cui *cui, struct config *config) |