Exemple #1
0
static int
continent_country_menu(dialogMenuItem *continent)
{
	int rv;
	struct continent *contp = continent->data;
	char title[256];
	int isocean = OCEANP(continent - continents);
	int menulen;

	/* Short cut -- if there's only one country, don't post a menu. */
	if (contp->nitems == 1)
		return (contp->menu[0].fire(&contp->menu[0]));

	/* It's amazing how much good grammar really matters... */
	if (!isocean)
		snprintf(title, sizeof title, "Countries in %s", 
			 continent->title);
	else 
		snprintf(title, sizeof title, "Islands and groups in the %s",
			 continent->title);

	menulen = contp->nitems < 16 ? contp->nitems : 16;
	rv = dialog_menu(title, (isocean ? "Select an island or group"
                                 : "Select a country"), -1, -1, menulen,
			 -contp->nitems, contp->menu, 0, &contp->ch,
			 &contp->sc);
	if (rv == 0)
		return DITEM_LEAVE_MENU;
	return DITEM_RECREATE;
}
Exemple #2
0
static DC_Dev *menu_choose_device(DC_DevList *devlist) {
    int devs_num = dc_dev_list_size(devlist);
    if (devs_num == 0) {
        dialog_msgbox("Info", "No devices found", 0, 0, 1);
        return NULL;
    }
    char *items[2 * devs_num];
    int i;
    for (i = 0; i < devs_num; i++) {
        DC_Dev *dev = dc_dev_list_get_entry(devlist, i);
        char dev_descr_buf[80];
        ui_dev_descr_format(dev_descr_buf, sizeof(dev_descr_buf), dev);
        items[2*i] = dev->dev_fs_name;
        items[2*i+1] = strdup(dev_descr_buf);
    }

    clear_body();
    dialog_vars.no_items = 0;
    dialog_vars.item_help = 0;
    dialog_vars.input_result = NULL;
    dialog_vars.default_button = 0;  // Focus on "OK"
    int ret = dialog_menu("Choose device", "", 0, 0, 0, devs_num, items);
    for (i = 0; i < devs_num; i++)
        free(items[2*i+1]);

    if (ret != 0)
        return NULL;
    for (i = 0; i < devs_num; i++) {
        DC_Dev *dev = dc_dev_list_get_entry(devlist, i);
        if (!strcmp(dev->dev_fs_name, dialog_vars.input_result))
            return dev;
    }
    assert(0);
    return NULL;
}
Exemple #3
0
int _afi_menu(dialogMenuItem *self)
{
	dialog_clear();
	dialog_menu("ClosedBSD: Advanced Firewall Configuration", "Please select the appropriate option:", -1, -1, 3, -3, afi, NULL, NULL, NULL);
	
	return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
} 
Exemple #4
0
int _afm_menu()
{
	dialog_clear();
	dialog_menu("ClosedBSD: Firewall Configuration", "Please select the appropriate option:", -1, -1, 5, -5, afm, NULL, NULL, NULL);
	
	return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; 
}
Exemple #5
0
int 
main_menu()
{
	int retval;

	retval = dialog_menu("ClosedBSD Configuration Menu", "Please select the appropriate option:", -1, -1, 8, -8, menu1, NULL, NULL, NULL);

	dialog_clear();

	return 0;
}
Exemple #6
0
/* Traverse over an internal menu */
Boolean
dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
{
    int n, rval = 0;
    dialogMenuItem *items;

    items = menu->items;
    if (buttons)
	items += 2;
    /* Count up all the items */
    for (n = 0; items[n].title; n++);

    while (1) {
	char buf[FILENAME_MAX];
	WINDOW *w = savescr();

	/* Any helpful hints, put 'em up! */
	use_helpline(menu->helpline);
	use_helpfile(systemHelpFile(menu->helpfile, buf));
	dialog_clear_norefresh();
	/* Pop up that dialog! */
	if (menu->type & DMENU_NORMAL_TYPE)
	    rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt,
		-1, -1, menu_height(menu, n), -n, items,
		(char *)(uintptr_t)buttons, choice, scroll);

	else if (menu->type & DMENU_RADIO_TYPE)
	    rval = dialog_radiolist((u_char *)menu->title,
		(u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
		items, (char *)(uintptr_t)buttons);

	else if (menu->type & DMENU_CHECKLIST_TYPE)
	    rval = dialog_checklist((u_char *)menu->title,
		(u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
		items, (char *)(uintptr_t)buttons);
	else
	    msgFatal("Menu: `%s' is of an unknown type\n", menu->title);
	if (exited) {
	    exited = FALSE;
	    restorescr(w);
	    return TRUE;
	}
	else if (rval) {
	    restorescr(w);
	    return FALSE;
	}
	else if (menu->type & DMENU_SELECTION_RETURNS) {
	    restorescr(w);
	    return TRUE;
	}
    }
}
Exemple #7
0
int 
delete_rule()
{
	FILE *stream = NULL;
	int i = 0;
	char buf[256];
	char pr[3];
	char *s;

	dialog_clear();

	stream = fopen(RULESCRIPT, "r");
	if (stream == NULL) {
		end_dialog();
		return -1;
	}
	dialog_clear();

	bzero(rlist, sizeof(rlist));

	while (fgets(buf, sizeof(buf), stream) != NULL) {
		if (strlen(buf) > 1) {
			buf[strlen(buf) - 1] = '\0';
			if (i < 9)
				snprintf(pr, sizeof(pr), "0%d", i + 1);
			else
				snprintf(pr, sizeof(pr), "%d", i + 1);

			strtok(strdup(buf), "q");
			s = strtok(NULL, "q");
			rlist[i].prompt = strdup(pr);
			rlist[i].title = s;
			rlist[i].checked = NULL;
			rlist[i].fire = drop_rule;
			i++;
		}
	}

	if (i == 0) {
		dialog_msgbox("ClosedBSD", "There are no rules to delete    ", -1, -1, 1);
		fclose(stream);
		return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
	}
	fclose(stream);
	dialog_menu("ClosedBSD", "Please select a rule to remove", -1, -1, i, -i, rlist, NULL, NULL, NULL);

	return 0;
}
Exemple #8
0
static void
handle_intr(int sig)
{
    WINDOW *save = savescr();

    use_helpline(NULL);
    use_helpfile(NULL);
    if (OnVTY) {
        ioctl(0, VT_ACTIVATE, 1);       /* Switch back */
        msgInfo(NULL);
    }
    (void)dialog_menu("Installation interrupt",
		     "Do you want to abort the installation?",
		     -1, -1, 2, -2, intrmenu, NULL, NULL, NULL);
    restorescr(save);
}
Exemple #9
0
/* Kick it off, James! */
int
main(int argc, char **argv)
{
    int retval;

    init_dialog();

    retval = dialog_menu("this is dialog_menu() in action, test #1",
                         "this simple menu shows off some of the straight-forward features\n"
                         "of the new menu system's action dispatch hooks.  Select Cancel to leave",
                         -1, -1, 3, -3, menu1, NULL, NULL, NULL);
    dialog_clear();
    fprintf(stderr, "returned value for dialog_menu was %d\n", retval);

    end_dialog();
    return 0;
}
Exemple #10
0
static int
set_zone_menu(dialogMenuItem *dmi)
{
	int rv;
	char buf[256];
	struct country *cp = dmi->data;
	int menulen;

	snprintf(buf, sizeof buf, "%s Time Zones", cp->name);
	menulen = cp->nzones < 16 ? cp->nzones : 16;
	rv = dialog_menu(buf, "Select a zone which observes the same time as "
			 "your locality.", -1, -1, menulen, -cp->nzones,
			 cp->submenu, 0, 0, 0);
	if (rv != 0)
		return DITEM_RECREATE;
	return DITEM_LEAVE_MENU;
}
Exemple #11
0
static int
j_menu(JUMPARGS)
{
    int ret;
    int tags = howmany_tags(av + 5, MENUBOX_TAGS);
    *offset_add = 5 + tags * MENUBOX_TAGS;
    ret = dialog_menu(t,
		      av[1],
		      numeric_arg(av, 2),
		      numeric_arg(av, 3),
		      numeric_arg(av, 4),
		      tags, av + 5);
    if (ret >= 0) {
	fprintf(dialog_vars.output, av[5 + ret * MENUBOX_TAGS]);
	return 0;
    } else if (ret == -2)
	return 1;		/* CANCEL */
    return ret;			/* ESC pressed, ret == -1 */
}
Exemple #12
0
static DC_Procedure *menu_choose_procedure(DC_Dev *dev) {
    (void)dev;
    int nb_procedures = dc_get_nb_procedures();
    const char *items[nb_procedures];
    DC_Procedure *procedures[nb_procedures];
    int nb_items = 0;
    DC_Procedure *procedure = NULL;
    while ((procedure = dc_get_next_procedure(procedure))) {
        if (!dev->ata_capable && (procedure->flags & DC_PROC_FLAG_REQUIRES_ATA))
            continue;
        items[nb_items] = procedure->display_name;
        procedures[nb_items] = procedure;
        nb_items++;
    }

    while (1) {
        clear_body();
        dialog_vars.no_items = 1;
        dialog_vars.item_help = 0;
        dialog_vars.input_result = NULL;
        dialog_vars.default_button = 0;  // Focus on "OK"
        dialog_vars.extra_button = 1;
        dialog_vars.extra_label = "Help";
        int ret = dialog_menu("Choose procedure", "", 0, 0, 0, nb_items, (/* should be const */char**)items);
        dialog_vars.extra_button = 0;
        if ((ret != DLG_EXIT_OK) && (ret != DLG_EXIT_EXTRA))
            return NULL;  // User quit dialog, exit

        procedure = NULL;
        for (int i = 0; i < nb_items; i++)
            if (!strcmp(items[i], dialog_vars.input_result)) {
                procedure = procedures[i];
                break;
            }
        assert(procedure);

        if (ret == DLG_EXIT_EXTRA) {
            dialog_msgbox(procedure->display_name, procedure->help ? : "No help", 0, 0, 1);
            continue;
        }
        assert(ret == DLG_EXIT_OK);
        return procedure;
    }
int
dialog_sysinstall(void)
{
	int i;
	int res;
	int dialog;
	dialogMenuItem *menus;

	i = 0;
	dialog = 0;
	menus = safe_malloc(sizeof(*menus)*MAXLABELS+2);
	DMENUFD(&menus[i++], "Next", NULL, next_fire, &dialog);
	DMENUF(&menus[i++], "Exit", NULL, exit_fire);
	DMENUFD(&menus[i++], "Install", "Install PC-BSD or FreeBSD",
		install_fire, &dialog);
	DMENUFD(&menus[i++], "Upgrade", "Upgrade PC-BSD or FreeBSD",
		upgrade_fire, &dialog);
	DMENUFD(&menus[i++], "Configure Network", "Setup network interfaces",
		netif_fire, &dialog);
	DMENUFD(&menus[i++], "Shell", "Run tcsh", shell_fire, &dialog);

	screen_clear(MODULE);
	res = dialog_menu("Welcome to "OSNAME" install",
	    "Welcome to the "OSNAME" installer.\nPlease select your "
	    "choice from the menu below.",
	    12, 60, 4, -4, menus+2, "", 
	    NULL, NULL);

	free(menus);

	switch(dialog) {
		case DO_DISKSEL:
			dialog_disksel();
			break;

		case DO_NETIF:
			dialog_netif();
			break;
	}

	return (res);
}
Exemple #14
0
/* Kick it off, James! */
int
main(int argc, char **argv)
{
    int retval;
    
    init_dialog();
    
    
    DialogX = 5;
    DialogY = 1;
    retval = dialog_menu("Do you have the GUTS?",
			 "C'mon, macho man!  Do you have what it takes to do something REALLY\n"
			 "dangerous and stupid?  WHAT ARE YOU WAITING FOR?!",
			 -1, -1, 3, -3, doit + 2, (char *)TRUE, NULL, NULL);
    dialog_clear();
    fprintf(stderr, "returned value for dialog_menu was %d\n", retval);
    
    end_dialog();
    return 0;
}
Exemple #15
0
void MainWindow::exec()
{
    bool success   = false;
    size_t pos;
    string datadev, options = b.getBootOptions();

    if ((pos = options.find("datadev=")) != string::npos)
    {
        datadev = options.substr(pos+8);
        if ((pos = datadev.find(" ")) != string::npos || (pos = datadev.find("\n")) != string::npos)
            datadev = datadev.substr(0, pos);

        if (datadev == "iscsi")
        {
            startISCSI();
        }
    }
    else
    {
        initializeA10();
        startInstaller();
        return;
    }

    reinitScreen();
    progress("Mounting data partition...", "Waiting for storage... "+datadev);

    /* Wait 10 seconds for named data partition */
    b.waitForDevice(datadev);
    success = b.mountDataPartition(datadev);
    if (!success)
    {
        progress("Searching other partitions...", "Data is not at "+datadev);
        datadev.clear();

        /* Search 4 times */
        for (unsigned int i=0; i<4 && datadev.empty(); i++)
        {
            if (i != 0)
                sleep(1);

            datadev = b.getPartitionByLabel();
        }

        if (!datadev.empty())
        {
            progress("Mounting data partition...", "Found other berryboot partition to mount... "+datadev);
            success = b.mountDataPartition(datadev);
        }
    }
    initializeA10();
    reinitScreen();

    if (!success)
    {
        //dialog_msgbox("No data found...", "No existing data found, performing a new installation",0,0,1);
        dialog_msgbox("No data found...", "Cannot find my data partition :-(",5,50,1);
        return;
    }

    if (b.file_exists(runonce_file))
    {
        progress("Removing runonce file");
        string runonce = b.file_get_contents(runonce_file);
        unlink(runonce_file);
        sync();
        std::cerr << runonce;
        return;
    }

    map<string,string> images = b.listInstalledImages();

    /* Default selection */
    if (!images.empty() && options.find("nobootmenutimeout") == string::npos )
    {
        string def;

        if (b.file_exists(default_file))
            def = b.file_get_contents(default_file);
        else
            def = images.begin()->first;

        if (b.file_exists("/mnt/images/"+def))
        {
            time_t t1 = time(NULL);
            dialog_pause("", "Press <enter> if you wish to access the boot menu...",9,50,2);
            /* return code from dialog_pause is not very useful (returns both OK in case of timeout and when key is pressed)
             * as a workaround just look at the time elapsed */
            if (time(NULL)-t1 >= 3)
            {
                bootImage(def);
                return;
            }
        }
    }

    /* Boot menu */
    const char **menulist = new const char *[(images.size()+1)*2];
    unsigned int nr = 0;

    for (map<string,string>::iterator iter = images.begin(); iter != images.end(); iter++)
    {
        menulist[nr++] = iter->second.c_str();
        menulist[nr++] = "";
    }
    menulist[nr++] = "Operating system installer";
    menulist[nr++] = "";
    dialog_menu("", "Select operating system to boot:", 15, 50, 10, images.size()+1, (char **) menulist);

    if (dialog_vars.input_result && dialog_vars.input_result[0])
    {
        if (strcmp(dialog_vars.input_result, "Operating system installer") == 0)
        {
            startInstaller();
        }
        else
        {
            /* Find image name by friendly name */
            string friendlyname = dialog_vars.input_result;
            for (map<string,string>::iterator iter = images.begin(); iter != images.end(); iter++)
            {
                if (iter->second == friendlyname)
                {
                    bootImage(iter->first);
                    break;
                }
            }
        }
    }

    delete menulist;
}
Exemple #16
0
int run(GList **config)
{
	GList *partlist;
	char **nrdevs, *ptr, *op, *np, *dest;
	int ret;
	char my_buffer[MAX_LEN + 1] = "";

	detect_parts(0);

	// select swap partitions to use
	partlist = selswap();

	// format swap partitions
	if(doswap(partlist, config) == -1)
		return(-1);

	// root partition
	ptr = selrootdev();
	if(ptr == NULL)
		return(-1);
	if(formatdev(ptr) == -1)
		return(-1);
	mountdev(ptr, "/", config);

	// move temporarily stuff to the final location
	chdir(TARGETDIR);
	np = g_strdup_printf("%s/%s", TARGETDIR, "/etc/profile.d");
	makepath(np);
	FREE(np);
	op = (char*)data_get(*config, "fstab");
	np = g_strdup_printf("%s/%s", TARGETDIR, "/etc/fstab");
	copyfile(op, np);
	unlink(op);
	chmod (np, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
	data_put(config, "fstab", strdup(np));
	FREE(np);

	np = g_strdup_printf("%s/%s", TARGETDIR, "/etc/sysconfig");
	makepath(np);
	FREE(np);

	// so that 1) the user can't mount a partition as /dev because
	// it'll be used 2) install scriptlets will be able to do
	// >/dev/null
	makepath(TARGETDIR "/dev");
	makepath(TARGETDIR "/proc");
	makepath(TARGETDIR "/sys");
	fw_system("mount none -t devtmpfs " TARGETDIR "/dev");
	fw_system("mount none -t proc " TARGETDIR "/proc");
	fw_system("mount none -t sysfs " TARGETDIR "/sys");

	// non-root partitions
	dialog_vars.backtitle=gen_backtitle(_("Selecting other partitions"));
	while(1)
	{
		dialog_vars.input_result = my_buffer;
		nrdevs = parts2dialog(parts);
		dlg_put_backtitle();
		dlg_clear();
		dialog_vars.cancel_label = _("Continue");
		dialog_vars.input_result = my_buffer;
		dialog_vars.input_result[0]='\0';
		ret = dialog_menu(
		_("Select other Linux partitions for /etc/fstab"),
		_("You may use your other partitions to distribute your Linux "
		"system across more than one partition. Currently, you have "
		"only mounted your / partition. You might want to mount "
		"directories such as /boot, /home or /usr/local on separate "
		"partitions. You should not try to mount /usr, /etc, /sbin or "
		"/bin on their own partitions since they contain utilities "
		"needed to bring the system up and mount partitions. Also, "
		"do not reuse a partition that you've already entered before. "
		"Please select one of the partitions listed below, or if "
		"you're done, hit Continue."),
		0, 0, 0, g_list_length(parts)/2, nrdevs);
		dialog_vars.cancel_label = '\0';
		FREE(nrdevs);
		if (ret != DLG_EXIT_CANCEL)
		{
			if(!strcmp(_("(in use)"), dialog_vars.input_result))
				continue;
			ptr = strdup(dialog_vars.input_result);
			if(formatdev(ptr) == -1)
				return(-1);
			dest = asktowhere(ptr);
			if(dest == NULL)
				return(-1);
			mountdev(ptr, dest, config);
			FREE(dest);
			FREE(ptr);
		}
		else
			break;
	}

	makepath(g_strdup_printf("%s/%s", TARGETDIR, "/var/log"));
	np = g_strdup_printf("%s/%s", TARGETDIR, LOGFILE);
	copyfile(LOGFILE, np);
	unlink(LOGFILE);
	chmod (np, S_IRUSR|S_IWUSR);
	FREE(np);

	// disable caching for cds
	// this is needed here since when the cds is loaded we had no
	// formatted root partition
	if((char*)data_get(*config, "netinstall")==NULL)
	{
		char *pacbindir = g_strdup_printf("%s/frugalware-%s", SOURCEDIR, ARCH);
		char *ptr;

		ptr = g_strdup_printf("%s/var/cache/pacman-g2/pkg", TARGETDIR);
		makepath(ptr);
		FREE(ptr);
		disable_cache(pacbindir);
		FREE(pacbindir);
	}
	return(0);
}
Exemple #17
0
static void conf(struct menu *menu)
{
	struct menu *submenu;
	const char *prompt = menu_get_prompt(menu);
	struct symbol *sym;
	struct menu *active_menu = NULL;
	int res;
	int s_scroll = 0;

	while (1) {
		item_reset();
		current_menu = menu;
		build_conf(menu);
		if (!child_count)
			break;
		if (menu == &rootmenu) {
			item_make("--- ");
			item_set_tag(':');
			item_make(_("    Load an Alternate Configuration File"));
			item_set_tag('L');
			item_make(_("    Save an Alternate Configuration File"));
			item_set_tag('S');
		}
		dialog_clear();
		res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
				  _(menu_instructions),
				  active_menu, &s_scroll);
		if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
			break;
		if (!item_activate_selected())
			continue;
		if (!item_tag())
			continue;

		submenu = item_data();
		active_menu = item_data();
		if (submenu)
			sym = submenu->sym;
		else
			sym = NULL;

		switch (res) {
		case 0:
			switch (item_tag()) {
			case 'm':
				if (single_menu_mode)
					submenu->data = (void *) (long) !submenu->data;
				else
					conf(submenu);
				break;
			case 't':
				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
					conf_choice(submenu);
				else if (submenu->prompt->type == P_MENU)
					conf(submenu);
				break;
			case 's':
				conf_string(submenu);
				break;
			case 'L':
				conf_load();
				break;
			case 'S':
				conf_save();
				break;
			}
			break;
		case 2:
			if (sym)
				show_help(submenu);
			else
				show_helptext(_("README"), _(mconf_readme));
			break;
		case 3:
			if (item_is_tag('t')) {
				if (sym_set_tristate_value(sym, yes))
					break;
				if (sym_set_tristate_value(sym, mod))
					show_textbox(NULL, setmod_text, 6, 74);
			}
			break;
		case 4:
			if (item_is_tag('t'))
				sym_set_tristate_value(sym, no);
			break;
		case 5:
			if (item_is_tag('t'))
				sym_set_tristate_value(sym, mod);
			break;
		case 6:
			if (item_is_tag('t'))
				sym_toggle_tristate_value(sym);
			else if (item_is_tag('m'))
				conf(submenu);
			break;
		case 7:
			search_conf();
			break;
		}
	}
}
Exemple #18
0
int
main(int argc, char **argv)
{
	int c, fd;
	int (*dialog_utc)(unsigned char *, unsigned char *, int, int);

	dialog_utc = dialog_noyes;

	while ((c = getopt(argc, argv, "n")) != -1) {
		switch(c) {
		case 'n':
			reallydoit = 0;
			break;

		default:
			usage();
		}
	}

	if (argc - optind > 1)
		usage();

	/* Override the user-supplied umask. */
	umask(S_IWGRP|S_IWOTH);

	read_iso3166_table();
	read_zones();
	sort_countries();
	make_menus();

	init_dialog();
	if (!dialog_utc("Select local or UTC (Greenwich Mean Time) clock",
			"Is this machine's CMOS clock set to UTC?  If it is set to local time,\n"
			"or you don't know, please choose NO here!", 7, 72)) {
		if (reallydoit)
			unlink(_PATH_WALL_CMOS_CLOCK);
	} else {
		if (reallydoit) {
			fd = open(_PATH_WALL_CMOS_CLOCK,
				  O_WRONLY|O_CREAT|O_TRUNC,
				  S_IRUSR|S_IRGRP|S_IROTH);
			if (fd < 0)
				err(1, "create %s", _PATH_WALL_CMOS_CLOCK);
			close(fd);
		}
	}
	dialog_clear_norefresh();
	if (optind == argc - 1) {
		char *msg;
		asprintf(&msg, "\nUse the default `%s' zone?", argv[optind]);
		if (!dialog_yesno("Default timezone provided", msg, 7, 72)) {
			install_zone_file(argv[optind]);
			dialog_clear();
			end_dialog();
			return 0;
		}
		free(msg);
		dialog_clear_norefresh();
	}
	dialog_menu("Time Zone Selector", "Select a region", -1, -1, 
		    NCONTINENTS, -NCONTINENTS, continents, 0, NULL, NULL);

	dialog_clear();
	end_dialog();
	return 0;
}
Exemple #19
0
static void conf(struct menu *menu)
{
	struct dialog_list_item *active_item = NULL;
	struct menu *submenu;
	const char *prompt = menu_get_prompt(menu);
	struct symbol *sym;
	char active_entry[40];
	int stat, type;

	unlink("lxdialog.scrltmp");
	active_entry[0] = 0;
	while (1) {
		indent = 0;
		child_count = 0;
		current_menu = menu;
		cdone(); cinit();
		build_conf(menu);
		if (!child_count)
			break;
		if (menu == &rootmenu) {
			cmake(); cprint_tag(":"); cprint_name("--- ");
			cmake(); cprint_tag("L"); cprint_name("Load an Alternate Configuration File");
			cmake(); cprint_tag("S"); cprint_name("Save Configuration to an Alternate File");
		}
		dialog_clear();
		stat = dialog_menu(prompt ? prompt : "Main Menu",
				menu_instructions, rows, cols, rows - 10,
				active_entry, item_no, items);
		if (stat < 0)
			return;

		if (stat == 1 || stat == 255)
			break;

		active_item = first_sel_item(item_no, items);
		if (!active_item)
			continue;
		active_item->selected = 0;
		strncpy(active_entry, active_item->tag, sizeof(active_entry));
		active_entry[sizeof(active_entry)-1] = 0;
		type = active_entry[0];
		if (!type)
			continue;

		sym = NULL;
		submenu = NULL;
		if (sscanf(active_entry + 1, "%p", &submenu) == 1)
			sym = submenu->sym;

		switch (stat) {
		case 0:
			switch (type) {
			case 'm':
				if (single_menu_mode)
					submenu->data = (void *) (long) !submenu->data;
				else
					conf(submenu);
				break;
			case 't':
				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
					conf_choice(submenu);
				else if (submenu->prompt->type == P_MENU)
					conf(submenu);
				break;
			case 's':
				conf_string(submenu);
				break;
			case 'L':
				conf_load();
				break;
			case 'S':
				conf_save();
				break;
			}
			break;
		case 2:
			if (sym)
				show_help(submenu);
			else
				show_helptext("README", mconf_readme);
			break;
		case 3:
			if (type == 't') {
				if (sym_set_tristate_value(sym, yes))
					break;
				if (sym_set_tristate_value(sym, mod))
					show_textbox(NULL, setmod_text, 6, 74);
			}
			break;
		case 4:
			if (type == 't')
				sym_set_tristate_value(sym, no);
			break;
		case 5:
			if (type == 't')
				sym_set_tristate_value(sym, mod);
			break;
		case 6:
			if (type == 't')
				sym_toggle_tristate_value(sym);
			else if (type == 'm')
				conf(submenu);
			break;
		case 7:
			search_conf();
			break;
		}
	}
}
Exemple #20
0
int
index_menu(PkgNodePtr root, PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll)
{
    struct ListPtrs lists;
    size_t maxname;
    int n, rval;
    int curr, max;
    PkgNodePtr kp;
    dialogMenuItem *nitems;
    Boolean hasPackages;
    WINDOW *w;
    
    lists.root = root;
    lists.top = top;
    lists.plist = plist;

    hasPackages = FALSE;
    nitems = NULL;
    n = maxname = 0;

    /* Figure out if this menu is full of "leaves" or "branches" */
    for (kp = top->kids; kp && kp->name; kp = kp->next) {
	size_t len;

	++n;
	if (kp->type == PACKAGE && plist) {
	    hasPackages = TRUE;
	    if ((len = strlen(kp->name)) > maxname)
		maxname = len;
	}
    }
    if (!n && plist) {
	msgConfirm("The %s menu is empty.", top->name);
	return DITEM_LEAVE_MENU;
    }

    w = savescr();
    while (1) {
	n = 0;
	curr = max = 0;
	use_helpline(NULL);
	use_helpfile(NULL);
	kp = top->kids;
	if (!hasPackages && plist) {
	    nitems = item_add(nitems, "OK", NULL, NULL, NULL, NULL, NULL, NULL, &curr, &max);
	    nitems = item_add(nitems, "Install", NULL, NULL, NULL, NULL, NULL, NULL, &curr, &max);
	}
	while (kp && kp->name) {
	    char buf[256];
	    IndexEntryPtr ie = kp->data;

	    /* Brutally adjust description to fit in menu */
	    if (kp->type == PACKAGE)
		snprintf(buf, sizeof buf, "[%s]", ie->path ? ie->path : "External vendor");
	    else
		SAFE_STRCPY(buf, kp->desc);
	    if (strlen(buf) > (_MAX_DESC - maxname))
		buf[_MAX_DESC - maxname] = '\0';
	    nitems = item_add(nitems, kp->name, buf, pkg_checked, 
			      pkg_fire, pkg_selected, kp, &lists, 
			      &curr, &max);
	    ++n;
	    kp = kp->next;
	}
	/* NULL delimiter so item_free() knows when to stop later */
	nitems = item_add(nitems, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
			  &curr, &max);

recycle:
	dialog_clear_norefresh();
	if (hasPackages)
	    rval = dialog_checklist(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n, nitems, NULL);
	else
	    rval = dialog_menu(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n, nitems + (plist ? 2 : 0), (char *)plist, pos, scroll);
	if (rval == -1 && plist) {
	    static char *cp;
	    PkgNodePtr menu;

	    /* Search */
	    if ((cp = msgGetInput(cp, "Search by package name.  Please enter search string:")) != NULL) {
		PkgNodePtr p = index_search(top, cp, &menu);

		if (p) {
		    int pos, scroll;

		    /* These need to be set to point at the found item, actually.  Hmmm! */
		    pos = scroll = 0;
		    index_menu(root, menu, plist, &pos, &scroll);
		}
		else
		    msgConfirm("Search string: %s yielded no hits.", cp);
	    }
	    goto recycle;
	}
	items_free(nitems, &curr, &max);
	restorescr(w);
	return rval ? DITEM_FAILURE : DITEM_SUCCESS;
    }
}
Exemple #21
0
void		/* ANSI C can bite me */
main()
{
    int rc;
    char result[20];
    int sc=0, ch=0;

    extern int LINES, COLS;

    init_dialog();

    while (1) {
	rc = dialog_menu(0, "Choose a dialog function to test",
			    LINES-2, COLS-2, NRCHOICES, NRCHOICES,
			    choices, result, &sc, &ch);

	if (rc != 0)
	    break;

	if (strstr(result, "menu")) {
	    int sc2=0, ch2=0;
	    rc = dialog_menu("menu", "menu box",
				-1, -1, 4, 7, menu, result, &sc2, &ch2);
	    if (rc == 0)
		dialog_notify(result);
	    else if (rc == 1)
		dialog_notify("CANCEL");
	    else
		dialog_notify("Ooops");

	    sc2=0, ch2=0;
	    rc = dialog_menu("menu", "menu box\nnumber 2",
				13, 35, 4, 7, menu, result, &sc2, &ch2);
	    if (rc == 0)
		dialog_notify(result);
	    else if (rc == 1)
		dialog_notify("CANCEL");
	    else
		dialog_notify("Ooops");
	}
	else if (strstr(result,"check")) {
	    rc = dialog_checklist("checklist", "checklist box",
				    -1, -1, 4, 7, checklist, result);
	    if (rc == 0)
		dialog_notify(result);
	    else if (rc == 1)
		dialog_notify("CANCEL");
	    else
		dialog_notify("Ooops");
	}
	else if (strstr(result,"radio")) {
	    rc = dialog_radiolist("radiolist", "radiolist box",
				    -1, -1, 4, 7, checklist, result);
	    if (rc == 0)
		dialog_notify(result);
	    else if (rc == 1)
		dialog_notify("CANCEL");
	    else
		dialog_notify("Ooops");
	}
	else if (strstr(result, "notify"))
	    dialog_notify("A Notification box");
	else if (strstr(result, "msg")) {
	    dialog_msgbox("msgbox", "Sleeping 2 seconds on a\n"
				    "msg box without user input", -1, -1, 0);
	    sleep(1);
	    dialog_msgbox("msgbox", "Sleeping 1 second on a\n"
				    "msg box without user input", -1, -1, 0);
	    sleep(1);
	    dialog_msgbox("msgbox", "A msg box that wants user input",
				    -1, -1, 1);
	}
	else if (strstr(result, "mesg"))
	    dialog_mesgbox("mesgbox", "A mesg box", -1, -1);
	else if (strstr(result, "yesno")) {
	    rc = dialog_yesno("yesno", "Test me\nPress YES or NO", -1, -1);

	    if (rc == 0)
		dialog_notify("You pressed YES");
	    else if (rc > 0)
		dialog_notify("You pressed NO");
	    else
		dialog_notify("Something Wicked Happened!");
	}
	else if (strstr(result, "gauge")) { 
	    int x;
	    for (x=0; x<=20; x++) {
		dialog_gauge("test", "gauge", -1, -1, -1, 40, x*5);
		usleep(300000);
	    }
	}
    }
    end_dialog();
    exit((rc < 0) ? 1 : 0);
}