(gtk) handle TR_RATIO_NA and TR_RATIO_INF everywhere
This commit is contained in:
parent
514f96418b
commit
802f34a245
|
@ -40,10 +40,7 @@ static void
|
|||
setLabelFromRatio( GtkWidget * w, double d )
|
||||
{
|
||||
char buf[128];
|
||||
if( ( (int)d == TR_RATIO_NA ) )
|
||||
g_strlcpy( buf, _("None"), sizeof(buf) );
|
||||
else
|
||||
g_snprintf( buf, sizeof(buf), "%.1f", d );
|
||||
tr_strlratio( buf, d, sizeof( buf ) );
|
||||
setLabel( w, buf );
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ 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];
|
||||
char buf1[32], buf2[32], buf3[32], buf4[32];
|
||||
char * str;
|
||||
|
||||
if( !isDone )
|
||||
|
@ -81,18 +81,18 @@ getProgressString( const tr_info * info, const tr_stat * torStat )
|
|||
torStat->percentDone * 100.0 );
|
||||
else if( !isSeed )
|
||||
str = g_strdup_printf(
|
||||
_("%s of %s (%.2f%%), uploaded %s (Ratio: %.1f"),
|
||||
_("%s of %s (%.2f%%), uploaded %s (Ratio: %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) ),
|
||||
torStat->ratio );
|
||||
tr_strlratio( buf4, torStat->ratio, sizeof( buf4 ) ) );
|
||||
else
|
||||
str = g_strdup_printf(
|
||||
_("%s, uploaded %s (Ratio: %.1f)"),
|
||||
_("%s, uploaded %s (Ratio: %s)"),
|
||||
tr_strlsize( buf1, info->totalSize, sizeof(buf1) ),
|
||||
tr_strlsize( buf2, torStat->uploadedEver, sizeof(buf2) ),
|
||||
torStat->ratio );
|
||||
tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) );
|
||||
|
||||
return str;
|
||||
}
|
||||
|
@ -144,8 +144,10 @@ getShortStatusString( const tr_stat * torStat )
|
|||
case TR_STATUS_SEED:
|
||||
case TR_STATUS_DONE: {
|
||||
char buf[128];
|
||||
if( torStat->status != TR_STATUS_DOWNLOAD )
|
||||
g_string_append_printf( gstr, _("Ratio: %.1f, " ), torStat->ratio );
|
||||
if( torStat->status != TR_STATUS_DOWNLOAD ) {
|
||||
tr_strlratio( buf, torStat->ratio, sizeof( buf ) );
|
||||
g_string_append_printf( gstr, _("Ratio: %s, " ), buf );
|
||||
}
|
||||
getShortTransferString( torStat, buf, sizeof( buf ) );
|
||||
g_string_append( gstr, buf );
|
||||
break;
|
||||
|
|
|
@ -883,11 +883,11 @@ refresh_activity (GtkWidget * top)
|
|||
tr_strlsize( sizeStr, stat->uploadedEver, sizeof(sizeStr) );
|
||||
gtk_label_set_text( GTK_LABEL(a->ul_lb), sizeStr );
|
||||
|
||||
tr_strlsize( sizeStr, stat->corruptEver, sizeof(sizeStr) );
|
||||
gtk_label_set_text (GTK_LABEL(a->failed_lb), sizeStr );
|
||||
tr_strlsize( sizeStr, stat->corruptEver, sizeof( sizeStr ) );
|
||||
gtk_label_set_text( GTK_LABEL( a->failed_lb ), sizeStr );
|
||||
|
||||
g_snprintf( buf, sizeof(buf), "%.1f", stat->ratio );
|
||||
gtk_label_set_text (GTK_LABEL(a->ratio_lb), buf );
|
||||
tr_strlratio( buf, stat->ratio, sizeof( buf ) );
|
||||
gtk_label_set_text( GTK_LABEL( a->ratio_lb ), buf );
|
||||
|
||||
tr_strlspeed( buf, stat->swarmspeed, sizeof(buf) );
|
||||
gtk_label_set_text (GTK_LABEL(a->swarm_lb), buf );
|
||||
|
|
|
@ -620,7 +620,7 @@ static void
|
|||
updateStats( PrivateData * p )
|
||||
{
|
||||
char * pch;
|
||||
char up[32], down[32], buf[128];
|
||||
char up[32], down[32], ratio[32], buf[128];
|
||||
struct tr_session_stats stats;
|
||||
tr_handle * handle = tr_core_handle( p->core );
|
||||
|
||||
|
@ -628,7 +628,8 @@ updateStats( PrivateData * p )
|
|||
pch = pref_string_get( PREF_KEY_STATUS_BAR_STATS );
|
||||
if( !strcmp( pch, "session-ratio" ) ) {
|
||||
tr_getSessionStats( handle, &stats );
|
||||
g_snprintf( buf, sizeof(buf), _("Ratio: %.1f"), stats.ratio );
|
||||
tr_strlratio( ratio, stats.ratio, sizeof( ratio ) );
|
||||
g_snprintf( buf, sizeof(buf), _("Ratio: %s"), ratio );
|
||||
} else if( !strcmp( pch, "session-transfer" ) ) {
|
||||
tr_getSessionStats( handle, &stats );
|
||||
tr_strlsize( up, stats.uploadedBytes, sizeof( up ) );
|
||||
|
@ -641,7 +642,8 @@ updateStats( PrivateData * p )
|
|||
g_snprintf( buf, sizeof( buf ), _( "Down: %s Up: %s" ), down, up );
|
||||
} else { /* default is total-ratio */
|
||||
tr_getCumulativeSessionStats( handle, &stats );
|
||||
g_snprintf( buf, sizeof(buf), _("Ratio: %.1f"), stats.ratio );
|
||||
tr_strlratio( ratio, stats.ratio, sizeof( ratio ) );
|
||||
g_snprintf( buf, sizeof(buf), _("Ratio: %s"), ratio );
|
||||
}
|
||||
g_free( pch );
|
||||
gtk_label_set_text( GTK_LABEL( p->stats_lb ), buf );
|
||||
|
|
21
gtk/util.c
21
gtk/util.c
|
@ -50,11 +50,27 @@ tr_strcmp( const char * a, const char * b )
|
|||
return 0;
|
||||
}
|
||||
|
||||
char*
|
||||
tr_strlratio( char * buf, double ratio, size_t buflen )
|
||||
{
|
||||
if( (int)ratio == TR_RATIO_NA )
|
||||
g_strlcpy( buf, _( "None" ), buflen );
|
||||
else if( (int)ratio == TR_RATIO_INF )
|
||||
g_strlcpy( buf, "\xE2\x88\x9E", buflen );
|
||||
else if( ratio < 10.0 )
|
||||
g_snprintf( buf, buflen, "%.2f", ratio );
|
||||
else if( ratio < 100.0 )
|
||||
g_snprintf( buf, buflen, "%.1f", ratio );
|
||||
else
|
||||
g_snprintf( buf, buflen, "%.0f", ratio );
|
||||
return buf;
|
||||
}
|
||||
|
||||
char*
|
||||
tr_strlsize( char * buf, guint64 size, size_t buflen )
|
||||
{
|
||||
if( !size )
|
||||
g_strlcpy( buf, _("None"), buflen );
|
||||
g_strlcpy( buf, _( "None" ), buflen );
|
||||
else {
|
||||
static const char *units[] = {
|
||||
N_("B"), N_("KiB"), N_("MiB"), N_("GiB"), N_("TiB"),
|
||||
|
@ -77,7 +93,7 @@ tr_strlspeed( char * buf, double KiBps, size_t buflen )
|
|||
{
|
||||
const guint64 bps = KiBps * 1024;
|
||||
if( !bps )
|
||||
g_strlcpy( buf, _("None"), buflen );
|
||||
g_strlcpy( buf, _( "None" ), buflen );
|
||||
else {
|
||||
char bbuf[64];
|
||||
tr_strlsize( bbuf, (guint64)(KiBps*1024), sizeof(bbuf) );
|
||||
|
@ -121,6 +137,7 @@ tr_strltime( char * buf, int secs, size_t buflen )
|
|||
return buf;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
rfc822date (guint64 epoch_msec)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,9 @@ char* tr_strlsize( char * buf, guint64 size, size_t buflen );
|
|||
/* return a human-readable string for the transfer rate given in bytes. */
|
||||
char* tr_strlspeed (char * buf, double KiBps, size_t buflen );
|
||||
|
||||
/* return a human-readable string for the given ratio. */
|
||||
char* tr_strlratio( char * buf, double ratio, size_t buflen );
|
||||
|
||||
/* return a human-readable string for the time given in seconds. */
|
||||
char* tr_strltime( char * buf, int secs, size_t buflen );
|
||||
|
||||
|
|
Loading…
Reference in New Issue