ui/ncurses: Properly size cancel and help buttons
[petitboot] / ui / ncurses / nc-menu.c
index a5794f7a63608067a7de2839ea1bee342dcd6161..7ff2468cb1c47d3b1caae9cf3180523ad920f939 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "log/log.h"
 #include "talloc/talloc.h"
+#include "i18n/i18n.h"
 #include "ui/common/ui-system.h"
 #include "nc-cui.h"
 #include "nc-menu.h"
@@ -99,7 +100,7 @@ static const char *pmenu_item_label(struct pmenu_item *item, const char *name)
        /* if we have an invalid multibyte sequence, create an entirely
         * new name, indicating that we had invalid input */
        if (len == SIZE_MAX) {
-               name = talloc_asprintf(item, "!Invalid option %d\n",
+               name = talloc_asprintf(item, _("!Invalid option %d"),
                                ++invalid_idx);
                return name;
        }
@@ -264,7 +265,7 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
                if (matched) {
                        snprintf(buf,sizeof(buf),"[%s: %s / %s]",
                                dev->type == DEVICE_TYPE_DISK ?
-                               "Disk" : "CD/DVD",
+                                       _("Disk") : _("CD/DVD"),
                                bd->name, bd->uuid);
                }
                break;
@@ -281,8 +282,8 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
                if (matched) {
                        mac_str(intf->hwaddr, intf->hwaddr_size,
                                hwaddr, sizeof(hwaddr));
-                       snprintf(buf,sizeof(buf),"[Interface %s / %s]",
-                               intf->name, hwaddr);
+                       snprintf(buf,sizeof(buf),"[%s: %s / %s]",
+                               _("Network"), intf->name, hwaddr);
                }
                break;
 
@@ -293,8 +294,8 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
        if (!matched) {
                pb_debug("%s: No matching device found for %s (%s)\n",
                        __func__,opt->device_id, dev->id);
-               snprintf(buf,sizeof(buf),"[Unknown Device: %s]",
-                       dev->id);
+               snprintf(buf, sizeof(buf), "[%s: %s]",
+                       _("Unknown Device"), dev->id);
        }
 
        dev_hdr = pmenu_item_create(menu, buf);
@@ -408,6 +409,9 @@ static void pmenu_process_key(struct nc_scr *scr, int key)
        case 'c':
                cui_show_config(cui_from_arg(scr->ui_ctx));
                break;
+       case 'l':
+               cui_show_lang(cui_from_arg(scr->ui_ctx));
+               break;
        case KEY_F(1):
        case 'h':
                if (menu->help_text)
@@ -491,6 +495,19 @@ int pmenu_remove(struct pmenu *menu, struct pmenu_item *item)
        return 0;
 }
 
+static int pmenu_destructor(void *ptr)
+{
+       struct pmenu *menu = ptr;
+       assert(menu->scr.sig == pb_pmenu_sig);
+       menu->scr.sig = pb_removed_sig;
+
+       unpost_menu(menu->ncm);
+       free_menu(menu->ncm);
+       delwin(menu->scr.sub_ncw);
+       delwin(menu->scr.main_ncw);
+       return 0;
+}
+
 /**
  * pmenu_init - Allocate and initialize a new menu instance.
  *
@@ -503,14 +520,13 @@ struct pmenu *pmenu_init(void *ui_ctx, unsigned int item_count,
        void (*on_exit)(struct pmenu *))
 {
        struct pmenu *menu = talloc_zero(ui_ctx, struct pmenu);
-
        if (!menu)
                return NULL;
 
-       /* note items array has a null terminator */
+       talloc_set_destructor(menu, pmenu_destructor);
 
+       /* note items array has a null terminator */
        menu->items = talloc_zero_array(menu, ITEM *, item_count + 1);
-
        if (!menu->items) {
                talloc_free(menu);
                return NULL;
@@ -554,19 +570,3 @@ int pmenu_setup(struct pmenu *menu)
        return 0;
 }
 
-/**
- * pmenu_delete - Delete a menu instance.
- *
- */
-
-void pmenu_delete(struct pmenu *menu)
-{
-       assert(menu->scr.sig == pb_pmenu_sig);
-       menu->scr.sig = pb_removed_sig;
-
-       unpost_menu(menu->ncm);
-       free_menu(menu->ncm);
-       delwin(menu->scr.sub_ncw);
-       delwin(menu->scr.main_ncw);
-       talloc_free(menu);
-}