Esempio n. 1
0
File: scripts.c Progetto: IR4T4/xqf
void install_file_dialog_ok_callback (GtkWidget *widget, gpointer data) {
	const char *filename = NULL;
	char dest[PATH_MAX];
	GtkWidget* filesel = topmost_parent(widget);
	const char* msg;

	filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));

	if (!filename) {
		return;
	}

	mkdir((const char*)scriptdirs->data, 0777);

	snprintf(dest, sizeof(dest), "%s/%s", (const char*)scriptdirs->data, g_path_get_basename(filename));

	if (!access(dest, F_OK)) {
		if (!dialog_yesno(NULL, 0, NULL, NULL, _("Script %s already exists, overwrite?"), dest)) {
			return;
		}
	}

	if ((msg = copy_file(filename, dest))) {
		dialog_ok(NULL, "%s", msg);
		return;
	}

	g_datalist_remove_data(&scriptdata, g_path_get_basename(filename));
	scripts_load();

	dialog_ok(NULL, _("Script saved as\n%s\nPlease close and reopen the preferences dialog"), dest);
}
Esempio n. 2
0
File: launch.c Progetto: aufau/xqf
static int already_running (enum server_type type) {
	int another = FALSE;
	struct server *s = NULL;
	struct running_client *cl;
	GSList *tmp;
	int res;

	detach_unused ();

	if (!clients)
		return FALSE;

	for (tmp = clients; tmp; tmp = tmp->next) {
		cl = (struct running_client *) tmp->data;
		if (cl->server->type == type) {
			another = TRUE;
			break;
		}
	}

	s = (struct server *) ((struct running_client *) clients->data) -> server;

	res = dialog_yesno (NULL, 1, _("Launch"), _("Cancel"), 
			_("There is %s client running.\n\nLaunch %s client?"),
			(another)? games[type].name : games[s->type].name,
			(another)? "another" : games[type].name);

	return TRUE - res;
}
Esempio n. 3
0
int main(int ac, char **av)
{
	char *mode;
	int res;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	conf_parse(av[1]);
	conf_read(NULL);

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}

	tcgetattr(1, &ios_org);
	atexit(conf_cleanup);
	init_wsize();
	reset_dialog();
	init_dialog(NULL);
	set_config_filename(conf_get_configname());
	do {
		conf(&rootmenu);
		dialog_clear();
		if (conf_get_changed())
			res = dialog_yesno(NULL,
					   _("Do you wish to save your "
					     "new configuration?\n"
					     "<ESC><ESC> to continue."),
					   6, 60);
		else
			res = -1;
	} while (res == KEY_ESC);
	end_dialog();

	switch (res) {
	case 0:
		if (conf_write(filename)) {
			fprintf(stderr, _("\n\n"
				"Error during writing of the configuration.\n"
				"Your configuration changes were NOT saved."
				"\n\n"));
			return 1;
		}
	case -1:
		printf(_("\n\n"
			"*** End of configuration.\n"
			"\n\n"));
		break;
	default:
		fprintf(stderr, _("\n\n"
			"Your configuration changes were NOT saved."
			"\n\n"));
	}

	return 0;
}
Esempio n. 4
0
int main(int ac, char **av)
{
	struct symbol *sym;
	char *mode;
	int res;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	conf_parse(av[1]);
	conf_read(NULL);

	sym = sym_lookup("KERNELVERSION", 0);
	sym_calc_value(sym);
	sprintf(menu_backtitle, _("Linux Kernel v%s Configuration"),
		sym_get_string_value(sym));

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}

	tcgetattr(1, &ios_org);
	atexit(conf_cleanup);
	init_wsize();
	reset_dialog();
	init_dialog(menu_backtitle);
	do {
		conf(&rootmenu);
		dialog_clear();
		res = dialog_yesno(NULL,
				   _("Do you wish to save your "
				     "new kernel configuration?\n"
				     "<ESC><ESC> to continue."),
				   6, 60);
	} while (res == KEY_ESC);
	end_dialog();
	if (res == 0) {
		if (conf_write(NULL)) {
			fprintf(stderr, _("\n\n"
				"Error during writing of the kernel configuration.\n"
				"Your kernel configuration changes were NOT saved."
				"\n\n"));
			return 1;
		}
		printf(_("\n\n"
			"*** End of Linux kernel configuration.\n"
			"*** Execute 'make' to build the kernel or try 'make help'."
			"\n\n"));
	} else {
		fprintf(stderr, _("\n\n"
			"Your kernel configuration changes were NOT saved."
			"\n\n"));
	}

	return 0;
}
Esempio n. 5
0
static int
j_yesno(JUMPARGS)
{
    *offset_add = 4;
    return dialog_yesno(t,
			av[1],
			numeric_arg(av, 2),
			numeric_arg(av, 3), defaultno);
}
Esempio n. 6
0
static int
keep_going(void)
{
	int ret;

	do_init_dialog();
	ret = !dialog_yesno(NULL,"Do you want to process the new leaves packages?",-1,-1);
	end_dialog();
	return(ret);
}
Esempio n. 7
0
int
gpart_partition(const char *lg_name, const char *scheme)
{
	int cancel, choice;
	struct gctl_req *r;
	const char *errstr;

	DIALOG_LISTITEM items[] = {
		{"APM", "Apple Partition Map",
		    "Bootable on PowerPC Apple Hardware", 0 },
		{"BSD", "BSD Labels",
		    "Bootable on most x86 systems", 0 },
		{"GPT", "GUID Partition Table",
		    "Bootable on most x86 systems", 0 },
		{"MBR", "DOS Partitions",
		    "Bootable on most x86 systems", 0 },
		{"PC98", "NEC PC9801 Partition Table",
		    "Bootable on NEC PC9801 systems", 0 },
		{"VTOC8", "Sun VTOC8 Partition Table",
		    "Bootable on Sun SPARC systems", 0 },
	};

schememenu:
	if (scheme == NULL) {
		dialog_vars.default_item = __DECONST(char *, default_scheme());
		cancel = dlg_menu("Partition Scheme",
		    "Select a partition scheme for this volume:", 0, 0, 0,
		    sizeof(items) / sizeof(items[0]), items, &choice, NULL);
		dialog_vars.default_item = NULL;

		if (cancel)
			return (-1);

		if (!is_scheme_bootable(items[choice].name)) {
			char message[512];
			sprintf(message, "This partition scheme (%s) is not "
			    "bootable on this platform. Are you sure you want "
			    "to proceed?", items[choice].name);
			dialog_vars.defaultno = TRUE;
			cancel = dialog_yesno("Warning", message, 0, 0);
			dialog_vars.defaultno = FALSE;
			if (cancel) /* cancel */
				goto schememenu;
		}

		scheme = items[choice].name;
	}
Esempio n. 8
0
int main(int ac, char **av)
{
	int stat;
	char *mode;
	struct symbol *sym;

	conf_parse(av[1]);
	conf_read(NULL);

	sym = sym_lookup("VERSION", 0);
	sym_calc_value(sym);
	snprintf(menu_backtitle, 128, "Core v%s Configuration",
		sym_get_string_value(sym));

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}
  
	tcgetattr(1, &ios_org);
	atexit(conf_cleanup);
	init_wsize();
	init_dialog();
	signal(SIGWINCH, winch_handler); 
	conf(&rootmenu);
	end_dialog();

	/* Restart dialog to act more like when lxdialog was still separate */
	init_dialog();
	do {
		stat = dialog_yesno(NULL, 
				"Do you wish to save your new Core configuration?", 5, 60);
	} while (stat < 0);
	end_dialog();

	if (stat == 0) {
		conf_write(NULL);
		printf("\n\n"
			"*** End of Core configuration.\n"
			"*** Check the top-level Makefile for additional configuration options.\n\n");
	} else
		printf("\n\nYour Core configuration changes were NOT saved.\n\n");

	return 0;
}
Esempio n. 9
0
File: mconf.c Progetto: WTHsieh/diag
int main(int ac, char **av)
{
	struct symbol *sym;
	char *mode;
	int stat;

	conf_parse(av[1]);
	conf_read(NULL);

	sym = sym_lookup("VERSION", 0);
	sym_calc_value(sym);
	snprintf(menu_backtitle, 128, "BusyBox v%s Configuration",
		sym_get_string_value(sym));

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}

	tcgetattr(1, &ios_org);
	atexit(conf_cleanup);
	init_wsize();
	init_dialog();
	signal(SIGWINCH, winch_handler);
	conf(&rootmenu);
	end_dialog();

	/* Restart dialog to act more like when lxdialog was still separate */
	init_dialog();
	do {
		stat = dialog_yesno(NULL,
				    "Do you wish to save your new diagnostic program configuration?", 6, 60);
	} while (stat < 0);
	end_dialog();

	if (stat == 0) {
		conf_write(NULL);
		printf("\n\n"
			"*** End of SQ diagnostic program configuration.\n");
		printf("*** Execute 'make' to build the diagnostic program or try 'make help'.\n\n");
	} else
		printf("\n\nYour diagnostic program configuration changes were NOT saved.\n\n");

	return 0;
}
Esempio n. 10
0
static int
confirm_zone(const char *filename)
{
	char *msg;
	struct tm *tm;
	time_t t = time(0);
	int rv;
	
	if (setenv("TZ", filename, 1) == -1)
		err(1, "setenv: cannot set TZ=%s", filename);
	tzset();
	tm = localtime(&t);

	asprintf(&msg, "Does the abbreviation `%s' look reasonable?",
		 tm->tm_zone);
	rv = !dialog_yesno("Confirmation", msg, 4, 72);
	free(msg);
	return rv;
}
static int handle_exit(void)
{
    int res;

    dialog_clear();
    if (conf_get_changed())
        res = dialog_yesno(NULL,
                           _("Do you wish to save your new configuration ?\n"
                             "<ESC><ESC> to continue."),
                           6, 60);
    else
        res = -1;

    end_dialog(saved_x, saved_y);

    switch (res) {
    case 0:
        if (conf_write(filename)) {
            fprintf(stderr, _("\n\n"
                              "Error while writing of the configuration.\n"
                              "Your configuration changes were NOT saved."
                              "\n\n"));
            return 1;
        }
    /* fall through */
    case -1:
        printf(_("\n\n"
                 "*** End of the configuration.\n"
                 "*** Execute 'make' to start the build or try 'make help'."
                 "\n\n"));
        res = 0;
        break;
    default:
        fprintf(stderr, _("\n\n"
                          "Your configuration changes were NOT saved."
                          "\n\n"));
        if (res != KEY_ESC)
            res = 0;
    }

    return res;
}
Esempio n. 12
0
/* Put up a message in a popup yes/no box and return 0 for YES, 1 for NO */
int
msgYesNo(const char *fmt, ...)
{
    va_list args;
    char *errstr;
    int ret;
    WINDOW *w = savescr();
    
    errstr = (char *)alloca(FILENAME_MAX);
    va_start(args, fmt);
    vsnprintf(errstr, FILENAME_MAX, fmt, args);
    va_end(args);
    use_helpline(NULL);
    use_helpfile(NULL);
    if (OnVTY) {
	ioctl(0, VT_ACTIVATE, 1);	/* Switch back */
	msgInfo(NULL);
    }
    if (variable_get(VAR_NONINTERACTIVE))
	return 0;	/* If non-interactive, return YES all the time */
    ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1);
    restorescr(w);
    return ret;
}
Esempio n. 13
0
int
main(int argc, const char **argv)
{
	struct partition_metadata *md;
	const char *prompt;
	struct partedit_item *items = NULL;
	struct gmesh mesh;
	int i, op, nitems, nscroll;
	int error;

	if (strcmp(basename(argv[0]), "sade") == 0)
		sade_mode = 1;

	TAILQ_INIT(&part_metadata);

	init_fstab_metadata();

	init_dialog(stdin, stdout);
	if (!sade_mode)
		dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer");
	dialog_vars.item_help = TRUE;
	nscroll = i = 0;

	/* Revert changes on SIGINT */
	signal(SIGINT, sigint_handler);

	if (strcmp(basename(argv[0]), "autopart") == 0) { /* Guided */
		prompt = "Please review the disk setup. When complete, press "
		    "the Finish button.";
		/* Experimental ZFS autopartition support */
		if (argc > 1 && strcmp(argv[1], "zfs") == 0) {
			part_wizard("zfs");
		} else {
			part_wizard("ufs");
		}
	} else if (strcmp(basename(argv[0]), "scriptedpart") == 0) {
		error = scripted_editor(argc, argv);
		prompt = NULL;
		if (error != 0) {
			end_dialog();
			return (error);
		}
	} else {
		prompt = "Create partitions for FreeBSD. No changes will be "
		    "made until you select Finish.";
	}

	/* Show the part editor either immediately, or to confirm wizard */
	while (prompt != NULL) {
		dlg_clear();
		dlg_put_backtitle();

		error = geom_gettree(&mesh);
		if (error == 0)
			items = read_geom_mesh(&mesh, &nitems);
		if (error || items == NULL) {
			dialog_msgbox("Error", "No disks found. If you need to "
			    "install a kernel driver, choose Shell at the "
			    "installation menu.", 0, 0, TRUE);
			break;
		}
			
		get_mount_points(items, nitems);

		if (i >= nitems)
			i = nitems - 1;
		op = diskeditor_show("Partition Editor", prompt,
		    items, nitems, &i, &nscroll);

		switch (op) {
		case 0: /* Create */
			gpart_create((struct gprovider *)(items[i].cookie),
			    NULL, NULL, NULL, NULL, 1);
			break;
		case 1: /* Delete */
			gpart_delete((struct gprovider *)(items[i].cookie));
			break;
		case 2: /* Modify */
			gpart_edit((struct gprovider *)(items[i].cookie));
			break;
		case 3: /* Revert */
			gpart_revert_all(&mesh);
			while ((md = TAILQ_FIRST(&part_metadata)) != NULL) {
				if (md->fstab != NULL) {
					free(md->fstab->fs_spec);
					free(md->fstab->fs_file);
					free(md->fstab->fs_vfstype);
					free(md->fstab->fs_mntops);
					free(md->fstab->fs_type);
					free(md->fstab);
				}
				if (md->newfs != NULL)
					free(md->newfs);
				free(md->name);

				TAILQ_REMOVE(&part_metadata, md, metadata);
				free(md);
			}
			init_fstab_metadata();
			break;
		case 4: /* Auto */
			part_wizard("ufs");
			break;
		}

		error = 0;
		if (op == 5) { /* Finished */
			dialog_vars.ok_label = __DECONST(char *, "Commit");
			dialog_vars.extra_label =
			    __DECONST(char *, "Revert & Exit");
			dialog_vars.extra_button = TRUE;
			dialog_vars.cancel_label = __DECONST(char *, "Back");
			op = dialog_yesno("Confirmation", "Your changes will "
			    "now be written to disk. If you have chosen to "
			    "overwrite existing data, it will be PERMANENTLY "
			    "ERASED. Are you sure you want to commit your "
			    "changes?", 0, 0);
			dialog_vars.ok_label = NULL;
			dialog_vars.extra_button = FALSE;
			dialog_vars.cancel_label = NULL;

			if (op == 0 && validate_setup()) { /* Save */
				error = apply_changes(&mesh);
				if (!error)
					apply_workaround(&mesh);
				break;
			} else if (op == 3) { /* Quit */
				gpart_revert_all(&mesh);
				error =	-1;
				break;
			}
		}

		geom_deletetree(&mesh);
		free(items);
	}
Esempio n. 14
0
void
do_install(void)
{
	int fd[2];
	int status;
	struct pollfd pfd;

	screen_clear(MODULE);

	if (dialog_yesno(MODULE, "Do you want to start the installation?",
	    5, 60))
		return;

	dialog_busy(5, 60, "Initializing installation...");

	if (pipe(fd) < 0) {
		end_dialog();
		err(1, "cannot create a pipe");
	}

	signal(SIGCHLD, sig_chld);

	switch (fork()) {
	case 0:
		close(fd[1]);
		dup2(fd[0], STDERR_FILENO);
		dup2(fd[0], STDOUT_FILENO);
		close(fd[0]);
		execl(PCSYSINSTALL, "pc-sysinstall", "-c", "result.cfg", NULL);
		_exit(1);
		close(STDIN_FILENO);
		close(STDOUT_FILENO);
		close(STDERR_FILENO);
		break;
	case -1:
		close(fd[0]);
		close(fd[1]);
		break;
	default:
	{
		int i, ret;
		char buf[1];
		char line[1024];


		pfd.fd = fd[1];
		pfd.events = POLLIN;
		i = 0;
		while (!signaled) {
			ret = poll(&pfd, 1, 1000);
			if (ret == 0)
				continue;
			if (ret < 0)
				break;
			/* XXX really optimize this */
			if (read(fd[1], buf, 1) < 0)
				break;
			if (*buf == '\n') {
				line[i] = 0;
				show_progress(line);
				i = 0;
			} else {
				line[i] = *buf;
				i++;
			}
		}
		wait(&status);

	}
	}
	close(fd[0]);
	close(fd[1]);

	if (status != 0)
		dialog_textbox("Error occured",
		    "/tmp/.pc-sysinstall/pc-sysinstall.log", 20, 70);
	else {
		screen_clear(MODULE);
		dialog_mesgbox("Installation finished",
		    "Congratulations, you now have PC-BSD or FreeBSD "
		    "installed\nin your system.\n\n", 7, 70);
	}

	system("/bin/sh");
	exit(0);
}
Esempio n. 15
0
File: mconf.c Progetto: 16rd/rt-n56u
int main(int ac, char **av)
{
	int saved_x, saved_y;
	char *mode;
	int res;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	conf_parse(av[1]);
	conf_read(NULL);

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}

	getyx(stdscr, saved_y, saved_x);
	if (init_dialog(NULL)) {
		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
		return 1;
	}

	set_config_filename(conf_get_configname());
	do {
		conf(&rootmenu);
		dialog_clear();
		if (conf_get_changed())
			res = dialog_yesno(NULL,
					   _("Do you wish to save your "
					     "new configuration?\n"
					     "<ESC><ESC> to continue."),
					   6, 60);
		else
			res = -1;
	} while (res == KEY_ESC);
	end_dialog(saved_x, saved_y);

	switch (res) {
	case 0:
		if (conf_write(filename)) {
			fprintf(stderr, _("\n\n"
				"Error during writing of the configuration.\n"
				"Your configuration changes were NOT saved."
				"\n\n"));
			return 1;
		}
	case -1:
		printf(_("\n\n"
			"*** End of configuration.\n"
			"*** Execute 'make' to build or try 'make help'."
			"\n\n"));
		break;
	default:
		fprintf(stderr, _("\n\n"
			"Your configuration changes were NOT saved."
			"\n\n"));
	}

	return conf_write_autoconf();
}
Esempio n. 16
0
File: main.c Progetto: fillods/whdd
int main() {
    int r;
    r = global_init();
    if (r) {
        fprintf(stderr, "init fail\n");
        return r;
    }
    // get list of devices
    DC_DevList *devlist = dc_dev_list();
    assert(devlist);

    while (1) {
        // draw menu of device choice
        DC_Dev *chosen_dev = menu_choose_device(devlist);
        if (!chosen_dev) {
            break;
        }
        // draw procedures menu
        DC_Procedure *act = menu_choose_procedure(chosen_dev);
        if (!act)
            continue;
        if (act->flags & DC_PROC_FLAG_INVASIVE) {
            char *ask;
            r = asprintf(&ask, "This operation is invasive, i.e. it may make your data unreachable or even destroy it completely. Are you sure you want to proceed it on %s (%s)?",
                    chosen_dev->dev_fs_name, chosen_dev->model_str);
            assert(r != -1);
            dialog_vars.default_button = 1;  // Focus on "No"
            r = dialog_yesno("Confirmation", ask, 0, 0);
            // Yes = 0 (FALSE), No = 1, Escape = -1
            free(ask);
            if (/* No */ r)
                continue;
            if (chosen_dev->mounted) {
                dialog_vars.default_button = 1;  // Focus on "No"
                r = dialog_yesno("Confirmation", "This disk is mounted. Are you really sure you want to proceed?", 0, 0);
                if (r)
                    continue;
            }
        }
        DC_OptionSetting *option_set = calloc(act->options_num + 1, sizeof(DC_OptionSetting));
        int i;
        r = 0;
        for (i = 0; i < act->options_num; i++) {
            option_set[i].name = act->options[i].name;
            r = act->suggest_default_value(chosen_dev, &option_set[i]);
            if (r) {
                dc_log(DC_LOG_ERROR, "Failed to get default value suggestion on '%s'", option_set[i].name);
                break;
            }
            r = ask_option_value(act, &option_set[i], &act->options[i]);
            if (r)
                break;
        }
        if (r)
            continue;
        // Show relaxing banner when copying with journal. Copy journal processing takes some time.
        if (!strcmp(act->name, "copy")) {
            int uses_journal = 0;
            for (i = 0; i < act->options_num; i++) {
                if (!strcmp(option_set[i].name, "use_journal")) {
                    uses_journal = 1;
                    break;
                }
            }
            if (uses_journal)
                dialog_msgbox("Info", "Please wait while operation journal is processed", 0, 0, 0 /* non-pausing */);
        }
        DC_ProcedureCtx *actctx;
        r = dc_procedure_open(act, chosen_dev, &actctx, option_set);
        if (r) {
            dialog_msgbox("Error", "Procedure init fail", 0, 0, 1);
            continue;
        }
        if (!act->perform)
            continue;
        DC_Renderer *renderer;
        if (!strcmp(act->name, "copy"))
            renderer = dc_find_renderer("whole_space");
        else
            renderer = dc_find_renderer("sliding_window");
        render_procedure(actctx, renderer);
    } // while(1)

    return 0;
}
Esempio n. 17
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);
}
Esempio n. 18
0
int 
ifs_cfg(char *title, char *prompt, int height, int width, int y, int x, char *dev)
{
	WINDOW *w;
	int i, n, k, j;
	char titlez[80];
	char devz[80];
	int foo, done, key, set;
	struct device d;
	int ret = -1;
	int dev_id;

	init_dialog();
	dialog_clear();

	draw_shadow(stdscr, y, x, height, width);
	w = newwin(height, width, y, x);

	draw_box(w, 0, 0, height, width, dialog_attr, border_attr);
	wattrset(w, border_attr);
	keypad(w, TRUE);
	/* draw pretty lines outside. */
	/* box(w, ACS_VLINE, ACS_HLINE); */

	wrefresh(w);
	snprintf(titlez, sizeof(titlez), " [ %s ] ", title);

	foo = ((width / 2) - strlen(title));
	wmove(w, 0, foo);
	wattrset(w, title_attr);
	waddstr(w, titlez);
	wattrset(w, border_attr);
	for (i = 1; i < (height - 1); i++) {
		for (n = 1; n < (width - 1); n++) {
			wmove(w, i, n);
			waddch(w, ' ');
		}
	}

	draw_box(w, 2, 3, 12, 44, dialog_attr, border_attr);
	wattrset(w, title_attr);
	wmove(w, 4, 4);
	waddstr(w, "        IP ->");
	draw_box(w, 3, 18, 3, 25, dialog_attr, border_attr);

	wattrset(w, title_attr);
	wmove(w, 7, 4);
	waddstr(w, "   Netmask ->");
	draw_box(w, 6, 18, 3, 25, dialog_attr, border_attr);

	wattrset(w, title_attr);
	wmove(w, 10, 4);
	waddstr(w, "   Gateway ->");
	draw_box(w, 9, 18, 3, 25, dialog_attr, border_attr);

	print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE);
	print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);

	d.dhcp = DHCP_DISABLED;

	if ((ret = device_exist(dev)) >= 0) {
		wattrset(w, dialog_attr);
		wrefresh(w);
		/* fill in the previously configured values */
		snprintf(d.ip, sizeof(d.ip), "%s", dev_ip(dev));
		if (strlen(d.ip) > 6)
			mvwprintw(w, 4, 19, "%s", d.ip);
		else
			bzero(d.ip, sizeof(d.ip));

		snprintf(d.netmask, sizeof(d.netmask), "%s", dev_netmask(dev));
		if (strlen(d.netmask) > 6)
			mvwprintw(w, 7, 19, "%s", d.netmask);
		else
			bzero(d.netmask, sizeof(d.netmask));

		snprintf(d.gateway, sizeof(d.gateway), "%s", dev_gateway(dev));
		if (strlen(d.gateway) > 6)
			mvwprintw(w, 10, 19, "%s", d.gateway);
		else
			bzero(d.gateway, sizeof(d.gateway));

		snprintf(devz, sizeof(devz), "Editing device %s", dev);
		wmove(w, 1, (width / 2) - (strlen(devz) / 2));
		wattrset(w, dialog_attr);
		waddstr(w, devz);
		wrefresh(w);
	} else {
		bzero(d.ip, sizeof(d.ip));
		bzero(d.netmask, sizeof(d.netmask));
		bzero(d.gateway, sizeof(d.gateway));
		snprintf(devz, sizeof(devz), "Configuring device %s", dev);
		wmove(w, 1, (width / 2) - (strlen(devz) / 2));
		wattrset(w, dialog_attr);
		waddstr(w, devz);
	}


	/* start off in first window. */
	done = key = set = 0;
	j = 1;

	while (!done) {
		wrefresh(w);
		switch (j) {
		case 1:
			wattrset(w, inputbox_attr);
			wrefresh(w);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);
			print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE);

			if (strlen(d.ip) < 1)
				bzero(d.ip, sizeof(d.ip));

			k = line_edit(w, 4, 19, 23, 23, inputbox_attr, 1, d.ip, DialogInputAttrs);
			if (k == KEY_DOWN) {
				j++;
				break;
			} else if (k == 9) {
				j++;
				break;
			} else if (k == KEY_UP) {
				j = 1;
				break;
			} else if (k == 10) {
				j++;
				break;
			}
			break;

		case 2:
			wattrset(w, inputbox_attr);
			wrefresh(w);
			/*
			 * print_button(w, "  OK
			 * ",height-2,(width/2)-11,FALSE);
			 */

			if (strlen(d.netmask) < 1)
				bzero(d.netmask, sizeof(d.netmask));

			k = line_edit(w, 7, 19, 23, 23, inputbox_attr, 1, d.netmask, DialogInputAttrs);
			if (k == KEY_DOWN) {
				j++;
				break;
			} else if (k == 10) {
				j++;
				break;
			} else if (k == 9) {
				j++;
				break;
			} else if (k == KEY_UP) {
				j = 1;
				break;
			}
			break;

		case 3:
			wattrset(w, inputbox_attr);
			wrefresh(w);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);
			if (strlen(d.gateway) < 1)
				bzero(d.gateway, sizeof(d.gateway));

			k = line_edit(w, 10, 19, 23, 23, inputbox_attr, 1, d.gateway, DialogInputAttrs);
			if (k == KEY_DOWN) {
				j++;
				break;
			} else if (k == 10) {
				j++;
				break;
			} else if (k == 9) {
				j++;
				break;
			} else if (k == KEY_UP) {
				j--;
				break;
			}
			break;

		case 4:
			wattrset(w, title_attr);
			wrefresh(w);
			curs_set(0);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, TRUE);
			print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE);
			wrefresh(w);
			key = wgetch(w);
			if (key == KEY_UP) {
				j--;
				break;
			} else if (key == 9) {
				j++;
				break;
			} else if (key == KEY_DOWN) {
				j++;
				break;
			} else if (key == 10) {
				done = 1;
				set = 1;
				break;
			}
			break;

		case 5:
			wattrset(w, title_attr);
			wrefresh(w);
			curs_set(0);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);
			print_button(w, "Cancel", height - 2, (width / 2) + 3, TRUE);
			wrefresh(w);
			key = wgetch(w);
			if (key == KEY_UP) {
				j = 4;
				break;
			} else if (key == KEY_DOWN) {
				j = 4;
				break;
			} else if (key == 9) {
				j = 1;
				break;
			} else if (key == 10) {
				dialog_clear();
				return -1;
				break;
			}
			break;
		}
	}

	if (strlen(d.gateway) > 1) {
		ret = dialog_yesno("ClosedBSD", "Would you like this device to be the default gateway?", -1, -1);
		if (ret == 0) {
			if ((ext_exist()) == -1) {
				d.ext = 1;
			} else {
				dialog_clear();
				ret = dialog_yesno("ClosedBSD", "You already have a default gateway set.  Overwrite?", -1, -1);
				if (ret == 0) {
					unset_ext(d.id);
				} else {
					d.ext = 0;
				}
			}
		} else {
			d.ext = 0;
		}
	} else
		d.ext = 0;

	strcpy(d.device, dev);

	if (set == 1) {
		dialog_clear();
		dev_id = device_exist(d.device);

		switch (dev_id) {
		case -1:
			d.id = next_device_id();
			insert_device(d);
			break;
		default:
			ret = dialog_yesno("ClosedBSD", "This device is already configured. Overwrite?", -1, -1);
			if (ret == 0) {
				d.id = dev_id;
				insert_device(d);
				break;
			} else {
				break;
			}
		}
	}
	dialog_clear();
	wrefresh(w);
	end_dialog();
	return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
}
Esempio n. 19
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;
}