Changeset 4273


Ignore:
Timestamp:
Dec 22, 2007, 3:01:14 AM (14 years ago)
Author:
charles
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r4271 r4273  
    6262        };
    6363        unsigned int i;
    64         guint64 small = size;
    65         for( i=0; i<G_N_ELEMENTS(units) && small>=1024; ++i )
    66             small >>= 10;
     64        double small = size;
     65        for( i=0; i<G_N_ELEMENTS(units) && (small>=1024.0); ++i )
     66            small /= 1024.0;
    6767        if( i < 2 ) /* B & KiB */
    6868            g_snprintf( buf, buflen, "%d %s", (int)small, _(units[i]) );
    6969        else
    70             g_snprintf( buf, buflen, "%.1f %s", (double)small, _(units[i]) );
     70            g_snprintf( buf, buflen, "%.1f %s", small, _(units[i]) );
    7171    }
    7272    return buf;
  • trunk/libtransmission/stats.c

    r4143 r4273  
    133133}
    134134
     135static void
     136updateRatio( tr_session_stats * setme )
     137{
     138    if( setme->downloadedBytes )
     139        setme->ratio = setme->uploadedBytes / (double)setme->downloadedBytes;
     140    else if( setme->uploadedBytes )
     141        setme->ratio = TR_RATIO_INF;
     142    else
     143        setme->ratio = TR_RATIO_NA;
     144}
     145
    135146void
    136147tr_getSessionStats( const tr_handle   * handle,
     
    139150    const struct tr_stats_handle * stats = handle->sessionStats;
    140151    *setme = stats->single;
    141    
    142     setme->ratio = setme->downloadedBytes ? (double)setme->uploadedBytes / (double)setme->downloadedBytes
    143                                             : ( setme->uploadedBytes ? TR_RATIO_INF : TR_RATIO_NA );
    144    
    145152    setme->secondsActive += ( time(NULL) - stats->startTime );
     153    updateRatio( setme );
    146154}
    147155
     
    152160    const struct tr_stats_handle * stats = handle->sessionStats;
    153161    *setme = stats->cumulative;
    154     setme->ratio = setme->downloadedBytes ? (double)setme->uploadedBytes / (double)setme->downloadedBytes : TR_RATIO_NA;
    155162    setme->secondsActive += ( time(NULL) - stats->startTime );
     163    updateRatio( setme );
    156164}
    157165
Note: See TracChangeset for help on using the changeset viewer.