#3298 Move percentage string formatting into its own method, and don't append .00 to 100%

This commit is contained in:
Mitchell Livingston 2010-06-24 00:00:43 +00:00
parent 075169b409
commit 2980120847
7 changed files with 36 additions and 28 deletions

View File

@ -206,8 +206,7 @@
FileListNode * node = (FileListNode *)[self objectValue];
const CGFloat progress = [torrent fileProgress: node];
NSString * percentString = progress == 1.0 ? @"100%"
: [NSString localizedStringWithFormat: @"%.2f%%", tr_truncd(progress * 100.0, 2)];
NSString * percentString = [NSString percentString: [self floatValue] longDecimals: YES];
NSString * status = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@",
"Inspector -> Files tab -> file status string"), percentString, [NSString stringForFileSize: [node size]]];

View File

@ -124,12 +124,12 @@
[fStateField setStringValue: [torrent stateString]];
NSString * progressString = [NSString localizedStringWithFormat: @"%.2f%%", tr_truncd(100.0 * [torrent progress], 2)];
NSString * progressString = [NSString percentString: [torrent progress] longDecimals: YES];
if ([torrent isFolder])
{
NSString * progressSelectedString = [NSString localizedStringWithFormat:
NSLocalizedString(@"%.2f%% selected", "Inspector -> Activity tab -> progress"),
tr_truncd(100.0 * [torrent progressDone], 2)];
NSString * progressSelectedString = [NSString stringWithFormat:
NSLocalizedString(@"%@ selected", "Inspector -> Activity tab -> progress"),
[NSString percentString: [torrent progressDone] longDecimals: YES]];
progressString = [progressString stringByAppendingFormat: @" (%@)", progressSelectedString];
}
[fProgressField setStringValue: progressString];

View File

@ -358,8 +358,9 @@
[components addObject: [peer objectForKey: @"Name"]];
const CGFloat progress = [[peer objectForKey: @"Progress"] floatValue];
NSString * progressString = [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%",
"Inspector -> Peers tab -> table row tooltip"), tr_truncd(progress * 100.0, 1)];
NSString * progressString = [NSString stringWithFormat: NSLocalizedString(@"Progress: %@",
"Inspector -> Peers tab -> table row tooltip"),
[NSString percentString: progress longDecimals: NO]];
if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue])
progressString = [progressString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"Partial Seed",
"Inspector -> Peers tab -> table row tooltip")];

View File

@ -35,6 +35,8 @@
+ (NSString *) stringForSpeedAbbrev: (CGFloat) speed;
+ (NSString *) stringForRatio: (CGFloat) ratio;
+ (NSString *) percentString: (CGFloat) progress longDecimals: (BOOL) longDecimals;
+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds;
+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max;

View File

@ -116,6 +116,16 @@
}
}
+ (NSString *) percentString: (CGFloat) progress longDecimals: (BOOL) longDecimals
{
if (progress >= 1.0)
return @"100%";
else if (longDecimals)
return [NSString localizedStringWithFormat: @"%.2f%%", tr_truncd(progress * 100.0, 2)];
else
return [NSString localizedStringWithFormat: @"%.1f%%", tr_truncd(progress * 100.0, 1)];
}
+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds
{
return [NSString timeString: seconds showSeconds: showSeconds maxFields: NSUIntegerMax];

View File

@ -24,6 +24,7 @@
#import "PeerProgressIndicatorCell.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#import "transmission.h" // required by utils.h
#import "utils.h"
@ -63,8 +64,7 @@
[paragraphStyle release];
}
[[NSString localizedStringWithFormat: @"%.1f%%", tr_truncd([self floatValue] * 100.0, 1)] drawInRect: cellFrame
withAttributes: fAttributes];
[[NSString percentString: [self floatValue] longDecimals: NO] drawInRect: cellFrame withAttributes: fAttributes];
}
else
{

View File

@ -928,8 +928,8 @@ int trashDataFile(const char * filename)
if ([self isMagnet])
{
NSString * progressString = fStat->metadataPercentComplete > 0.0
? [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% of torrent metadata retrieved",
"Torrent -> progress string"), tr_truncd(100.0 * fStat->metadataPercentComplete, 2)]
? [NSString stringWithFormat: NSLocalizedString(@"%@ of torrent metadata retrieved",
"Torrent -> progress string"), [NSString percentString: fStat->metadataPercentComplete longDecimals: YES]]
: NSLocalizedString(@"torrent metadata needed", "Torrent -> progress string");
return [NSString stringWithFormat: @"%@ - %@", NSLocalizedString(@"Magnetized transfer", "Torrent -> progress string"),
@ -945,16 +945,16 @@ int trashDataFile(const char * filename)
{
string = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@ selected", "Torrent -> progress string"),
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self totalSizeSelected]]];
progress = 100.0 * [self progressDone];
progress = [self progressDone];
}
else
{
string = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Torrent -> progress string"),
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]]];
progress = 100.0 * [self progress];
progress = [self progress];
}
string = [NSString localizedStringWithFormat: @"%@ (%.2f%%)", string, tr_truncd(progress, 2)];
string = [string stringByAppendingFormat: @" (%@)", [NSString percentString: progress longDecimals: YES]];
}
else
{
@ -965,13 +965,9 @@ int trashDataFile(const char * filename)
downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ selected", "Torrent -> progress string"),
[NSString stringForFileSize: [self haveTotal]]];
else
{
downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Torrent -> progress string"),
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]]];
downloadString = [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
downloadString, tr_truncd(100.0 * [self progress], 2)];
}
downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@ (%@)", "Torrent -> progress string"),
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]],
[NSString percentString: [self progress] longDecimals: YES]];
}
else
downloadString = [NSString stringForFileSize: [self size]];
@ -1030,9 +1026,9 @@ int trashDataFile(const char * filename)
break;
case TR_STATUS_CHECK:
string = [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
string = [NSString stringWithFormat: @"%@ (%@)",
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
tr_truncd(100.0 * [self checkingProgress], 2)];
[NSString percentString: [self checkingProgress] longDecimals: YES]];
break;
case TR_STATUS_DOWNLOAD:
@ -1110,9 +1106,9 @@ int trashDataFile(const char * filename)
break;
case TR_STATUS_CHECK:
string = [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
string = [NSString stringWithFormat: @"%@ (%@)",
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
tr_truncd(100.0 * [self checkingProgress], 2)];
[NSString percentString: [self checkingProgress] longDecimals: YES]];
break;
case TR_STATUS_DOWNLOAD:
@ -1164,9 +1160,9 @@ int trashDataFile(const char * filename)
return [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
case TR_STATUS_CHECK:
return [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
return [NSString stringWithFormat: @"%@ (%@)",
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
tr_truncd(100.0 * [self checkingProgress], 2)];
[NSString percentString: [self checkingProgress] longDecimals: YES]];
case TR_STATUS_DOWNLOAD:
return NSLocalizedString(@"Downloading", "Torrent -> status string");