Changeset 1378


Ignore:
Timestamp:
Jan 17, 2007, 2:43:07 AM (15 years ago)
Author:
livings124
Message:

retain/release arrays instead of using mutable arrays, and file table only shows files when a single torrent is selected

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/transmission.c

    r1377 r1378  
    600600        tr_peer_t * peer;
    601601        struct in_addr * addr;
    602         int i = 0;
     602        int i;
    603603        for( i = 0; i < tor->peerCount; i++ )
    604604        {
  • trunk/macosx/InfoWindowController.h

    r1341 r1378  
    3131{
    3232    NSArray * fTorrents;
    33     NSMutableArray * fPeers, * fFiles;
     33    NSArray * fPeers, * fFiles;
    3434    NSImage * fAppIcon, * fDotGreen, * fDotRed;
    3535   
  • trunk/macosx/InfoWindowController.m

    r1341 r1378  
    7171- (void) awakeFromNib
    7272{
    73     fPeers = [[NSMutableArray alloc] initWithCapacity: 75];
    74     fFiles = [[NSMutableArray alloc] initWithCapacity: 15];
    7573    [fFileTable setDoubleAction: @selector(revealFile:)];
    7674   
     
    102100{
    103101    [fTorrents release];
    104     [fPeers release];
    105     [fFiles release];
     102    if (fPeers)
     103        [fPeers release];
     104    if (fFiles)
     105        [fFiles release];
    106106
    107107    [fAppIcon release];
     
    188188        [fErrorMessageView setSelectable: NO];
    189189       
    190         [fPeers removeAllObjects];
    191         [fPeerTable reloadData];
    192        
    193190        [fPiecesView setTorrent: nil];
     191       
     192        if (fPeers)
     193        {
     194            [fPeers release];
     195            fPeers = nil;
     196        }
     197       
     198        if (fFiles)
     199        {
     200            [fFiles release];
     201            fFiles = nil;
     202        }
     203        [fFileTableStatusField setStringValue: NSLocalizedString(@"info not available",
     204                                        "Inspector -> Files tab -> bottom text (number of files)")];
    194205    }
    195206    else
     
    242253       
    243254        [fPiecesView setTorrent: torrent];
    244     }
    245    
    246     //update stats and settings
    247     [self updateInfoStats];
    248     [self updateInfoSettings];
    249 
    250     //set file table
    251     [fFiles removeAllObjects];
    252    
    253     if (numberSelected > 0)
    254     {
    255         Torrent * torrent;
    256         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    257         while ((torrent = [enumerator nextObject]))
    258             [fFiles addObjectsFromArray: [torrent fileList]];
     255       
     256        //set file table
     257        [fFileTable deselectAll: nil];
     258        if (fFiles)
     259            [fFiles release];
     260        fFiles = [[torrent fileList] retain];
    259261       
    260262        if ([fFiles count] > 1)
     
    265267                                        "Inspector -> Files tab -> bottom text (number of files)"), [fFiles count]]];
    266268    }
    267     else
    268         [fFileTableStatusField setStringValue: NSLocalizedString(@"info not available",
    269                                         "Inspector -> Files tab -> bottom text (number of files)")];
    270    
    271     [fFileTable deselectAll: nil];
     269   
     270    //update stats and settings
     271    [self updateInfoStats];
     272    [self updateInfoSettings];
     273   
     274    [fPeerTable reloadData];
    272275    [fFileTable reloadData];
    273276}
     
    363366    [fUploadingToField setStringValue: active ? [NSString stringWithInt: [torrent peersDownloading]] : @""];
    364367   
    365     [fPeers setArray: [torrent peers]];
    366     [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
     368    if (fPeers)
     369        [fPeers release];
     370    fPeers = [[[torrent peers] sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
    367371   
    368372    [fPeerTable reloadData];
     
    581585{
    582586    if (tableView == fPeerTable)
    583         return [fPeers count];
    584     else
    585         return [fFiles count];
     587        return fPeers ? [fPeers count] : 0;
     588    else
     589        return fFiles ? [fFiles count] : 0;
    586590}
    587591
     
    616620            return [NSString stringForFileSize: [[file objectForKey: @"Size"] unsignedLongLongValue]];
    617621        else
    618             return [[file objectForKey: @"Name"] lastPathComponent];
     622            return [file objectForKey: @"Name"];
    619623    }
    620624}
     
    624628    if (tableView == fPeerTable)
    625629    {
    626         [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
    627         [tableView reloadData];
     630        if (fPeers)
     631        {
     632            NSArray * oldPeers = fPeers;
     633            fPeers = [[fPeers sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
     634            [oldPeers release];
     635            [tableView reloadData];
     636        }
    628637    }
    629638}
     
    690699- (void) revealFile: (id) sender
    691700{
    692     NSIndexSet * indexSet = [fFileTable selectedRowIndexes];
    693     unsigned int i;
    694     for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    695         [[NSWorkspace sharedWorkspace] selectFile: [[fFiles objectAtIndex: i] objectForKey: @"Name"]
    696                                         inFileViewerRootedAtPath: nil];
     701    Torrent * torrent = [fTorrents objectAtIndex: 0];
     702    NSEnumerator * enumerator = [[fFiles objectsAtIndexes: [fFileTable selectedRowIndexes]] objectEnumerator];
     703    NSDictionary * file;
     704    while ((file = [enumerator nextObject]))
     705        [[NSWorkspace sharedWorkspace] selectFile: [[torrent downloadFolder]
     706            stringByAppendingPathComponent: [file objectForKey: @"Name"]] inFileViewerRootedAtPath: nil];
    697707}
    698708
  • trunk/macosx/Torrent.m

    r1370 r1378  
    10751075        file = fInfo->files[i];
    10761076        [files addObject: [NSDictionary dictionaryWithObjectsAndKeys:
    1077             [[self downloadFolder] stringByAppendingPathComponent: [NSString stringWithUTF8String: file.name]], @"Name",
     1077            [NSString stringWithUTF8String: file.name], @"Name",
    10781078            [NSNumber numberWithUnsignedLongLong: file.length], @"Size", nil]];
    10791079    }
Note: See TracChangeset for help on using the changeset viewer.