nui/ncurses: Allow config screen updates
authorJeremy Kerr <jk@ozlabs.org>
Fri, 25 Oct 2013 01:19:35 +0000 (09:19 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 14 Nov 2013 02:23:52 +0000 (13:23 +1100)
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>
ui/ncurses/nc-config.c
ui/ncurses/nc-config.h
ui/ncurses/nc-cui.c

index 00fe72c30b835a01ef5fd4adb2029f4688460c05..49f2e2f6093255c1ca2331634e4c9509d013c263 100644 (file)
@@ -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;
 }
index 71e0ea4550f4c8a42d8b6dfb11882e1c69db44ff..dd5fd11a1d087a786fdd3df2fd3fc53b7afbbd4f 100644 (file)
@@ -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 */
index 93377bb56f94584d88e732999fedaed908b86f5d..268060c8d36eeab786af3835da2dcf820b945b0d 100644 (file)
@@ -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)