Changeset 1023


Ignore:
Timestamp:
Oct 21, 2006, 3:36:20 PM (15 years ago)
Author:
livings124
Message:

Only update info when necessary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoWindowController.m

    r1010 r1023  
    4848@interface InfoWindowController (Private)
    4949
    50 - (void) reloadPeerTable;
     50- (void) updateInfoActivity;
     51- (void) updateInfoPeers;
     52
    5153- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate;
    5254- (NSArray *) peerSortDescriptors;
     
    244246- (void) updateInfoStats
    245247{
     248    if ([[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_ACTIVITY_IDENT])
     249        [self updateInfoActivity];
     250    else if ([[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_PEERS_IDENT])
     251        [self updateInfoPeers];
     252    else;
     253}
     254
     255- (void) updateInfoActivity
     256{
    246257    int numberSelected = [fTorrents count];
    247258    if (numberSelected == 0)
     
    262273    [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
    263274    [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
    264 
     275   
    265276    if (numberSelected == 1)
    266277    {
     
    273284        [fStateField setStringValue: [torrent stateString]];
    274285       
    275         int seeders = [torrent seeders], leechers = [torrent leechers];
    276         [fSeedersField setStringValue: seeders < 0 ? @"" : [NSString stringWithInt: seeders]];
    277         [fLeechersField setStringValue: leechers < 0 ? @"" : [NSString stringWithInt: leechers]];
    278        
    279         BOOL active = [torrent isActive];
    280        
    281         [fConnectedPeersField setStringValue: active ? [NSString stringWithFormat: @"%d (%d incoming)",
    282                                                         [torrent totalPeers], [torrent totalPeersIncoming]]: @""];
    283         [fDownloadingFromField setStringValue: active ? [NSString stringWithInt: [torrent peersUploading]] : @""];
    284         [fUploadingToField setStringValue: active ? [NSString stringWithInt: [torrent peersDownloading]] : @""];
    285        
    286286        [fRatioField setStringValue: [NSString stringForRatioWithDownload: downloadedTotal upload: uploadedTotal]];
    287287       
    288288        [fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""];
    289289       
    290         //set peers table if visible
    291         if ([[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_PEERS_IDENT])
    292             [self reloadPeerTable];
    293        
    294         //update pieces view if visible
    295         if ([[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_ACTIVITY_IDENT])
    296             [fPiecesView updateView: NO];
    297     }
     290        [fPiecesView updateView: NO];
     291    }
     292}
     293
     294- (void) updateInfoPeers
     295{
     296    if ([fTorrents count] != 1)
     297        return;
     298    Torrent * torrent = [fTorrents objectAtIndex: 0];
     299   
     300    int seeders = [torrent seeders], leechers = [torrent leechers];
     301    [fSeedersField setStringValue: seeders < 0 ? @"" : [NSString stringWithInt: seeders]];
     302    [fLeechersField setStringValue: leechers < 0 ? @"" : [NSString stringWithInt: leechers]];
     303   
     304    BOOL active = [torrent isActive];
     305    [fConnectedPeersField setStringValue: active ? [NSString stringWithFormat: @"%d (%d incoming)",
     306                                                    [torrent totalPeers], [torrent totalPeersIncoming]]: @""];
     307    [fDownloadingFromField setStringValue: active ? [NSString stringWithInt: [torrent peersUploading]] : @""];
     308    [fUploadingToField setStringValue: active ? [NSString stringWithInt: [torrent peersDownloading]] : @""];
     309   
     310    [fPeers setArray: [torrent peers]];
     311    [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
     312   
     313    [fPeerTable reloadData];
    298314}
    299315
     
    357373}
    358374
    359 //requires a non-empty torrent array
    360 - (void) reloadPeerTable
    361 {
    362     Torrent * torrent = [fTorrents objectAtIndex: 0];
    363    
    364     [fPeers setArray: [torrent peers]];
    365     [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
    366    
    367     [fPeerTable reloadData];
    368 }
    369 
    370375- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
    371376{
     
    395400- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate
    396401{
     402    [self updateInfoStats];
     403   
    397404    float height;
    398405    if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
    399406    {
    400407        height = TAB_ACTIVITY_HEIGHT;
    401        
    402408        [fPiecesView updateView: YES];
    403409    }
     
    405411    {
    406412        height = TAB_PEERS_HEIGHT;
    407        
    408         if ([fTorrents count] == 1)
    409             [self reloadPeerTable]; //initial update of peer table
    410413    }
    411414    else if ([identifier isEqualToString: TAB_FILES_IDENT])
Note: See TracChangeset for help on using the changeset viewer.