]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: Make boot editor API consistent with config & sysinfo screens
authorJeremy Kerr <jk@ozlabs.org>
Sun, 17 Nov 2013 03:04:08 +0000 (14:04 +1100)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 22 Nov 2013 02:45:54 +0000 (10:45 +0800)
The boot-editor API is a little more exposed than it needs to be: the
boot_editor struct does not need to be available to other files, and the
init function and on_exit functions differ from those provided for the
config and sysinfo screens.

This change unifies the boot_editor API with those for the other
screens.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
ui/ncurses/nc-boot-editor.c
ui/ncurses/nc-boot-editor.h
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h
ui/ncurses/nc-menu.h
ui/ncurses/nc-widgets.c

index c7c2ed8e3723594b4a2471b965e5128dd8eb1c26..02187e0adac685208083a48ba3b5a6f531611788 100644 (file)
 #include "nc-boot-editor.h"
 #include "nc-widgets.h"
 
 #include "nc-boot-editor.h"
 #include "nc-widgets.h"
 
+struct boot_editor {
+       struct nc_scr           scr;
+       struct cui              *cui;
+       void                    *data;
+       struct pmenu_item       *item;
+       void                    (*on_exit)(struct cui *cui,
+                                       struct pmenu_item *item,
+                                       struct pb_boot_data *bd);
+
+       struct nc_widgetset     *widgetset;
+       struct {
+               struct nc_widget_label          *image_l;
+               struct nc_widget_textbox        *image_f;
+               struct nc_widget_label          *initrd_l;
+               struct nc_widget_textbox        *initrd_f;
+               struct nc_widget_label          *dtb_l;
+               struct nc_widget_textbox        *dtb_f;
+               struct nc_widget_label          *args_l;
+               struct nc_widget_textbox        *args_f;
+               struct nc_widget_button         *ok_b;
+               struct nc_widget_button         *cancel_b;
+       } widgets;
+};
+
 static struct boot_editor *boot_editor_from_scr(struct nc_scr *scr)
 {
        struct boot_editor *boot_editor;
 static struct boot_editor *boot_editor_from_scr(struct nc_scr *scr)
 {
        struct boot_editor *boot_editor;
@@ -65,6 +89,11 @@ static int boot_editor_unpost(struct nc_scr *scr)
        return 0;
 }
 
        return 0;
 }
 
+struct nc_scr *boot_editor_scr(struct boot_editor *boot_editor)
+{
+       return &boot_editor->scr;
+}
+
 static void boot_editor_resize(struct nc_scr *scr)
 {
        /* FIXME: forms can't be resized, need to recreate here */
 static void boot_editor_resize(struct nc_scr *scr)
 {
        /* FIXME: forms can't be resized, need to recreate here */
@@ -118,7 +147,7 @@ static void boot_editor_process_key(struct nc_scr *scr, int key)
        switch (key) {
        case 'x':
        case 27: /* ESC */
        switch (key) {
        case 'x':
        case 27: /* ESC */
-               boot_editor->on_exit(boot_editor, boot_editor_cancel, NULL);
+               boot_editor->on_exit(boot_editor->cui, NULL, NULL);
                nc_flush_keys();
        }
 }
                nc_flush_keys();
        }
 }
@@ -140,38 +169,41 @@ static void ok_click(void *arg)
        struct pb_boot_data *bd;
 
        bd = boot_editor_prepare_data(boot_editor);
        struct pb_boot_data *bd;
 
        bd = boot_editor_prepare_data(boot_editor);
-       boot_editor->on_exit(boot_editor, boot_editor_update, bd);
+       boot_editor->on_exit(boot_editor->cui, boot_editor->item, bd);
 }
 
 static void cancel_click(void *arg)
 {
        struct boot_editor *boot_editor = arg;
 }
 
 static void cancel_click(void *arg)
 {
        struct boot_editor *boot_editor = arg;
-       boot_editor->on_exit(boot_editor, boot_editor_cancel, NULL);
+       boot_editor->on_exit(boot_editor->cui, NULL, NULL);
 }
 
 }
 
