Example #1
0
/*
 * Create a new curses form with the given title text.
 */
struct curses_form *
curses_form_new(const char *title)
{
	struct curses_form *cf;

	AURA_MALLOC(cf, curses_form);

	cf->win = NULL;
	cf->pan = NULL;

	cf->widget_head = NULL;
	cf->widget_tail = NULL;
	cf->widget_focus = NULL;
	cf->height = 0;
	cf->width = strlen(title) + 4;
	cf->x_offset = 0;
	cf->y_offset = 0;
	cf->int_width = 0;
	cf->int_height = 0;
	cf->want_x = 0;
	cf->want_y = 0;

	cf->title = aura_strdup(title);

	cf->userdata = NULL;
	cf->cleanup = 0;

	cf->help_text = NULL;

	return(cf);
}
Example #2
0
/*
 * Add a new, empty command to an existing queue of commands.
 */
static struct command *
command_new(struct commands *cmds)
{
	struct command *cmd;

	AURA_MALLOC(cmd, command);

	cmd->cmdline = NULL;
	cmd->desc = NULL;
	cmd->log_mode = COMMAND_LOG_VERBOSE;
	cmd->failure_mode = COMMAND_FAILURE_ABORT;
	cmd->tag = NULL;
	cmd->result = COMMAND_RESULT_NEVER_EXECUTED;
	cmd->output = NULL;

	cmd->next = NULL;
	if (cmds->head == NULL)
		cmds->head = cmd;
	else
		cmds->tail->next = cmd;

	cmd->prev = cmds->tail;
	cmds->tail = cmd;

	return(cmd);
}
Example #3
0
/*
 * Create a new queue of commands.
 */
