Changeset 11207


Ignore:
Timestamp:
Sep 12, 2010, 10:20:19 PM (11 years ago)
Author:
livings124
Message:

#3518 Snow Leopard systems should show file sizes and speeds in base 10

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r11178 r11207  
    335335        tr_bencDictAddBool(&settings, TR_PREFS_KEY_START, [fDefaults boolForKey: @"AutoStartDownload"]);
    336336       
    337         tr_formatter_size_init(1024, [NSLocalizedString(@"KB", "File size - kilobytes") UTF8String],
     337        tr_formatter_size_init([NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024,
     338                                    [NSLocalizedString(@"KB", "File size - kilobytes") UTF8String],
    338339                                    [NSLocalizedString(@"MB", "File size - megabytes") UTF8String],
    339340                                    [NSLocalizedString(@"GB", "File size - gigabytes") UTF8String],
    340341                                    [NSLocalizedString(@"TB", "File size - terabytes") UTF8String]);
    341342
    342         tr_formatter_speed_init(1024, [NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String],
     343        tr_formatter_speed_init([NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024,
     344                                    [NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String],
    343345                                    [NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)") UTF8String],
    344346                                    [NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)") UTF8String],
  • trunk/macosx/NSStringAdditions.m

    r10988 r11207  
    4949+ (NSString *) stringForFileSize: (uint64_t) size
    5050{
    51     if (size < 1024)
     51    const CGFloat baseFloat = [NSApp isOnSnowLeopardOrBetter] ? 1000.0 : 1024.0;
     52    const NSInteger baseInt = [NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024;
     53   
     54    if (size < baseInt)
    5255    {
    5356        if (size != 1)
     
    5962    CGFloat convertedSize;
    6063    NSString * unit;
    61     if (size < pow(1024, 2))
    62     {
    63         convertedSize = size / 1024.0;
     64    if (size < pow(baseInt, 2))
     65    {
     66        convertedSize = size / baseFloat;
    6467        unit = NSLocalizedString(@"KB", "File size - kilobytes");
    6568    }
    66     else if (size < pow(1024, 3))
    67     {
    68         convertedSize = size / (CGFloat)pow(1024, 2);
     69    else if (size < pow(baseInt, 3))
     70    {
     71        convertedSize = size / pow(baseFloat, 2);
    6972        unit = NSLocalizedString(@"MB", "File size - megabytes");
    7073    }
    71     else if (size < pow(1024, 4))
    72     {
    73         convertedSize = size / (CGFloat)pow(1024, 3);
     74    else if (size < pow(baseInt, 4))
     75    {
     76        convertedSize = size / pow(baseFloat, 3);
    7477        unit = NSLocalizedString(@"GB", "File size - gigabytes");
    7578    }
    7679    else
    7780    {
    78         convertedSize = size / (CGFloat)pow(1024, 4);
     81        convertedSize = size / pow(baseFloat, 4);
    7982        unit = NSLocalizedString(@"TB", "File size - terabytes");
    8083    }
     
    191194+ (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb
    192195{
     196    const CGFloat baseFloat = [NSApp isOnSnowLeopardOrBetter] ? 1000.0 : 1024.0;
     197   
    193198    if (speed <= 999.95) //0.0 KB/s to 999.9 KB/s
    194199        return [NSString localizedStringWithFormat: @"%.1f %@", speed, kb];
    195200   
    196     speed /= 1024.0;
    197    
    198     if (speed <= 99.995) //0.98 MB/s to 99.99 MB/s
     201    speed /= baseFloat;
     202   
     203    if (speed <= 99.995) //1.00 MB/s to 99.99 MB/s
    199204        return [NSString localizedStringWithFormat: @"%.2f %@", speed, mb];
    200205    else if (speed <= 999.95) //100.0 MB/s to 999.9 MB/s
    201206        return [NSString localizedStringWithFormat: @"%.1f %@", speed, mb];
    202207    else //insane speeds
    203         return [NSString localizedStringWithFormat: @"%.2f %@", (speed / 1024.0), gb];
     208        return [NSString localizedStringWithFormat: @"%.2f %@", (speed / baseFloat), gb];
    204209}
    205210
Note: See TracChangeset for help on using the changeset viewer.