(gtk) tweak the display speed/size units again.

This commit is contained in:
Charles Kerr 2007-12-22 03:01:14 +00:00
parent 93f69d2b5c
commit 9148c9211f
2 changed files with 17 additions and 9 deletions

View File

@ -61,13 +61,13 @@ tr_strlsize( char * buf, guint64 size, size_t buflen )
N_("PiB"), N_("EiB"), N_("ZiB"), N_("YiB") N_("PiB"), N_("EiB"), N_("ZiB"), N_("YiB")
}; };
unsigned int i; unsigned int i;
guint64 small = size; double small = size;
for( i=0; i<G_N_ELEMENTS(units) && small>=1024; ++i ) for( i=0; i<G_N_ELEMENTS(units) && (small>=1024.0); ++i )
small >>= 10; small /= 1024.0;
if( i < 2 ) /* B & KiB */ if( i < 2 ) /* B & KiB */
g_snprintf( buf, buflen, "%d %s", (int)small, _(units[i]) ); g_snprintf( buf, buflen, "%d %s", (int)small, _(units[i]) );
else else
g_snprintf( buf, buflen, "%.1f %s", (double)small, _(units[i]) ); g_snprintf( buf, buflen, "%.1f %s", small, _(units[i]) );
} }
return buf; return buf;
} }

View File

@ -132,17 +132,25 @@ tr_statsClose( tr_handle * handle )
handle->sessionStats = NULL; handle->sessionStats = NULL;
} }
static void
updateRatio( tr_session_stats * setme )
{
if( setme->downloadedBytes )
setme->ratio = setme->uploadedBytes / (double)setme->downloadedBytes;
else if( setme->uploadedBytes )
setme->ratio = TR_RATIO_INF;
else
setme->ratio = TR_RATIO_NA;
}
void void
tr_getSessionStats( const tr_handle * handle, tr_getSessionStats( const tr_handle * handle,
tr_session_stats * setme ) tr_session_stats * setme )
{ {
const struct tr_stats_handle * stats = handle->sessionStats; const struct tr_stats_handle * stats = handle->sessionStats;
*setme = stats->single; *setme = stats->single;
setme->ratio = setme->downloadedBytes ? (double)setme->uploadedBytes / (double)setme->downloadedBytes
: ( setme->uploadedBytes ? TR_RATIO_INF : TR_RATIO_NA );
setme->secondsActive += ( time(NULL) - stats->startTime ); setme->secondsActive += ( time(NULL) - stats->startTime );
updateRatio( setme );
} }
void void
@ -151,8 +159,8 @@ tr_getCumulativeSessionStats( const tr_handle * handle,
{ {
const struct tr_stats_handle * stats = handle->sessionStats; const struct tr_stats_handle * stats = handle->sessionStats;
*setme = stats->cumulative; *setme = stats->cumulative;
setme->ratio = setme->downloadedBytes ? (double)setme->uploadedBytes / (double)setme->downloadedBytes : TR_RATIO_NA;
setme->secondsActive += ( time(NULL) - stats->startTime ); setme->secondsActive += ( time(NULL) - stats->startTime );
updateRatio( setme );
} }
/** /**