]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-config.c
ui/ncurses: Remove net_conf parameter from sconfig_screen_layout_widgets
[petitboot] / ui / ncurses / nc-config.c
index 8d68e7446499e700a16122c6726da68d6171ac98..6aecb33cfb07622641e040f62f6408df5fcfedc6 100644 (file)
@@ -118,10 +118,23 @@ static void config_screen_process_key(struct nc_scr *scr, int key)
        bool handled;
 
        handled = widgetset_process_key(screen->widgetset, key);
+
+       if (!handled) {
+               switch (key) {
+               case 'x':
+               case 27: /* esc */
+                       screen->exit = true;
+                       break;
+               case 'h':
+                       screen->show_help = true;
+                       break;
+               }
+       }
+
        if (screen->exit) {
                screen->on_exit(screen->cui);
 
-       } else if (screen->show_help || (!handled && key == 'h')) {
+       } else if (screen->show_help) {
                screen->show_help = false;
                cui_show_help(screen->cui, "System Configuration",
                                config_help_text);
@@ -236,6 +249,10 @@ static int screen_process_form(struct config_screen *screen)
        }
 
        str = widget_textbox_get_value(screen->widgets.dns_f);
+       talloc_free(config->network.dns_servers);
+       config->network.dns_servers = NULL;
+       config->network.n_dns_servers = 0;
+
        if (str && strlen(str)) {
                char *dns, *tmp;
                int i;
@@ -302,8 +319,7 @@ static int layout_pair(struct config_screen *screen, int y,
        return max(widget_height(label_w), widget_height(field));
 }
 
-static void config_screen_layout_widgets(struct config_screen *screen,
-               enum net_conf_type net_conf)
+static void config_screen_layout_widgets(struct config_screen *screen)
 {
        struct nc_widget *wl, *wf, *wh;
        int y, x, help_x;
@@ -334,8 +350,8 @@ static void config_screen_layout_widgets(struct config_screen *screen,
        wl = widget_label_base(screen->widgets.iface_l);
        wf = widget_select_base(screen->widgets.iface_f);
 
-       show = net_conf == NET_CONF_TYPE_DHCP_ONE ||
-               net_conf == NET_CONF_TYPE_STATIC;
+       show = screen->net_conf_type == NET_CONF_TYPE_DHCP_ONE ||
+               screen->net_conf_type == NET_CONF_TYPE_STATIC;
 
        widget_set_visible(wl, show);
        widget_set_visible(wf, show);
@@ -344,7 +360,7 @@ static void config_screen_layout_widgets(struct config_screen *screen,
                y += layout_pair(screen, y, screen->widgets.iface_l, wf) + 1;
 
        /* conditionally show static IP params */
-       show = net_conf == NET_CONF_TYPE_STATIC;
+       show = screen->net_conf_type == NET_CONF_TYPE_STATIC;
 
        wl = widget_label_base(screen->widgets.ip_addr_l);
        wf = widget_textbox_base(screen->widgets.ip_addr_f);
@@ -393,7 +409,7 @@ static void config_screen_layout_widgets(struct config_screen *screen,
        y++;
 
        /* we show the DNS/DHCP help if we're configuring DHCP */
-       show = net_conf != NET_CONF_TYPE_STATIC;
+       show = screen->net_conf_type != NET_CONF_TYPE_STATIC;
        wl = widget_label_base(screen->widgets.dns_dhcp_help_l);
        widget_set_visible(wl, show);
        if (show) {
@@ -416,7 +432,7 @@ static void config_screen_network_change(void *arg, int value)
        struct config_screen *screen = arg;
        screen->net_conf_type = value;
        widgetset_unpost(screen->widgetset);
-       config_screen_layout_widgets(screen, value);
+       config_screen_layout_widgets(screen);
        widgetset_post(screen->widgetset);
 }
 
@@ -486,6 +502,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        screen->widgets.timeout_f = widget_new_textbox(set, 0, 0, 5, str);
        screen->widgets.timeout_help_l = widget_new_label(set, 0, 0, "seconds");
 
+       widget_textbox_set_fixed_size(screen->widgets.timeout_f);
        widget_textbox_set_validator_integer(screen->widgets.timeout_f, 0, 999);
 
        screen->widgets.network_l = widget_new_label(set, 0, 0, "Network");
@@ -544,10 +561,12 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, "IP/mask:");
        screen->widgets.ip_addr_f = widget_new_textbox(set, 0, 0, 16, ip);
        screen->widgets.ip_mask_l = widget_new_label(set, 0, 0, "/");
-       screen->widgets.ip_mask_f = widget_new_textbox(set, 0, 0, 4, mask);
+       screen->widgets.ip_mask_f = widget_new_textbox(set, 0, 0, 3, mask);
        screen->widgets.ip_addr_mask_help_l =
                widget_new_label(set, 0, 0, "(eg. 192.168.0.10 / 24)");
 
+       widget_textbox_set_fixed_size(screen->widgets.ip_addr_f);
+       widget_textbox_set_fixed_size(screen->widgets.ip_mask_f);
        widget_textbox_set_validator_ipv4(screen->widgets.ip_addr_f);
        widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 31);
 
@@ -556,6 +575,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        screen->widgets.gateway_help_l =
                widget_new_label(set, 0, 0, "(eg. 192.168.0.1)");
 
+       widget_textbox_set_fixed_size(screen->widgets.gateway_f);
        widget_textbox_set_validator_ipv4(screen->widgets.gateway_f);
 
        str = talloc_strdup(screen, "");
@@ -643,7 +663,7 @@ static void config_screen_draw(struct config_screen *screen,
                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);
+               config_screen_layout_widgets(screen);
        }
 
        if (repost)
@@ -689,7 +709,7 @@ struct config_screen *config_screen_init(struct cui *cui,
                        "Petitboot System Configuration");
        screen->scr.frame.rtitle = NULL;
        screen->scr.frame.help = talloc_strdup(screen,
-                       "tab=next, shift+tab=previous");
+                       "tab=next, shift+tab=previous, x=exit, h=help");
        nc_scr_frame_draw(&screen->scr);
 
        scrollok(screen->scr.sub_ncw, true);