1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 21:03:02 +01:00

don't excessively update percentage complete line during file transfers

This commit is contained in:
Jfreegman 2014-06-30 14:15:24 -04:00
parent 44d524134f
commit a126f9c1a6
4 changed files with 20 additions and 11 deletions

View File

@ -394,16 +394,20 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
}
}
/* refresh line with percentage complete */
uint8_t msg[MAX_STR_SIZE];
uint64_t size = friends[num].file_receiver.size[filenum];
long double remain = (long double) tox_file_data_remaining(m, num, filenum, 1);
long double pct_remain = remain ? (1 - (remain / size)) * 100 : 100;
uint64_t curtime = get_unix_time();
const uint8_t *name = friends[num].file_receiver.filenames[filenum];
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1Lf%%)", name, pct_remain);
line_info_set(self, friends[num].file_receiver.line_id[filenum], msg);
/* refresh line with percentage complete */
if (!remain || timed_out(friends[num].file_receiver.last_progress[filenum], curtime, 1)) {
friends[num].file_receiver.last_progress[filenum] = curtime;
uint8_t msg[MAX_STR_SIZE];
uint64_t size = friends[num].file_receiver.size[filenum];
long double pct_remain = remain ? (1 - (remain / size)) * 100 : 100;
const uint8_t *name = friends[num].file_receiver.filenames[filenum];
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1Lf%%)", name, pct_remain);
line_info_set(self, friends[num].file_receiver.line_id[filenum], msg);
}
}
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t *group_pub_key)

View File

@ -102,14 +102,17 @@ void do_file_senders(Tox *m)
file_senders[i].piecelen) == -1)
break;
file_senders[i].timestamp = get_unix_time();
uint64_t curtime = get_unix_time();
file_senders[i].timestamp = curtime;
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_file_data_size(m, friendnum), fp);
long double remain = (long double) tox_file_data_remaining(m, friendnum, filenum, 0);
/* refresh line with percentage complete */
if (self->chatwin != NULL) {
if ((self->chatwin != NULL && timed_out(file_senders[i].last_progress, curtime, 1)) || !remain) {
file_senders[i].last_progress = curtime;
uint64_t size = file_senders[i].size;
long double remain = (long double) tox_file_data_remaining(m, friendnum, filenum, 0);
long double pct_remain = remain ? (1 - (remain / size)) * 100 : 100;
snprintf(msg, sizeof(msg), "File transfer for '%s' accepted (%.1Lf%%)", pathname, pct_remain);

View File

@ -40,6 +40,7 @@ typedef struct {
uint16_t piecelen;
uint8_t pathname[MAX_STR_SIZE];
uint64_t timestamp;
uint64_t last_progress;
uint64_t size;
uint32_t line_id;
} FileSender;

View File

@ -34,13 +34,14 @@ struct FileReceiver {
FILE *files[MAX_FILES];
bool pending[MAX_FILES];
uint64_t size[MAX_FILES];
uint64_t last_progress[MAX_FILES];
uint32_t line_id[MAX_FILES];
};
struct LastOnline {
uint64_t last_on;
struct tm tm;
uint8_t hour_min_str[TIME_STR_SIZE]; /* holds 12-hour time string e.g. "10:43 PM" */
uint8_t hour_min_str[TIME_STR_SIZE]; /* holds 12/24-hour time string e.g. "10:43 PM" */
};
typedef struct {