petitboot: Implement ordered boot options
[petitboot] / ui / ncurses / nc-config.c
index ca8c44c0e6bfb74a3208f251e83cdd135fb3eb01..3156b9bf1057bc609bdf031908ee401d7d574b18 100644 (file)
@@ -15,7 +15,9 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define _GNU_SOURCE
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
 
 #include <errno.h>
 #include <stdlib.h>
 #include <talloc/talloc.h>
 #include <types/types.h>
 #include <log/log.h>
+#include <i18n/i18n.h>
 
-#include "config.h"
 #include "nc-cui.h"
 #include "nc-config.h"
 #include "nc-widgets.h"
 
-#define N_FIELDS       23
+#define N_FIELDS       29
+
+extern struct help_text config_help_text;
 
 enum net_conf_type {
        NET_CONF_TYPE_DHCP_ALL,
@@ -46,6 +50,10 @@ struct config_screen {
        WINDOW                  *pad;
 
        bool                    exit;
+       bool                    show_help;
+       bool                    show_subset;
+       bool                    need_redraw;
+
        void                    (*on_exit)(struct cui *);
 
        int                     scroll_y;
@@ -56,9 +64,15 @@ struct config_screen {
 
        enum net_conf_type      net_conf_type;
 
+       bool                    autoboot_enabled;
+
        struct {
-               struct nc_widget_checkbox       *autoboot_f;
-               struct nc_widget_label          *autoboot_l;
+               struct nc_widget_label          *boot_order_l;
+               struct nc_widget_subset         *boot_order_f;
+               struct nc_widget_label          *boot_empty_l;
+               struct nc_widget_button         *boot_add_b;
+               struct nc_widget_button         *boot_none_b;
+               struct nc_widget_button         *boot_any_b;
                struct nc_widget_textbox        *timeout_f;
                struct nc_widget_label          *timeout_l;
                struct nc_widget_label          *timeout_help_l;
@@ -81,7 +95,9 @@ struct config_screen {
                struct nc_widget_label          *dns_dhcp_help_l;
                struct nc_widget_label          *dns_help_l;
 
+               struct nc_widget_label          *safe_mode;
                struct nc_widget_button         *ok_b;
+               struct nc_widget_button         *help_b;
                struct nc_widget_button         *cancel_b;
        } widgets;
 };
@@ -113,10 +129,31 @@ static void config_screen_process_key(struct nc_scr *scr, int key)
        bool handled;
 
        handled = widgetset_process_key(screen->widgetset, key);
-       if (screen->exit)
+
+       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 (handled)
+
+       } else if (screen->show_help) {
+               screen->show_help = false;
+               screen->need_redraw = true;
+               cui_show_help(screen->cui, _("System Configuration"),
+                               &config_help_text);
+
+       } else if (handled && !screen->show_subset) {
                pad_refresh(screen);
+       }
 }
 
 static void config_screen_resize(struct nc_scr *scr)
@@ -128,8 +165,14 @@ static void config_screen_resize(struct nc_scr *scr)
 static int config_screen_post(struct nc_scr *scr)
 {
        struct config_screen *screen = config_screen_from_scr(scr);
+       screen->show_subset = false;
        widgetset_post(screen->widgetset);
        nc_scr_frame_draw(scr);
+       if (screen->need_redraw) {
+               redrawwin(scr->main_ncw);
+               screen->need_redraw = false;
+       }
+       wrefresh(screen->scr.main_ncw);
        pad_refresh(screen);
        return 0;
 }
@@ -149,17 +192,49 @@ struct nc_scr *config_screen_scr(struct config_screen *screen)
 static int screen_process_form(struct config_screen *screen)
 {
        const struct system_info *sysinfo = screen->cui->sysinfo;
-       struct config *config = talloc_zero(screen, struct config);
        enum net_conf_type net_conf_type;
        struct interface_config *iface;
        char *str, *end;
-       int rc;
-
-       config_set_defaults(config);
-
-       config->autoboot_enabled =
-               widget_checkbox_get_value(screen->widgets.autoboot_f);
-
+       struct config *config;
+       int i, n_boot_opts, rc, idx;
+       unsigned int *order;
+       char mac[20];
+
+       config = config_copy(screen, screen->cui->config);
+
+       talloc_free(config->autoboot_opts);
+       config->n_autoboot_opts = 0;
+
+       n_boot_opts = widget_subset_get_order(config, &order,
+                                             screen->widgets.boot_order_f);
+
+       config->autoboot_enabled = n_boot_opts > 0;
+
+       config->n_autoboot_opts = n_boot_opts;
+       config->autoboot_opts = talloc_array(config, struct autoboot_option,
+                                            n_boot_opts);
+
+       for (i = 0; i < n_boot_opts; i++) {
+               if (order[i] < sysinfo->n_blockdevs) {
+                       /* disk uuid */
+                       config->autoboot_opts[i].boot_type = BOOT_DEVICE_UUID;
+                       config->autoboot_opts[i].uuid = talloc_strdup(config,
+                                                       sysinfo->blockdevs[order[i]]->uuid);
+               } else if(order[i] < (sysinfo->n_blockdevs + sysinfo->n_interfaces)) {
+                       /* net uuid */
+                       order[i] -= sysinfo->n_blockdevs;
+                       config->autoboot_opts[i].boot_type = BOOT_DEVICE_UUID;
+                       mac_str(sysinfo->interfaces[order[i]]->hwaddr,
+                               sysinfo->interfaces[order[i]]->hwaddr_size,
+                               mac, sizeof(mac));
+                       config->autoboot_opts[i].uuid = talloc_strdup(config, mac);
+               } else {
+                       /* device type */
+                       order[i] -= (sysinfo->n_blockdevs + sysinfo->n_interfaces);
+                       config->autoboot_opts[i].boot_type = BOOT_DEVICE_TYPE;
+                       config->autoboot_opts[i].type = order[i];
+               }
+       }
 
        str = widget_textbox_get_value(screen->widgets.timeout_f);
        if (str) {
@@ -181,8 +256,6 @@ static int screen_process_form(struct config_screen *screen)
                config->network.n_interfaces = 0;
 
        } else {
-               int idx;
-
                iface = talloc_zero(config, struct interface_config);
                config->network.n_interfaces = 1;
                config->network.interfaces = talloc_array(config,
@@ -201,18 +274,31 @@ static int screen_process_form(struct config_screen *screen)
        }
 
        if (net_conf_type == NET_CONF_TYPE_STATIC) {
+               char *ip, *mask, *gateway;
+
+               ip = widget_textbox_get_value(screen->widgets.ip_addr_f);
+               mask = widget_textbox_get_value(screen->widgets.ip_mask_f);
+               gateway = widget_textbox_get_value(screen->widgets.gateway_f);
+
+               if (!ip || !*ip || !mask || !*mask) {
+                       screen->scr.frame.status =
+                               _("No IP / mask values are set");
+                       nc_scr_frame_draw(&screen->scr);
+                       talloc_free(config);
+                       return -1;
+               }
+
                iface->method = CONFIG_METHOD_STATIC;
                iface->static_config.address = talloc_asprintf(iface, "%s/%s",
-                               widget_textbox_get_value(
-                                       screen->widgets.ip_addr_f),
-                               widget_textbox_get_value(
-                                       screen->widgets.ip_mask_f));
-               iface->static_config.gateway = talloc_strdup(iface,
-                               widget_textbox_get_value(
-                                       screen->widgets.gateway_f));
+                               ip, mask);
+               iface->static_config.gateway = talloc_strdup(iface, gateway);
        }
 
        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;
@@ -235,6 +321,7 @@ static int screen_process_form(struct config_screen *screen)
                }
        }
 
