Changeset 10537


Ignore:
Timestamp:
Apr 28, 2010, 1:38:20 AM (11 years ago)
Author:
charles
Message:

(trunk gtk) #3174 "Use IEC standard units (KiB, MiB, GiB) instead of (KB, MB, GB)" -- don't use g_format_size_for_display(), since we can't control what units it uses

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r10536 r10537  
    106106}
    107107
    108 #define KILOBYTE_FACTOR 1024.0
    109 #define MEGABYTE_FACTOR ( 1024.0 * 1024.0 )
    110 #define GIGABYTE_FACTOR ( 1024.0 * 1024.0 * 1024.0 )
     108static double KiB = 1024.0;
     109static double MiB = ( 1024.0 * 1024.0 );
     110static double GiB = ( 1024.0 * 1024.0 * 1024.0 );
    111111
    112112char*
    113 tr_strlsize( char *  buf,
    114              guint64 size,
    115              size_t  buflen )
    116 {
    117     if( !size )
     113tr_strlsize( char * buf, guint64 bytes, size_t buflen )
     114{
     115    if( !bytes )
    118116        g_strlcpy( buf, _( "None" ), buflen );
    119 #if GLIB_CHECK_VERSION( 2, 16, 0 )
     117    else if( bytes < KiB )
     118        g_snprintf( buf, buflen, ngettext( "%'u byte", "%'u bytes", (guint)bytes ), (guint)bytes );
     119    else if( bytes < MiB )
     120        g_snprintf( buf, buflen, _( "%'.1f KiB" ), bytes / KiB );
     121    else if( bytes < GiB )
     122        g_snprintf( buf, buflen, _( "%'.1f MiB" ), bytes / MiB );
    120123    else
    121     {
    122         char * tmp = g_format_size_for_display( size );
    123         g_strlcpy( buf, tmp, buflen );
    124         g_free( tmp );
    125     }
    126 #else
    127     else if( size < (guint64)KILOBYTE_FACTOR )
    128         g_snprintf( buf, buflen,
    129                     ngettext( "%'u byte", "%'u bytes",
    130                               (guint)size ), (guint)size );
    131     else
    132     {
    133         gdouble displayed_size;
    134         if( size < (guint64)MEGABYTE_FACTOR )
    135         {
    136             displayed_size = (gdouble) size / KILOBYTE_FACTOR;
    137             g_snprintf( buf, buflen, _( "%'.1f KiB" ), displayed_size );
    138         }
    139         else if( size < (guint64)GIGABYTE_FACTOR )
    140         {
    141             displayed_size = (gdouble) size / MEGABYTE_FACTOR;
    142             g_snprintf( buf, buflen, _( "%'.1f MiB" ), displayed_size );
    143         }
    144         else
    145         {
    146             displayed_size = (gdouble) size / GIGABYTE_FACTOR;
    147             g_snprintf( buf, buflen, _( "%'.1f GiB" ), displayed_size );
    148         }
    149     }
    150 #endif
     124        g_snprintf( buf, buflen, _( "%'.1f GiB" ), bytes / GiB );
    151125    return buf;
    152126}
    153127
    154128char*
    155 tr_strlspeed( char * buf,
    156               double kb_sec,
    157               size_t buflen )
     129tr_strlspeed( char * buf, double kb_sec, size_t buflen )
    158130{
    159131    const double speed = kb_sec;
     
    162134        g_snprintf( buf, buflen, _( "%'.1f KiB/s" ), speed );
    163135    else if( speed < 102400.0 ) /* 0.98 MiB to 99.99 MiB */
    164         g_snprintf( buf, buflen, _( "%'.2f MiB/s" ), ( speed / KILOBYTE_FACTOR ) );
     136        g_snprintf( buf, buflen, _( "%'.2f MiB/s" ), ( speed / KiB ) );
    165137    else if( speed < 1024000.0 ) /* 100.0 MiB to 999.9 MiB */
    166         g_snprintf( buf, buflen, _( "%'.1f MiB/s" ), ( speed / MEGABYTE_FACTOR ) );
     138        g_snprintf( buf, buflen, _( "%'.1f MiB/s" ), ( speed / MiB ) );
    167139    else /* insane speeds */
    168         g_snprintf( buf, buflen, _( "%'.2f GiB/s" ), ( speed / GIGABYTE_FACTOR ) );
     140        g_snprintf( buf, buflen, _( "%'.2f GiB/s" ), ( speed / GiB ) );
    169141
    170142    return buf;
     
    172144
    173145char*
    174 tr_strltime( char * buf,
    175              int    seconds,
    176              size_t buflen )
     146tr_strltime( char * buf, int seconds, size_t buflen )
    177147{
    178148    int  days, hours, minutes;
Note: See TracChangeset for help on using the changeset viewer.