Changeset 10832


Ignore:
Timestamp:
Jun 24, 2010, 12:00:43 AM (12 years ago)
Author:
livings124
Message:

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

Location:
trunk/macosx
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/FileNameCell.m

    r10711 r10832  
    207207   
    208208    const CGFloat progress = [torrent fileProgress: node];
    209     NSString * percentString = progress == 1.0 ? @"100%"
    210                                 : [NSString localizedStringWithFormat: @"%.2f%%", tr_truncd(progress * 100.0, 2)];
     209    NSString * percentString = [NSString percentString: [self floatValue] longDecimals: YES];
    211210   
    212211    NSString * status = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@",
  • trunk/macosx/InfoActivityViewController.m

    r10794 r10832  
    125125        [fStateField setStringValue: [torrent stateString]];
    126126       
    127         NSString * progressString = [NSString localizedStringWithFormat: @"%.2f%%", tr_truncd(100.0 * [torrent progress], 2)];
     127        NSString * progressString = [NSString percentString: [torrent progress] longDecimals: YES];
    128128        if ([torrent isFolder])
    129129        {
    130             NSString * progressSelectedString = [NSString localizedStringWithFormat:
    131                                                     NSLocalizedString(@"%.2f%% selected", "Inspector -> Activity tab -> progress"),
    132                                                     tr_truncd(100.0 * [torrent progressDone], 2)];
     130            NSString * progressSelectedString = [NSString stringWithFormat:
     131                                                    NSLocalizedString(@"%@ selected", "Inspector -> Activity tab -> progress"),
     132                                                    [NSString percentString: [torrent progressDone] longDecimals: YES]];
    133133            progressString = [progressString stringByAppendingFormat: @" (%@)", progressSelectedString];
    134134        }
  • trunk/macosx/InfoPeersViewController.m

    r10711 r10832  
    359359       
    360360        const CGFloat progress = [[peer objectForKey: @"Progress"] floatValue];
    361         NSString * progressString = [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%",
    362                                         "Inspector -> Peers tab -> table row tooltip"), tr_truncd(progress * 100.0, 1)];
     361        NSString * progressString = [NSString stringWithFormat: NSLocalizedString(@"Progress: %@",
     362                                        "Inspector -> Peers tab -> table row tooltip"),
     363                                        [NSString percentString: progress longDecimals: NO]];
    363364        if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue])
    364365            progressString = [progressString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"Partial Seed",
  • trunk/macosx/NSStringAdditions.h

    r9844 r10832  
    3636+ (NSString *) stringForRatio: (CGFloat) ratio;
    3737
     38+ (NSString *) percentString: (CGFloat) progress longDecimals: (BOOL) longDecimals;
     39
    3840+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds;
    3941+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max;
  • trunk/macosx/NSStringAdditions.m

    r10522 r10832  
    117117}
    118118
     119+ (NSString *) percentString: (CGFloat) progress longDecimals: (BOOL) longDecimals
     120{
     121    if (progress >= 1.0)
     122        return @"100%";
     123    else if (longDecimals)
     124        return [NSString localizedStringWithFormat: @"%.2f%%", tr_truncd(progress * 100.0, 2)];
     125    else
     126        return [NSString localizedStringWithFormat: @"%.1f%%", tr_truncd(progress * 100.0, 1)];
     127}
     128
    119129+ (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds
    120130{
  • trunk/macosx/PeerProgressIndicatorCell.m

    r10711 r10832  
    2525#import "PeerProgressIndicatorCell.h"
    2626#import "NSApplicationAdditions.h"
     27#import "NSStringAdditions.h"
    2728
    2829#import "transmission.h" // required by utils.h
     
    6465        }
    6566       
    66         [[NSString localizedStringWithFormat: @"%.1f%%", tr_truncd([self floatValue] * 100.0, 1)] drawInRect: cellFrame
    67             withAttributes: fAttributes];
     67        [[NSString percentString: [self floatValue] longDecimals: NO] drawInRect: cellFrame withAttributes: fAttributes];
    6868    }
    6969    else
  • trunk/macosx/Torrent.m

    r10712 r10832  
    929929    {
    930930        NSString * progressString = fStat->metadataPercentComplete > 0.0
    931                     ? [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% of torrent metadata retrieved",
    932                         "Torrent -> progress string"), tr_truncd(100.0 * fStat->metadataPercentComplete, 2)]
     931                    ? [NSString stringWithFormat: NSLocalizedString(@"%@ of torrent metadata retrieved",
     932                        "Torrent -> progress string"), [NSString percentString: fStat->metadataPercentComplete longDecimals: YES]]
    933933                    : NSLocalizedString(@"torrent metadata needed", "Torrent -> progress string");
    934934       
     
    946946            string = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@ selected", "Torrent -> progress string"),
    947947                        [NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self totalSizeSelected]]];
    948             progress = 100.0 * [self progressDone];
     948            progress = [self progressDone];
    949949        }
    950950        else
     
    952952            string = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Torrent -> progress string"),
    953953                        [NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]]];
    954             progress = 100.0 * [self progress];
     954            progress = [self progress];
    955955        }
    956956       
    957         string = [NSString localizedStringWithFormat: @"%@ (%.2f%%)", string, tr_truncd(progress, 2)];
     957        string = [string stringByAppendingFormat: @" (%@)", [NSString percentString: progress longDecimals: YES]];
    958958    }
    959959    else
     
    966966                                    [NSString stringForFileSize: [self haveTotal]]];
    967967            else
    968             {
    969                 downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Torrent -> progress string"),
    970                                     [NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]]];
    971                
    972                 downloadString = [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
    973                                     downloadString, tr_truncd(100.0 * [self progress], 2)];
    974             }
     968                downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@ (%@)", "Torrent -> progress string"),
     969                                    [NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]],
     970                                    [NSString percentString: [self progress] longDecimals: YES]];
    975971        }
    976972        else
     
    10311027
    10321028            case TR_STATUS_CHECK:
    1033                 string = [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
     1029                string = [NSString stringWithFormat: @"%@ (%@)",
    10341030                            NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
    1035                                 tr_truncd(100.0 * [self checkingProgress], 2)];
     1031                            [NSString percentString: [self checkingProgress] longDecimals: YES]];
    10361032                break;
    10371033
     
    11111107
    11121108        case TR_STATUS_CHECK:
    1113             string = [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
     1109            string = [NSString stringWithFormat: @"%@ (%@)",
    11141110                        NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
    1115                             tr_truncd(100.0 * [self checkingProgress], 2)];
     1111                        [NSString percentString: [self checkingProgress] longDecimals: YES]];
    11161112            break;
    11171113       
     
    11651161
    11661162        case TR_STATUS_CHECK:
    1167             return [NSString localizedStringWithFormat: @"%@ (%.2f%%)",
     1163            return [NSString stringWithFormat: @"%@ (%@)",
    11681164                    NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
    1169                         tr_truncd(100.0 * [self checkingProgress], 2)];
     1165                    [NSString percentString: [self checkingProgress] longDecimals: YES]];
    11701166
    11711167        case TR_STATUS_DOWNLOAD:
Note: See TracChangeset for help on using the changeset viewer.