+       config->safe_mode = false;
        rc = cui_send_config(screen->cui, config);
        talloc_free(config);
 
@@ -249,8 +336,18 @@ static int screen_process_form(struct config_screen *screen)
 static void ok_click(void *arg)
 {
        struct config_screen *screen = arg;
-       screen_process_form(screen);
-       screen->exit = true;
+       if (screen_process_form(screen))
+               /* errors are written to the status line, so we'll need
+                * to refresh */
+               wrefresh(screen->scr.main_ncw);
+       else
+               screen->exit = true;
+}
+
+static void help_click(void *arg)
+{
+       struct config_screen *screen = arg;
+       screen->show_help = true;
 }
 
 static void cancel_click(void *arg)
@@ -269,8 +366,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;
@@ -280,18 +376,57 @@ static void config_screen_layout_widgets(struct config_screen *screen,
        help_x = screen->field_x + 2 +
                widget_width(widget_textbox_base(screen->widgets.dns_f));
 
-       y += layout_pair(screen, y, screen->widgets.autoboot_l,
-                       widget_checkbox_base(screen->widgets.autoboot_f));
+       y += 1;
 
-       wf = widget_textbox_base(screen->widgets.timeout_f);
-       widget_move(widget_label_base(screen->widgets.timeout_l),
-                       y, screen->label_x);
+       wl = widget_label_base(screen->widgets.boot_order_l);
+       widget_set_visible(wl, true);
+       widget_move(wl, y, screen->label_x);
+
+       wf = widget_subset_base(screen->widgets.boot_order_f);
        widget_move(wf, y, screen->field_x);
-       widget_move(widget_label_base(screen->widgets.timeout_help_l),
-                       y, screen->field_x + widget_width(wf) + 1);
+       wl = widget_label_base(screen->widgets.boot_empty_l);
+       widget_move(wl, y, screen->field_x);
+
+       if (widget_subset_height(screen->widgets.boot_order_f)) {
+               widget_set_visible(wf, true);
+               widget_set_visible(wl, false);
+               y += widget_height(wf);
+       } else {
+               widget_set_visible(wl, true);
+               widget_set_visible(wf, false);
+               y += 1;
+       }
+
+       y += 1;
+
+       widget_move(widget_button_base(screen->widgets.boot_add_b),
+                       y, screen->field_x);
+       widget_move(widget_button_base(screen->widgets.boot_any_b),
+                       y, screen->field_x + 12);
+       widget_move(widget_button_base(screen->widgets.boot_none_b),
+                       y, screen->field_x + 30);
+
+       wf = widget_button_base(screen->widgets.boot_add_b);
+       if (widget_subset_n_inactive(screen->widgets.boot_order_f))
+               widget_set_visible(wf, true);
+       else
+               widget_set_visible(wf, false);
 
        y += 2;
 
+       wf = widget_textbox_base(screen->widgets.timeout_f);
+       wl = widget_label_base(screen->widgets.timeout_l);
+       wh = widget_label_base(screen->widgets.timeout_help_l);
+       widget_set_visible(wl, screen->autoboot_enabled);
+       widget_set_visible(wf, screen->autoboot_enabled);
+       if (screen->autoboot_enabled) {
+               widget_set_visible(wh, screen->autoboot_enabled);
+               widget_move(wl, y, screen->label_x);
+               widget_move(wf, y, screen->field_x);
+               widget_move(wh, y, screen->field_x + widget_width(wf) + 1);
+               y += 2;
+       }
+
        y += layout_pair(screen, y, screen->widgets.network_l,
                        widget_select_base(screen->widgets.network_f));
 
@@ -301,8 +436,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);
@@ -311,7 +446,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);
@@ -360,7 +495,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) {
@@ -370,10 +505,19 @@ static void config_screen_layout_widgets(struct config_screen *screen,
 
        y += 1;
 
+       show = screen->cui->config->safe_mode;
+       if (show) {
+               widget_move(widget_label_base(screen->widgets.safe_mode),
+                       y, screen->field_x);
+               y += 1;
+       }
+
        widget_move(widget_button_base(screen->widgets.ok_b),
                        y, screen->field_x);
-       widget_move(widget_button_base(screen->widgets.cancel_b),
+       widget_move(widget_button_base(screen->widgets.help_b),
                        y, screen->field_x + 10);
+       widget_move(widget_button_base(screen->widgets.cancel_b),
+                       y, screen->field_x + 24);
 }
 
 static void config_screen_network_change(void *arg, int value)
@@ -381,10 +525,73 @@ 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);
+}
+
+static void config_screen_boot_order_change(void *arg, int value)
+{
+       (void)value;
+       struct config_screen *screen = arg;
+       widgetset_unpost(screen->widgetset);
+       config_screen_layout_widgets(screen);
+       widgetset_post(screen->widgetset);
+}
+
+static void config_screen_add_device(void *arg)
+{
+       struct config_screen *screen = arg;
+
+       screen->show_subset = true;
+       cui_show_subset(screen->cui, _("Select an option"),
+                       screen->widgets.boot_order_f);
+}
+
+static void config_screen_autoboot_none(void *arg)
+{
+       struct config_screen *screen = arg;
+       struct nc_widget_subset *subset = screen->widgets.boot_order_f;
+
+       widget_subset_clear_active(subset);
+       screen->autoboot_enabled = false;
+
+       widgetset_unpost(screen->widgetset);
+       config_screen_layout_widgets(screen);
        widgetset_post(screen->widgetset);
 }
 
