petitboot: Implement ordered boot options
[petitboot] / ui / ncurses / nc-config.c
index 8c5e9a2fc1756577cd61ad12d305de3e445f384b..3156b9bf1057bc609bdf031908ee401d7d574b18 100644 (file)
 #include <talloc/talloc.h>
 #include <types/types.h>
 #include <log/log.h>
+#include <i18n/i18n.h>
 
 #include "nc-cui.h"
 #include "nc-config.h"
 #include "nc-widgets.h"
 
-#define N_FIELDS       25
+#define N_FIELDS       29
 
-extern const char *config_help_text;
-
-enum autoboot_type {
-       AUTOBOOT_ANY,
-       AUTOBOOT_ONE,
-       AUTOBOOT_DISABLED,
-};
+extern struct help_text config_help_text;
 
 enum net_conf_type {
        NET_CONF_TYPE_DHCP_ALL,
@@ -56,6 +51,9 @@ struct config_screen {
 
        bool                    exit;
        bool                    show_help;
+       bool                    show_subset;
+       bool                    need_redraw;
+
        void                    (*on_exit)(struct cui *);
 
        int                     scroll_y;
@@ -65,12 +63,16 @@ struct config_screen {
        int                     network_config_y;
 
        enum net_conf_type      net_conf_type;
-       enum autoboot_type      autoboot_type;
+
+       bool                    autoboot_enabled;
 
        struct {
-               struct nc_widget_select         *autoboot_f;
-               struct nc_widget_label          *autoboot_l;
-               struct nc_widget_select         *boot_device_f;
+               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;
@@ -93,6 +95,7 @@ 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;
@@ -144,10 +147,11 @@ static void config_screen_process_key(struct nc_scr *scr, int key)
 
        } else if (screen->show_help) {
                screen->show_help = false;
-               cui_show_help(screen->cui, "System Configuration",
-                               config_help_text);
+               screen->need_redraw = true;
+               cui_show_help(screen->cui, _("System Configuration"),
+                               &config_help_text);
 
-       } else if (handled) {
+       } else if (handled && !screen->show_subset) {
                pad_refresh(screen);
        }
 }
@@ -161,9 +165,13 @@ 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);
-       redrawwin(scr->main_ncw);
+       if (screen->need_redraw) {
+               redrawwin(scr->main_ncw);
+               screen->need_redraw = false;
+       }
        wrefresh(screen->scr.main_ncw);
        pad_refresh(screen);
        return 0;
@@ -186,38 +194,45 @@ static int screen_process_form(struct config_screen *screen)
        const struct system_info *sysinfo = screen->cui->sysinfo;
        enum net_conf_type net_conf_type;
        struct interface_config *iface;
-       struct config *config;
        char *str, *end;
-       int rc, idx;
+       struct config *config;
+       int i, n_boot_opts, rc, idx;
+       unsigned int *order;
+       char mac[20];
 
        config = config_copy(screen, screen->cui->config);
 
-       screen->autoboot_type =
-               widget_select_get_value(screen->widgets.autoboot_f);
-
-       config->autoboot_enabled = screen->autoboot_type != AUTOBOOT_DISABLED;
-
-       if (screen->autoboot_type == AUTOBOOT_ONE) {
-               char mac[20], *uuid = NULL;
-
-               /* if idx is -1 here, we have an unknown UUID selected.
-                * Otherwise, it's a blockdev index (idx <= n_blockdevs) or an
-                * interface index.
-                */
-               idx = widget_select_get_value(screen->widgets.boot_device_f);
-               if (idx >= (int)sysinfo->n_blockdevs) {
-                       struct interface_info *info = sysinfo->
-                               interfaces[idx - sysinfo->n_blockdevs];
-                       mac_str(info->hwaddr, info->hwaddr_size,
-                                       mac, sizeof(mac));
-                       uuid = mac;
-               } else if (idx != -1) {
-                       uuid = sysinfo->blockdevs[idx]->uuid;
-               }
-
-               if (uuid) {
-                       talloc_free(config->boot_device);
-                       config->boot_device = talloc_strdup(config, uuid);
+       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];
                }
        }
 
@@ -267,7 +282,7 @@ static int screen_process_form(struct config_screen *screen)
 
                if (!ip || !*ip || !mask || !*mask) {
                        screen->scr.frame.status =
-                               "No IP / mask values are set";
+                               _("No IP / mask values are set");
                        nc_scr_frame_draw(&screen->scr);
                        talloc_free(config);
                        return -1;
@@ -306,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);
 
@@ -360,35 +376,55 @@ 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_select_base(screen->widgets.autoboot_f));
+       y += 1;
+
+       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);
+       wl = widget_label_base(screen->widgets.boot_empty_l);
+       widget_move(wl, y, screen->field_x);
 
-       wf = widget_select_base(screen->widgets.boot_device_f);
-       if (screen->autoboot_type == AUTOBOOT_ONE) {
+       if (widget_subset_height(screen->widgets.boot_order_f)) {
                widget_set_visible(wf, true);
-               widget_move(wf, y, screen->field_x + 3);
+               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);
-       if (screen->autoboot_type != AUTOBOOT_DISABLED) {
-               widget_set_visible(wl, true);
-               widget_set_visible(wf, true);
-               widget_set_visible(wh, true);
+       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;
-       } else {
-               widget_set_visible(wl, false);
-               widget_set_visible(wf, false);
-               widget_set_visible(wh, false);
        }
 
        y += layout_pair(screen, y, screen->widgets.network_l,
@@ -469,12 +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.help_b),
                        y, screen->field_x + 10);
        widget_move(widget_button_base(screen->widgets.cancel_b),
-                       y, screen->field_x + 20);
+                       y, screen->field_x + 24);
 }
 
 static void config_screen_network_change(void *arg, int value)