struct commands	*
commands_new(void)
{
	struct commands *cmds;

	AURA_MALLOC(cmds, commands);

	cmds->head = NULL;
	cmds->tail = NULL;

	return(cmds);
}
Example #4
0
struct curses_bar *
curses_bar_new(unsigned int x, unsigned int y,
		unsigned int width, unsigned int height,
		int colors, int flags)
{
	struct curses_bar *b;

	AURA_MALLOC(b, curses_bar);

	if (flags & CURSES_BAR_WIDEN)
		width = xmax;
	if (flags & CURSES_BAR_BOTTOM)
		y = ymax - 1;

	b->x = x;
	b->y = y;
	b->width = width;
	b->height = height;
	b->colors = colors;

	if ((b->win = newwin(height, width, y, x)) == NULL) {
		AURA_FREE(b, curses_bar);
		return(NULL);
	}

	curses_colors_set(b->win, colors);
	curses_window_blank(b->win);

	if ((b->pan = new_panel(b->win)) == NULL) {
		delwin(b->win);
		AURA_FREE(b, curses_bar);
		return(NULL);
	}

	return(b);
}
Example #5
0
static struct curses_form *
curses_form_construct_from_dfui_form_multiple(const struct dfui_form *f)
{
	struct curses_form *cf;
	struct curses_form_userdata *cfu;
	const char *min_width_str;
	unsigned int desc_width, min_width = 0;
	unsigned int len, max_label_width, total_label_width;
	unsigned int max_button_width, total_button_width;
	struct dfui_field *fi;
	struct dfui_action *a;
	struct curses_widget *label, *button;
	struct dfui_dataset *ds;
	const char *name;
	int left_acc, top_acc;
	int row = 1, col = 0, ins_x = 1, is_menu = 0;

	dfui_debug("-----\nconstructing multiple form: %s\n",
	    dfui_info_get_name(dfui_form_get_info(f)));

	cf = curses_form_new(dfui_info_get_name(dfui_form_get_info(f)));
	AURA_MALLOC(cfu, curses_form_userdata);
	cfu->f = f;
	cf->userdata = cfu;
	cf->cleanup = 1;

	set_help(f, cf);

	/* Calculate offsets for nice positioning of labels and buttons. */

	/*
	 * Determine the widths of the widest field and the widest
	 * button, and the total widths of all fields and all buttons.
	 */

	max_label_width = 0;
	total_label_width = 0;
	max_button_width = 0;
	total_button_width = 0;

	for (fi = dfui_form_field_get_first(f); fi != NULL;
	     fi = dfui_field_get_next(fi)) {
		len = MIN(60, strlen(dfui_info_get_name(dfui_field_get_info(fi))));
		if (len > max_label_width)
			max_label_width = len;
		total_label_width += (len + 2);
	}
	for (a = dfui_form_action_get_first(f); a != NULL;
	     a = dfui_action_get_next(a)) {
		len = strlen(dfui_info_get_name(dfui_action_get_info(a)));
		if (len > max_button_width)
			max_button_width = len;
		total_button_width += (len + 6);
	}

	/* Take the short description and turn it into a set of labels. */

	if ((min_width_str = dfui_form_property_get(f, "minimum_width")) != NULL)
		min_width = atoi(min_width_str);

	desc_width = 40;
	desc_width = MAX(desc_width, min_width);
	desc_width = MAX(desc_width, total_button_width);
	desc_width = MAX(desc_width, total_label_width);
	desc_width = MIN(desc_width, xmax - 3);

	dfui_debug("min width: %d\n", min_width);
	dfui_debug("button width: %d\n", total_button_width);
	dfui_debug("label width: %d\n", total_label_width);
	dfui_debug("resulting width: %d\n", desc_width);
	dfui_debug("form width: %d\n", cf->width);

	cf->height = curses_form_descriptive_labels_add(cf,
	    dfui_info_get_short_desc(dfui_form_get_info(f)),
	    1, cf->height + 1, desc_width);

	dfui_debug("form width now: %d\n", cf->width);

	/* Add the fields. */

	top_acc = cf->height + 1;
	cf->height += dfui_form_dataset_count(f) + 2;

	/*
	 * Create the widgets for a multiple=true form.  For each field
	 * in the form, a label containing the field's name, which serves
	 * as a heading, is created.  Underneath these labels, for each
	 * dataset in the form, a row of input widgets (typically textboxes)
	 * is added.  Non-action, manipulation buttons are also added to
	 * the right of each row.
	 */
	left_acc = 1;
	for (fi = dfui_form_field_get_first(f); fi != NULL;
	     fi = dfui_field_get_next(fi)) {
		/*
		 * Create a label to serve as a heading for the column.
		 */
		name = dfui_info_get_name(dfui_field_get_info(fi));
		label = curses_form_widget_add(cf, left_acc,
		    top_acc, 0, CURSES_LABEL, name, 0,
		    CURSES_WIDGET_WIDEN);
		cfu->widths[col++] = label->width + 2;
		left_acc += (label->width + 2);
	}

	/*
	 * Create a row of widgets for each dataset.
	 */
	top_acc++;
	for (ds = dfui_form_dataset_get_first(f); ds != NULL;
	     ds = dfui_dataset_get_next(ds)) {
		ins_x = curses_form_create_widget_row(cf, NULL, ds,
		     1, top_acc++, row++);
	}

	/*
	 * Finally, create an 'Add' button to add a new row
	 * if this is an extensible form.
	 */
	if (dfui_form_is_extensible(f)) {
		button = curses_form_widget_add(cf,
		    ins_x, top_acc, 0,
		    CURSES_BUTTON, "Add", 0, CURSES_WIDGET_WIDEN);
		button->user_id = row;
		curses_widget_set_click_cb(button, cb_click_insert_row);
		cf->height++;
	}

	cf->height++;

	/* Add the buttons. */

	create_buttons(f, cf, is_menu);

	cf->height++;

	curses_form_finalize(cf);

	return(cf);
}
Example #6
0
static struct curses_form *
curses_form_construct_from_dfui_form_single(const struct dfui_form *f)
{
	struct curses_form *cf;
	struct curses_form_userdata *cfu;
	const char *min_width_str;
	unsigned int desc_width, min_width = 0;
	unsigned int len, max_label_width, total_label_width;
	unsigned int max_button_width, total_button_width;
	struct dfui_field *fi;
	struct dfui_action *a;
	struct curses_widget *label, *xbox;
	struct dfui_celldata *cd;
	const char *value;
	int is_menu;

	dfui_debug("-----\nconstructing single form: %s\n",
	    dfui_info_get_name(dfui_form_get_info(f)));

	is_menu = dfui_form_property_is(f, "role", "menu");
	cf = curses_form_new(dfui_info_get_name(dfui_form_get_info(f)));
	AURA_MALLOC(cfu, curses_form_userdata);
	cfu->f = f;
	cf->userdata = cfu;
	cf->cleanup = 1;

	set_help(f, cf);

	/* Calculate offsets for nice positioning of labels and buttons. */

	/*
	 * Determine the widths of the widest field and the widest
	 * button, and the total widths of all fields and all buttons.
	 */

	max_label_width = 0;
	total_label_width = 0;
	max_button_width = 0;
	total_button_width = 0;

	for (fi = dfui_form_field_get_first(f); fi != NULL;
	     fi = dfui_field_get_next(fi)) {
		len = MIN(60, strlen(dfui_info_get_name(dfui_field_get_info(fi))));
		if (len > max_label_width)
			max_label_width = len;
		total_label_width += (len + 2);
	}
	for (a = dfui_form_action_get_first(f); a != NULL;
	     a = dfui_action_get_next(a)) {
		len = strlen(dfui_info_get_name(dfui_action_get_info(a)));
		if (len > max_button_width)
			max_button_width = len;
		total_button_width += (len + 6);
	}

	if (total_label_width > (xmax - 2))
		total_label_width = (xmax - 2);		/* XXX scroll/wrap? */

	/* Take the short description and turn it into a set of labels. */

	if ((min_width_str = dfui_form_property_get(f, "minimum_width")) != NULL)
		min_width = atoi(min_width_str);

	desc_width = 40;
	desc_width = MAX(desc_width, min_width);
	if (is_menu) {
		desc_width = MAX(desc_width, max_button_width);
	} else {
		desc_width = MAX(desc_width, total_button_width);
	}
	desc_width = MAX(desc_width, max_label_width);  /* XXX + max_field_width */
	desc_width = MIN(desc_width, xmax - 4); /* -2 for borders, -2 for spaces */

	dfui_debug("min width: %d\n", min_width);
	dfui_debug("button width: %d\n", total_button_width);
	dfui_debug("label width: %d\n", total_label_width);
	dfui_debug("resulting width: %d\n", desc_width);
	dfui_debug("form width: %d\n", cf->width);

	cf->height = curses_form_descriptive_labels_add(cf,
	    dfui_info_get_short_desc(dfui_form_get_info(f)),
	    1, cf->height + 1, desc_width);

	dfui_debug("form width now: %d\n", cf->width);

	if (!is_menu)
		cf->height++;

	/*
	 * Add one label and one textbox (or other control) to a
	 * curses_form for each field in the dfui_form.  Each set of
	 * labels and controls is added one row below the previous set.
	 */
	for (fi = dfui_form_field_get_first(f); fi != NULL;
	     fi = dfui_field_get_next(fi)) {
		label = curses_form_widget_add(cf, 1,
		    cf->height, max_label_width, CURSES_LABEL,
		    dfui_info_get_name(dfui_field_get_info(fi)), 0, 0);

		cd = dfui_dataset_celldata_find(dfui_form_dataset_get_first(f),
		    dfui_field_get_id(fi));

		value = dfui_celldata_get_value(cd);

		if (dfui_field_property_is(fi, "control", "checkbox")) {
			xbox = curses_form_widget_add(cf,
			    max_label_width + 3,
			    cf->height, 4, CURSES_CHECKBOX, "", 0, 0);
			xbox->amount = (value[0] == 'Y' ? 1 : 0);
		} else {
			xbox = curses_form_widget_add(cf,
			    max_label_width + 3,
			    cf->height, 20, CURSES_TEXTBOX, value, 256, 0);
		}
		curses_widget_tooltip_set(xbox,
		    dfui_info_get_short_desc(dfui_field_get_info(fi)));
		xbox->user_id = 1;
		xbox->userdata = fi;

		if (dfui_field_property_is(fi, "editable", "false"))
			xbox->editable = 0;
		if (dfui_field_property_is(fi, "obscured", "true"))
			xbox->obscured = 1;

		if (dfui_field_option_get_first(fi) != NULL) {
			curses_widget_set_click_cb(xbox, cb_click_select_option);
		}

		cf->height++;
	}

	if (dfui_form_field_get_first(f) != NULL)
		cf->height++;

	create_buttons(f, cf, is_menu);

	cf->height++;

	curses_form_finalize(cf);

	return(cf);
}
Example #7
0
struct i_fn_args *
i_fn_args_new(const char *os_root, const char *def_tmp_dir,
	      const char *def_cmds_file, int transport, const char *rendezvous)
{
	struct i_fn_args *a;
	char *filename;

	AURA_MALLOC(a, i_fn_args);

	a->c = NULL;
	a->os_root = aura_strdup(os_root);
	a->cfg_root = "";
	a->name = "";
	a->short_desc = "";
	a->long_desc = "";
	a->result = 0;
	a->log = NULL;
	a->s = NULL;
	a->tmp = NULL;
	a->temp_files = NULL;
	a->cmd_names = NULL;

	asprintf(&filename, "%sinstall.log", def_tmp_dir);
	a->log = fopen(filename, "w");
	free(filename);
	if (a->log == NULL) {
		i_fn_args_free(a);
		return(NULL);
	}

	i_log(a, "Installer started");
	i_log(a, "-----------------");

	i_log(a, "+ Creating DFUI connection on ``%s''\n", rendezvous);

	if ((a->c = dfui_connection_new(transport, rendezvous)) == NULL) {
		i_log(a, "! ERROR: Couldn't create connection on ``%s''\n", rendezvous);
		i_fn_args_free(a);
		return(NULL);
	}

	i_log(a, "+ Connecting on ``%s''\n", rendezvous);

	if (!dfui_be_start(a->c)) {
		i_log(a, "! ERROR: Couldn't connect to frontend on ``%s''\n", rendezvous);
		i_fn_args_free(a);
		return(NULL);
	}

	if ((a->s = storage_new()) == NULL) {
		i_log(a, "! ERROR: Couldn't create storage descriptor");
		i_fn_args_free(a);
		return(NULL);
	}

	a->tmp = def_tmp_dir;	/* XXX temporarily set to this */
	a->temp_files = aura_dict_new(23, AURA_DICT_HASH);
	a->cmd_names = config_vars_new();
	if (!config_vars_read(a, a->cmd_names, CONFIG_TYPE_SH, "%s",
		def_cmds_file)) {
		i_log(a, "! ERROR: Couldn't read cmdnames config file");
		i_fn_args_free(a);
		return(NULL);
	}

	a->tmp = cmd_name(a, "INSTALLER_TEMP");

	i_log(a, "+ Starting installer state machine");

	return(a);
}