Only update peer table when it's visible

This commit is contained in:
Mitchell Livingston
2006-09-03 16:16:35 +00:00
parent 4d0bc33f92
commit 4c100c1bf9
2 changed files with 27 additions and 15 deletions

View File

@@ -47,6 +47,7 @@
@interface InfoWindowController (Private)
- (void) reloadPeerTable;
- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate;
- (NSArray *) peerSortDescriptors;
@@ -267,24 +268,17 @@
BOOL active = [torrent isActive];
[fConnectedPeersField setStringValue: active ? [NSString
stringWithInt: [torrent totalPeers]] : @""];
[fDownloadingFromField setStringValue: active ? [NSString
stringWithInt: [torrent peersUploading]] : @""];
[fUploadingToField setStringValue: active ? [NSString
stringWithInt: [torrent peersDownloading]] : @""];
[fConnectedPeersField setStringValue: active ? [NSString stringWithInt: [torrent totalPeers]] : @""];
[fDownloadingFromField setStringValue: active ? [NSString stringWithInt: [torrent peersUploading]] : @""];
[fUploadingToField setStringValue: active ? [NSString stringWithInt: [torrent peersDownloading]] : @""];
[fRatioField setStringValue: [NSString stringForRatioWithDownload: downloadedTotal upload: uploadedTotal]];
[fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""];
//set peers table
[fPeers setArray: [torrent peers]];
[fPeers sortUsingDescriptors: [self peerSortDescriptors]];
[fPeerTable reloadData];
[fPeerTableStatusField setStringValue: [NSString stringWithFormat: @"%d of %d connected",
[torrent totalPeers], [fPeers count]]];
//set peers table if visible
if ([[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_PEERS_IDENT])
[self reloadPeerTable];
}
}
@@ -368,6 +362,19 @@
[self updateInfoStats];
}
//requires a non-empty torrent array
- (void) reloadPeerTable
{
Torrent * torrent = [fTorrents objectAtIndex: 0];
[fPeers setArray: [torrent peers]];
[fPeers sortUsingDescriptors: [self peerSortDescriptors]];
[fPeerTable reloadData];
[fPeerTableStatusField setStringValue: [NSString stringWithFormat: @"%d of %d connected",
[torrent totalPeers], [fPeers count]]];
}
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
{
SEL action = [menuItem action];
@@ -399,7 +406,12 @@
if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
height = TAB_ACTIVITY_HEIGHT;
else if ([identifier isEqualToString: TAB_PEERS_IDENT])
{
height = TAB_PEERS_HEIGHT;
if ([fTorrents count] == 1)
[self reloadPeerTable]; //initial update of peer table
}
else if ([identifier isEqualToString: TAB_FILES_IDENT])
height = TAB_FILES_HEIGHT;
else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])

View File

@@ -38,7 +38,7 @@
{
if ((self = [super initWithWindowNibName: name]))
{
NSMutableParagraphStyle * paragraph = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
NSMutableParagraphStyle * paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraph setHeadIndent: 20.0];
fAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
@@ -87,7 +87,7 @@
- (void) updateLog: (NSTimer *) timer
{
tr_msg_list_t * messages, * currentMessage;
if (!(messages = tr_getQueuedMessages()))
if ((messages = tr_getQueuedMessages()) == NULL)
return;
//keep scrolled to bottom if already at bottom or there is no scroll bar yet