+static void config_screen_autoboot_any(void *arg)
+{
+       struct config_screen *screen = arg;
+       const struct system_info *sysinfo = screen->cui->sysinfo;
+       struct nc_widget_subset *subset = screen->widgets.boot_order_f;
+       int idx;
+
+       widget_subset_clear_active(subset);
+
+       idx = sysinfo->n_blockdevs + sysinfo->n_interfaces + DEVICE_TYPE_ANY;
+
+       widget_subset_make_active(screen->widgets.boot_order_f, idx);
+
+       screen->autoboot_enabled = true;
+
+       widgetset_unpost(screen->widgetset);
+       config_screen_layout_widgets(screen);
+       widgetset_post(screen->widgetset);
+}
+
+static void config_screen_update_subset(void *arg,
+                       struct nc_widget_subset *subset, int idx)
+{
+       struct config_screen *screen = arg;
+
+       if (idx >= 0)
+               widget_subset_make_active(subset, idx);
+       if (!screen->autoboot_enabled)
+               screen->autoboot_enabled = true;
+       config_screen_layout_widgets(screen);
+}
+
 static struct interface_config *first_active_interface(
                const struct config *config)
 {
@@ -420,11 +627,37 @@ static enum net_conf_type find_net_conf_type(const struct config *config)
 static void config_screen_setup_empty(struct config_screen *screen)
 {
        widget_new_label(screen->widgetset, 2, screen->field_x,
-                       "Waiting for configuration data...");
+                       _("Waiting for configuration data..."));
        screen->widgets.cancel_b = widget_new_button(screen->widgetset,
-                       4, screen->field_x, 6, "Cancel", cancel_click, screen);
+                       4, screen->field_x, 9, _("Cancel"),
+                       cancel_click, screen);
 }
 
