From e03d7dd65828f52e408c52a663a3113ba36657dd Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 6 Feb 2010 03:34:49 +0000 Subject: [PATCH] #2867 Display peers and web seeds for all selected torrents in the inspector --- macosx/InfoWindowController.h | 2 +- macosx/InfoWindowController.m | 149 +++++++++++++++++++++------------- macosx/Torrent.m | 6 +- 3 files changed, 97 insertions(+), 60 deletions(-) diff --git a/macosx/InfoWindowController.h b/macosx/InfoWindowController.h index 974cf3f6b..0c6f2cfd7 100644 --- a/macosx/InfoWindowController.h +++ b/macosx/InfoWindowController.h @@ -57,7 +57,7 @@ TrackerCell * fTrackerCell; IBOutlet NSSegmentedControl * fTrackerAddRemoveControl; - NSArray * fPeers, * fWebSeeds; + NSMutableArray * fPeers, * fWebSeeds; IBOutlet NSTableView * fPeerTable, * fWebSeedTable; IBOutlet NSTextField * fConnectedPeersField; IBOutlet NSTextView * fErrorMessageView; diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 330bda08f..f734493aa 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -778,10 +778,15 @@ typedef enum { if (tableView == fPeerTable) { + const BOOL multiple = [fTorrents count] > 1; + NSDictionary * peer = [fPeers objectAtIndex: row]; - NSMutableArray * components = [NSMutableArray arrayWithCapacity: 5]; + NSMutableArray * components = [NSMutableArray arrayWithCapacity: multiple ? 6 : 5]; + + if (multiple) + [components addObject: [peer objectForKey: @"Name"]]; - CGFloat progress = [[peer objectForKey: @"Progress"] floatValue]; + const CGFloat progress = [[peer objectForKey: @"Progress"] floatValue]; NSString * progressString = [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%", "Inspector -> Peers tab -> table row tooltip"), progress * 100.0]; if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue]) @@ -864,6 +869,11 @@ typedef enum if ([node isKindOfClass: [TrackerNode class]]) return [(TrackerNode *)node fullAnnounceAddress]; } + else if (tableView == fWebSeedTable) + { + if ([fTorrents count] > 1) + return [[fWebSeeds objectAtIndex: row] objectForKey: @"Name"]; + } return nil; } @@ -1247,6 +1257,15 @@ typedef enum [fPeersConnectField setEnabled: NO]; [fPeersConnectField setStringValue: @""]; [fPeersConnectLabel setEnabled: NO]; + + [fPeers release]; + fPeers = nil; + [fPeerTable reloadData]; + + [fWebSeeds release]; + fWebSeeds = nil; + [fWebSeedTable reloadData]; + [self setWebSeedTableHidden: YES animate: YES]; } [fFileController setTorrent: nil]; @@ -1282,15 +1301,6 @@ typedef enum [fPiecesControl setEnabled: NO]; [fPiecesView setTorrent: nil]; - [fPeers release]; - fPeers = nil; - [fPeerTable reloadData]; - - [fWebSeeds release]; - fWebSeeds = nil; - [fWebSeedTable reloadData]; - [self setWebSeedTableHidden: YES animate: YES]; - [fTrackerTable setTorrent: nil]; [fTrackers release]; @@ -1374,16 +1384,6 @@ typedef enum [fPiecesControl setEnabled: YES]; [fPiecesView setTorrent: torrent]; - //get webseeds for table - if no webseeds for this torrent, clear the table - BOOL hasWebSeeds = [torrent webSeedCount] > 0; - [self setWebSeedTableHidden: !hasWebSeeds animate: YES]; - if (!hasWebSeeds) - { - [fWebSeeds release]; - fWebSeeds = nil; - [fWebSeedTable reloadData]; - } - [fTrackerTable setTorrent: torrent]; [fTrackerTable deselectAll: self]; [fTrackerAddRemoveControl setEnabled: YES forSegment: TRACKER_ADD_TAG]; @@ -1533,48 +1533,76 @@ typedef enum - (void) updateInfoPeers { - if ([fTorrents count] != 1) + if ([fTorrents count] == 0) return; - Torrent * torrent = [fTorrents objectAtIndex: 0]; - NSString * knownString = [NSString stringWithFormat: NSLocalizedString(@"%d known", "Inspector -> Peers tab -> peers"), - [torrent totalPeersKnown]]; - if ([torrent isActive]) + [fPeers release]; + fPeers = [[NSMutableArray alloc] init]; + + NSUInteger known = 0, connected = 0, tracker = 0, incoming = 0, cache = 0, pex = 0, dht = 0, ltep = 0, + toUs = 0, fromUs = 0; + BOOL anyActive = false; + for (Torrent * torrent in fTorrents) + { + [fPeers addObjectsFromArray: [torrent peers]]; + + known += [torrent totalPeersKnown]; + + if ([torrent isActive]) + { + anyActive = YES; + const NSUInteger connectedThis = [torrent totalPeersConnected]; + if (connectedThis > 0) + { + connected += [torrent totalPeersConnected]; + tracker += [torrent totalPeersTracker]; + incoming += [torrent totalPeersIncoming]; + cache += [torrent totalPeersCache]; + pex += [torrent totalPeersPex]; + dht += [torrent totalPeersDHT]; + ltep += [torrent totalPeersLTEP]; + + toUs += [torrent peersSendingToUs]; + fromUs += [torrent peersGettingFromUs]; + } + } + } + + NSString * knownString = [NSString stringWithFormat: NSLocalizedString(@"%d known", "Inspector -> Peers tab -> peers"), known]; + if (anyActive) { - const NSInteger total = [torrent totalPeersConnected]; NSString * connectedText = [NSString stringWithFormat: NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"), - total]; + connected]; - if (total > 0) + if (connected > 0) { - NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 5]; - NSInteger count; - if ((count = [torrent totalPeersTracker]) > 0) + NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 6]; + if (tracker > 0) [fromComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), count]]; - if ((count = [torrent totalPeersIncoming]) > 0) + NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), tracker]]; + if (incoming > 0) [fromComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), count]]; - if ((count = [torrent totalPeersCache]) > 0) + NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), incoming]]; + if (cache > 0) [fromComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), count]]; - if ((count = [torrent totalPeersPex]) > 0) + NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), cache]]; + if (pex > 0) [fromComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), count]]; - if ((count = [torrent totalPeersDHT]) > 0) + NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), pex]]; + if (dht > 0) [fromComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"%d DHT", "Inspector -> Peers tab -> peers"), count]]; - if ((count = [torrent totalPeersLTEP]) > 0) + NSLocalizedString(@"%d DHT", "Inspector -> Peers tab -> peers"), dht]]; + if (ltep > 0) [fromComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"%d LTEP", "Inspector -> Peers tab -> peers"), count]]; + NSLocalizedString(@"%d LTEP", "Inspector -> Peers tab -> peers"), ltep]]; NSMutableArray * upDownComponents = [NSMutableArray arrayWithCapacity: 3]; - if ((count = [torrent peersSendingToUs]) > 0) + if (toUs > 0) [upDownComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"DL from %d", "Inspector -> Peers tab -> peers"), count]]; - if ((count = [torrent peersGettingFromUs]) > 0) + NSLocalizedString(@"DL from %d", "Inspector -> Peers tab -> peers"), toUs]]; + if (fromUs > 0) [upDownComponents addObject: [NSString stringWithFormat: - NSLocalizedString(@"UL to %d", "Inspector -> Peers tab -> peers"), count]]; + NSLocalizedString(@"UL to %d", "Inspector -> Peers tab -> peers"), fromUs]]; [upDownComponents addObject: knownString]; connectedText = [connectedText stringByAppendingFormat: @": %@\n%@", [fromComponents componentsJoinedByString: @", "], @@ -1587,21 +1615,28 @@ typedef enum } else { - NSString * connectedText = [NSString stringWithFormat: @"%@\n%@", - NSLocalizedString(@"Not Connected", "Inspector -> Peers tab -> peers"), knownString]; + NSString * activeString; + if ([fTorrents count] == 1) + activeString = NSLocalizedString(@"Transfer Not Active", "Inspector -> Peers tab -> peers"); + else + activeString = NSLocalizedString(@"Transfers Not Active", "Inspector -> Peers tab -> peers"); + + NSString * connectedText = [NSString stringWithFormat: @"%@\n%@", activeString, knownString]; [fConnectedPeersField setStringValue: connectedText]; } - [fPeers release]; - fPeers = [[[torrent peers] sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain]; + [fPeers sortUsingDescriptors: [self peerSortDescriptors]]; [fPeerTable reloadData]; - if ([torrent webSeedCount] > 0) - { - [fWebSeeds release]; - fWebSeeds = [[[torrent webSeeds] sortedArrayUsingDescriptors: [fWebSeedTable sortDescriptors]] retain]; - [fWebSeedTable reloadData]; - } + [fWebSeeds release]; + fWebSeeds = [[NSMutableArray alloc] init]; + + for (Torrent * torrent in fTorrents) + [fWebSeeds addObjectsFromArray: [torrent webSeeds]]; + + [fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]]; + [fWebSeedTable reloadData]; + [self setWebSeedTableHidden: [fWebSeeds count] == 0 animate: YES]; } - (void) updateInfoFiles diff --git a/macosx/Torrent.m b/macosx/Torrent.m index d4824a4ca..d4d17c277 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -858,8 +858,9 @@ int trashDataFile(const char * filename) for (int i = 0; i < totalPeers; i++) { tr_peer_stat * peer = &peers[i]; - NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 10]; + NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 11]; + [dict setObject: [self name] forKey: @"Name"]; [dict setObject: [NSNumber numberWithInt: peer->from] forKey: @"From"]; [dict setObject: [NSString stringWithUTF8String: peer->addr] forKey: @"IP"]; [dict setObject: [NSNumber numberWithInt: peer->port] forKey: @"Port"]; @@ -896,8 +897,9 @@ int trashDataFile(const char * filename) for (NSInteger i = 0; i < webSeedCount; i++) { - NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 2]; + NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 3]; + [dict setObject: [self name] forKey: @"Name"]; [dict setObject: [NSString stringWithUTF8String: fInfo->webseeds[i]] forKey: @"Address"]; if (dlSpeeds[i] != -1.0) -- 2.40.0