Changeset 9527


Ignore:
Timestamp:
Nov 17, 2009, 1:48:00 AM (13 years ago)
Author:
livings124
Message:

have the Mac UI build its own ratio string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/NSStringAdditions.m

    r9490 r9527  
    8585+ (NSString *) stringForSpeedAbbrev: (CGFloat) speed
    8686{
    87     if (speed <= 999.95f) //0.0 K to 999.9 K
     87    if (speed <= 999.95) //0.0 K to 999.9 K
    8888        return [NSString localizedStringWithFormat: @"%.1f K", speed];
    8989   
    90     speed /= 1024.0f;
     90    speed /= 1024.0;
    9191   
    92     if (speed <= 99.995f) //0.98 M to 99.99 M
     92    if (speed <= 99.995) //0.98 M to 99.99 M
    9393        return [NSString localizedStringWithFormat: @"%.2f M", speed];
    94     else if (speed <= 999.95f) //100.0 M to 999.9 M
     94    else if (speed <= 999.95) //100.0 M to 999.9 M
    9595        return [NSString localizedStringWithFormat: @"%.1f M", speed];
    9696    else //insane speeds
     
    101101{
    102102    //N/A is different than libtransmission's
    103     if (ratio == TR_RATIO_NA)
     103    if ((int)ratio == TR_RATIO_NA)
    104104        return NSLocalizedString(@"N/A", "No Ratio");
    105    
    106     char buf[12];
    107     return [NSString stringWithUTF8String: tr_strratio(buf, sizeof(buf), ratio, "\xE2\x88\x9E")];
     105    else if ((int)ratio == TR_RATIO_INF)
     106        return [NSString stringWithUTF8String: "\xE2\x88\x9E"];
     107    else
     108    {
     109        if (ratio < 10.0)
     110            return [NSString localizedStringWithFormat: @"%.2f", tr_truncd(ratio, 2)];
     111        else if (ratio < 100.0)
     112            return [NSString localizedStringWithFormat: @"%.1f", tr_truncd(ratio, 1)];
     113        else
     114            return [NSString localizedStringWithFormat: @"%.0f", tr_truncd(ratio, 0)];
     115    }
    108116}
    109117
Note: See TracChangeset for help on using the changeset viewer.