+static int find_autoboot_idx(const struct system_info *sysinfo,
+               struct autoboot_option *opt)
+{
+       unsigned int i;
+
+       if (opt->boot_type == BOOT_DEVICE_TYPE)
+               return sysinfo->n_blockdevs + sysinfo->n_interfaces + opt->type;
+
+       for (i = 0; i < sysinfo->n_blockdevs; i++) {
+               if (!strcmp(sysinfo->blockdevs[i]->uuid, opt->uuid))
+                       return i;
+       }
+
+       for (i = 0; i < sysinfo->n_interfaces; i++) {
+               struct interface_info *info = sysinfo->interfaces[i];
+               char mac[20];
+
+               mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
+
+               if (!strcmp(mac, opt->uuid))
+                       return sysinfo->n_blockdevs + i;
+       }
+
+       return -1;
+}
 
 static void config_screen_setup_widgets(struct config_screen *screen,
                const struct config *config,
@@ -442,46 +675,129 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        type = screen->net_conf_type;
        ifcfg = first_active_interface(config);
 
-       screen->widgets.autoboot_l = widget_new_label(set, 0, 0, "Autoboot:");
-       screen->widgets.autoboot_f = widget_new_checkbox(set, 0, 0,
-                                       config->autoboot_enabled);
+       screen->widgets.boot_add_b = widget_new_button(set, 0, 0, 10,
+                                       _("Add Device"), config_screen_add_device,
+                                       screen);
+
+       screen->widgets.boot_none_b = widget_new_button(set, 0, 0, 10,
+                                       _("Clear"),
+                                       config_screen_autoboot_none, screen);
+
+       screen->widgets.boot_any_b = widget_new_button(set, 0, 0, 16,
+                                       _("Clear & Boot Any"), config_screen_autoboot_any,
+                                       screen);
+
+       screen->widgets.boot_order_l = widget_new_label(set, 0, 0,
+                                       _("Boot order:"));
+       screen->widgets.boot_order_f = widget_new_subset(set, 0, 0,
+                                       COLS - screen->field_x,
+                                       config_screen_update_subset);
+       screen->widgets.boot_empty_l = widget_new_label(set, 0, 0,
+                                       _("(None)"));
+
+       widget_subset_on_change(screen->widgets.boot_order_f,
+                       config_screen_boot_order_change, screen);
+
+       for (i = 0; i < sysinfo->n_blockdevs; i++) {
+               struct blockdev_info *bd = sysinfo->blockdevs[i];
+               char *label;
+
+               label = talloc_asprintf(screen, _("disk: %s [uuid: %s]"),
+                               bd->name, bd->uuid);
+
+               widget_subset_add_option(screen->widgets.boot_order_f, label);
+       }
+
+       for (i = 0; i < sysinfo->n_interfaces; i++) {
+               struct interface_info *info = sysinfo->interfaces[i];
+               char *label, mac[20];
+
+               mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
+
+               label = talloc_asprintf(screen, _("net:  %s [mac: %s]"),
+                               info->name, mac);
+
+               widget_subset_add_option(screen->widgets.boot_order_f, label);
+       }
+
+       for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_NETWORK + 4; i++) {
+               char *label;
+
+               if (i == DEVICE_TYPE_ANY)
+                       label = talloc_asprintf(screen, _("Any Device"));
+               else
+                       label = talloc_asprintf(screen, _("Any %s device"),
+                                               device_type_display_name(i));
+
+               widget_subset_add_option(screen->widgets.boot_order_f, label);
+       }
+
+       screen->autoboot_enabled = config->n_autoboot_opts;
+       for (i = 0; i < config->n_autoboot_opts; i++) {
+               struct autoboot_option *opt = &config->autoboot_opts[i];
+               int idx;
+
+               idx = find_autoboot_idx(sysinfo, opt);
+
+               if (idx >= 0) {
+                       widget_subset_make_active(screen->widgets.boot_order_f,
+                                                 idx);
+               } else {
+                       if (opt->boot_type == BOOT_DEVICE_TYPE)
+                               pb_log("%s: Unknown autoboot option: %d\n",
+                                      __func__, opt->type);
+                       else
+                               pb_log("%s: Unknown autoboot UUID: %s\n",
+                                      __func__, opt->uuid);
+               }
+       }
+
 
        str = talloc_asprintf(screen, "%d", config->autoboot_timeout_sec);
