// ======================================================= void CRestoringWindow::showImageFileInfo(char *szImageFile, int nCompressionMode, char *szFullyBatchMode) { BEGIN; char szTemp[2048]; SNPRINTF(szTemp, i18n("Current image file:...............%s"), szImageFile); newtLabelSetText(m_labelImageFile, szTemp); if (nCompressionMode != -1) { switch (nCompressionMode) { case COMPRESS_NONE: SNPRINTF(szTemp, i18n("Compression level:................None\n")); 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; default: memset(szTemp, 0, sizeof(szTemp)); } newtLabelSetText(m_labelCompression, szTemp); } RETURN; }
// ======================================================= void CSavingWindow::showStats(const time_t timeStart, QWORD qwBlockSize, QWORD qwBlocksDone, QWORD qwBlocksTotal, char *szFullyBatchMode) { BEGIN; char szTemp[1024]; char szTemp2[1024]; char szTemp3[1024]; time_t timeElapsed, timeRemaining; QWORD qwBytesPerMin; float fMinElapsed; QWORD qwPercent; // progress bar qwPercent = (100 * qwBlocksDone) / qwBlocksTotal; SNPRINTF(szTemp, "%d %%", (int)qwPercent); newtScaleSet(m_progressSaving, (int)qwPercent); newtLabelSetText(m_labelPercent, szTemp); // stats if (timeStart != 0) { QWORD qwDone = qwBlockSize * qwBlocksDone; QWORD qwTotal = qwBlockSize * qwBlocksTotal; timeElapsed = time(0) - timeStart; timeRemaining = (timeElapsed * (qwTotal - qwDone)) / qwDone; SNPRINTF(szTemp, i18n("Time elapsed:................%s"), formatTime((DWORD)timeElapsed, szTemp2)); newtLabelSetText(m_labelStatsTime, szTemp); SNPRINTF(szTemp, i18n("Estimated time remaining:....%s"), formatTime((DWORD)timeRemaining, szTemp2)); newtLabelSetText(m_labelStatsTimeRemaining, szTemp); fMinElapsed = ((float)timeElapsed) / 60.0; qwBytesPerMin = (QWORD) (((float)qwDone) / fMinElapsed); SNPRINTF(szTemp, i18n("Speed:.......................%s/min"), formatSize(qwBytesPerMin, szTemp2)); newtLabelSetText(m_labelStatsSpeed, szTemp); SNPRINTF(szTemp, i18n("Data copied:.................%s / %s"), formatSize(qwDone, szTemp2), formatSize(qwTotal, szTemp3)); newtLabelSetText(m_labelStatsSpace, szTemp); //option -B gui=no show stats if ((szFullyBatchMode) && (strlen(szFullyBatchMode)>0)) { SNPRINTF(szTemp, "stats: %3d%%", (int)qwPercent); fprintf(stderr,"%-s ",szTemp); SNPRINTF(szTemp, i18n("%-s %-s"), formatTimeNG((DWORD)timeElapsed, szTemp2), formatTimeNG((DWORD)timeRemaining, szTemp3)); fprintf(stderr,"%-s ",szTemp); SNPRINTF(szTemp, i18n("%s/min"), formatSizeNG(qwBytesPerMin, szTemp2)); fprintf(stderr,"%-s\n",szTemp); } } newtRefresh(); RETURN; }
void progressCallback(void *pbdata, long long pos, long long total) { struct progressCBdata *data = pbdata; char tickmark[2] = "-"; char *ticks = "-\\|/"; int x = ceil(pos * 100.0 / total); newtScaleSet(data->scale, x); *tickmark = ticks[x % 4]; newtLabelSetText(data->label, tickmark); newtRefresh(); }
// ======================================================= void CSavingWindow::showImageFileInfo(char *szImageFile, QWORD qwFreeSpace, QWORD qwImageSize, char *szFullyBatchMode) { BEGIN; char szTemp[2048]; char szTemp2[2048]; SNPRINTF(szTemp, i18n("Current image file:..........%s"), szImageFile); newtLabelSetText(m_labelImageFile, szTemp); if (qwImageSize) { SNPRINTF(szTemp, i18n("Image file size:.............%s"), formatSize(qwImageSize, szTemp2)); newtLabelSetText(m_labelImageFileSize, szTemp); } SNPRINTF (szTemp, i18n("Available space for image:...%s = %llu bytes"), formatSize(qwFreeSpace, szTemp2), qwFreeSpace); newtLabelSetText(m_labelFreeSpace, szTemp); RETURN; }
static void readCB(void *co, long long pos) { struct progressCBdata *data = co; static int tick = 0; char tickmark[2] = "-"; char * ticks = "-\\|/"; newtScaleSet(data->scale, pos); tick++; if (tick > 399) tick = 0; *tickmark = ticks[tick / 100]; newtLabelSetText(data->label, tickmark); newtRefresh(); }
/** * Update the evalcall form to show <tt>num</tt> %. * @param num The numerator of the ratio. */ void update_evalcall_form(int num) { /*@ long ************************************************************ */ long current_time = 0; long time_taken = 0; long time_total_est = 0; long time_remaining = 0; /*@ buffers ********************************************************** */ char *timeline_str; char *pcline_str; char *taskprogress; char *tmp1; char *tmp2; char *p; /*@ int ************************************************************** */ int percentage = 0; int i = 0; int j = 0; //log_it("update_eval_call_form called"); if (num < 1) { percentage = 1; } else { percentage = (int) trunc(num); } current_time = get_time(); time_taken = current_time - g_isoform_starttime; if (num) { time_total_est = time_taken * 100 / num; time_remaining = time_total_est - time_taken; } else { time_remaining = 0; } if (!g_text_mode) { newtLabelSetText(g_isoform_header, g_isoform_header_str); } /* BERLIOS: 27 should be a parameter */ g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; if ((percentage < 3 && g_isoform_old_progress < 3) || percentage > g_isoform_old_progress) { g_isoform_old_progress = percentage; asprintf(&timeline_str, _("%2ld:%02ld taken %2ld:%02ld remaining"), time_taken / 60, time_taken % 60, time_remaining / 60, time_remaining % 60); if (percentage < 3) { tmp1 = (char *) malloc(g_mysterious_dot_counter * sizeof(char)); for (i = 0, p = tmp1; i < g_mysterious_dot_counter - 1; i++, p++) { *p = '.'; } *p = '\0'; /* BERLIOS: 27 should be a parameter */ tmp2 = (char *) malloc(27 - g_mysterious_dot_counter * sizeof(char)); for (i = 0, p = tmp2; i < 27 - g_mysterious_dot_counter - 1; i++, p++) { *p = ' '; } *p = '\0'; asprintf(&pcline_str, " Working%s%s %c", tmp1, tmp2, special_dot_char(g_mysterious_dot_counter)); paranoid_free(tmp1); paranoid_free(tmp2); } else { asprintf(&pcline_str, _(" %3d%% done %3d%% to go"), percentage, 100 - percentage); } if (g_text_mode) { j = trunc(percentage / 5); tmp1 = (char *) malloc((j + 1) * sizeof(char)); for (i = 0, p = tmp1; i < j; i++, p++) { *p = '*'; } *p = '\0'; tmp2 = (char *) malloc((20 - j + 1) * sizeof(char)); for (i = 0, p = tmp2; i < 20 - j; i++, p++) { *p = '.'; } *p = '\0'; if (percentage >= 3) { asprintf(&taskprogress, "TASK: [%s%s] %3d%% done; %2ld:%02ld to go", tmp1, tmp2, percentage, time_remaining / 60, time_remaining % 60); printf("---evalcall---1--- %s\r\n", g_isoform_header_str); printf("---evalcall---2--- %s\r\n", taskprogress); printf("---evalcall---E---\r\n"); paranoid_free(taskprogress); } } else { newtScaleSet(g_isoform_scale, (unsigned long long) percentage); newtLabelSetText(g_isoform_pcline, pcline_str); if (percentage >= 3) { newtLabelSetText(g_isoform_timeline, timeline_str); } } paranoid_free(timeline_str); paranoid_free(pcline_str); } if (!g_text_mode) { // log_it("refreshing"); newtRefresh(); } }
/** * Update the progress form's complete blurb and show @p g_current_progress. * @param blurb1 The first line of the blurb. Use @p g_blurb_str_1 to keep it unchanged. * @param blurb2 The second line of the blurb. Use @p g_blurb_str_3 (no, that's not a typo) to keep it the same. * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same. */ void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { /*@ long ***************************************************** */ long current_time = 0; long time_taken = 0; long time_remaining = 0; long time_total_est = 0; /*@ int ******************************************************* */ int percentage = 0; int i = 0; int j = 0; /*@ buffers *************************************************** */ char *percentline_str; char *timeline_str; char *taskprogress; char *tmp; char *tmp1; char *tmp2; char *p; // log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3); if (!g_text_mode) { assert(blurb1 != NULL); assert(blurb2 != NULL); assert(blurb3 != NULL); assert(g_timeline != NULL); } current_time = get_time(); time_taken = current_time - g_start_time; if (g_maximum_progress == 0) { percentage = 0; } else { if (g_current_progress > g_maximum_progress) { asprintf(&tmp, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", blurb1, blurb2, blurb3, g_current_progress, g_maximum_progress); log_msg(0, tmp); paranoid_free(tmp); g_current_progress = g_maximum_progress; } percentage = (int) ((g_current_progress * 100L) / g_maximum_progress); } if (percentage < 1) { percentage = 1; } if (percentage > 100) { percentage = 100; } if (g_current_progress) { time_total_est = time_taken * (long) g_maximum_progress / (long) (g_current_progress); time_remaining = time_total_est - time_taken; } else { time_remaining = 0; } /* BERLIOS/ Is it useful here ? */ //g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; asprintf(&timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining ", time_taken / 60, time_taken % 60, time_remaining / 60, time_remaining % 60); asprintf(&percentline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage); if (g_text_mode) { printf(_("---progress-form---1--- %s%s"), blurb1, "\r\n"); printf(_("---progress-form---2--- %s%s"), blurb2, "\r\n"); printf(_("---progress-form---3--- %s%s"), blurb3, "\r\n"); printf(_("---progress-form---E---\n")); j = trunc(percentage / 5); tmp1 = (char *) malloc((j + 1) * sizeof(char)); for (i = 0, p = tmp1; i < j; i++, p++) { *p = '*'; } *p = '\0'; tmp2 = (char *) malloc((20 - j + 1) * sizeof(char)); for (i = 0, p = tmp2; i < 20 - j; i++, p++) { *p = '.'; } *p = '\0'; if (percentage > 100) { log_msg(2, _("percentage = %d"), percentage); } asprintf(&taskprogress, _("TASK: [%s%s] %3d%% done; %2ld:%02ld to go"), tmp1, tmp2, percentage, time_remaining / 60, time_remaining % 60); printf(_("---progress-form---4--- %s\r\n"), taskprogress); paranoid_free(taskprogress); } else { /* BERLIOS: center_string is now broken replace it ! */ //center_string(blurb1, 54); /* BERLIOS: center_string is now broken replace it ! */ //center_string(blurb2, 54); /* BERLIOS: center_string is now broken replace it ! */ //center_string(blurb3, 54); newtLabelSetText(g_blurb1, blurb1); newtLabelSetText(g_blurb2, blurb3); newtLabelSetText(g_blurb3, blurb2); newtScaleSet(g_scale, (unsigned long long) g_current_progress); if (percentage >= 2) { newtLabelSetText(g_timeline, timeline_str); } newtLabelSetText(g_percentline, percentline_str); newtRefresh(); } paranoid_free(percentline_str); paranoid_free(timeline_str); }
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; }
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; }