* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#if defined(HAVE_CONFIG_H)
#include "config.h"
-
-#define _GNU_SOURCE
+#endif
#include <assert.h>
#include <errno.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-boot-editor.h"
#include "nc-config.h"
#include "nc-sysinfo.h"
-
-static struct cui_opt_data *cod_from_item(struct pmenu_item *item)
-{
- return item->data;
-}
+#include "nc-helpscreen.h"
static void cui_start(void)
{
nc_scr_status_printf(cui->current, "Booting %s...", cod->name);
- def_prog_mode();
-
result = discover_client_boot(cui->client, NULL, cod->opt, cod->bd);
- reset_prog_mode();
- redrawwin(cui->current->main_ncw);
-
if (result) {
nc_scr_status_printf(cui->current,
"Failed: boot %s", cod->bd->image);
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 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;
- if (boot_editor_result != boot_editor_update) {
+ /* Was the edit cancelled? */
+ if (!bd) {
cui_set_current(cui, &cui->main->scr);
- talloc_free(boot_editor);
+ talloc_free(cui->boot_editor);
+ cui->boot_editor = NULL;
return;
}
- assert(bd);
-
/* 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. */
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);
- 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);
- 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);
- 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)
cui_set_current(cui, config_screen_scr(cui->config_screen));
}
+static void cui_help_exit(struct cui *cui)
+{
+ cui_set_current(cui, help_screen_return_scr(cui->help_screen));
+ talloc_free(cui->help_screen);
+ cui->help_screen = NULL;
+}
+
+void cui_show_help(struct cui *cui, const char *title, const char *text)
+{
+ if (!cui->current)
+ return;
+
+ if (cui->help_screen)
+ return;
+
+ cui->help_screen = help_screen_init(cui, cui->current,
+ title, text, cui_help_exit);
+
+ if (cui->help_screen)
+ cui_set_current(cui, help_screen_scr(cui->help_screen));
+}
+
/**
* cui_set_current - Set the currently active screen and redraw it.
*/
{
switch (key) {
case 0xc:
- if (cui->current && cui->current->main_ncw) {
- redrawwin(cui->current->main_ncw);
- wrefresh(cui->current->main_ncw);
- }
+ if (cui->current && cui->current->main_ncw)
+ wrefresh(curscr);
return true;
}
return false;
for (;;) {
int c = getch();
+ pb_debug("%s: got key %d\n", __func__, c);
+
if (c == ERR)
break;
struct cui *cui = cui_from_arg(arg);
struct cui_opt_data *cod;
unsigned int insert_pt;
+ int result, rows, cols;
struct pmenu_item *i;
ITEM *selected;
- int result;
pb_debug("%s: %p %s\n", __func__, opt, opt->id);
selected = current_item(cui->main->ncm);
+ menu_format(cui->main->ncm, &rows, &cols);
if (cui->current == &cui->main->scr)
nc_scr_unpost(cui->current);
item_count(cui->main->ncm) + 1);
}
- /* FIXME: need to make item visible somehow */
- menu_driver(cui->main->ncm, REQ_SCR_UPAGE);
- menu_driver(cui->main->ncm, REQ_SCR_DPAGE);
- set_current_item(cui->main->ncm, selected);
+ if (!item_visible(selected)) {
+ int idx, top;
+
+ top = top_row(cui->main->ncm);
+ idx = item_index(selected);
+
+ /* If our index is above the current top row, align
+ * us to the new top. Otherwise, align us to the new
+ * bottom */
+ top = top < idx ? idx - rows : idx;
+
+ set_top_row(cui->main->ncm, top);
+ set_current_item(cui->main->ncm, selected);
+ }
if (cui->current == &cui->main->scr)
nc_scr_post(cui->current);
if (cui->sysinfo_screen)
sysinfo_screen_update(cui->sysinfo_screen, sysinfo);
+ /* ... and do the same with the config screen... */
+ if (cui->config_screen)
+ config_screen_update(cui->config_screen, cui->config, sysinfo);
+
+ /* ... and the boot editor. */
+ if (cui->boot_editor)
+ boot_editor_update(cui->boot_editor, sysinfo);
+
cui_update_mm_title(cui);
}
{
struct cui *cui = cui_from_arg(arg);
cui->config = talloc_steal(cui, config);
+
+ if (cui->config_screen)
+ config_screen_update(cui->config_screen, config, cui->sysinfo);
+}
+
+int cui_send_config(struct cui *cui, struct config *config)
+{
+ return discover_client_send_config(cui->client, config);
}
static struct discover_client_ops cui_client_ops = {