-       screen->widgets.timeout_l = widget_new_label(set, 0, 0, "Timeout:");
+       screen->widgets.timeout_l = widget_new_label(set, 0, 0, _("Timeout:"));
        screen->widgets.timeout_f = widget_new_textbox(set, 0, 0, 5, str);
-       screen->widgets.timeout_help_l = widget_new_label(set, 0, 0, "seconds");
+       screen->widgets.timeout_help_l = widget_new_label(set, 0, 0,
+                                       _("seconds"));
 
-       screen->widgets.network_l = widget_new_label(set, 0, 0, "Network");
+       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:"));
        screen->widgets.network_f = widget_new_select(set, 0, 0, 50);
 
        widget_select_add_option(screen->widgets.network_f,
                                        NET_CONF_TYPE_DHCP_ALL,
-                                       "DHCP on all active interfaces",
+                                       _("DHCP on all active interfaces"),
                                        type == NET_CONF_TYPE_DHCP_ALL);
        widget_select_add_option(screen->widgets.network_f,
                                        NET_CONF_TYPE_DHCP_ONE,
-                                       "DHCP on a specific interface",
+                                       _("DHCP on a specific interface"),
                                        type == NET_CONF_TYPE_DHCP_ONE);
        widget_select_add_option(screen->widgets.network_f,
                                        NET_CONF_TYPE_STATIC,
-                                       "Static IP configuration",
+                                       _("Static IP configuration"),
                                        type == NET_CONF_TYPE_STATIC);
 
        widget_select_on_change(screen->widgets.network_f,
                        config_screen_network_change, screen);
 
