static gboolean updateStats( gpointer gdata ) { const char * fmt; char buf[128]; struct stat_ui * ui = gdata; tr_session_stats one, all; tr_sessionGetStats( tr_core_session( ui->core ), &one ); tr_sessionGetCumulativeStats( tr_core_session( ui->core ), &all ); setLabel( ui->one_up_lb, tr_strlsize( buf, one.uploadedBytes, sizeof( buf ) ) ); setLabel( ui->one_down_lb, tr_strlsize( buf, one.downloadedBytes, sizeof( buf ) ) ); setLabel( ui->one_time_lb, tr_strltime( buf, one.secondsActive, sizeof( buf ) ) ); setLabelFromRatio( ui->one_ratio_lb, one.ratio ); fmt = ngettext( "Started %'d time", "Started %'d times", (int)all.sessionCount ); g_snprintf( buf, sizeof( buf ), fmt, (int)all.sessionCount ); setLabel( ui->all_sessions_lb, buf ); setLabel( ui->all_up_lb, tr_strlsize( buf, all.uploadedBytes, sizeof( buf ) ) ); setLabel( ui->all_down_lb, tr_strlsize( buf, all.downloadedBytes, sizeof( buf ) ) ); setLabel( ui->all_time_lb, tr_strltime( buf, all.secondsActive, sizeof( buf ) ) ); setLabelFromRatio( ui->all_ratio_lb, all.ratio ); return TRUE; }
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 ); } } }
static char* getProgressString( const tr_info * info, const tr_stat * torStat ) { const int isDone = torStat->leftUntilDone == 0; const uint64_t haveTotal = torStat->haveUnchecked + torStat->haveValid; const int isSeed = torStat->haveValid >= info->totalSize; char buf1[32], buf2[32], buf3[32], buf4[32]; char * str; if( !isDone ) str = g_strdup_printf( /* %1$s is how much we've got, %2$s is how much we'll have when done, %3$.2f%% is a percentage of the two */ _( "%1$s of %2$s (%3$.2f%%)" ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf2, torStat->sizeWhenDone, sizeof( buf2 ) ), torStat->percentDone * 100.0 ); else if( !isSeed ) str = g_strdup_printf( /* %1$s is how much we've got, %2$s is the torrent's total size, %3$.2f%% 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$.2f%%), uploaded %4$s (Ratio: %5$s)" ), tr_strlsize( buf1, haveTotal, sizeof( buf1 ) ), tr_strlsize( buf2, info->totalSize, sizeof( buf2 ) ), torStat->percentComplete * 100.0, tr_strlsize( buf3, torStat->uploadedEver, sizeof( buf3 ) ), tr_strlratio( buf4, torStat->ratio, sizeof( buf4 ) ) ); else str = g_strdup_printf( /* %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, torStat->uploadedEver, sizeof( buf2 ) ), tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) ); /* add time when downloading */ if( torStat->activity == TR_STATUS_DOWNLOAD ) { const int eta = torStat->eta; GString * gstr = g_string_new( str ); 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 ); } g_free( str ); str = g_string_free( gstr, FALSE ); } return str; }