/* prints a progress bar for file transfers. if friendnum is -1 we're sending the file, otherwise we're receiving. */ void print_progress_bar(ToxWindow *self, double bps, double pct_done, uint32_t line_id) { if (bps < 0 || pct_done < 0 || pct_done > 100) return; char msg[MAX_STR_SIZE]; bytes_convert_str(msg, sizeof(msg), bps); strcat(msg, "/s ["); int n = pct_done / (100 / NUM_PROG_MARKS); int i, j; for (i = 0; i < n; ++i) strcat(msg, "#"); for (j = i; j < NUM_PROG_MARKS; ++j) strcat(msg, "-"); strcat(msg, "] "); char pctstr[16]; const char *frmt = pct_done == 100 ? "%.f%%" : "%.1f%%"; snprintf(pctstr, sizeof(pctstr), frmt, pct_done); strcat(msg, pctstr); line_info_set(self, line_id, msg); }
/* prints a progress bar for file transfers. if friendnum is -1 we're sending the file, otherwise we're receiving. */ void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_done) { double bps; uint32_t line_id; if (friendnum < 0) { bps = file_senders[idx].bps; line_id = file_senders[idx].line_id; } else { bps = friends[friendnum].file_receiver[idx].bps; line_id = friends[friendnum].file_receiver[idx].line_id; } const char *unit; if (bps < KiB) { unit = "B/s"; } else if (bps < MiB) { unit = "KiB/s"; bps /= (double) KiB; } else if (bps < GiB) { unit = "MiB/s"; bps /= (double) MiB; } else { unit = "GiB/s"; bps /= (double) GiB; } char msg[MAX_STR_SIZE]; snprintf(msg, sizeof(msg), "%.1f %s [", bps, unit); int n = pct_done / (100 / NUM_PROG_MARKS); int i; for (i = 0; i < n; ++i) strcat(msg, "#"); int j; for (j = i; j < NUM_PROG_MARKS; ++j) strcat(msg, "-"); strcat(msg, "] "); char pctstr[16]; const char *frmt = pct_done == 100 ? "%.f%%" : "%.1f%%"; snprintf(pctstr, sizeof(pctstr), frmt, pct_done); strcat(msg, pctstr); line_info_set(self, line_id, msg); }