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 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); }
/** * 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(); }
// 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; }