static int _menu1_rome_action(dialogMenuItem *self) { if (where == rome) { dialog_mesgbox("The wine must be getting to you..", "You're already in Rome!", -1, -1); } else { where = rome; dialog_mesgbox("whoosh!", "Welcome to Rome! Have a coffee!", -1, -1); } return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
static int _menu1_ny_action(dialogMenuItem *self) { if (where == ny) { dialog_mesgbox("Say what?", "You're already there!", -1, -1); } else { where = ny; dialog_mesgbox("whoosh!", "Welcome to New York! Now go someplace else!", -1, -1); } return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
static int _menu1_berlin_action(dialogMenuItem *self) { if (where == berlin) { dialog_mesgbox("excuse me?", "But you're already *in* Berlin!", -1, -1); } else { where = berlin; dialog_mesgbox("whoosh!", "Welcome to Berlin! Have a beer!", -1, -1); } return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
/* Display a help file in a filebox */ int systemDisplayHelp(char *file) { char *fname = NULL; char buf[FILENAME_MAX]; int ret = 0; WINDOW *w = savescr(); printf("zzz"); fname = systemHelpFile(file, buf); if (!fname) { snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file); use_helpfile(NULL); use_helpline(NULL); dialog_mesgbox("Sorry!", buf, -1, -1); ret = 1; } else { use_helpfile(NULL); use_helpline(NULL); dialog_textbox(file, fname, LINES, COLS); } restorescr(w); return ret; }
static int buyBooks(dialogMenuItem *self) { char foo[256]; if (german_book || italian_book || slang_book) { strcpy(foo, "Ok, you're buying books on"); if (german_book) strcat(foo, " german"); if (italian_book) strcat(foo, " italian"); if (slang_book) strcat(foo, " slang"); } else strcpy(foo, "You're not buying any books?"); dialog_mesgbox("This is a direct callback for the `Buy' button", foo, -1, -1); return DITEM_SUCCESS; }
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); }
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); }
static int install_zone_file(const char *filename) { struct stat sb; int fd1, fd2; int copymode; char *msg; ssize_t len; char buf[1024]; if (lstat(_PATH_LOCALTIME, &sb) < 0) /* Nothing there yet... */ copymode = 1; else if(S_ISLNK(sb.st_mode)) copymode = 0; else copymode = 1; #ifdef VERBOSE if (copymode) asprintf(&msg, "Copying %s to " _PATH_LOCALTIME, filename); else asprintf(&msg, "Creating symbolic link " _PATH_LOCALTIME " to %s", filename); dialog_notify(msg); free(msg); #endif if (reallydoit) { if (copymode) { fd1 = open(filename, O_RDONLY, 0); if (fd1 < 0) { asprintf(&msg, "Could not open %s: %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } unlink(_PATH_LOCALTIME); fd2 = open(_PATH_LOCALTIME, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IRGRP|S_IROTH); if (fd2 < 0) { asprintf(&msg, "Could not open " _PATH_LOCALTIME ": %s", strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } while ((len = read(fd1, buf, sizeof buf)) > 0) len = write(fd2, buf, len); if (len == -1) { asprintf(&msg, "Error copying %s to " _PATH_LOCALTIME ": %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); /* Better to leave none than a corrupt one. */ unlink(_PATH_LOCALTIME); return DITEM_FAILURE | DITEM_RECREATE; } close(fd1); close(fd2); } else { if (access(filename, R_OK) != 0) { asprintf(&msg, "Cannot access %s: %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } unlink(_PATH_LOCALTIME); if (symlink(filename, _PATH_LOCALTIME) < 0) { asprintf(&msg, "Cannot create symbolic link " _PATH_LOCALTIME " to %s: %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } } } #ifdef VERBOSE if (copymode) asprintf(&msg, "Copied timezone file from %s to " _PATH_LOCALTIME, filename); else asprintf(&msg, "Created symbolic link from " _PATH_LOCALTIME " to %s", filename); dialog_mesgbox("Done", msg, 8, 72); free(msg); #endif return DITEM_LEAVE_MENU; }
static int maybe(dialogMenuItem *self) { dialog_mesgbox("!", "I said don't rush me! I'm THINKING!", -1, -1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
static int stop(dialogMenuItem *self) { dialog_mesgbox("!", "I'm no idiot!", -1, -1); return DITEM_SUCCESS; }