]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-config.c
ui/ncurses: Exit safe mode on configuration change
[petitboot] / ui / ncurses / nc-config.c
index d345c853b23a4e2f1a70b6bfcbecf63d14dac412..7a709ab1a3e3cf69914e65a717775fdb2f6354cc 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       26
 
-extern const char *config_help_text;
+extern struct help_text config_help_text;
 
 enum autoboot_type {
        AUTOBOOT_ANY,
@@ -93,6 +94,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,8 +146,8 @@ 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);
+               cui_show_help(screen->cui, _("System Configuration"),
+                               &config_help_text);
 
        } else if (handled) {
                pad_refresh(screen);
@@ -267,7 +269,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 +308,7 @@ static int screen_process_form(struct config_screen *screen)
                }
        }
 
+       config->safe_mode = false;
        rc = cui_send_config(screen->cui, config);
        talloc_free(config);
 
@@ -469,6 +472,13 @@ 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),
@@ -530,9 +540,10 @@ 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, 6, _("Cancel"),
+                       cancel_click, screen);
 }
 
 
@@ -553,7 +564,8 @@ 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_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,
@@ -563,18 +575,19 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 
        widget_select_add_option(screen->widgets.autoboot_f,
                                        AUTOBOOT_DISABLED,
-                                       "Don't autoboot",
+                                       _("Don't autoboot"),
                                        screen->autoboot_type ==
                                                AUTOBOOT_DISABLED);
        widget_select_add_option(screen->widgets.autoboot_f,
                                        AUTOBOOT_ANY,
-                                       "Autoboot from any disk/network device",
+                                       _("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",
+                                       _("Only autoboot from a specific "
+                                               "disk/network device"),
                                        screen->autoboot_type ==
                                                AUTOBOOT_ONE);
 
@@ -590,7 +603,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                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,
@@ -608,7 +621,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                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,
@@ -619,7 +632,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        if (screen->autoboot_type == AUTOBOOT_ONE && !found) {
                char *label;
 
-               label = talloc_asprintf(screen, "Unknown UUID: %s",
+               label = talloc_asprintf(screen, _("Unknown UUID: %s"),
                                config->boot_device);
 
                widget_select_add_option(screen->widgets.boot_device_f, -1,
@@ -627,33 +640,34 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        }
 
        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 +680,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 +701,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 +728,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, 6, _("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, 6, _("Cancel"),
                        cancel_click, screen);
 }
 
@@ -840,10 +859,10 @@ struct config_screen *config_screen_init(struct cui *cui,
        screen->field_x = 17;
 
        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);