static double get_percent_done(tr_torrent const* tor, tr_stat const* st, bool* seed) { double d; if (st->activity == TR_STATUS_SEED && tr_torrentGetSeedRatio(tor, &d)) { *seed = true; d = MAX(0.0, st->seedRatioPercentDone); } else { *seed = false; d = MAX(0.0, st->percentDone); } return d; }
static void getProgressString( GString * gstr, const tr_torrent * tor, const tr_info * info, const tr_stat * st ) { const int isDone = st->leftUntilDone == 0; const uint64_t haveTotal = st->haveUnchecked + st->haveValid; const int isSeed = st->haveValid >= info->totalSize; char buf1[32], buf2[32], buf3[32], buf4[32], buf5[32], buf6[32]; double seedRatio; const gboolean hasSeedRatio = tr_torrentGetSeedRatio( tor, &seedRatio ); if( !isDone ) /* downloading */ { g_string_append_printf( gstr, /* %1$s is how much we've got, %2$s is how much we'll have when done, %3$s%% is a percentage of the two */ _( "%1$s of %2$s (%3$s%%)" ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf2, st->sizeWhenDone, sizeof( buf2 ) ), tr_strlpercent( buf3, st->percentDone * 100.0, sizeof( buf3 ) ) ); } else if( !isSeed ) /* partial seeds */ { if( hasSeedRatio ) { g_string_append_printf( gstr, /* %1$s is how much we've got, %2$s is the torrent's total size, %3$s%% is a percentage of the two, %4$s is how much we've uploaded, %5$s is our upload-to-download ratio, %6$s is the ratio we want to reach before we stop uploading */ _( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s Goal: %6$s)" ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ), tr_strlpercent( buf3, st->percentComplete * 100.0, sizeof( buf3 ) ), tr_strlsize( buf4, st->uploadedEver, sizeof( buf4 ) ), tr_strlratio( buf5, st->ratio, sizeof( buf5 ) ), tr_strlratio( buf6, seedRatio, sizeof( buf6 ) ) ); } else { g_string_append_printf( gstr, /* %1$s is how much we've got, %2$s is the torrent's total size, %3$s%% is a percentage of the two, %4$s is how much we've uploaded, %5$s is our upload-to-download ratio */ _( "%1$s of %2$s (%3$s%%), uploaded %4$s (Ratio: %5$s)" ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ), tr_strlpercent( buf3, st->percentComplete * 100.0, sizeof( buf3 ) ), tr_strlsize( buf4, st->uploadedEver, sizeof( buf4 ) ), tr_strlratio( buf5, st->ratio, sizeof( buf5 ) ) ); } } else /* seeding */ { if( hasSeedRatio ) { g_string_append_printf( gstr, /* %1$s is the torrent's total size, %2$s is how much we've uploaded, %3$s is our upload-to-download ratio, %4$s is the ratio we want to reach before we stop uploading */ _( "%1$s, uploaded %2$s (Ratio: %3$s Goal: %4$s)" ), tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ), tr_strlsize( buf2, st->uploadedEver, sizeof( buf2 ) ), tr_strlratio( buf3, st->ratio, sizeof( buf3 ) ), tr_strlratio( buf4, seedRatio, sizeof( buf4 ) ) ); } else /* seeding w/o a ratio */ { g_string_append_printf( gstr, /* %1$s is the torrent's total size, %2$s is how much we've uploaded, %3$s is our upload-to-download ratio */ _( "%1$s, uploaded %2$s (Ratio: %3$s)" ), tr_strlsize( buf1, info->totalSize, sizeof( buf1 ) ), tr_strlsize( buf2, st->uploadedEver, sizeof( buf2 ) ), tr_strlratio( buf3, st->ratio, sizeof( buf3 ) ) ); } } /* add time when downloading */ if( ( st->activity == TR_STATUS_DOWNLOAD ) || ( hasSeedRatio && ( st->activity == TR_STATUS_SEED ) ) ) { const int eta = st->eta; g_string_append( gstr, " - " ); if( eta < 0 ) g_string_append( gstr, _( "Remaining time unknown" ) ); else { char timestr[128]; tr_strltime( timestr, eta, sizeof( timestr ) ); /* time remaining */ g_string_append_printf( gstr, _( "%s remaining" ), timestr ); } } }