int ui__popup_menu(int argc, char * const argv[]) { struct newtExitStruct es; int i, rc = -1, max_len = 5; newtComponent listbox, form = newt_form__new(); if (form == NULL) return -1; listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); if (listbox == NULL) goto out_destroy_form; newtFormAddComponent(form, listbox); for (i = 0; i < argc; ++i) { int len = strlen(argv[i]); if (len > max_len) max_len = len; if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) goto out_destroy_form; } newtCenteredWindow(max_len, argc, NULL); newtFormRun(form, &es); rc = newtListboxGetCurrent(listbox) - NULL; if (es.reason == NEWT_EXIT_HOTKEY) rc = -1; newtPopWindow(); out_destroy_form: newtFormDestroy(form); return rc; }
// ======================================================= void CRestoreMbrWindow::getValues(DWORD *dwCurrentMbrNb, DWORD *dwOriginalMbrNb, int *nRestoreMode) { BEGIN; *dwCurrentMbrNb = (DWORD) newtListboxGetCurrent(m_list1); *dwOriginalMbrNb = (DWORD) newtListboxGetCurrent(m_list2); if (newtRadioGetCurrent(m_radioFull) == m_radioFull) *nRestoreMode = MBR_RESTORE_WHOLE; else if (newtRadioGetCurrent(m_radioFull) == m_radioBoot) *nRestoreMode = MBR_RESTORE_BOOT; else if (newtRadioGetCurrent(m_radioFull) == m_radioTable) *nRestoreMode = MBR_RESTORE_TABLE; RETURN; }
static void rebuild_channels(newtComponent c) { void *prev = NULL; struct ast_chan *chan; char tmpn[42]; char tmp[256]; int x=0; prev = newtListboxGetCurrent(c); newtListboxClear(c); chan = chans; while(chan) { snprintf(tmpn, sizeof(tmpn), "%s (%s)", chan->name, chan->callerid); if (strlen(chan->exten)) snprintf(tmp, sizeof(tmp), "%-30s %8s -> %s@%s:%s", tmpn, chan->state, chan->exten, chan->context, chan->priority); else snprintf(tmp, sizeof(tmp), "%-30s %8s", tmpn, chan->state); newtListboxAppendEntry(c, tmp, chan); x++; chan = chan->next; } if (!x) newtListboxAppendEntry(c, " << No Active Channels >> ", NULL); newtListboxSetCurrentByKey(c, prev); }
static void try_redirect(newtComponent c) { struct ast_chan *chan; char dest[256]; struct message *m; char channame[256]; char tmp[80]; char *context; chan = newtListboxGetCurrent(c); if (chan) { strncpy(channame, chan->name, sizeof(channame) - 1); snprintf(tmp, sizeof(tmp), "Enter new extension for %s", channame); if (get_user_input(tmp, dest, sizeof(dest))) return; if ((context = strchr(dest, '@'))) { *context = '\0'; context++; manager_action("Redirect", "Channel: %s\r\nContext: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name,context,dest); } else { manager_action("Redirect", "Channel: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name, dest); } m = wait_for_response(10000); if (!m) { show_message("Hangup Failed", "Timeout waiting for response"); } else if (strcasecmp(get_header(m, "Response"), "Success")) { show_message("Hangup Failed", get_header(m, "Message")); } } }
static void nmt_newt_listbox_activated (NmtNewtWidget *widget) { NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (widget); newtComponent co = nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)); nmt_newt_listbox_set_active (listbox, GPOINTER_TO_UINT (newtListboxGetCurrent (co))); NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)->activated (widget); }
static void selection_changed_callback (newtComponent co, void *user_data) { NmtNewtListbox *listbox = user_data; NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox); int new_active; new_active = GPOINTER_TO_UINT (newtListboxGetCurrent (co)); update_active_internal (listbox, new_active); if (priv->active != new_active) newtListboxSetCurrent (co, priv->active); }
static void try_hangup(newtComponent c) { struct ast_chan *chan; struct message *m; chan = newtListboxGetCurrent(c); if (chan) { manager_action("Hangup", "Channel: %s\r\n", chan->name); m = wait_for_response(10000); if (!m) { show_message("Hangup Failed", "Timeout waiting for response"); } else if (strcasecmp(get_header(m, "Response"), "Success")) { show_message("Hangup Failed", get_header(m, "Message")); } } }
static void sel_callback(newtComponent c, void *cbdata) { int span; char info[256]; char info2[256]; cbdata = newtListboxGetCurrent(c); if (cbdata) { span = (long)(cbdata); snprintf(info, sizeof (info), "Span %d: %d total channels, %d configured", span, s[span].totalchans, s[span].numchans); snprintf(info2, sizeof(info2), "%-59s F1=Details F10=Quit", info); } else { span = -1; strcpy(info, "There are no DAHDI spans on this system."); snprintf(info2, sizeof(info2), "%-59s F10=Quit", info); } newtPopHelpLine(); newtPushHelpLine(info2); }
static void add_cards(newtComponent spans) { int x; char *s; void *prev=NULL; if (spans) prev = newtListboxGetCurrent(spans); newtListboxClear(spans); for (x=0;x<DAHDI_MAX_SPANS;x++) { s = getalarms(x, 0); if (s && spans) { /* Found one! */ newtListboxAppendEntry(spans, s, (void *)(long)x); } } if (spans) newtListboxSetCurrentByKey(spans, prev); }
static void show_span(int span) { newtComponent form; newtComponent back; newtComponent loop; newtComponent label; newtComponent bitbox; newtComponent inuse; newtComponent levels; newtComponent bpvcount; newtComponent alarms; newtComponent syncsrc; newtComponent irqmisses; char s1[] = " 1111111111222222222233"; char s2[] = "1234567890123456789012345678901"; int x; int looped = 0; struct newtExitStruct es; void *ss; char info2[256]; if (span < 0) { /* Display info on a span */ ss = newtListboxGetCurrent(spans); if (ss) { span = (long)(ss); } } snprintf(info2, sizeof(info2), "%-59s F10=Back", s[span].desc); newtOpenWindow(10,2,60,20, s[span].desc); newtPushHelpLine(info2); back = newtButton(48,8,"Back"); loop = newtButton(48,14,"Loop"); form = newtForm(NULL, NULL, 0); newtFormAddComponents(form, back, loop, NULL); span_max_chan_pos = s[span].totalchans; for (x=0;x<DAHDI_MAX_CHANNELS;x++) { DAHDI_PARAMS zp; int res; memset(&zp, 0, sizeof(zp)); zp.channo = x; res = ioctl(ctl, DAHDI_GET_PARAMS, &zp); if (!res && zp.spanno == span && zp.chanpos > span_max_chan_pos ) span_max_chan_pos = zp.chanpos; } if (span_max_chan_pos > 32) span_max_chan_pos = 32; s1[span_max_chan_pos] = '\0'; s2[span_max_chan_pos] = '\0'; bitbox = newtTextbox(8,10,span_max_chan_pos,9,0); newtFormAddComponent(form, bitbox); label = newtLabel(8,8,s1); newtFormAddComponent(form, label); label = newtLabel(8,9,s2); newtFormAddComponent(form, label); newtFormAddHotKey(form, NEWT_KEY_F10); newtFormSetTimer(form, 200); label = newtLabel(4,10,"TxA"); newtFormAddComponent(form, label); label = newtLabel(4,11,"TxB"); newtFormAddComponent(form, label); label = newtLabel(4,12,"TxC"); newtFormAddComponent(form, label); label = newtLabel(4,13,"TxD"); newtFormAddComponent(form, label); label = newtLabel(4,15,"RxA"); newtFormAddComponent(form, label); label = newtLabel(4,16,"RxB"); newtFormAddComponent(form, label); label = newtLabel(4,17,"RxC"); newtFormAddComponent(form, label); label = newtLabel(4,18,"RxD"); newtFormAddComponent(form, label); label = newtLabel(4,7,"Total/Conf/Act: "); newtFormAddComponent(form, label); inuse = newtTextbox(24,7,12,1,0); newtFormAddComponent(form, inuse); label = newtLabel(4,6,"Tx/Rx Levels: "); newtFormAddComponent(form, label); levels = newtTextbox(24,6,30,1,0); newtFormAddComponent(form, levels); label = newtLabel(4,5,"Bipolar Viol: "); newtFormAddComponent(form, label); bpvcount = newtTextbox(24,5,30,1,0); newtFormAddComponent(form, bpvcount); label = newtLabel(4,4,"IRQ Misses: "); newtFormAddComponent(form, label); irqmisses = newtTextbox(24,4,30,1,0); newtFormAddComponent(form, irqmisses); label = newtLabel(4,3,"Sync Source: "); newtFormAddComponent(form, label); syncsrc = newtTextbox(24,3,30,1,0); newtFormAddComponent(form, syncsrc); label = newtLabel(4,2,"Current Alarms: "); newtFormAddComponent(form, label); alarms = newtTextbox(24,2,30,1,0); newtFormAddComponent(form, alarms); for(;;) { /* Wait for user to select something */ do { add_cards(NULL); show_bits(span, bitbox, inuse, levels, bpvcount, alarms, syncsrc, irqmisses); newtFormRun(form, &es); } while(es.reason == NEWT_EXIT_TIMER); switch(es.reason) { case NEWT_EXIT_COMPONENT: if (es.u.co == loop) { looped = !looped; do_loop(span, looped); newtFormSetTimer(form, 200); } if (es.u.co == back) { goto out; } break; case NEWT_EXIT_HOTKEY: switch(es.u.key) { #if 0 case NEWT_KEY_F1: show_span(-1); break; #endif case NEWT_KEY_F10: goto out; } break; default: break; } } out: newtFormDestroy(form); newtPopWindow(); newtPopHelpLine(); span_max_chan_pos = 0; }
int listBox(const char * text, int height, int width, poptContext optCon, int flags, char ** result) { newtComponent form, okay, tb, answer, listBox; newtComponent cancel = NULL; const char * arg; char * end; int listHeight; int numItems = 0; int allocedItems = 5; int i, top; int rc = DLG_OKAY; char buf[80], format[20]; int maxTagWidth = 0; int maxTextWidth = 0; int scrollFlag; struct { const char * text; const char * tag; } * itemInfo = malloc(allocedItems * sizeof(*itemInfo)); if (!(arg = poptGetArg(optCon))) return DLG_ERROR; listHeight = strtoul(arg, &end, 10); if (*end) return DLG_ERROR; while ((arg = poptGetArg(optCon))) { if (allocedItems == numItems) { allocedItems += 5; itemInfo = realloc(itemInfo, sizeof(*itemInfo) * allocedItems); } itemInfo[numItems].tag = arg; if (!(arg = poptGetArg(optCon))) return DLG_ERROR; if (!(flags & FLAG_NOITEM)) { itemInfo[numItems].text = arg; } else itemInfo[numItems].text = ""; if (wstrlen(itemInfo[numItems].text,-1) > (unsigned int)maxTextWidth) maxTextWidth = wstrlen(itemInfo[numItems].text,-1); if (wstrlen(itemInfo[numItems].tag,-1) > (unsigned int)maxTagWidth) maxTagWidth = wstrlen(itemInfo[numItems].tag,-1); numItems++; } form = newtForm(NULL, NULL, 0); tb = textbox(height - 4 - buttonHeight - listHeight, width - 2, text, flags, &top); if (listHeight >= numItems) { scrollFlag = 0; i = 0; } else { scrollFlag = NEWT_FLAG_SCROLL; i = 2; } listBox = newtListbox(3 + ((width - 10 - maxTagWidth - maxTextWidth - i) / 2), top + 1, listHeight, NEWT_FLAG_RETURNEXIT | scrollFlag); sprintf(format, "%%-%ds %%s", maxTagWidth); for (i = 0; i < numItems; i++) { sprintf(buf, format, itemInfo[i].tag, itemInfo[i].text); newtListboxAddEntry(listBox, buf, (void *) i); } newtFormAddComponents(form, tb, listBox, NULL); addButtons(height, width, form, &okay, &cancel, flags); answer = newtRunForm(form); if (answer == cancel) rc = DLG_CANCEL; i = (int) newtListboxGetCurrent(listBox); *result = itemInfo[i].tag; return rc; }
/** * Pop up a list containing the filenames in @p source_file and the severity if they have changed since the * last backup. There can be no more than @p ARBITRARY_MAXIMUM files in @p source_file. * @param source_file The file containing a list of changed files. */ void popup_changelist_from_file(char *source_file) { char *reason = NULL; newtComponent myForm; newtComponent bClose; newtComponent bSelect; newtComponent b_res; newtComponent fileListbox; newtComponent headerMsg; /*@ ???? ************************************************************ */ void *curr_choice; void *keylist[ARBITRARY_MAXIMUM]; /*@ int ************************************************************* */ int i = 0; int currline = 0; int finished = FALSE; long lng = 0; /*@ buffers ********************************************************* */ char *tmp; char *differ_sz; struct s_filelist *filelist; assert_string_is_neither_NULL_nor_zerolength(source_file); if (g_text_mode) { log_msg(2, "Text mode. Therefore, no popup list."); return; } log_msg(2, "Examining file %s", source_file); lng = count_lines_in_file(source_file); if (lng < 1) { log_msg(2, "No lines in file. Therefore, no popup list."); return; } else if (lng >= ARBITRARY_MAXIMUM) { log_msg(2, "Too many files differ for me to list."); return; } filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist)); fileListbox = newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); newtListboxClear(fileListbox); if (load_filelist_into_array(filelist, source_file)) { log_msg(2, "Can't open %s; therefore, cannot popup list", source_file); return; } log_msg(2, "%d files loaded into filelist array", filelist->entries); for (i = 0; i < filelist->entries; i++) { keylist[i] = (void *) i; newtListboxAppendEntry(fileListbox, filelist_entry_to_string(& (filelist-> el[i])), keylist[i]); } asprintf(&differ_sz, _(" %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list."), i); newtPushHelpLine(differ_sz); paranoid_free(differ_sz); bClose = newtCompactButton(10, 15, _(" Close ")); bSelect = newtCompactButton(30, 15, _(" Select ")); asprintf(&tmp, "%-10s %-20s", _("Priority"), _("Filename")); headerMsg = newtLabel(2, 1, tmp); paranoid_free(tmp); newtOpenWindow(5, 4, 70, 16, _("Non-matching files")); myForm = newtForm(NULL, NULL, 0); newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, bSelect, NULL); while (!finished) { b_res = newtRunForm(myForm); if (b_res == bClose) { finished = TRUE; } else { curr_choice = newtListboxGetCurrent(fileListbox); for (i = 0; i < filelist->entries && keylist[i] != curr_choice; i++); if (i == filelist->entries && filelist->entries > 0) { log_to_screen(_("I don't know what that button does!")); } else { currline = i; if (filelist->entries > 0) { severity_of_difference(filelist->el[currline]. filename, reason); asprintf(&tmp, "%s --- %s", filelist->el[currline].filename, reason); popup_and_OK(tmp); paranoid_free(tmp); paranoid_free(reason); } } } } newtFormDestroy(myForm); newtPopWindow(); newtPopHelpLine(); }
/* setup hard drive based install from a partition with a filesystem and * ISO images on that filesystem */ char * mountHardDrive(struct installMethod * method, char * location, struct loaderData_s * loaderData) { int rc; int i; newtComponent listbox, label, dirEntry, form, okay, back, text; struct newtExitStruct es; newtGrid entryGrid, grid, buttons; int done = 0; char * dir = strdup(""); char * tmpDir; char * url = NULL; char * buf, *substr; int numPartitions; char **partition_list; char *selpart; char *kspartition = NULL, *ksdirectory = NULL; /* handle kickstart/stage2= data first if available */ if (loaderData->method == METHOD_HD && loaderData->stage2Data) { kspartition = ((struct hdInstallData *)loaderData->stage2Data)->partition; ksdirectory = ((struct hdInstallData *)loaderData->stage2Data)->directory; logMessage(INFO, "partition is %s, dir is %s", kspartition, ksdirectory); /* if exist, duplicate */ if (kspartition) kspartition = strdup(kspartition); if (ksdirectory) { ksdirectory = strdup(ksdirectory); } else { ksdirectory = strdup("/images/install.img"); } if (!kspartition || !ksdirectory) { logMessage(ERROR, "missing partition or directory specification"); loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; } else { /* if we start with /dev, strip it (#121486) */ char *kspart = kspartition; if (!strncmp(kspart, "/dev/", 5)) kspart = kspart + 5; url = setupIsoImages(kspart, ksdirectory, location); if (!url) { logMessage(ERROR, "unable to find %s installation images on hd", getProductName()); loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; } else { free(kspartition); free(ksdirectory); return url; } } } else { kspartition = NULL; ksdirectory = NULL; } /* if we're here its either because this is interactive, or the */ /* hd kickstart directive was faulty and we have to prompt for */ /* location of harddrive image */ partition_list = NULL; while (!done) { /* if we're doing another pass free this up first */ if (partition_list) freePartitionsList(partition_list); partition_list = getPartitionsList(NULL); numPartitions = lenPartitionsList(partition_list); /* no partitions found, try to load a device driver disk for storage */ if (!numPartitions) { rc = newtWinChoice(_("Hard Drives"), _("Yes"), _("Back"), _("You don't seem to have any hard drives on " "your system! Would you like to configure " "additional devices?")); if (rc == 2) { loaderData->stage2Data = NULL; return NULL; } rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0); continue; } /* now find out which partition has the stage2 image */ checked_asprintf(&buf, _("What partition and directory on that " "partition holds the installation image " "for %s? If you don't see the disk drive " "you're using listed here, press F2 to " "configure additional devices."), getProductName()); text = newtTextboxReflowed(-1, -1, buf, 62, 5, 5, 0); free(buf); listbox = newtListbox(-1, -1, numPartitions > 5 ? 5 : numPartitions, NEWT_FLAG_RETURNEXIT | (numPartitions > 5 ? NEWT_FLAG_SCROLL : 0)); for (i = 0; i < numPartitions; i++) newtListboxAppendEntry(listbox,partition_list[i],partition_list[i]); /* if we had ks data around use it to prime entry, then get rid of it*/ if (kspartition) { newtListboxSetCurrentByKey(listbox, kspartition); free(kspartition); kspartition = NULL; } label = newtLabel(-1, -1, _("Directory holding image:")); dirEntry = newtEntry(28, 11, dir, 28, (const char **) &tmpDir, NEWT_ENTRY_SCROLL); /* if we had ks data around use it to prime entry, then get rid of it*/ if (ksdirectory) { newtEntrySet(dirEntry, ksdirectory, 1); free(ksdirectory); ksdirectory = NULL; } entryGrid = newtGridHStacked(NEWT_GRID_COMPONENT, label, NEWT_GRID_COMPONENT, dirEntry, NEWT_GRID_EMPTY); buttons = newtButtonBar(_("OK"), &okay, _("Back"), &back, NULL); grid = newtCreateGrid(1, 4); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, entryGrid, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); newtGridWrappedWindow(grid, _("Select Partition")); form = newtForm(NULL, NULL, 0); newtFormAddHotKey(form, NEWT_KEY_F2); newtFormAddHotKey(form, NEWT_KEY_F12); newtGridAddComponentsToForm(grid, form, 1); newtGridFree(grid, 1); newtFormRun(form, &es); selpart = newtListboxGetCurrent(listbox); free(dir); if (tmpDir && *tmpDir) { /* Protect from form free. */ dir = strdup(tmpDir); } else { dir = strdup(""); } newtFormDestroy(form); newtPopWindow(); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == back) { loaderData->stage2Data = NULL; return NULL; } else if (es.reason == NEWT_EXIT_HOTKEY && es.u.key == NEWT_KEY_F2) { rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0); continue; } logMessage(INFO, "partition %s selected", selpart); /* If the user-provided URL points at a repo instead of a stage2 * image, fix that up now. */ substr = strstr(dir, ".img"); if (!substr || (substr && *(substr+4) != '\0')) { checked_asprintf(&dir, "%s/images/install.img", dir); } loaderData->invalidRepoParam = 1; url = setupIsoImages(selpart, dir, location); if (!url) { newtWinMessage(_("Error"), _("OK"), _("Device %s does not appear to contain " "an installation image."), selpart, getProductName()); continue; } done = 1; } free(dir); return url; }
/* Browse through a directory structure looking for a file. * Returns the full path to the file. * * Parameters: * title: Title for newt dialog window * dirname: Directory to use for root of browsing. NOTE: you cannot go * up above this root. * filterfunc: An (optional) function to filter out files based on whatever * criteria you want. Returns 1 if it passes, 0 if not. * Function should take arguments of the directory name and * the dirent for the file. */ char * newt_select_file(char * title, char * text, char * dirname, int (*filterfunc)(char *, struct dirent *)) { char ** files; char * fn = NULL; int i, done = 0; char * topdir = dirname; char * dir = malloc(PATH_MAX); char * path = NULL; newtGrid grid, buttons; newtComponent f, tb, listbox, ok, cancel; struct stat sb; struct newtExitStruct es; dir = realpath(dirname, dir); do { files = get_file_list(dir, filterfunc); f = newtForm(NULL, NULL, 0); grid = newtCreateGrid(1, 4); tb = newtTextboxReflowed(-1, -1, text, 60, 0, 10, 0); listbox = newtListbox(12, 65, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); newtListboxSetWidth(listbox, 55); buttons = newtButtonBar(_("OK"), &ok, _("Cancel"), &cancel, NULL); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, tb, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); /* if this isn't our topdir, we want to let them go up a dir */ if (strcmp(topdir, dir)) newtListboxAppendEntry(listbox, "../", ".."); for (i = 0; (files[i] != NULL); i++) { if ((files[i] == NULL) || (strlen(files[i]) == 0)) continue; path = malloc(strlen(files[i]) + strlen(dir) + 2); sprintf(path, "%s/%s", dir, files[i]); stat(path, &sb); free(path); if (S_ISDIR(sb.st_mode)) { char *dir = malloc(strlen(files[i]) + 2); sprintf(dir, "%s/", files[i]); newtListboxAppendEntry(listbox, dir, files[i]); } else { newtListboxAppendEntry(listbox, files[i], files[i]); } } newtGridWrappedWindow(grid, title); newtGridAddComponentsToForm(grid, f, 1); newtFormRun(f, &es); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == cancel) { fn = NULL; done = -1; } else { fn = (char *) newtListboxGetCurrent(listbox); path = malloc(strlen(fn) + strlen(dir) + 2); sprintf(path, "%s/%s", dir, fn); stat(path, &sb); if (!S_ISDIR(sb.st_mode)) { fn = path; done = 1; } else { dir = realpath(path, dir); free(path); } } newtGridFree(grid, 1); newtFormDestroy(f); newtPopWindow(); } while (done == 0); return fn; }
static struct eventResult listboxEvent(newtComponent co, struct event ev) { struct eventResult er; struct listbox * li = co->data; struct items *item; int i; er.result = ER_IGNORED; if(ev.when == EV_EARLY || ev.when == EV_LATE) { return er; } switch(ev.event) { case EV_KEYPRESS: if (!li->isActive) break; switch(ev.u.key) { case ' ': if(!(li->flags & NEWT_FLAG_MULTIPLE)) break; newtListboxSelectItem(co, newtListboxGetCurrent(co), NEWT_FLAGS_TOGGLE); er.result = ER_SWALLOWED; /* We don't break here, because it is cool to be able to hold space to select a bunch of items in a list at once */ case NEWT_KEY_DOWN: if(li->numItems <= 0) break; if(li->currItem < li->numItems - 1) { li->currItem++; if(li->currItem > (li->startShowItem + li->curHeight - 1)) { li->startShowItem = li->currItem - li->curHeight + 1; if(li->startShowItem + li->curHeight > li->numItems) li->startShowItem = li->numItems - li->curHeight; } if(li->sb) newtScrollbarSet(li->sb, li->currItem + 1, li->numItems); listboxDraw(co); } if(co->callback) co->callback(co, co->callbackData); er.result = ER_SWALLOWED; break; case NEWT_KEY_ENTER: if(li->numItems <= 0) break; if(li->flags & NEWT_FLAG_RETURNEXIT) er.result = ER_EXITFORM; break; case NEWT_KEY_UP: if(li->numItems <= 0) break; if(li->currItem > 0) { li->currItem--; if(li->currItem < li->startShowItem) li->startShowItem = li->currItem; if(li->sb) newtScrollbarSet(li->sb, li->currItem + 1, li->numItems); listboxDraw(co); } if(co->callback) co->callback(co, co->callbackData); er.result = ER_SWALLOWED; break; case NEWT_KEY_PGUP: if(li->numItems <= 0) break; li->startShowItem -= li->curHeight - 1; if(li->startShowItem < 0) li->startShowItem = 0; li->currItem -= li->curHeight - 1; if(li->currItem < 0) li->currItem = 0; newtListboxRealSetCurrent(co); er.result = ER_SWALLOWED; break; case NEWT_KEY_PGDN: if(li->numItems <= 0) break; li->startShowItem += li->curHeight; if(li->startShowItem > (li->numItems - li->curHeight)) { li->startShowItem = li->numItems - li->curHeight; } li->currItem += li->curHeight; if(li->currItem >= li->numItems) { li->currItem = li->numItems - 1; } newtListboxRealSetCurrent(co); er.result = ER_SWALLOWED; break; case NEWT_KEY_HOME: if(li->numItems <= 0) break; newtListboxSetCurrent(co, 0); er.result = ER_SWALLOWED; break; case NEWT_KEY_END: if(li->numItems <= 0) break; li->startShowItem = li->numItems - li->curHeight; if(li->startShowItem < 0) li->startShowItem = 0; li->currItem = li->numItems - 1; newtListboxRealSetCurrent(co); er.result = ER_SWALLOWED; break; default: if (li->numItems <= 0) break; if (ev.u.key < NEWT_KEY_EXTRA_BASE && isalpha(ev.u.key)) { for(i = 0, item = li->boxItems; item != NULL && i < li->currItem; i++, item = item->next); if (item && item->text && (toupper(*item->text) == toupper(ev.u.key))) { item = item->next; i++; } else { item = li->boxItems; i = 0; } while (item && item->text && toupper(*item->text) != toupper(ev.u.key)) { item = item->next; i++; } if (item) { li->currItem = i; if(li->currItem < li->startShowItem || li->currItem > li->startShowItem) li->startShowItem = li->currItem > li->numItems - li->curHeight ? li->startShowItem = li->numItems - li->curHeight : li->currItem; if(li->sb) newtScrollbarSet(li->sb, li->currItem + 1, li->numItems); newtListboxRealSetCurrent(co); er.result = ER_SWALLOWED; } } } break; case EV_FOCUS: li->isActive = 1; listboxDraw(co); if(li->flags & NEWT_FLAG_SHOWCURSOR) newtCursorOn(); er.result = ER_SWALLOWED; break; case EV_UNFOCUS: li->isActive = 0; listboxDraw(co); if(li->flags & NEWT_FLAG_SHOWCURSOR) newtCursorOff(); er.result = ER_SWALLOWED; break; case EV_MOUSE: /* if this mouse click was within the listbox, make the current item the item clicked on. */ /* Up scroll arrow */ if (li->sb && ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 && ev.u.mouse.y == co->top + li->bdyAdjust) { if(li->numItems <= 0) break; if(li->currItem > 0) { li->currItem--; if(li->currItem < li->startShowItem) li->startShowItem = li->currItem; if(li->sb) newtScrollbarSet(li->sb, li->currItem + 1, li->numItems); listboxDraw(co); } if(co->callback) co->callback(co, co->callbackData); er.result = ER_SWALLOWED; break; } /* Down scroll arrow */ if (li->sb && ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 && ev.u.mouse.y == co->top + co->height - li->bdyAdjust - 1) { if(li->numItems <= 0) break; if(li->currItem < li->numItems - 1) { li->currItem++; if(li->currItem > (li->startShowItem + li->curHeight - 1)) { li->startShowItem = li->currItem - li->curHeight + 1; if(li->startShowItem + li->curHeight > li->numItems) li->startShowItem = li->numItems - li->curHeight; } if(li->sb) newtScrollbarSet(li->sb, li->currItem + 1, li->numItems); listboxDraw(co); } if(co->callback) co->callback(co, co->callbackData); er.result = ER_SWALLOWED; break; } if ((ev.u.mouse.y >= co->top + li->bdyAdjust) && (ev.u.mouse.y <= co->top + co->height - (li->bdyAdjust * 2)) && (ev.u.mouse.x >= co->left + li->bdxAdjust) && (ev.u.mouse.x <= co->left + co->width + (li->bdxAdjust * 2))) { li->currItem = li->startShowItem + (ev.u.mouse.y - li->bdyAdjust - co->top); newtListboxRealSetCurrent(co); listboxDraw(co); if(co->callback) co->callback(co, co->callbackData); er.result = ER_SWALLOWED; break; } } return er; }
// return a malloc()ed path char *filesel(char *dr) { newtComponent lb, b1, b2, b3, l1, l2, f; const char *enr2, *enr3; char *curv; char curvv[PATH_MAX]; // stupid, but who cares... int i, cnt; fde *sel, *sela; char cwd[PATH_MAX], cwdcd[PATH_MAX], *ret=NULL; struct newtExitStruct es; struct stat st; newtCenteredWindow(65, 15, i18n("Select path")); f = newtForm(NULL, NULL, 0); b1 = newtCompactButton(59, 14, i18n("Ok")); b3 = newtCompactButton(45, 14, i18n("Cancel")); l2 = newtEntry(1, 14, "", 25, &enr3, NEWT_FLAG_SCROLL); b2 = newtCompactButton(26, 14, i18n("Create dir")); lb = newtListbox(1, 2, 12, /*NEWT_FLAG_MULTIPLE |*/ /*NEWT_FLAG_BORDER | */ NEWT_FLAG_RETURNEXIT | NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR); if(dr && strlen(dr) > 0) { // let it show the file or dir at any case l1 = newtEntry(1, 0, dr, 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED); stat(dr,&st); if(S_ISDIR(st.st_mode)) { dir_here(lb,dr); strcpy(cwd,dr); } else { dir_here(lb,dirname(dr)); strcpy(cwd,dirname(dr)); } } else { // if NULL, show the current dir l1 = newtEntry(1, 0, get_current_dir_name(), 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED); dir_here(lb,get_current_dir_name()); strcpy(cwd,get_current_dir_name()); } newtListboxSetWidth(lb,63); newtFormAddComponents(f, lb,l1, l2, b2, b1, b3, NULL); newtRefresh(); newtFormSetTimer(f, 200); do { newtFormRun(f, &es); if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == lb) { sel=(fde*)newtListboxGetCurrent(lb); if (sel && S_ISDIR(sel->st.st_mode)) { cnt=newtListboxItemCount(lb); // delete items there: for(i=0; i < cnt; i++) { newtListboxGetEntry(lb, i, &curv, (void**)&sela); if(sela != sel) { free(sela->name); free(sela); } else { strcpy(curvv, curv); } } newtListboxClear(lb); dir_here(lb,sel->name); if(strcmp(curvv,"..") == 0) set_lb_cursor(lb,cwdcd); strcpy(cwd,sel->name); strcpy(cwdcd,sel->name); newtEntrySet(l1, sel->name, 1); if(sel) { free(sel->name); free(sel); } } if(sel && S_ISREG(sel->st.st_mode)) // is a directory { newtEntrySet(l1, sel->name, 1); } } else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b2) { if(strlen(enr3) > 0) { strcpy(cwdcd,cwd); strcat(cwdcd,"/"); strcat(cwdcd,enr3); if(mkdir(cwdcd,0755) == 0) { newtListboxClear(lb); dir_here(lb,cwd); set_lb_cursor(lb,cwdcd); newtEntrySet(l2, "", 1); } } } else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b1) { ret=strdup(enr2); } } while (es.reason != es.NEWT_EXIT_COMPONENT || es.u.co == lb || es.u.co == b2); newtFormDestroy(f); newtPopWindow(); return ret; }
// ======================================================= int CInterfaceNewt::guiInitMainWindow(char *szDevice, char *szImageFile, char *szNetworkIP, DWORD *dwServerPort, bool *bSsl) { newtComponent formMain, btnContinue, btnExit, btnAbout; newtComponent labelPartition, labelImage, editPartition, editImage, btnImage; newtComponent widgetTemp, labelAction, radioSave, radioRestore, radioMbr; newtComponent checkNetwork, labelNetwork, labelPort, editNetwork, editPort, checkSsl; newtExitStruct event; char szTemp[1024]; int nAction; int nRes; showDebug(8, "guiInitMainWindow\n"); SNPRINTF(szTemp, "Partition Image %s", PACKAGE_VERSION); newtCenteredWindow(67, 20, szTemp); labelPartition = newtLabel(1, 0, i18n("* Partition to save/restore")); editPartition = newtListbox(3, 1, 7, NEWT_FLAG_SCROLL); labelImage = newtLabel(1, 9, i18n("* Image file to create/use")); editImage = newtEntry(3, 10, szImageFile, 59, NULL, NEWT_FLAG_SCROLL); btnImage = newtCompactButton(62, 10, "*"); labelAction = newtLabel(1, 12, i18n("Action to be done:")); radioSave = newtRadiobutton(1, 13, i18n("Save partition into a new image file"), true, NULL); radioRestore = newtRadiobutton(1, 14, i18n("Restore partition from an image file"), false, radioSave); radioMbr = newtRadiobutton(1, 15, i18n("Restore an MBR from the image file"), false, radioRestore); checkNetwork = newtCheckbox(1, 17, i18n("Connect to server"), (!!(*szNetworkIP) ? 'X' : ' '), " X", NULL); #ifdef HAVE_SSL checkSsl = newtCheckbox(5, 19, i18n("Encrypt data on the network with SSL"), (*bSsl ? 'X' : ' '), " X", NULL); #else #ifdef MUST_LOGIN checkSsl = newtLabel(5, 19,i18n("SSL disabled at compile time")); #else checkSsl = newtLabel(5, 19,i18n("SSL&login disabled at compile time")); #endif #endif labelNetwork = newtLabel(5, 18, i18n("IP/name of the server:")); editNetwork = newtEntry(28, 18, szNetworkIP, 25, NULL, 0); labelPort = newtLabel(54, 18, i18n("Port:")); SNPRINTF(szTemp, "%u", *dwServerPort); editPort = newtEntry(60, 18, szTemp, 6, NULL, 0); btnContinue = newtCompactButton(50, 12, i18n("Next (F5)")); btnAbout = newtCompactButton(50, 14, i18n("About")); btnExit = newtCompactButton(50, 16, i18n("Exit (F6)")); nRes = fillPartitionList(editPartition); if (nRes == -1) RETURN_int(-1); formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(formMain, labelPartition, labelImage, editPartition, editImage, btnImage, labelAction, radioSave, radioRestore, radioMbr, checkNetwork, labelNetwork, editNetwork, labelPort, editPort, checkSsl, btnContinue, btnAbout, btnExit, NULL); newtFormAddHotKey(formMain, KEY_EXIT); // Exit newtFormAddHotKey(formMain, KEY_OKAY); // Okay begin: /*widgetTemp = */newtFormRun(formMain, &event); widgetTemp = newtFormGetCurrent(formMain); if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_EXIT)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnExit))) //if(widgetTemp == btnExit) return OPERATION_EXIT; if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnAbout)) { showAboutDialog(); goto begin; } if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnImage)) { char *fs_; fs_=filesel(newtEntryGetValue(editImage)); if(fs_) { newtEntrySet(editImage, fs_, 1); // free(fs_); } goto begin; } if (strcmp(newtEntryGetValue(editImage), "") == 0) // if "image" field empty { msgBoxError(i18n("The \"Image\" field is empty. Cannot continue")); goto begin; } if (newtCheckboxGetValue(checkNetwork) == 'X') { if (!(*newtEntryGetValue(editNetwork))) { msgBoxError(i18n("The \"Server IP/Name\" field is empty. Cannot continue")); goto begin; } if (!atoi((char*)newtEntryGetValue(editPort))) { msgBoxError(i18n("The \"Server Port\" field is not a valid integer. Cannot continue")); goto begin; } } // get device strcpy(szDevice, (char*)newtListboxGetCurrent(editPartition)); // image file strcpy(szImageFile, newtEntryGetValue(editImage)); // network if (newtCheckboxGetValue(checkNetwork) == 'X') // If network is activated { strcpy(szNetworkIP, (char*)newtEntryGetValue(editNetwork)); *dwServerPort = atoi((char*)newtEntryGetValue(editPort)); #ifdef HAVE_SSL *bSsl = (newtCheckboxGetValue(checkSsl) == 'X'); #endif } else // no network { *szNetworkIP = 0; *dwServerPort = OPTIONS_DEFAULT_SERVERPORT; } nAction = 0; if (newtRadioGetCurrent(radioRestore) == radioSave) { nAction = OPERATION_SAVE; } else if (newtRadioGetCurrent(radioRestore) == radioRestore) { nAction = OPERATION_RESTORE; } else if (newtRadioGetCurrent(radioRestore) == radioMbr) { nAction = OPERATION_RESTMBR; } newtFormDestroy(formMain); newtPopWindow(); return nAction; }