Changeset 855


Ignore:
Timestamp:
Sep 11, 2006, 11:52:03 PM (15 years ago)
Author:
livings124
Message:

Use tableView:objectValueForTableColumn:row: instead of tableView:willDisplayCell:...

This required passing in a dictionary of values to display, but should make it 10.5 compatible and potentially a little more efficient. Those using Leopard please report any issues, because I don't have it to test.

Location:
trunk/macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r853 r855  
    15871587}
    15881588
    1589 - (void) tableView: (NSTableView *) t willDisplayCell: (id) cell
     1589/*- (void) tableView: (NSTableView *) t willDisplayCell: (id) cell
    15901590    forTableColumn: (NSTableColumn *) tableColumn row: (int) row
    15911591{
    15921592    [cell setTorrent: [fDisplayedTorrents objectAtIndex: row]];
     1593}*/
     1594
     1595- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) tableColumn row: (int) row
     1596{
     1597    return [[fDisplayedTorrents objectAtIndex: row] infoForCurrentView];
    15931598}
    15941599
  • trunk/macosx/Torrent.h

    r835 r855  
    6464- (void)       getAvailability: (int8_t *) tab size: (int) size;
    6565
    66 - (void)        update;
     66- (void)            update;
     67- (NSDictionary *)  infoForCurrentView;
     68
    6769- (void)        startTransfer;
    6870- (void)        stopTransfer;
  • trunk/macosx/Torrent.m

    r842 r855  
    272272}
    273273
     274- (NSDictionary *) infoForCurrentView
     275{
     276    NSMutableDictionary * info = [NSMutableDictionary dictionaryWithObjectsAndKeys:
     277                                    [self name], @"Name",
     278                                    [NSNumber numberWithBool: [self isSeeding]], @"Seeding",
     279                                    [NSNumber numberWithFloat: [self progress]], @"Progress",
     280                                    [NSNumber numberWithBool: [self isActive]], @"Active",
     281                                    [NSNumber numberWithBool: [self isError]], @"Error", nil];
     282   
     283    if (![fDefaults boolForKey: @"SmallView"])
     284    {
     285        [info setObject: fIconFlipped forKey: @"Icon"];
     286        [info setObject: [self progressString] forKey: @"ProgressString"];
     287        [info setObject: [self statusString] forKey: @"StatusString"];
     288    }
     289    else
     290    {
     291        [info setObject: fIconSmall forKey: @"Icon"];
     292        [info setObject: [self remainingTimeString] forKey: @"RemainingTimeString"];
     293        [info setObject: [self shortStatusString] forKey: @"ShortStatusString"];
     294    }
     295   
     296    return info;
     297}
     298
    274299- (void) startTransfer
    275300{
  • trunk/macosx/TorrentCell.h

    r835 r855  
    3131@interface TorrentCell : NSCell
    3232{
    33     Torrent * fTorrent;
    3433    BOOL fStatusRegular;
    3534   
     
    4241}
    4342
    44 - (void) setTorrent: (Torrent *) torrent;
    45 
    4643- (void) toggleMinimalStatus;
    4744
  • trunk/macosx/TorrentCell.m

    r844 r855  
    3333- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point;
    3434- (void) buildSimpleBar: (float) width point: (NSPoint) point;
    35 - (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point;
     35//- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point;
    3636
    3737@end
     
    102102}
    103103
    104 - (void) setTorrent: (Torrent *) torrent
    105 {
    106     fTorrent = torrent;
    107 }
    108 
    109104- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point
    110105{
     
    117112- (void) buildSimpleBar: (float) width point: (NSPoint) point
    118113{
     114    NSDictionary * info = [self objectValue];
     115
    119116    width -= 2.0;
    120     if ([fTorrent isSeeding])
     117    if ([[info objectForKey: @"Seeding"] boolValue])
    121118    {
    122119        [fProgressEndGreen compositeToPoint: point operation: NSCompositeSourceOver];
     
    130127    else
    131128    {
    132         float completedWidth = [fTorrent progress] * width,
     129        float completedWidth = [[info objectForKey: @"Progress"] floatValue] * width,
    133130                remainingWidth = width - completedWidth;
    134         BOOL isActive = [fTorrent isActive];
     131        BOOL isActive = [[info objectForKey: @"Active"] boolValue];
    135132       
    136133        //left end
     
    167164}
    168165
    169 - (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point
     166/*- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point
    170167{
    171168    //if seeding, there's no need for the advanced bar
     
    271268    point.x += widthFloat;
    272269    [fProgressEndAdvanced compositeToPoint: point operation: NSCompositeSourceOver];
    273 }
     270}*/
    274271
    275272- (void) toggleMinimalStatus
     
    292289    NSPoint pen = cellFrame.origin;
    293290    const float PADDING = 3.0, LINE_PADDING = 2.0, EXTRA_NAME_SHIFT = 1.0;
    294 
     291   
     292    NSDictionary * info = [self objectValue];
     293   
    295294    if (![fDefaults boolForKey: @"SmallView"]) //regular size
    296295    {
    297296        //icon
    298         NSImage * icon = [fTorrent iconFlipped];
     297        NSImage * icon = [info objectForKey: @"Icon"];
    299298        NSSize iconSize = [icon size];
    300299       
     
    306305       
    307306        //error badge
    308         if ([fTorrent isError])
     307        if ([[info objectForKey: @"Error"] boolValue])
    309308        {
    310309            NSSize errorIconSize = [fErrorImage size];
     
    320319        pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
    321320        pen.y = cellFrame.origin.y + PADDING;
    322         NSAttributedString * nameString = [[fTorrent name] attributedStringFittingInWidth: mainWidth
     321        NSAttributedString * nameString = [[info objectForKey: @"Name"] attributedStringFittingInWidth: mainWidth
    323322                                                attributes: nameAttributes];
    324323        [nameString drawAtPoint: pen];
     
    327326        pen.y += [nameString size].height + LINE_PADDING - 1.0;
    328327       
    329         NSAttributedString * progressString = [[fTorrent progressString]
     328        NSAttributedString * progressString = [[info objectForKey: @"ProgressString"]
    330329            attributedStringFittingInWidth: mainWidth attributes: statusAttributes];
    331330        [progressString drawAtPoint: pen];
     
    337336        float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
    338337       
    339         if ([fDefaults boolForKey: @"UseAdvancedBar"])
     338        /*if ([fDefaults boolForKey: @"UseAdvancedBar"])
    340339            [self buildAdvancedBar: barWidth point: pen];
    341         else
     340        else*/
    342341            [self buildSimpleBar: barWidth point: pen];
    343342
     
    345344        pen.x += EXTRA_NAME_SHIFT;
    346345        pen.y += LINE_PADDING;
    347         NSAttributedString * statusString = [[fTorrent statusString]
     346        NSAttributedString * statusString = [[info objectForKey: @"StatusString"]
    348347            attributedStringFittingInWidth: mainWidth attributes: statusAttributes];
    349348        [statusString drawAtPoint: pen];
     
    352351    {
    353352        //icon
    354         NSImage * icon = ![fTorrent isError] ? [fTorrent iconSmall] : fErrorImage;
     353        NSImage * icon = ![[info objectForKey: @"Error"] boolValue] ? [info objectForKey: @"Icon"] : fErrorImage;
    355354        NSSize iconSize = [icon size];
    356355       
     
    364363        float mainWidth = cellFrame.size.width - iconSize.width - 3.0 * PADDING - EXTRA_NAME_SHIFT;
    365364       
    366         NSString * realStatusString = !fStatusRegular && [fTorrent isActive] ? [fTorrent remainingTimeString]
    367                                                                             : [fTorrent shortStatusString];
     365        NSString * realStatusString = !fStatusRegular && [[info objectForKey: @"Active"] boolValue]
     366                                        ? [info objectForKey: @"RemainingTimeString"]
     367                                        : [info objectForKey: @"ShortStatusString"];
    368368       
    369369        NSAttributedString * statusString = [[[NSAttributedString alloc] initWithString: realStatusString
    370370                                                    attributes: statusAttributes] autorelease];
    371         NSAttributedString * nameString = [[fTorrent name] attributedStringFittingInWidth:
     371        NSAttributedString * nameString = [[info objectForKey: @"Name"] attributedStringFittingInWidth:
    372372                                mainWidth - [statusString size].width - LINE_PADDING attributes: nameAttributes];
    373373                     
     
    390390        float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
    391391       
    392         if ([fDefaults boolForKey: @"UseAdvancedBar"])
     392        /*if ([fDefaults boolForKey: @"UseAdvancedBar"])
    393393            [self buildAdvancedBar: barWidth point: pen];
    394         else
     394        else*/
    395395            [self buildSimpleBar: barWidth point: pen];
    396396    }
Note: See TracChangeset for help on using the changeset viewer.