Changeset 13495


Ignore:
Timestamp:
Sep 11, 2012, 12:46:32 AM (9 years ago)
Author:
livings124
Message:

Refine the logic for determining the "partial/full file size" string. It's better, but not perfect, depending on how languages are localized for special cases. A partial size of zero will now always hide the unit.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13494 r13495  
    319319           
    320320            [unitFormatter setAllowedUnits: NSByteCountFormatterUseKB];
    321             kbString = [unitFormatter stringFromByteCount: 17]; //use a random value to avoid possible pluralization issues with 1 or 0
     321            kbString = [unitFormatter stringFromByteCount: 17]; //use a random value to avoid possible pluralization issues with 1 or 0 (an example is if we use 1 for bytes, we'd get "byte" when we'd want "bytes" for the generic libtransmission value at least)
    322322           
    323323            [unitFormatter setAllowedUnits: NSByteCountFormatterUseMB];
  • trunk/macosx/NSStringAdditions.m

    r13493 r13495  
    8585        NSByteCountFormatter * fileSizeFormatter = [[NSByteCountFormatterMtLion alloc] init];
    8686       
    87         //only show units for the partial file size if it's different than the full file size's
    88         [fileSizeFormatter setIncludesCount: NO];
    89         const BOOL partialUnitsDifferent = ![[fileSizeFormatter stringFromByteCount: partialSize] isEqualToString: [fileSizeFormatter stringFromByteCount: fullSize]];
    90        
    91         [fileSizeFormatter setIncludesCount: YES];
    9287        fullString = [fileSizeFormatter stringFromByteCount: fullSize];
    9388       
    94         [fileSizeFormatter setIncludesUnit: partialUnitsDifferent];
     89        //figure out the magniture of the two, since we can't rely on comparing the units because of localization and pluralization issues (for example, "1 byte of 2 bytes")
     90        BOOL partialUnitsSame;
     91        if (partialSize == 0)
     92            partialUnitsSame = YES; //we want to just show "0" when we have no partial data, so always set to the same units
     93        else
     94        {
     95            //we have to catch 0 with a special case, so might as well avoid the math for all of magnitude 0
     96            const unsigned int magnitudePartial = partialSize >= 1000 ? log(partialSize)/log(1000) : 0;
     97            const unsigned int magnitudeFull = fullSize >= 1000 ? log(fullSize)/log(1000) : 0;
     98            partialUnitsSame = magnitudePartial == magnitudeFull;
     99        }
     100       
     101        [fileSizeFormatter setIncludesUnit: !partialUnitsSame];
    95102        partialString = [fileSizeFormatter stringFromByteCount: partialSize];
    96103       
Note: See TracChangeset for help on using the changeset viewer.