diff options
author | Geoff Levand <geoffrey.levand@am.sony.com> | 2009-07-09 10:40:44 -0700 |
---|---|---|
committer | Geoff Levand <geoffrey.levand@am.sony.com> | 2009-07-09 10:40:44 -0700 |
commit | 25cb540c8b73a044911ef7dab5b57879de1779e9 (patch) | |
tree | 98ba5afa33d41c7c063d8d50d706d55cdd1c57ea /ui | |
parent | ea0a5877530a801713c80963c918c0a6f4072d8a (diff) | |
download | petitboot-25cb540c8b73a044911ef7dab5b57879de1779e9.zip petitboot-25cb540c8b73a044911ef7dab5b57879de1779e9.tar.gz |
CUI add empty item
Add a CUI hot-key 'o' that opens a new empty menu item.
Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/ncurses/nc-cui.c | 52 | ||||
-rw-r--r-- | ui/ncurses/nc-cui.h | 6 | ||||
-rw-r--r-- | ui/ncurses/nc-ked.c | 5 | ||||
-rw-r--r-- | ui/ncurses/nc-menu.c | 7 | ||||
-rw-r--r-- | ui/ncurses/nc-menu.h | 1 | ||||
-rw-r--r-- | ui/ncurses/pb-cui.c | 6 | ||||
-rw-r--r-- | ui/ncurses/ps3-cui.c | 9 |
7 files changed, 72 insertions, 14 deletions
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 83e2939..179222e 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -108,8 +108,8 @@ static int cui_run_kexec(struct pmenu_item *item) assert(cui->current == &cui->main->scr); assert(cui->on_kexec); - pb_log("%s: %s\n", __func__, cod->dev->name, cod->opt->name); - nc_scr_status_printf(cui->current, "Booting %s...", cod->opt->name); + pb_log("%s: %s\n", __func__, cod->name); + nc_scr_status_printf(cui->current, "Booting %s...", cod->name); def_prog_mode(); @@ -150,7 +150,7 @@ static void cui_ked_on_exit(struct ked *ked, enum ked_result ked_result, talloc_free(cod->kd); cod->kd = kd; - pb_log("%s: updating opt '%s'\n", __func__, cod->opt->name); + pb_log("%s: updating opt '%s'\n", __func__, cod->name); pb_log(" image '%s'\n", cod->kd->image); pb_log(" initrd '%s'\n", cod->kd->initrd); pb_log(" args '%s'\n", cod->kd->args); @@ -267,6 +267,49 @@ static void cui_handle_resize(struct cui *cui) } /** + * cui_on_open - Open new item callback. + */ + +void cui_on_open(struct pmenu *menu) +{ + unsigned int insert_pt; + struct pmenu_item *i; + struct cui_opt_data *cod; + char *name; + + menu->scr.unpost(&menu->scr); + + /* This disconnects items array from menu. */ + + set_menu_items(menu->ncm, NULL); + + /* Insert new items at insert_pt. */ + + insert_pt = pmenu_grow(menu, 1); + i = pmenu_item_alloc(menu); + + name = talloc_asprintf(i, "User item %u:", insert_pt); + pmenu_item_setup(menu, i, insert_pt, name, NULL); + + i->on_edit = cui_ked_run; + i->on_execute = cui_run_kexec; + i->data = cod = talloc_zero(i, struct cui_opt_data); + + cod->kd = talloc_zero(i, struct pb_kexec_data); + cod->name = name; + + /* Re-attach the items array. */ + + set_menu_items(menu->ncm, menu->items); + + set_current_item(menu->ncm, i->nci); + menu->scr.post(&menu->scr); + pos_menu_cursor(menu->ncm); + + i->on_edit(i); +} + +/** * cui_device_add - Client device_add callback. * * Creates menu_items for all the device boot_options and inserts those @@ -332,6 +375,7 @@ static int cui_device_add(struct device *dev, void *arg) cod->dev = dev; cod->opt = opt; cod->opt_hash = pb_opt_hash(dev, opt); + cod->name = opt->name; cod->kd = talloc(i, struct pb_kexec_data); cod->kd->image = talloc_strdup(cod->kd, opt->boot_image_file); @@ -340,7 +384,7 @@ static int cui_device_add(struct device *dev, void *arg) insert_pt++; - pb_log("%s: adding opt '%s'\n", __func__, cod->opt->name); + pb_log("%s: adding opt '%s'\n", __func__, cod->name); pb_log(" image '%s'\n", cod->kd->image); pb_log(" initrd '%s'\n", cod->kd->initrd); pb_log(" args '%s'\n", cod->kd->args); diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h index 79c41a4..b225caa 100644 --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -26,10 +26,13 @@ #include "nc-ked.h" struct cui_opt_data { + const char *name; + struct pb_kexec_data *kd; + + /* optional data */ const struct device *dev; const struct boot_option *opt; uint32_t opt_hash; - struct pb_kexec_data *kd; }; /** @@ -66,6 +69,7 @@ int cui_ked_run(struct pmenu_item *item); void cui_abort(struct cui *cui); void cui_resize(struct cui *cui); void cui_on_exit(struct pmenu *menu); +void cui_on_open(struct pmenu *menu); int cui_run_cmd(struct pmenu_item *item); static inline struct cui *cui_from_arg(void *arg) diff --git a/ui/ncurses/nc-ked.c b/ui/ncurses/nc-ked.c index c326f91..806d389 100644 --- a/ui/ncurses/nc-ked.c +++ b/ui/ncurses/nc-ked.c @@ -149,9 +149,10 @@ static char *ked_chomp(char *s) for (; s < s_end; s++) if (*s != ' ' && *s != '\t') break; - start = s; - for (++s; s < s_end; s++) + start = end = s; + + for (; s < s_end; s++) if (*s != ' ' && *s != '\t') end = s; *(end + 1) = 0; diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c index 0a76b11..1dc34a1 100644 --- a/ui/ncurses/nc-menu.c +++ b/ui/ncurses/nc-menu.c @@ -174,13 +174,16 @@ static void pmenu_process_key(struct nc_scr *scr) case '\t': pmenu_move_cursor(menu, REQ_DOWN_ITEM); break; - case KEY_LEFT: - case 'E': case 'e': if (item->on_edit) item->on_edit(item); break; + case 'o': + DBGS("on_open: %p\n", menu->on_open); + if (menu->on_open) + menu->on_open(menu); + break; case '\n': case '\r': if (item->on_execute) diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h index b487df9..907c328 100644 --- a/ui/ncurses/nc-menu.h +++ b/ui/ncurses/nc-menu.h @@ -77,6 +77,7 @@ struct pmenu { unsigned int insert_pt; int (*hot_key)(struct pmenu *menu, struct pmenu_item *item, int c); void (*on_exit)(struct pmenu *menu); + void (*on_open)(struct pmenu *menu); }; struct pmenu *pmenu_init(void *ui_ctx, unsigned int item_count, diff --git a/ui/ncurses/pb-cui.c b/ui/ncurses/pb-cui.c index 8022789..2e37210 100644 --- a/ui/ncurses/pb-cui.c +++ b/ui/ncurses/pb-cui.c @@ -138,7 +138,7 @@ static int pb_kexec_cb(struct cui *cui, struct cui_opt_data *cod) { struct pb_cui *pb = pb_from_cui(cui); - pb_log("%s: %s:%s\n", __func__, cod->dev->name, cod->opt->name); + pb_log("%s: %s\n", __func__, cod->name); assert(pb->cui->current == &pb->cui->main->scr); @@ -162,9 +162,11 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui) return NULL; } + m->on_open = cui_on_open; + m->scr.frame.title = talloc_strdup(m, "Petitboot"); m->scr.frame.help = talloc_strdup(m, - "ESC=exit, Enter=accept, E,e=edit"); + "ESC=exit, Enter=accept, e=edit, o=open"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); i = pmenu_item_init(m, 0, "Exit to Shell", diff --git a/ui/ncurses/ps3-cui.c b/ui/ncurses/ps3-cui.c index f4c9841..cb63849 100644 --- a/ui/ncurses/ps3-cui.c +++ b/ui/ncurses/ps3-cui.c @@ -199,11 +199,12 @@ static int ps3_kexec_cb(struct cui *cui, struct cui_opt_data *cod) { struct ps3_cui *ps3 = ps3_from_cui(cui); - pb_log("%s: %s:%s\n", __func__, cod->dev->name, cod->opt->name); + pb_log("%s: %s\n", __func__, cod->name); assert(ps3->cui->current == &ps3->cui->main->scr); - if (cui->default_item != cod->opt_hash || ps3->dirty_values) { + if ((cod->opt_hash && cod->opt_hash != cui->default_item) + || ps3->dirty_values) { ps3->values.default_item = cod->opt_hash; ps3_flash_set_values(&ps3->values); } @@ -326,6 +327,8 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui) } m->hot_key = ps3_hot_key; + m->on_open = cui_on_open; + #if defined(DEBUG) m->scr.frame.title = talloc_strdup(m, "Petitboot PS3 (ver " PACKAGE_VERSION ")"); @@ -333,7 +336,7 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui) m->scr.frame.title = talloc_strdup(m, "Petitboot PS3"); #endif m->scr.frame.help = talloc_strdup(m, - "ESC=exit, Enter=accept, E,e=edit"); + "ESC=exit, Enter=accept, e=edit, o=open"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); i = pmenu_item_init(m, 0, "Boot GameOS", |