-struct boot_editor *boot_editor_init(struct pmenu *menu,
-               const struct pb_boot_data *bd,
-               void (*on_exit)(struct boot_editor *,
-                               enum boot_editor_result,
-                               struct pb_boot_data *))
+struct boot_editor *boot_editor_init(struct cui *cui,
+               struct pmenu_item *item,
+               const struct system_info *sysinfo,
+               void (*on_exit)(struct cui *cui,
+                               struct pmenu_item *item,
+                               struct pb_boot_data *bd))
 {
        int y, field_size, label_x = 1, field_x = 9;
        char *image, *initrd, *dtb, *args;
        struct boot_editor *boot_editor;
        struct nc_widgetset *set;
 
 {
        int y, field_size, label_x = 1, field_x = 9;
        char *image, *initrd, *dtb, *args;
        struct boot_editor *boot_editor;
        struct nc_widgetset *set;
 
-       assert(on_exit);
+       (void)sysinfo;
 
 
-       boot_editor = talloc_zero(menu, struct boot_editor);
+       boot_editor = talloc_zero(cui, struct boot_editor);
 
        if (!boot_editor)
                return NULL;
 
        talloc_set_destructor(boot_editor, boot_editor_destructor);
 
        if (!boot_editor)
                return NULL;
 
        talloc_set_destructor(boot_editor, boot_editor_destructor);
-       boot_editor->original_pmenu = menu;
+       boot_editor->cui = cui;
+       boot_editor->item = item;
+       boot_editor->on_exit = on_exit;
 
        nc_scr_init(&boot_editor->scr, pb_boot_editor_sig, 0,
 
        nc_scr_init(&boot_editor->scr, pb_boot_editor_sig, 0,
-                       menu, boot_editor_process_key,
+                       cui, boot_editor_process_key,
                boot_editor_post, boot_editor_unpost, boot_editor_resize);
 
        boot_editor->scr.frame.ltitle = talloc_strdup(boot_editor,
                boot_editor_post, boot_editor_unpost, boot_editor_resize);
 
        boot_editor->scr.frame.ltitle = talloc_strdup(boot_editor,
@@ -180,9 +212,8 @@ struct boot_editor *boot_editor_init(struct pmenu *menu,
        boot_editor->scr.frame.help = talloc_strdup(boot_editor,
                        "Enter=accept");
 
        boot_editor->scr.frame.help = talloc_strdup(boot_editor,
                        "Enter=accept");
 
-       boot_editor->on_exit = on_exit;
-
-       if (bd) {
+       if (item) {
+               struct pb_boot_data *bd = cod_from_item(item)->bd;
                image = bd->image;
                initrd = bd->initrd;
                dtb = bd->dtb;
                image = bd->image;
                initrd = bd->initrd;
                dtb = bd->dtb;
index 6b72f253bccfa82ceba150f07e9938e6a7e27db2..5c22598ba7f544f94736458bb804854f7e1d9dd9 100644 (file)
 #if !defined(_PB_NC_KED_H)
 #define _PB_NC_KED_H
 
 #if !defined(_PB_NC_KED_H)
 #define _PB_NC_KED_H
 
-#include <linux/input.h> /* This must be included before ncurses.h */
-#if defined HAVE_NCURSESW_FORM_H
-#  include <ncursesw/form.h>
-#elif defined HAVE_NCURSES_FORM_H
-#  include <ncurses/form.h>
-#elif defined HAVE_FORM_H
-#  include <form.h>
-#else
-#  error "Curses form.h not found."
-#endif
+#include "ui/common/discover-client.h"
 
 #include "types/types.h"
 
 #include "types/types.h"
-#include "ui/common/ui-system.h"
-#include "nc-scr.h"
-
-enum boot_editor_attr_cursor {
-       boot_editor_attr_cursor_ins = A_NORMAL,
-       boot_editor_attr_cursor_ovl = A_NORMAL | A_UNDERLINE,
-};
+#include "nc-cui.h"
 
 
-/**
- * enum boot_editor_result - Result code for boot_editor:on_exit().
- * @boot_editor_cancel: The user canceled the operation.
- * @boot_editor_update: The args were updated.
- */
+struct boot_editor;
 
 
-enum boot_editor_result {
-       boot_editor_cancel,
-       boot_editor_update,
-};
-
-/**
- * struct boot_editor - kexec args editor.
- */
+struct boot_editor *boot_editor_init(struct cui *cui,
+               struct pmenu_item *item,
+               const struct system_info *sysinfo,
+               void (*on_exit)(struct cui *cui,
+                               struct pmenu_item *item,
+                               struct pb_boot_data *bd));
 
 
-struct boot_editor {
-       struct nc_scr   scr;
-       void            *data;
-       struct pmenu    *original_pmenu;
-       void            (*on_exit)(struct boot_editor *boot_editor,
-                                       enum boot_editor_result result,
-                                       struct pb_boot_data *bd);
-       enum boot_editor_attr_cursor attr_cursor;
+struct nc_scr *boot_editor_scr(struct boot_editor *boot_editor);
 
 
-       struct nc_widgetset     *widgetset;
-       struct {
-               struct nc_widget_label          *image_l;
-               struct nc_widget_textbox        *image_f;
-               struct nc_widget_label          *initrd_l;
-               struct nc_widget_textbox        *initrd_f;
-               struct nc_widget_label          *dtb_l;
-               struct nc_widget_textbox        *dtb_f;
-               struct nc_widget_label          *args_l;
-               struct nc_widget_textbox        *args_f;
-               struct nc_widget_button         *ok_b;
-               struct nc_widget_button         *cancel_b;
-       } widgets;
-};
+void boot_editor_update(struct boot_editor *boot_editor,
+               const struct system_info *info);
 
 
-struct boot_editor *boot_editor_init(struct pmenu *menu,
-               const struct pb_boot_data *bd,
-               void (*on_exit)(struct boot_editor *,
-                               enum boot_editor_result,
-                               struct pb_boot_data *));
 
 #endif
 
 #endif
index 5af11717e42915017b95cc8eaf97555db6e95283..107539b32a11a1b5974d70caad18ac5d4c36425d 100644 (file)
 #include "waiter/waiter.h"
 #include "process/process.h"
 #include "ui/common/discover-client.h"
 #include "waiter/waiter.h"
 #include "process/process.h"
 #include "ui/common/discover-client.h"
+#include "ui/common/ui-system.h"
 #include "nc-cui.h"
 #include "nc-cui.h"
+#include "nc-boot-editor.h"
 #include "nc-config.h"
 #include "nc-sysinfo.h"
 
 #include "nc-config.h"
 #include "nc-sysinfo.h"
 
-static struct cui_opt_data *cod_from_item(struct pmenu_item *item)
-{
-       return item->data;
-}
-
 static void cui_start(void)
 {
        initscr();                      /* Initialize ncurses. */
 static void cui_start(void)
 {
        initscr();                      /* Initialize ncurses. */
@@ -157,29 +154,23 @@ static int cui_boot(struct pmenu_item *item)
        return 0;
 }
 
        return 0;
 }
 
-/**
- * cui_boot_editor_on_exit - The boot_editor on_exit callback.
- */
-
-static void cui_boot_editor_on_exit(struct boot_editor *boot_editor,
-               enum boot_editor_result boot_editor_result,
+static void cui_boot_editor_on_exit(struct cui *cui,
+               struct pmenu_item *item,
                struct pb_boot_data *bd)
 {
                struct pb_boot_data *bd)
 {
-       struct cui *cui = cui_from_pmenu(boot_editor->original_pmenu);
-       struct pmenu_item *item = boot_editor->data;
+       struct pmenu *menu = cui->main;
        struct cui_opt_data *cod;
 
        struct cui_opt_data *cod;
 
-       if (boot_editor_result != boot_editor_update) {
+       /* Was the edit cancelled? */
+       if (!bd) {
                cui_set_current(cui, &cui->main->scr);
                cui_set_current(cui, &cui->main->scr);
-               talloc_free(boot_editor);
+               talloc_free(cui->boot_editor);
+               cui->boot_editor = NULL;
                return;
        }
 
                return;
        }
 
-       assert(bd);
-
        /* Is this was a new item, we'll need to update the menu */
        if (!item) {
        /* Is this was a new item, we'll need to update the menu */
        if (!item) {
-               struct pmenu *menu = boot_editor->original_pmenu;
                int insert_pt;
 
                /* Detach the items array. */
                int insert_pt;
 
                /* Detach the items array. */
@@ -205,32 +196,26 @@ static void cui_boot_editor_on_exit(struct boot_editor *boot_editor,
 
        cod->bd = talloc_steal(cod, bd);
 
 
        cod->bd = talloc_steal(cod, bd);
 
-       /* FIXME: need to make item visible somehow */
        set_current_item(item->pmenu->ncm, item->nci);
        cui_set_current(cui, &cui->main->scr);
        set_current_item(item->pmenu->ncm, item->nci);
        cui_set_current(cui, &cui->main->scr);
-       talloc_free(boot_editor);
+       talloc_free(cui->boot_editor);
+       cui->boot_editor = NULL;
 }
 
 void cui_item_edit(struct pmenu_item *item)
 {
        struct cui *cui = cui_from_item(item);
 }
 
 void cui_item_edit(struct pmenu_item *item)
 {
        struct cui *cui = cui_from_item(item);
-       struct cui_opt_data *cod = cod_from_item(item);
-       struct boot_editor *boot_editor;
-
-       boot_editor = boot_editor_init(item->pmenu, cod->bd,
-                       cui_boot_editor_on_exit);
-       boot_editor->data = item;
-       cui_set_current(cui, &boot_editor->scr);
+       cui->boot_editor = boot_editor_init(cui, item, cui->sysinfo,
+                                       cui_boot_editor_on_exit);
+       cui_set_current(cui, boot_editor_scr(cui->boot_editor));
 }
 
 void cui_item_new(struct pmenu *menu)
 {
        struct cui *cui = cui_from_pmenu(menu);
 }
 
 void cui_item_new(struct pmenu *menu)
 {
        struct cui *cui = cui_from_pmenu(menu);
-       struct boot_editor *boot_editor;
-
-       boot_editor = boot_editor_init(menu, NULL,
-                       cui_boot_editor_on_exit);
-       cui_set_current(cui, &boot_editor->scr);
+       cui->boot_editor = boot_editor_init(cui, NULL, cui->sysinfo,
+                                       cui_boot_editor_on_exit);
+       cui_set_current(cui, boot_editor_scr(cui->boot_editor));
 }
 
 static void cui_sysinfo_exit(struct cui *cui)
 }
 
 static void cui_sysinfo_exit(struct cui *cui)
index aba682a3c43d90633831a7c24ffa3ce6d4c44cc3..90af3613cb880cdab94d12c8d8546e98021442b5 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "ui/common/joystick.h"
 #include "nc-menu.h"
 
 #include "ui/common/joystick.h"
 #include "nc-menu.h"
-#include "nc-boot-editor.h"
 
 struct cui_opt_data {
        const char *name;
 
 struct cui_opt_data {
        const char *name;
@@ -59,6 +58,7 @@ struct cui {
        struct sysinfo_screen *sysinfo_screen;
        struct config *config;
        struct config_screen *config_screen;
        struct sysinfo_screen *sysinfo_screen;
        struct config *config;
        struct config_screen *config_screen;
+       struct boot_editor *boot_editor;
        struct pjs *pjs;
        void *platform_info;
        unsigned int default_item;
        struct pjs *pjs;
        void *platform_info;
        unsigned int default_item;
index 693b96c8efd84b0988d79f006b2c089c8ed43545..4639c5537bd38d00d16115eb472aa4951acd17a9 100644 (file)
@@ -67,6 +67,11 @@ static inline struct pmenu_item *pmenu_item_from_arg(void *arg)
        return item;
 }
 
        return item;
 }
 
+static inline struct cui_opt_data *cod_from_item(struct pmenu_item *item)
+{
+       return item->data;
+}
+
 static inline struct pmenu_item *pmenu_item_init(struct pmenu *menu,
        unsigned int index, const char *name)
 {
 static inline struct pmenu_item *pmenu_item_init(struct pmenu *menu,
        unsigned int index, const char *name)
 {
index d17034dd685e14e42fb42294fa734aa4eb250ad6..98ea6be269774bf8186f7baedc1b597d0aa079be 100644 (file)
 
 #define _GNU_SOURCE
 
 
 #define _GNU_SOURCE
 
+#include "config.h"
+
+#include <linux/input.h> /* This must be included before ncurses.h */
+#if defined HAVE_NCURSESW_CURSES_H
+#  include <ncursesw/curses.h>
+#elif defined HAVE_NCURSESW_H
+#  include <ncursesw.h>
+#elif defined HAVE_NCURSES_CURSES_H
+#  include <ncurses/curses.h>
+#elif defined HAVE_NCURSES_H
+#  include <ncurses.h>
+#elif defined HAVE_CURSES_H
+#  include <curses.h>
+#else
+#  error "Curses header file not found."
+#endif
+
+#if defined HAVE_NCURSESW_FORM_H
+#  include <ncursesw/form.h>
+#elif defined HAVE_NCURSES_FORM_H
+#  include <ncurses/form.h>
+#elif defined HAVE_FORM_H
+#  include <form.h>
+#else
+#  error "Curses form.h not found."
+#endif
+
 #include <string.h>
 #include <ctype.h>
 
 #include <string.h>
 #include <ctype.h>