Changeset 9215


Ignore:
Timestamp:
Sep 28, 2009, 3:59:17 PM (13 years ago)
Author:
livings124
Message:

a little cleanup to the peer count code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TrackerCell.m

    r9214 r9215  
    5151- (NSAttributedString *) attributedNameWithColor: (NSColor *) color;
    5252- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString color: (NSColor *) color;
     53- (NSAttributedString *) attributedCount: (NSInteger) count color: (NSColor *) color;
    5354
    5455@end
     
    136137   
    137138    //count strings
    138     NSString * seederBaseString = [node totalSeeders] != -1 ? [NSString stringWithFormat: @"%d", [node totalSeeders]]
    139                                                             : NSLocalizedString(@"N/A", "tracker peer stat");
    140     NSAttributedString * seederString = [self attributedStatusWithString: seederBaseString color: statusColor];
     139    NSAttributedString * seederString = [self attributedCount: [node totalSeeders] color: statusColor];
    141140    const NSRect seederRect = [self rectForCountWithString: seederString withAboveRect: nameRect inBounds: cellFrame];
    142141    [seederString drawInRect: seederRect];
    143142   
    144     NSString * leecherBaseString = [node totalLeechers] != -1 ? [NSString stringWithFormat: @"%d", [node totalLeechers]]
    145                                                                 : NSLocalizedString(@"N/A", "tracker peer stat");
    146     NSAttributedString * leecherString = [self attributedStatusWithString: leecherBaseString color: statusColor];
     143    NSAttributedString * leecherString = [self attributedCount: [node totalLeechers] color: statusColor];
    147144    const NSRect leecherRect = [self rectForCountWithString: leecherString withAboveRect: seederRect inBounds: cellFrame];
    148145    [leecherString drawInRect: leecherRect];
    149146   
    150     NSString * downloadedBaseString = [node totalDownloaded] != -1 ? [NSString stringWithFormat: @"%d", [node totalDownloaded]]
    151                                                                     : NSLocalizedString(@"N/A", "tracker peer stat");
    152     NSAttributedString * downloadedString = [self attributedStatusWithString: downloadedBaseString color: statusColor];
     147    NSAttributedString * downloadedString = [self attributedCount: [node totalDownloaded] color: statusColor];
    153148    const NSRect downloadedRect = [self rectForCountWithString: downloadedString withAboveRect: leecherRect inBounds: cellFrame];
    154149    [downloadedString drawInRect: downloadedRect];
     
    298293- (NSAttributedString *) attributedNameWithColor: (NSColor *) color
    299294{
    300     if (color)
    301         [fNameAttributes setObject: color forKey: NSForegroundColorAttributeName];
    302        
     295    [fNameAttributes setObject: color forKey: NSForegroundColorAttributeName];
     296   
    303297    NSString * name = [(TrackerNode *)[self objectValue] host];
    304298    return [[[NSAttributedString alloc] initWithString: name attributes: fNameAttributes] autorelease];
     
    307301- (NSAttributedString *) attributedStatusWithString: (NSString *) statusString color: (NSColor *) color
    308302{
    309     if (color)
    310         [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
     303    [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    311304   
    312305    return [[[NSAttributedString alloc] initWithString: statusString attributes: fStatusAttributes] autorelease];
    313306}
    314307
     308- (NSAttributedString *) attributedCount: (NSInteger) count color: (NSColor *) color
     309{
     310    [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
     311   
     312    NSString * countString = count != -1 ? [NSString stringWithFormat: @"%d", count] : NSLocalizedString(@"N/A", "tracker peer stat");
     313    return [[[NSAttributedString alloc] initWithString: countString attributes: fStatusAttributes] autorelease];
     314}
     315
    315316@end
Note: See TracChangeset for help on using the changeset viewer.