Changeset 2723


Ignore:
Timestamp:
Aug 11, 2007, 4:46:21 AM (15 years ago)
Author:
livings124
Message:

combine similar code for attributes in the torrent cell

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TorrentCell.m

    r2721 r2723  
    5757
    5858- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
    59 - (NSAttributedString *) attributedProgressWithColor: (NSColor *) color;
    60 - (NSAttributedString *) attributedStatusWithColor: (NSColor *) color;
    61 - (NSAttributedString *) attributedMinimalStatusWithColor: (NSColor *) color;
     59- (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color;
    6260
    6361@end
     
    149147        return NSZeroRect;
    150148   
    151     NSAttributedString * status = [self attributedMinimalStatusWithColor: nil];
     149    Torrent * torrent = [self representedObject];
     150    NSString * string = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
     151                            ? [torrent remainingTimeString] : [torrent shortStatusString];
     152    NSAttributedString * status = [self attributedStatusString: string withColor: nil];
    152153   
    153154    NSRect result = bounds;
     
    222223    NSRect minimalStatusRect = [self minimalStatusRectForBounds: cellFrame];
    223224    if (minimal)
    224         [[self attributedMinimalStatusWithColor: statusColor] drawInRect: minimalStatusRect];
     225    {
     226        NSString * string = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
     227                                ? [torrent remainingTimeString] : [torrent shortStatusString];
     228        [[self attributedStatusString: string withColor: statusColor] drawInRect: minimalStatusRect];
     229    }
    225230   
    226231    //title
     
    233238    {
    234239        progressRect = [self rectForProgressBasedOnTitleRect: titleRect inBounds: cellFrame];
    235         [[self attributedProgressWithColor: statusColor] drawInRect: progressRect];
     240        [[self attributedStatusString: [torrent progressString] withColor: statusColor] drawInRect: progressRect];
    236241    }
    237242   
     
    245250    {
    246251        NSRect statusRect = [self rectForStatusBasedOnProgressRect: progressRect inBounds: cellFrame];
    247         [[self attributedStatusWithColor: statusColor] drawInRect: statusRect];
     252        [[self attributedStatusString: [torrent statusString] withColor: statusColor] drawInRect: statusRect];
    248253    }
    249254}
     
    540545        return NSZeroRect;
    541546   
    542     NSSize progressSize = [[self attributedProgressWithColor: nil] size];
     547    NSSize progressSize = [[self attributedStatusString: [[self representedObject] progressString] withColor: nil] size];
    543548   
    544549    NSRect result = titleRect;
     
    570575        return NSZeroRect;
    571576   
    572     NSSize statusSize = [[self attributedStatusWithColor: nil] size];
     577    NSSize statusSize = [[self attributedStatusString: [[self representedObject] statusString] withColor: nil] size];
    573578   
    574579    NSRect result = progressRect;
     
    590595}
    591596
    592 - (NSAttributedString *) attributedProgressWithColor: (NSColor *) color
     597- (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color
    593598{
    594599    if (color)
    595600        [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    596        
    597     NSString * progress = [[self representedObject] progressString];
    598     return [[[NSAttributedString alloc] initWithString: progress attributes: fStatusAttributes] autorelease];
    599 }
    600 
    601 - (NSAttributedString *) attributedStatusWithColor: (NSColor *) color
    602 {
    603     if (color)
    604         [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    605        
    606     NSString * status = [[self representedObject] statusString];
    607     return [[[NSAttributedString alloc] initWithString: status attributes: fStatusAttributes] autorelease];
    608 }
    609 
    610 #warning combine?
    611 - (NSAttributedString *) attributedMinimalStatusWithColor: (NSColor *) color
    612 {
    613     if (color)
    614         [fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
    615    
    616     Torrent * torrent = [self representedObject];
    617     NSString * status = ![fDefaults boolForKey: @"SmallStatusRegular"] && [torrent isActive]
    618                                     ? [torrent remainingTimeString] : [torrent shortStatusString];
    619    
    620     return [[[NSAttributedString alloc] initWithString: status attributes: fStatusAttributes] autorelease];
     601   
     602    return [[[NSAttributedString alloc] initWithString: string attributes: fStatusAttributes] autorelease];
    621603}
    622604
Note: See TracChangeset for help on using the changeset viewer.