From 69fcecce1ae1f388231f4ca7aec97065ac72038c Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 14 Nov 2010 18:33:57 +0000 Subject: [PATCH] use number formatters when displaying the number of transfers --- macosx/Controller.m | 16 +++++++++++----- macosx/FilterButton.m | 8 +++++++- macosx/PrefsController.m | 3 +-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 89b8aba32..5576cc278 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1785,21 +1785,27 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy - (void) setBottomCountText: (BOOL) filtering { + NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; + [numberFormatter setMaximumFractionDigits: 0]; + NSString * totalTorrentsString; - NSInteger totalCount = [fTorrents count]; + NSUInteger totalCount = [fTorrents count]; if (totalCount != 1) - totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%d transfers", "Status bar transfer count"), totalCount]; + totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%@ transfers", "Status bar transfer count"), + [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: totalCount]]]; else totalTorrentsString = NSLocalizedString(@"1 transfer", "Status bar transfer count"); if (filtering) { - NSInteger count = [fTableView numberOfRows]; //have to factor in collapsed rows + NSUInteger count = [fTableView numberOfRows]; //have to factor in collapsed rows if (count > 0 && ![[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [Torrent class]]) count -= [fDisplayedTorrents count]; - totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%d of %@", "Status bar transfer count"), - count, totalTorrentsString]; + totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Status bar transfer count"), + [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: count]], + totalTorrentsString]; } [fTotalTorrentsField setStringValue: totalTorrentsString]; diff --git a/macosx/FilterButton.m b/macosx/FilterButton.m index 238264373..92f11ee90 100644 --- a/macosx/FilterButton.m +++ b/macosx/FilterButton.m @@ -41,8 +41,14 @@ return; fCount = count; + + NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; + [numberFormatter setMaximumFractionDigits: 0]; + [self setToolTip: fCount == 1 ? NSLocalizedString(@"1 transfer", "Filter Button -> tool tip") - : [NSString stringWithFormat: NSLocalizedString(@"%d transfers", "Filter Bar Button -> tool tip"), fCount]]; + : [NSString stringWithFormat: NSLocalizedString(@"%@ transfers", "Filter Bar Button -> tool tip"), + [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: fCount]]]]; } @end diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index bf79cd0b7..0c20ea057 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -503,11 +503,10 @@ tr_session * fHandle; if (exists) { - NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init]; + NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; [numberFormatter setMaximumFractionDigits: 0]; NSString * countString = [numberFormatter stringFromNumber: [NSNumber numberWithInt: tr_blocklistGetRuleCount(fHandle)]]; - [numberFormatter release]; [fBlocklistMessageField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ IP address rules in list", "Prefs -> blocklist -> message"), countString]];