-       screen->widgets.iface_l = widget_new_label(set, 0, 0, "Device:");
-       screen->widgets.iface_f = widget_new_select(set, 0, 0, 20);
+       screen->widgets.iface_l = widget_new_label(set, 0, 0, _("Device:"));
+       screen->widgets.iface_f = widget_new_select(set, 0, 0, 50);
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *info = sysinfo->interfaces[i];
+               char str[50], mac[20];
                bool is_default;
 
                is_default = ifcfg && !memcmp(ifcfg->hwaddr, info->hwaddr,
                                        sizeof(ifcfg->hwaddr));
 
+               mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
+               snprintf(str, sizeof(str), "%s [%s, %s]", info->name, mac,
+                               info->link ? _("link up") : _("link down"));
+
                widget_select_add_option(screen->widgets.iface_f,
-                                               i, info->name, is_default);
+                                               i, str, is_default);
        }
 
        gw = ip = mask = NULL;
@@ -499,17 +815,25 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                gw = ifcfg->static_config.gateway;
        }
 
-       screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, "IP/mask:");
+       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, 3, mask);
        screen->widgets.ip_addr_mask_help_l =
-               widget_new_label(set, 0, 0, "(eg. 192.168.0.10 / 24)");
+               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);
 
-       screen->widgets.gateway_l = widget_new_label(set, 0, 0, "Gateway:");
+       screen->widgets.gateway_l = widget_new_label(set, 0, 0, _("Gateway:"));
        screen->widgets.gateway_f = widget_new_textbox(set, 0, 0, 16, gw);
        screen->widgets.gateway_help_l =
-               widget_new_label(set, 0, 0, "(eg. 192.168.0.1)");
+               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, "");
        for (i = 0; i < config->network.n_dns_servers; i++) {
@@ -518,34 +842,42 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                                config->network.dns_servers[i]);
        }
 
-       screen->widgets.dns_l = widget_new_label(set, 0, 0, "DNS Server(s):");
+       screen->widgets.dns_l = widget_new_label(set, 0, 0,
+                                       _("DNS Server(s):"));
        screen->widgets.dns_f = widget_new_textbox(set, 0, 0, 32, str);
        screen->widgets.dns_help_l =
-               widget_new_label(set, 0, 0, "(eg. 192.168.0.2)");
+               widget_new_label(set, 0, 0, _("(eg. 192.168.0.2)"));
+
+       widget_textbox_set_validator_ipv4_multi(screen->widgets.dns_f);
 
        screen->widgets.dns_dhcp_help_l = widget_new_label(set, 0, 0,
-                       "(if not provided by DHCP server)");
+                       _("(if not provided by DHCP server)"));
 
