static int manage_calls(char *host) { newtComponent form; newtComponent quit; newtComponent hangup; newtComponent redirect; newtComponent channels; struct newtExitStruct es; char tmp[80]; /* If there's one thing you learn from this code, it is this... Never, ever fly Air France. Their customer service is absolutely the worst. I've never heard the words "That's not my problem" as many times as I have from their staff -- It should, without doubt be their corporate motto if it isn't already. Don't bother giving them business because you're just a pain in their side and they will be sure to let you know the first time you speak to them. If you ever want to make me happy just tell me that you, too, will never fly Air France again either (in spite of their excellent cuisine). */ snprintf(tmp, sizeof(tmp), "Asterisk Manager at %s", host); newtCenteredWindow(74, 20, tmp); form = newtForm(NULL, NULL, 0); newtFormWatchFd(form, session.fd, NEWT_FD_READ); newtFormSetTimer(form, 100); quit = newtButton(62, 16, "Quit"); redirect = newtButton(35, 16, "Redirect"); hangup = newtButton(50, 16, "Hangup"); channels = newtListbox(1,1,14, NEWT_FLAG_SCROLL); newtFormAddComponents(form, channels, redirect, hangup, quit, NULL); newtListboxSetWidth(channels, 72); show_doing("Getting Status", "Retrieving system status..."); try_status(); hide_doing(); for(;;) { newtFormRun(form, &es); if (has_input(&session) || (es.reason == NEWT_EXIT_FDREADY)) { if (input_check(&session, NULL)) { show_message("Disconnected", "Disconnected from remote host"); break; } } else if (es.reason == NEWT_EXIT_COMPONENT) { if (es.u.co == quit) break; if (es.u.co == hangup) { try_hangup(channels); } else if (es.u.co == redirect) { try_redirect(channels); } } rebuild_channels(channels); } newtFormDestroy(form); return 0; }
static void nmt_newt_listbox_size_allocate (NmtNewtWidget *widget, int x, int y, int width, int height) { NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (widget); if (width > priv->width) { newtListboxSetWidth (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)), width); } NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)-> size_allocate (widget, x, y, width, height); priv->alloc_height = height; if (!priv->fixed_height && height != priv->height) { priv->height = height; nmt_newt_widget_needs_rebuild (widget); } }
static void show_spans(void) { newtComponent form; newtComponent quit; newtComponent label; newtComponent sel; struct newtExitStruct es; quit = newtButton(50,14,"Quit"); sel = newtButton(10,14,"Select"); spans = newtListbox(5, 2, 10, NEWT_FLAG_SCROLL); newtListboxSetWidth(spans, 65); label = newtLabel(5,1,"Alarms Span"); newtCenteredWindow(72,18, "DAHDI Telephony Interfaces"); form = newtForm(NULL, NULL, 0); newtFormSetTimer(form, 200); newtFormAddComponents(form, spans, sel, quit, label, NULL); newtComponentAddCallback(spans, sel_callback, NULL); newtFormAddHotKey(form, NEWT_KEY_F1); newtFormAddHotKey(form, NEWT_KEY_F10); for(;;) { /* Wait for user to select something */ do { add_cards(spans); newtFormRun(form, &es); } while(es.reason == NEWT_EXIT_TIMER); switch(es.reason) { case NEWT_EXIT_COMPONENT: if (es.u.co == quit) { /* Quit if appropriate */ newtFormDestroy(form); return; } else if (es.u.co == sel) { show_span(-1); } break; case NEWT_EXIT_HOTKEY: switch(es.u.key) { case NEWT_KEY_F1: show_span(-1); break; case NEWT_KEY_F10: newtFormDestroy(form); return; } break; default: break; } } }
/* 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; }
// 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; }