Changeset 13495
- Timestamp:
- Sep 11, 2012, 12:46:32 AM (11 years ago)
- Location:
- trunk/macosx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Controller.m
r13494 r13495 319 319 320 320 [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) 322 322 323 323 [unitFormatter setAllowedUnits: NSByteCountFormatterUseMB]; -
trunk/macosx/NSStringAdditions.m
r13493 r13495 85 85 NSByteCountFormatter * fileSizeFormatter = [[NSByteCountFormatterMtLion alloc] init]; 86 86 87 //only show units for the partial file size if it's different than the full file size's88 [fileSizeFormatter setIncludesCount: NO];89 const BOOL partialUnitsDifferent = ![[fileSizeFormatter stringFromByteCount: partialSize] isEqualToString: [fileSizeFormatter stringFromByteCount: fullSize]];90 91 [fileSizeFormatter setIncludesCount: YES];92 87 fullString = [fileSizeFormatter stringFromByteCount: fullSize]; 93 88 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]; 95 102 partialString = [fileSizeFormatter stringFromByteCount: partialSize]; 96 103
Note: See TracChangeset
for help on using the changeset viewer.