@@ -486,15 +529,69 @@ static void config_screen_network_change(void *arg, int value)
        widgetset_post(screen->widgetset);
 }
 
-static void config_screen_autoboot_change(void *arg, int value)
+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;
-       screen->autoboot_type = value;
+       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)
 {
@@ -530,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,
@@ -545,7 +668,6 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        char *str, *ip, *mask, *gw;
        enum net_conf_type type;
        unsigned int i;
-       bool found;
 
        build_assert(sizeof(screen->widgets) / sizeof(struct widget *)
                        == N_FIELDS);
@@ -553,107 +675,113 @@ 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_select(set, 0, 0, 55);
-
-       widget_select_on_change(screen->widgets.autoboot_f,
-                       config_screen_autoboot_change, screen);
-
-       screen->widgets.boot_device_f = widget_new_select(set, 0, 0, 55);
-
-       widget_select_add_option(screen->widgets.autoboot_f,
-                                       AUTOBOOT_DISABLED,
-                                       "Don't autoboot",
-                                       screen->autoboot_type ==
-                                               AUTOBOOT_DISABLED);
-       widget_select_add_option(screen->widgets.autoboot_f,
-                                       AUTOBOOT_ANY,
-                                       "Autoboot from any disk/network device",
-                                       screen->autoboot_type ==
-                                               AUTOBOOT_ANY);
-       widget_select_add_option(screen->widgets.autoboot_f,
-                                       AUTOBOOT_ONE,
-                                       "Only autoboot from a specific "
-                                       "disk/network device",
-                                       screen->autoboot_type ==
-                                               AUTOBOOT_ONE);
-
-       found = false;
+       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];
-               bool selected;
                char *label;
 
-               selected = config->boot_device &&
-                               !strcmp(config->boot_device, bd->uuid);
-               if (selected)
-                       found = true;
-
-               label = talloc_asprintf(screen, "disk: %s [uuid: %s]",
+               label = talloc_asprintf(screen, _("disk: %s [uuid: %s]"),
                                bd->name, bd->uuid);
 
-               widget_select_add_option(screen->widgets.boot_device_f, i,
-                                       label, selected);
+               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];
-               bool selected;
 
                mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
-               selected = config->boot_device &&
-                               !strcmp(config->boot_device, mac);
-               if (selected)
-                       found = true;
 
-               label = talloc_asprintf(screen, "net:  %s [mac: %s]",
+               label = talloc_asprintf(screen, _("net:  %s [mac: %s]"),
                                info->name, mac);
 
-               widget_select_add_option(screen->widgets.boot_device_f,
-                                               i + sysinfo->n_blockdevs,
-                                               label, selected);
+               widget_subset_add_option(screen->widgets.boot_order_f, label);
        }
 
-       if (screen->autoboot_type == AUTOBOOT_ONE && !found) {
+       for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_NETWORK + 4; i++) {
                char *label;
 
-               label = talloc_asprintf(screen, "Unknown UUID: %s",
-                               config->boot_device);
+               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);
+       }
 
-               widget_select_add_option(screen->widgets.boot_device_f, -1,
-                                               label, true);
+       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"));
 
        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_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_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++) {
@@ -666,7 +794,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 
                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");
+                               info->link ? _("link up") : _("link down"));
 
                widget_select_add_option(screen->widgets.iface_f,
                                                i, str, is_default);
@@ -687,22 +815,22 @@ 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);
@@ -714,21 +842,26 @@ 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)"));
+
+       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",
+       screen->widgets.ok_b = widget_new_button(set, 0, 0, 6, _("OK"),
                        ok_click, screen);
-       screen->widgets.help_b = widget_new_button(set, 0, 0, 6, "Help",
+       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, 6, "Cancel",
+       screen->widgets.cancel_b = widget_new_button(set, 0, 0, 10, _("Cancel"),
                        cancel_click, screen);
 }
 
@@ -762,17 +895,22 @@ static void config_screen_draw(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) {
@@ -790,12 +928,6 @@ static void config_screen_draw(struct config_screen *screen,
                config_screen_setup_empty(screen);
        } else {
                screen->net_conf_type = find_net_conf_type(config);
-               if (!config->autoboot_enabled)
-                       screen->autoboot_type = AUTOBOOT_DISABLED;
-               else
-                       screen->autoboot_type = config->boot_device ?
-                                       AUTOBOOT_ONE : AUTOBOOT_ANY;
-
                config_screen_setup_widgets(screen, config, sysinfo);
                config_screen_layout_widgets(screen);
        }
@@ -836,14 +968,17 @@ 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, x=exit, h=help");
+                       _("tab=next, shift+tab=previous, x=exit, h=help"));
        nc_scr_frame_draw(&screen->scr);
 
        scrollok(screen->scr.sub_ncw, true);