1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-01 18:07:46 +02:00

Improve file transfer progress bar

This commit is contained in:
Jfreegman 2015-12-04 19:41:50 -05:00
parent 88270827a9
commit 77238eeadf
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -40,6 +40,7 @@ extern FriendsList Friends;
/* Checks for timed out file transfers and closes them. */ /* Checks for timed out file transfers and closes them. */
#define CHECK_FILE_TIMEOUT_INTERAVAL 5 #define CHECK_FILE_TIMEOUT_INTERAVAL 5
void check_file_transfer_timeouts(Tox *m) void check_file_transfer_timeouts(Tox *m)
{ {
char msg[MAX_STR_SIZE]; char msg[MAX_STR_SIZE];
@ -79,46 +80,47 @@ void check_file_transfer_timeouts(Tox *m)
} }
/* creates initial progress line that will be updated during file transfer. /* creates initial progress line that will be updated during file transfer.
Assumes progline is of size MAX_STR_SIZE */ Assumes progline has room for at least MAX_STR_SIZE bytes */
void init_progress_bar(char *progline) void init_progress_bar(char *progline)
{ {
strcpy(progline, "0.0 B/s ["); strcpy(progline, "0% [");
int i; int i;
for (i = 0; i < NUM_PROG_MARKS; ++i) for (i = 0; i < NUM_PROG_MARKS; ++i)
strcat(progline, "-"); strcat(progline, "-");
strcat(progline, "] 0%"); strcat(progline, "] 0.0 B/s");
} }
/* prints a progress bar for file transfers. /* 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) void print_progress_bar(ToxWindow *self, double bps, double pct_done, uint32_t line_id)
{ {
if (bps < 0 || pct_done < 0 || pct_done > 100) if (bps < 0 || pct_done < 0 || pct_done > 100)
return; return;
char msg[MAX_STR_SIZE]; char pct_str[24];
bytes_convert_str(msg, sizeof(msg), bps); snprintf(pct_str, sizeof(pct_str), "%.1f%%", pct_done);
strcat(msg, "/s [");
char bps_str[24];
bytes_convert_str(bps_str, sizeof(bps_str), bps);
char prog_line[NUM_PROG_MARKS + 1] = {0};
int n = pct_done / (100 / NUM_PROG_MARKS); int n = pct_done / (100 / NUM_PROG_MARKS);
int i, j; int i, j;
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
strcat(msg, "#"); strcat(prog_line, "=");
for (j = i; j < NUM_PROG_MARKS; ++j) if (pct_done < 100)
strcat(msg, "-"); strcpy(prog_line + n, ">");
strcat(msg, "] "); for (j = i; j < NUM_PROG_MARKS - 1; ++j)
strcat(prog_line, "-");
char pctstr[16]; char full_line[strlen(pct_str) + NUM_PROG_MARKS + strlen(bps_str) + 7];
const char *frmt = pct_done == 100 ? "%.f%%" : "%.1f%%"; snprintf(full_line, sizeof(full_line), "%s [%s] %s/s", pct_str, prog_line, bps_str);
snprintf(pctstr, sizeof(pctstr), frmt, pct_done);
strcat(msg, pctstr);
line_info_set(self, line_id, msg); line_info_set(self, line_id, full_line);
} }
static void refresh_progress_helper(ToxWindow *self, Tox *m, struct FileTransfer *ft) static void refresh_progress_helper(ToxWindow *self, Tox *m, struct FileTransfer *ft)