struct ui_progress *ui_progress__new(const char *title, u64 total) { struct ui_progress *self = malloc(sizeof(*self)); if (self != NULL) { int cols; if (use_browser <= 0) return self; newtGetScreenSize(&cols, NULL); cols -= 4; newtCenteredWindow(cols, 1, title); self->form = newtForm(NULL, NULL, 0); if (self->form == NULL) goto out_free_self; self->scale = newtScale(0, 0, cols, total); if (self->scale == NULL) goto out_free_form; newtFormAddComponent(self->form, self->scale); newtRefresh(); } return self; out_free_form: newtFormDestroy(self->form); out_free_self: free(self); return NULL; }
/* newtScale mechanism borrowed from redhat installer */ int mysystem_progress(char *command, void *form, int left, int top, int width, int lines, int offset) { int progress = offset; newtComponent *f = (newtComponent *) form; newtComponent s; FILE *p; char buffer[STRING_SIZE]; s = newtScale(left, top, width, lines); newtScaleSet(s, progress); newtFormAddComponent(*f, s); newtDrawForm(*f); newtRefresh(); if (flog != NULL) { fprintf(flog, "Running command: %s\n", command); } if (!(p = popen(command, "r"))) { return 1; } setvbuf(p, NULL, _IOLBF, 255); while (fgets(buffer, STRING_SIZE, p)) { newtScaleSet(s, ++progress); newtRefresh(); } return pclose(p); }
// ======================================================= int CRestoringWindow::create(char *szDevice, char *szImageFile, QWORD qwCurPartSize, DWORD dwCompressionMode, char *szOriginalDevice, char *szFileSystem, tm dateCreate, QWORD qwOrigPartSize, COptions * options) { BEGIN; char szTemp[2048]; char szTemp2[2048]; if (options->bSimulateMode) SNPRINTF(szTemp, i18n("simulate partition restoration from image file")); else SNPRINTF(szTemp, i18n("restore partition from image file")); newtCenteredWindow(78, 20, szTemp); SNPRINTF(szTemp, i18n("Partition to restore:.............%s"), szDevice); m_labelPartition = newtLabel(1, 0, szTemp); SNPRINTF(szTemp, i18n("Size of partition to restore:.....%s = %llu bytes"), formatSize(qwCurPartSize, szTemp2), qwCurPartSize); m_labelPartitionSize = newtLabel(1, 1, szTemp); SNPRINTF(szTemp, i18n("Image file to use.................%s"), szImageFile); m_labelImageFile = newtLabel(1, 2, szTemp); SNPRINTF(szTemp, i18n("File system:......................%s"), szFileSystem); m_labelFS = newtLabel(1, 3, szTemp); m_labelCompression = newtLabel(1, 4, ""); SNPRINTF(szTemp, i18n("Partition was on device:..........%s\n"), szOriginalDevice); m_labelOldDevice = newtLabel(1, 5, szTemp); SNPRINTF(szTemp, i18n("Image created on:.................%s\n"), asctime(&dateCreate)); m_labelDate = newtLabel(1, 6, szTemp); SNPRINTF(szTemp, i18n("Size of the original partition:...%s = %llu bytes"), formatSize(qwOrigPartSize, szTemp2), qwOrigPartSize); m_labelOriginalPartitionSize = newtLabel(1, 7, szTemp); // stats m_labelStatsTime = newtLabel(1, 9, ""); m_labelStatsTimeRemaining = newtLabel(1, 10, ""); m_labelStatsSpeed = newtLabel(1, 11, ""); m_labelStatsSpace = newtLabel(1, 12, ""); m_progressRestoring = newtScale(1, 18, 70, 100); m_labelPercent = newtLabel(72, 18, ""); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelPartition, m_labelPartitionSize, m_labelImageFile, m_labelFS, m_labelCompression, NULL); newtFormAddComponents(m_formMain, m_labelOldDevice, m_labelDate, m_labelOriginalPartitionSize, NULL); newtFormAddComponents(m_formMain, m_labelStatsTime, m_labelStatsTimeRemaining, m_labelStatsSpeed, m_labelStatsSpace, NULL); newtFormAddComponents(m_formMain, m_progressRestoring, m_labelPercent, NULL); newtDrawForm(m_formMain); newtRefresh(); RETURN_int(0); }
/** * Open an evalcall form with title @p ttl. * @param ttl The title to use for the evalcall form. */ void open_evalcall_form(char *ttl) { /*@ buffers ********************************************************* */ char *title; char *tmp; /*@ initialize ****************************************************** */ g_isoform_old_progress = -1; g_mysterious_dot_counter = 0; assert(ttl != NULL); asprintf(&title, ttl); // BERLIOS: We need to unallocate it somewhere asprintf(&g_isoform_header_str, title); // center_string (title, 80); if (g_text_mode) { log_msg(0, title); } else { asprintf(&tmp, title); /* BERLIOS: center_string is now broken replace it ! */ //center_string(tmp, 80); newtPushHelpLine(tmp); paranoid_free(tmp); } /* BERLIOS: center_string is now broken replace it ! */ //center_string(g_isoform_header_str, 36); g_isoform_starttime = get_time(); if (g_text_mode) { log_msg(0, g_isoform_header_str); } else { g_isoform_header = newtLabel(1, 1, g_isoform_header_str); g_isoform_scale = newtScale(3, 3, 34, 100); // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); newtCenteredWindow(40, 7, title); g_isoform_main = newtForm(NULL, NULL, 0); g_isoform_timeline = newtLabel(1, 5, "This is the timeline"); g_isoform_pcline = newtLabel(1, 6, "This is the pcline"); newtFormAddComponents(g_isoform_main, g_isoform_timeline, g_isoform_pcline, g_isoform_header, g_isoform_scale, NULL); newtRefresh(); } update_evalcall_form(0); paranoid_free(title); }
void init_progression_raw_newt(const char *msg, int size) { size_progress = size; if (size) { actually_drawn = 0; newtCenteredWindow(70, 5, "Please wait..."); form = newtForm(NULL, NULL, 0); newtFormAddComponent(form, newtLabel(1, 1, msg)); scale = newtScale(1, 3, 68, size); newtFormAddComponent(form, scale); newtDrawForm(form); newtRefresh(); } else { wait_message("%s", msg); msg_progress = msg; } }
struct progressCBdata *winProgressBar(int width, int height, char *title, char *text, ...) { struct progressCBdata *data; char *buf = NULL; va_list args; int llen; newtComponent t, f, scale, label; va_start(args, text); if (vasprintf(&buf, text, args) != -1) { va_end(args); newtCenteredWindow(width, height, title); t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP); newtTextboxSetText(t, buf); llen = strlen(buf); free(buf); label = newtLabel(llen + 1, 1, "-"); f = newtForm(NULL, NULL, 0); newtFormAddComponent(f, t); scale = newtScale(3, 3, width - 6, 100); newtFormAddComponent(f, scale); newtDrawForm(f); newtRefresh(); if ((data = malloc(sizeof(struct progressCBdata))) == NULL) { logMessage(ERROR, "%s: %d: %m", __func__, __LINE__); abort(); } data->scale = scale; data->label = label; return data; } return NULL; }
int doMediaCheck(char *file, char *descr) { struct progressCBdata data; newtComponent t, f, scale, label; int rc; int dlen; int llen; char tmpstr[1024]; if (access(file, R_OK) < 0) { newtWinMessage(_("Error"), _("OK"), _("Unable to find install image " "%s"), file); return -1; } if (descr) snprintf(tmpstr, sizeof(tmpstr), _("Checking \"%s\"..."), descr); else snprintf(tmpstr, sizeof(tmpstr), _("Checking media now...")); dlen = strlen(tmpstr); if (dlen > 65) dlen = 65; newtCenteredWindow(dlen+8, 6, _("Media Check")); t = newtTextbox(1, 1, dlen+4, 3, NEWT_TEXTBOX_WRAP); newtTextboxSetText(t, tmpstr); llen = strlen(tmpstr); label = newtLabel(llen+1, 1, "-"); f = newtForm(NULL, NULL, 0); newtFormAddComponent(f, t); scale = newtScale(3, 3, dlen, 100); newtFormAddComponent(f, scale); newtDrawForm(f); newtRefresh(); data.scale = scale; data.label = label; rc = mediaCheckFile(file, progressCallback, &data); newtFormDestroy(f); newtPopWindow(); if (rc == -1) { logMessage(WARNING, "mediacheck: %s (%s) has no checksum info", file, descr); newtWinMessage(_("Error"), _("OK"), _("Unable to read the disc checksum from the " "primary volume descriptor. This probably " "means the disc was created without adding the " "checksum.")); } else if (rc == 0) { logMessage(ERROR, "mediacheck: %s (%s) FAILED", file, descr); newtWinMessage(_("Error"), _("OK"), _("The image which was just tested has errors. " "This could be due to a " "corrupt download or a bad disc. " "If applicable, please clean the disc " "and try again. If this test continues to fail you " "should not continue the install.")); } else if (rc > 0) { logMessage(INFO, "mediacheck: %s (%s) PASSED", file, descr); newtWinMessage(_("Success"), _("OK"), _("The image which was just tested was successfully " "verified. It should be OK to install from this " "media. Note that not all media/drive errors can " "be detected by the media check.")); } return rc; }
int gauge(const char * text, int height, int width, poptContext optCon, int fd, int flags) { newtComponent form, scale, tb; int top; const char * arg; char * end; int val; FILE * f = fdopen(fd, "r"); char buf[3000]; char buf3[50]; int i; setlinebuf(f); if (!(arg = poptGetArg(optCon))) return DLG_ERROR; val = strtoul(arg, &end, 10); if (*end) return DLG_ERROR; tb = textbox(height - 3, width - 2, text, flags, &top); form = newtForm(NULL, NULL, 0); scale = newtScale(2, height - 2, width - 4, 100); newtScaleSet(scale, val); newtFormAddComponents(form, tb, scale, NULL); newtDrawForm(form); newtRefresh(); while (fgets(buf, sizeof(buf) - 1, f)) { buf[strlen(buf) - 1] = '\0'; if (!strcmp(buf, "XXX")) { fgets(buf3, sizeof(buf3) - 1, f); buf3[strlen(buf3) - 1] = '\0'; arg = buf3; i = 0; while (fgets(buf + i, sizeof(buf) - 1 - i, f)) { buf[strlen(buf) - 1] = '\0'; if (!strcmp(buf + i, "XXX")) { *(buf + i) = '\0'; break; } i = strlen(buf); } newtTextboxSetText(tb, buf); } else { arg = buf; } val = strtoul(buf, &end, 10); if (!*end) { newtScaleSet(scale, val); newtDrawForm(form); newtRefresh(); } } return DLG_OKAY; }
/** * Open a progress form with title @p title. * @param title The title to use for the progress form (will be put in the title bar on Newt). * @param b1 The first line of the blurb; generally static. * @param b2 The second line of the blurb; generally static. * @param b3 The third line of the blurb; generally dynamic (it is passed * to update_evalcall_form() every time). * @param max_val The maximum amount of progress (number of filesets, etc.) */ void open_progress_form(char *title, char *b1, char *b2, char *b3, long max_val) { /*@ buffers ********************************************************* */ char *b1c; char *blurb1; char *blurb2; char *blurb3; /*@ initialize ****************************************************** */ g_mysterious_dot_counter = 0; assert(title != NULL); assert(b1 != NULL); assert(b2 != NULL); assert(b3 != NULL); asprintf(&blurb1, b1); asprintf(&blurb2, b2); asprintf(&blurb3, b3); asprintf(&b1c, b1); /* BERLIOS: center_string is now broken replace it ! */ //center_string(b1c, 80); if (max_val <= 0) { max_val = 1; } g_start_time = get_time(); g_maximum_progress = max_val; g_current_progress = 0; // BERLIOS: We need to unallocate them asprintf(&g_blurb_str_1, blurb1); asprintf(&g_blurb_str_2, blurb3); asprintf(&g_blurb_str_3, blurb2); if (g_text_mode) { log_msg(0, blurb1); log_msg(0, blurb2); log_msg(0, blurb3); } else { g_blurb1 = newtLabel(2, 1, blurb1); g_blurb2 = newtLabel(2, 2, blurb3); g_blurb3 = newtLabel(2, 4, blurb2); // newtOpenWindow (10, 4, 60, 11, title); newtCenteredWindow(60, 11, title); g_scale = newtScale(3, 6, 54, g_maximum_progress); g_progressForm = newtForm(NULL, NULL, 0); g_percentline = newtLabel(10, 9, "This is the percentline"); g_timeline = newtLabel(10, 8, "This is the timeline"); newtFormAddComponents(g_progressForm, g_percentline, g_timeline, g_scale, g_blurb1, g_blurb3, g_blurb2, NULL); newtPushHelpLine(b1c); newtRefresh(); } update_progress_form_full(blurb1, blurb2, blurb3); paranoid_free(b1c); paranoid_free(blurb1); paranoid_free(blurb2); paranoid_free(blurb3); }
int main(void) { newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale; newtComponent lb, t, rsf, answer, timeLabel; newtComponent cs[10]; newtComponent f, chklist, e1; struct callbackInfo cbis[3]; char results[10]; char * enr2, * enr3, * scaleVal; void ** selectedList; int i, numsel; char buf[20]; const char * spinner = "-\\|/\\|/"; const char * spinState; struct newtExitStruct es; newtInit(); newtCls(); newtSetSuspendCallback(suspend, NULL); newtSetHelpCallback(helpCallback); newtDrawRootText(0, 0, "Newt test program"); newtPushHelpLine(NULL); newtDrawRootText(-50, 0, "More root text"); newtOpenWindow(2, 2, 30, 10, "first window"); newtOpenWindow(10, 5, 65, 16, "window 2"); f = newtForm(NULL, "This is some help text", 0); chklist = newtForm(NULL, NULL, 0); b1 = newtButton(3, 1, "Exit"); b2 = newtButton(18, 1, "Update"); r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL); r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1); r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2); rsf = newtForm(NULL, NULL, 0); newtFormAddComponents(rsf, r1, r2, r3, NULL); newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX); for (i = 0; i < 10; i++) { sprintf(buf, "Check %d", i); cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]); newtFormAddComponent(chklist, cs[i]); } l1 = newtLabel(3, 6, "Scale:"); l2 = newtLabel(3, 7, "Scrolls:"); l3 = newtLabel(3, 8, "Hidden:"); e1 = newtEntry(12, 6, "", 20, &scaleVal, 0); e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL); /* e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */ e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD); cbis[0].state = &results[0]; cbis[0].en = e1; newtComponentAddCallback(cs[0], disableCallback, &cbis[0]); scale = newtScale(3, 14, 32, 100); newtFormSetHeight(chklist, 3); newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL); newtFormAddComponents(f, rsf, scale, NULL); lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER | NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR); newtListboxAppendEntry(lb, "First", (void *) 1); newtListboxAppendEntry(lb, "Second", (void *) 2); newtListboxAppendEntry(lb, "Third", (void *) 3); newtListboxAppendEntry(lb, "Fourth", (void *) 4); newtListboxAppendEntry(lb, "Sixth", (void *) 6); newtListboxAppendEntry(lb, "Seventh", (void *) 7); newtListboxAppendEntry(lb, "Eighth", (void *) 8); newtListboxAppendEntry(lb, "Ninth", (void *) 9); newtListboxAppendEntry(lb, "Tenth", (void *) 10); newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4); newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10); newtListboxDeleteEntry(lb, (void *) 11); spinState = spinner; timeLabel = newtLabel(45, 8, "Spinner: -"); t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP); newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed"); newtFormAddComponents(f, lb, timeLabel, t, NULL); newtRefresh(); newtFormSetTimer(f, 200); do { newtFormRun(f, &es); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) { newtScaleSet(scale, atoi(scaleVal)); newtRefresh(); answer = NULL; } else if (es.reason == NEWT_EXIT_TIMER) { spinState++; if (!*spinState) spinState = spinner; sprintf(buf, "Spinner: %c", *spinState); newtLabelSetText(timeLabel, buf); } } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2); scaleVal = strdup(scaleVal); enr2 = strdup(enr2); enr3 = strdup(enr3); selectedList = newtListboxGetSelection(lb, &numsel); newtFormDestroy(f); newtPopWindow(); newtPopWindow(); newtFinished(); printf("got string 1: %s\n", scaleVal); printf("got string 2: %s\n", enr2); printf("got string 3: %s\n", enr3); if(selectedList) { printf("\nSelected listbox items:\n"); for(i = 0; i < numsel; i++) puts(selectedList[i]); } return 0; }
// ======================================================= int CSavingWindow::create(const char *szDevice, const char *szImageFile, const char *szFilesystem, QWORD qwPartSize, COptions options) { BEGIN; char szTemp[1024]; char szTemp2[1024]; SNPRINTF(szTemp, i18n("save partition to image file")); newtCenteredWindow(78, 20, szTemp); SNPRINTF(szTemp, i18n("Partition to save:...........%s"), szDevice); m_labelPartition = newtLabel(1, 0, szTemp); SNPRINTF(szTemp, i18n("Size of the Partition:.......%s = %llu bytes"), formatSize(qwPartSize, szTemp2), qwPartSize); m_labelPartitionSize = newtLabel(1, 1, szTemp); SNPRINTF(szTemp, i18n("Image file to create.........%s"), szImageFile); m_labelImageFile = newtLabel(1, 2, szTemp); m_labelImageFileSize = newtLabel(1, 3, ""); m_labelFreeSpace = newtLabel(1, 4, ""); SNPRINTF(szTemp, i18n("Detected file system:........%s"), szFilesystem); m_labelFS = newtLabel(1, 5, szTemp); switch (options.dwCompression) { case COMPRESS_NONE: SNPRINTF(szTemp, i18n("Compression level:...........None")); break; case COMPRESS_GZIP: SNPRINTF(szTemp, i18n("Compression level:...........gzip")); break; case COMPRESS_BZIP2: SNPRINTF(szTemp, i18n("Compression level:...........bzip2")); break; case COMPRESS_LZO: SNPRINTF(szTemp, i18n("Compression level:...........lzo")); break; } m_labelCompression = newtLabel(1, 6, szTemp); // stats m_labelStatsTime = newtLabel(1, 9, ""); m_labelStatsTimeRemaining = newtLabel(1, 10, ""); m_labelStatsSpeed = newtLabel(1, 11, ""); m_labelStatsSpace = newtLabel(1, 12, ""); m_progressSaving = newtScale(1, 18, 70, 100); m_labelPercent = newtLabel(72, 18, ""); m_formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(m_formMain, m_labelPartition, m_labelPartitionSize, m_labelImageFile, m_labelImageFileSize, m_labelFreeSpace, m_labelFS, m_labelCompression, NULL); newtFormAddComponents(m_formMain, m_labelStatsTime, m_labelStatsTimeRemaining, m_labelStatsSpeed, m_labelStatsSpace, NULL); newtFormAddComponents(m_formMain, m_progressSaving, m_labelPercent, NULL); newtRefresh(); newtDrawForm(m_formMain); RETURN_int(0); }
void play_wav_file(char *filename) { char *inwavbuf; short *current; short *audioend; short *audio; WAVE_HEADER *wav_info; int wavfd; int dspfd; struct stat input_fstat; size_t interval; newtComponent vu_1sec; newtComponent vu_total; newtComponent wav_length; newtComponent label_length; newtComponent mainwaveform; newtComponent label_1sec; newtComponent label_total; newtComponent rf_result; char labelstr_1sec[10] = "0"; char labelstr_total[10] = "0"; char labelstr_length[10] = ""; short one_sec_max, total_max; wavfd = open(filename,O_RDONLY,0600); if (wavfd == -1) { printf("Error: open() %s\n",strerror(errno)); exit(1); } if (fstat(wavfd,&input_fstat) != 0) { printf("Error: fstat() %s\n",strerror(errno)); return; } if (input_fstat.st_size < sizeof(WAVE_HEADER)) { printf("File is not large enough to hold a .wav file header even!\n"); return; } inwavbuf = mmap(NULL,input_fstat.st_size,PROT_READ,MAP_SHARED,wavfd,0); if (inwavbuf == MAP_FAILED) { printf("Error: mmap() %s\n",strerror(errno)); exit(1); } audio = (short *)validate_wav_header(inwavbuf,0); current = audio; if (current == NULL) { printf("This program didn't like the wav file\n"); exit(1); } wav_info = (WAVE_HEADER *)inwavbuf; audioend = (short *)((char *)audio + wav_info->nDataBytes); dspfd = open_dsp(wav_info); newtCls(); newtDrawRootText(0, 0, filename); mainwaveform = newtForm(NULL, NULL, NEWT_FLAG_NOF12); vu_1sec = newtScale(9,5,68,(long long)(SHRT_MAX)); label_1sec = newtLabel(1,5,labelstr_1sec); wav_length = newtScale(9,3,68,audioend - audio); label_length = newtLabel(1,3,labelstr_length); vu_total = newtScale(9,8,68,(long long)(SHRT_MAX)); label_total = newtLabel(1,8,labelstr_total); newtFormAddComponent(mainwaveform,vu_1sec); newtFormAddComponent(mainwaveform,vu_total); newtFormAddComponent(mainwaveform,label_1sec); newtFormAddComponent(mainwaveform,label_total); one_sec_max = 0; total_max = 0; newtFormWatchFd(mainwaveform,dspfd,NEWT_FD_WRITE); newtFormAddHotKey(mainwaveform,NEWT_KEY_ENTER); newtPushHelpLine("Hit Enter to end playing"); newtCenteredWindow(78,10,"now playing .wav file"); newtRefresh(); /* presently every second */ interval = (size_t )((double )wav_info->nSamplesPerSec * interval_s * 2); while ((current) < audioend) { short *endcurrent = current + interval; if (endcurrent > audioend) { endcurrent = audioend; } one_sec_max = get_peak_value(current,endcurrent); newtScaleSet(vu_1sec,one_sec_max); sprintf(labelstr_1sec,"%1.6f",((float )one_sec_max/ (float )SHRT_MAX)); newtLabelSetText(label_1sec,labelstr_1sec); newtScaleSet(wav_length,current - audio); sprintf(labelstr_length,"%4.2f", ((double )(current - audio) / 88200)); newtLabelSetText(label_length,labelstr_length); if (one_sec_max > total_max) { total_max = one_sec_max; sprintf(labelstr_total,"%1.6f",((float )total_max/ (float )SHRT_MAX)); newtLabelSetText(label_total,labelstr_total); newtScaleSet(vu_total,total_max); } rf_result = newtRunForm(mainwaveform); if (play_buffer(dspfd,current,endcurrent) == -1) { current = audioend; } current = endcurrent; if (rf_result == NULL) current = audioend; newtRefresh(); } newtFormDestroy(mainwaveform); munmap(inwavbuf,input_fstat.st_size); close(wavfd); close(dspfd); return; }