1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

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

This commit is contained in:
Mitchell Livingston 2010-09-12 22:20:19 +00:00
parent 9135d5e061
commit 0e2dd87c08
2 changed files with 20 additions and 13 deletions

View file

@ -334,12 +334,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
tr_bencDictAddBool(&settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, [fDefaults boolForKey: @"RPCUseWhitelist"]); tr_bencDictAddBool(&settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, [fDefaults boolForKey: @"RPCUseWhitelist"]);
tr_bencDictAddBool(&settings, TR_PREFS_KEY_START, [fDefaults boolForKey: @"AutoStartDownload"]); tr_bencDictAddBool(&settings, TR_PREFS_KEY_START, [fDefaults boolForKey: @"AutoStartDownload"]);
tr_formatter_size_init(1024, [NSLocalizedString(@"KB", "File size - kilobytes") UTF8String], tr_formatter_size_init([NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024,
[NSLocalizedString(@"KB", "File size - kilobytes") UTF8String],
[NSLocalizedString(@"MB", "File size - megabytes") UTF8String], [NSLocalizedString(@"MB", "File size - megabytes") UTF8String],
[NSLocalizedString(@"GB", "File size - gigabytes") UTF8String], [NSLocalizedString(@"GB", "File size - gigabytes") UTF8String],
[NSLocalizedString(@"TB", "File size - terabytes") UTF8String]); [NSLocalizedString(@"TB", "File size - terabytes") UTF8String]);
tr_formatter_speed_init(1024, [NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String], tr_formatter_speed_init([NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024,
[NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String],
[NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)") UTF8String], [NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)") UTF8String],
[NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)") UTF8String], [NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)") UTF8String],
[NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)") UTF8String]); //why not? [NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)") UTF8String]); //why not?

View file

@ -48,7 +48,10 @@
+ (NSString *) stringForFileSize: (uint64_t) size + (NSString *) stringForFileSize: (uint64_t) size
{ {
if (size < 1024) const CGFloat baseFloat = [NSApp isOnSnowLeopardOrBetter] ? 1000.0 : 1024.0;
const NSInteger baseInt = [NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024;
if (size < baseInt)
{ {
if (size != 1) if (size != 1)
return [NSString stringWithFormat: @"%lld %@", size, NSLocalizedString(@"bytes", "File size - bytes")]; return [NSString stringWithFormat: @"%lld %@", size, NSLocalizedString(@"bytes", "File size - bytes")];
@ -58,24 +61,24 @@
CGFloat convertedSize; CGFloat convertedSize;
NSString * unit; NSString * unit;
if (size < pow(1024, 2)) if (size < pow(baseInt, 2))
{ {
convertedSize = size / 1024.0; convertedSize = size / baseFloat;
unit = NSLocalizedString(@"KB", "File size - kilobytes"); unit = NSLocalizedString(@"KB", "File size - kilobytes");
} }
else if (size < pow(1024, 3)) else if (size < pow(baseInt, 3))
{ {
convertedSize = size / (CGFloat)pow(1024, 2); convertedSize = size / pow(baseFloat, 2);
unit = NSLocalizedString(@"MB", "File size - megabytes"); unit = NSLocalizedString(@"MB", "File size - megabytes");
} }
else if (size < pow(1024, 4)) else if (size < pow(baseInt, 4))
{ {
convertedSize = size / (CGFloat)pow(1024, 3); convertedSize = size / pow(baseFloat, 3);
unit = NSLocalizedString(@"GB", "File size - gigabytes"); unit = NSLocalizedString(@"GB", "File size - gigabytes");
} }
else else
{ {
convertedSize = size / (CGFloat)pow(1024, 4); convertedSize = size / pow(baseFloat, 4);
unit = NSLocalizedString(@"TB", "File size - terabytes"); unit = NSLocalizedString(@"TB", "File size - terabytes");
} }
@ -190,17 +193,19 @@
+ (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb + (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb
{ {
const CGFloat baseFloat = [NSApp isOnSnowLeopardOrBetter] ? 1000.0 : 1024.0;
if (speed <= 999.95) //0.0 KB/s to 999.9 KB/s if (speed <= 999.95) //0.0 KB/s to 999.9 KB/s
return [NSString localizedStringWithFormat: @"%.1f %@", speed, kb]; return [NSString localizedStringWithFormat: @"%.1f %@", speed, kb];
speed /= 1024.0; speed /= baseFloat;
if (speed <= 99.995) //0.98 MB/s to 99.99 MB/s if (speed <= 99.995) //1.00 MB/s to 99.99 MB/s
return [NSString localizedStringWithFormat: @"%.2f %@", speed, mb]; return [NSString localizedStringWithFormat: @"%.2f %@", speed, mb];
else if (speed <= 999.95) //100.0 MB/s to 999.9 MB/s else if (speed <= 999.95) //100.0 MB/s to 999.9 MB/s
return [NSString localizedStringWithFormat: @"%.1f %@", speed, mb]; return [NSString localizedStringWithFormat: @"%.1f %@", speed, mb];
else //insane speeds else //insane speeds
return [NSString localizedStringWithFormat: @"%.2f %@", (speed / 1024.0), gb]; return [NSString localizedStringWithFormat: @"%.2f %@", (speed / baseFloat), gb];
} }
@end @end