-       screen->widgets.ok_b = widget_new_button(set, 0, 0, 6, "OK",
+       if (config->safe_mode)
+               screen->widgets.safe_mode = widget_new_label(set, 0, 0,
+                        _("Selecting 'OK' will exit safe mode"));
+
+       screen->widgets.ok_b = widget_new_button(set, 0, 0, 6, _("OK"),
                        ok_click, screen);
-       screen->widgets.cancel_b = widget_new_button(set, 0, 0, 6, "Cancel",
+       screen->widgets.help_b = widget_new_button(set, 0, 0, 10, _("Help"),
+                       help_click, screen);
+       screen->widgets.cancel_b = widget_new_button(set, 0, 0, 10, _("Cancel"),
                        cancel_click, screen);
 }
 
 static void config_screen_widget_focus(struct nc_widget *widget, void *arg)
 {
        struct config_screen *screen = arg;
-       int w_y, w_height, s_max;
+       int w_y, s_max;
 
-       w_y = widget_y(widget);
-       w_height = widget_height(widget);
-       s_max = getmaxy(screen->scr.sub_ncw);
+       w_y = widget_y(widget) + widget_focus_y(widget);
+       s_max = getmaxy(screen->scr.sub_ncw) - 1;
 
        if (w_y < screen->scroll_y)
                screen->scroll_y = w_y;
 
-       else if (w_y + w_height + screen->scroll_y > s_max - 1)
-               screen->scroll_y = 1 + w_y + w_height - s_max;
+       else if (w_y + screen->scroll_y + 1 > s_max)
+               screen->scroll_y = 1 + w_y - s_max;
 
        else
                return;
@@ -553,8 +885,7 @@ static void config_screen_widget_focus(struct nc_widget *widget, void *arg)
        pad_refresh(screen);
 }
 
-
-void config_screen_update(struct config_screen *screen,
+static void config_screen_draw(struct config_screen *screen,
                const struct config *config,
                const struct system_info *sysinfo)
 {
@@ -564,17 +895,22 @@ void config_screen_update(struct config_screen *screen,
        /* The size of the pad we'll need depends on the number of interfaces.
         *
         * We use N_FIELDS (which is quite conservative, as some fields share
-        * a line) as a base, then add 3 (as the network select field is
-        * takes 3 lines), and n_interfaces (as the network interface field
-        * has n_interfaces lines).
+        * a line) as a base, then:
+        * - add 6 (as the network select & boot device select fields take 3
+        *   lines each),
+        * - add n_interfaces for every field in the network select field, and
+        * - add (n_blockdevs + n_interfaces) for every field in the boot device
+        *   select field
         */
-       height = N_FIELDS + 3;
-       if (sysinfo)
+       height = N_FIELDS + 6;
+       if (sysinfo) {
                height += sysinfo->n_interfaces;
+               height += (sysinfo->n_blockdevs + sysinfo->n_interfaces);
+       }
        if (!screen->pad || getmaxy(screen->pad) < height) {
                if (screen->pad)
                        delwin(screen->pad);
-               screen->pad = newpad(height, COLS);
+               screen->pad = newpad(height, COLS + 10);
        }
 
        if (screen->widgetset) {
@@ -592,14 +928,19 @@ void config_screen_update(struct config_screen *screen,
                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);
+               config_screen_layout_widgets(screen);
        }
 
        if (repost)
                widgetset_post(screen->widgetset);
+}
 
+void config_screen_update(struct config_screen *screen,
+               const struct config *config,
+               const struct system_info *sysinfo)
+{
+       config_screen_draw(screen, config, sysinfo);
        pad_refresh(screen);
 }
 
@@ -627,21 +968,22 @@ struct config_screen *config_screen_init(struct cui *cui,
 
        screen->cui = cui;
        screen->on_exit = on_exit;
+       screen->need_redraw = false;
        screen->label_x = 2;
        screen->field_x = 17;
 
+       screen->show_subset = false;
+
        screen->scr.frame.ltitle = talloc_strdup(screen,
-                       "Petitboot System Configuration");
+                       _("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);
 
-       config_screen_update(screen, config, sysinfo);
-
-       wrefresh(screen->scr.main_ncw);
+       config_screen_draw(screen, config, sysinfo);
 
        return screen;
 }