2010-03-06 23:12:30 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2010-2012 Transmission authors and contributors
|
2010-03-06 23:12:30 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "InfoPeersViewController.h"
|
|
|
|
#import "NSApplicationAdditions.h"
|
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
#import "PeerProgressIndicatorCell.h"
|
|
|
|
#import "Torrent.h"
|
2012-04-29 00:53:34 +00:00
|
|
|
#import "WebSeedTableView.h"
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2010-05-31 14:06:54 +00:00
|
|
|
#import "transmission.h" // required by utils.h
|
|
|
|
#import "utils.h"
|
|
|
|
|
2016-03-03 22:27:45 +00:00
|
|
|
#define ANIMATION_ID_KEY @"animationId"
|
|
|
|
#define WEB_SEED_ANIMATION_ID @"webSeed"
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@interface InfoPeersViewController (Private)
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
- (void) setupInfo;
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
- (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate;
|
|
|
|
- (NSArray *) peerSortDescriptors;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoPeersViewController
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2010-03-14 03:09:12 +00:00
|
|
|
if ((self = [super initWithNibName: @"InfoPeersView" bundle: nil]))
|
|
|
|
{
|
|
|
|
[self setTitle: NSLocalizedString(@"Peers", "Inspector view -> title")];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2010-03-14 02:53:22 +00:00
|
|
|
const CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: @"InspectorContentHeightPeers"];
|
|
|
|
if (height != 0.0)
|
|
|
|
{
|
|
|
|
NSRect viewRect = [[self view] frame];
|
|
|
|
viewRect.size.height = height;
|
|
|
|
[[self view] setFrame: viewRect];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:56:44 +00:00
|
|
|
//set table header text
|
|
|
|
[[[fPeerTable tableColumnWithIdentifier: @"IP"] headerCell] setStringValue: NSLocalizedString(@"IP Address",
|
|
|
|
"inspector -> peer table -> header")];
|
|
|
|
[[[fPeerTable tableColumnWithIdentifier: @"Client"] headerCell] setStringValue: NSLocalizedString(@"Client",
|
|
|
|
"inspector -> peer table -> header")];
|
|
|
|
[[[fPeerTable tableColumnWithIdentifier: @"DL From"] headerCell] setStringValue: NSLocalizedString(@"DL",
|
|
|
|
"inspector -> peer table -> header")];
|
|
|
|
[[[fPeerTable tableColumnWithIdentifier: @"UL To"] headerCell] setStringValue: NSLocalizedString(@"UL",
|
|
|
|
"inspector -> peer table -> header")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:56:44 +00:00
|
|
|
[[[fWebSeedTable tableColumnWithIdentifier: @"Address"] headerCell] setStringValue: NSLocalizedString(@"Web Seeds",
|
|
|
|
"inspector -> web seed table -> header")];
|
|
|
|
[[[fWebSeedTable tableColumnWithIdentifier: @"DL From"] headerCell] setStringValue: NSLocalizedString(@"DL",
|
|
|
|
"inspector -> web seed table -> header")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//set table header tool tips
|
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"Encryption"] setHeaderToolTip: NSLocalizedString(@"Encrypted Connection",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"Progress"] setHeaderToolTip: NSLocalizedString(@"Available",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Peer",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
2010-03-06 23:56:44 +00:00
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"UL To"] setHeaderToolTip: NSLocalizedString(@"Uploading To Peer",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[[fWebSeedTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Web Seed",
|
|
|
|
"inspector -> web seed table -> header tool tip")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//prepare for animating peer table and web seed table
|
2016-03-03 22:27:45 +00:00
|
|
|
fViewTopMargin = fWebSeedTableTopConstraint.constant;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-02-27 20:29:57 +00:00
|
|
|
CABasicAnimation * webSeedTableAnimation = [CABasicAnimation animation];
|
2016-03-03 22:27:45 +00:00
|
|
|
[webSeedTableAnimation setTimingFunction: [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear]];
|
|
|
|
[webSeedTableAnimation setDuration: 0.125];
|
|
|
|
[webSeedTableAnimation setDelegate: self];
|
|
|
|
[webSeedTableAnimation setValue: WEB_SEED_ANIMATION_ID forKey: ANIMATION_ID_KEY];
|
|
|
|
[fWebSeedTableTopConstraint setAnimations: @{ @"constant": webSeedTableAnimation }];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[self setWebSeedTableHidden: YES animate: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#warning subclass?
|
|
|
|
- (void) setInfoForTorrents: (NSArray *) torrents
|
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2017-07-29 16:14:22 +00:00
|
|
|
fTorrents = torrents;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfo
|
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
if (!fSet)
|
|
|
|
[self setupInfo];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([fTorrents count] == 0)
|
|
|
|
return;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (!fPeers)
|
|
|
|
fPeers = [[NSMutableArray alloc] init];
|
|
|
|
else
|
|
|
|
[fPeers removeAllObjects];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (!fWebSeeds)
|
|
|
|
fWebSeeds = [[NSMutableArray alloc] init];
|
|
|
|
else
|
|
|
|
[fWebSeeds removeAllObjects];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-04 02:58:08 +00:00
|
|
|
NSUInteger connected = 0, tracker = 0, incoming = 0, cache = 0, lpd = 0, pex = 0, dht = 0, ltep = 0,
|
2010-03-06 23:12:30 +00:00
|
|
|
toUs = 0, fromUs = 0;
|
|
|
|
BOOL anyActive = false;
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
{
|
|
|
|
if ([torrent webSeedCount] > 0)
|
|
|
|
[fWebSeeds addObjectsFromArray: [torrent webSeeds]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([torrent isActive])
|
|
|
|
{
|
|
|
|
anyActive = YES;
|
|
|
|
[fPeers addObjectsFromArray: [torrent peers]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
const NSUInteger connectedThis = [torrent totalPeersConnected];
|
|
|
|
if (connectedThis > 0)
|
|
|
|
{
|
|
|
|
connected += [torrent totalPeersConnected];
|
|
|
|
tracker += [torrent totalPeersTracker];
|
|
|
|
incoming += [torrent totalPeersIncoming];
|
|
|
|
cache += [torrent totalPeersCache];
|
2010-05-19 23:08:14 +00:00
|
|
|
lpd += [torrent totalPeersLocal];
|
2010-03-06 23:12:30 +00:00
|
|
|
pex += [torrent totalPeersPex];
|
|
|
|
dht += [torrent totalPeersDHT];
|
|
|
|
ltep += [torrent totalPeersLTEP];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
toUs += [torrent peersSendingToUs];
|
|
|
|
fromUs += [torrent peersGettingFromUs];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fPeers sortUsingDescriptors: [self peerSortDescriptors]];
|
|
|
|
[fPeerTable reloadData];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]];
|
|
|
|
[fWebSeedTable reloadData];
|
2012-04-29 00:53:34 +00:00
|
|
|
[fWebSeedTable setWebSeeds: fWebSeeds];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (anyActive)
|
|
|
|
{
|
|
|
|
NSString * connectedText = [NSString stringWithFormat: NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"),
|
|
|
|
connected];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (connected > 0)
|
|
|
|
{
|
2011-03-04 02:58:08 +00:00
|
|
|
NSMutableArray * upDownComponents = [NSMutableArray arrayWithCapacity: 2];
|
|
|
|
if (toUs > 0)
|
|
|
|
[upDownComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"DL from %d", "Inspector -> Peers tab -> peers"), toUs]];
|
|
|
|
if (fromUs > 0)
|
|
|
|
[upDownComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"UL to %d", "Inspector -> Peers tab -> peers"), fromUs]];
|
|
|
|
if ([upDownComponents count] > 0)
|
|
|
|
connectedText = [connectedText stringByAppendingFormat: @": %@", [upDownComponents componentsJoinedByString: @", "]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-12-23 02:35:21 +00:00
|
|
|
NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 7];
|
2010-03-06 23:12:30 +00:00
|
|
|
if (tracker > 0)
|
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), tracker]];
|
|
|
|
if (incoming > 0)
|
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), incoming]];
|
|
|
|
if (cache > 0)
|
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), cache]];
|
2010-05-19 23:08:14 +00:00
|
|
|
if (lpd > 0)
|
2010-05-01 16:19:40 +00:00
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
2010-05-19 23:08:14 +00:00
|
|
|
NSLocalizedString(@"%d local discovery", "Inspector -> Peers tab -> peers"), lpd]];
|
2010-03-06 23:12:30 +00:00
|
|
|
if (pex > 0)
|
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), pex]];
|
|
|
|
if (dht > 0)
|
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d DHT", "Inspector -> Peers tab -> peers"), dht]];
|
|
|
|
if (ltep > 0)
|
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d LTEP", "Inspector -> Peers tab -> peers"), ltep]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-04 02:58:08 +00:00
|
|
|
connectedText = [connectedText stringByAppendingFormat: @"\n%@", [fromComponents componentsJoinedByString: @", "]];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fConnectedPeersField setStringValue: connectedText];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-04 02:58:08 +00:00
|
|
|
NSString * notActiveString;
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([fTorrents count] == 1)
|
2011-03-04 02:58:08 +00:00
|
|
|
notActiveString = NSLocalizedString(@"Transfer Not Active", "Inspector -> Peers tab -> peers");
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2011-03-04 02:58:08 +00:00
|
|
|
notActiveString = NSLocalizedString(@"Transfers Not Active", "Inspector -> Peers tab -> peers");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-04 02:58:08 +00:00
|
|
|
[fConnectedPeersField setStringValue: notActiveString];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-14 02:53:22 +00:00
|
|
|
- (void) saveViewSize
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setFloat: NSHeight([[self view] frame]) forKey: @"InspectorContentHeightPeers"];
|
|
|
|
}
|
|
|
|
|
2010-03-14 01:52:45 +00:00
|
|
|
- (void) clearView
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
fPeers = nil;
|
|
|
|
fWebSeeds = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView
|
|
|
|
{
|
|
|
|
if (tableView == fWebSeedTable)
|
|
|
|
return fWebSeeds ? [fWebSeeds count] : 0;
|
|
|
|
else
|
|
|
|
return fPeers ? [fPeers count] : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (NSInteger) row
|
|
|
|
{
|
|
|
|
if (tableView == fWebSeedTable)
|
|
|
|
{
|
|
|
|
NSString * ident = [column identifier];
|
2017-07-08 09:16:01 +00:00
|
|
|
NSDictionary * webSeed = fWebSeeds[row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([ident isEqualToString: @"DL From"])
|
|
|
|
{
|
|
|
|
NSNumber * rate;
|
2017-07-08 14:38:47 +00:00
|
|
|
return (rate = webSeed[@"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate doubleValue]] : @"";
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
2017-07-08 14:38:47 +00:00
|
|
|
return webSeed[@"Address"];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSString * ident = [column identifier];
|
2017-07-08 09:16:01 +00:00
|
|
|
NSDictionary * peer = fPeers[row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([ident isEqualToString: @"Encryption"])
|
2017-07-08 14:38:47 +00:00
|
|
|
return [peer[@"Encryption"] boolValue] ? [NSImage imageNamed: @"Lock"] : nil;
|
2010-03-06 23:12:30 +00:00
|
|
|
else if ([ident isEqualToString: @"Client"])
|
2017-07-08 14:38:47 +00:00
|
|
|
return peer[@"Client"];
|
2010-03-06 23:12:30 +00:00
|
|
|
else if ([ident isEqualToString: @"Progress"])
|
2017-07-08 14:38:47 +00:00
|
|
|
return peer[@"Progress"];
|
2010-03-06 23:12:30 +00:00
|
|
|
else if ([ident isEqualToString: @"UL To"])
|
|
|
|
{
|
|
|
|
NSNumber * rate;
|
2017-07-08 14:38:47 +00:00
|
|
|
return (rate = peer[@"UL To Rate"]) ? [NSString stringForSpeedAbbrev: [rate doubleValue]] : @"";
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: @"DL From"])
|
|
|
|
{
|
|
|
|
NSNumber * rate;
|
2017-07-08 14:38:47 +00:00
|
|
|
return (rate = peer[@"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate doubleValue]] : @"";
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
2017-07-08 14:38:47 +00:00
|
|
|
return peer[@"IP"];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn
|
|
|
|
row: (NSInteger) row
|
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
{
|
|
|
|
NSString * ident = [tableColumn identifier];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([ident isEqualToString: @"Progress"])
|
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
NSDictionary * peer = fPeers[row];
|
2017-07-08 14:38:47 +00:00
|
|
|
[(PeerProgressIndicatorCell *)cell setSeed: [peer[@"Seed"] boolValue]];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn
|
|
|
|
{
|
|
|
|
if (tableView == fWebSeedTable)
|
|
|
|
{
|
|
|
|
if (fWebSeeds)
|
|
|
|
{
|
|
|
|
[fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]];
|
|
|
|
[tableView reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fPeers)
|
|
|
|
{
|
|
|
|
[fPeers sortUsingDescriptors: [self peerSortDescriptors]];
|
|
|
|
[tableView reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) tableView: (NSTableView *) tableView shouldSelectRow: (NSInteger) row
|
|
|
|
{
|
2012-04-29 00:53:34 +00:00
|
|
|
return tableView != fPeerTable;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
|
|
|
|
tableColumn: (NSTableColumn *) column row: (NSInteger) row mouseLocation: (NSPoint) mouseLocation
|
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
{
|
|
|
|
const BOOL multiple = [fTorrents count] > 1;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-08 09:16:01 +00:00
|
|
|
NSDictionary * peer = fPeers[row];
|
2010-03-06 23:12:30 +00:00
|
|
|
NSMutableArray * components = [NSMutableArray arrayWithCapacity: multiple ? 6 : 5];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (multiple)
|
2017-07-08 14:38:47 +00:00
|
|
|
[components addObject: peer[@"Name"]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-08 14:38:47 +00:00
|
|
|
const CGFloat progress = [peer[@"Progress"] floatValue];
|
2010-06-24 00:00:43 +00:00
|
|
|
NSString * progressString = [NSString stringWithFormat: NSLocalizedString(@"Progress: %@",
|
|
|
|
"Inspector -> Peers tab -> table row tooltip"),
|
|
|
|
[NSString percentString: progress longDecimals: NO]];
|
2017-07-08 14:38:47 +00:00
|
|
|
if (progress < 1.0 && [peer[@"Seed"] boolValue])
|
2010-03-06 23:12:30 +00:00
|
|
|
progressString = [progressString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"Partial Seed",
|
|
|
|
"Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
[components addObject: progressString];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-08 14:38:47 +00:00
|
|
|
NSString * protocolString = [peer[@"uTP"] boolValue] ? @"\u00b5TP" : @"TCP";
|
|
|
|
if ([peer[@"Encryption"] boolValue])
|
2011-02-18 04:28:59 +00:00
|
|
|
protocolString = [protocolString stringByAppendingFormat: @" (%@)",
|
|
|
|
NSLocalizedString(@"encrypted", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
[components addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Protocol: %@", "Inspector -> Peers tab -> table row tooltip"),
|
|
|
|
protocolString]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
NSString * portString;
|
|
|
|
NSInteger port;
|
2017-07-08 14:38:47 +00:00
|
|
|
if ((port = [peer[@"Port"] intValue]) > 0)
|
2012-08-13 00:52:04 +00:00
|
|
|
portString = [NSString stringWithFormat: @"%ld", port];
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
|
|
|
portString = NSLocalizedString(@"N/A", "Inspector -> Peers tab -> table row tooltip");
|
|
|
|
[components addObject: [NSString stringWithFormat: @"%@: %@", NSLocalizedString(@"Port",
|
|
|
|
"Inspector -> Peers tab -> table row tooltip"), portString]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-08 14:38:47 +00:00
|
|
|
const NSInteger peerFrom = [peer[@"From"] integerValue];
|
2010-03-06 23:12:30 +00:00
|
|
|
switch (peerFrom)
|
|
|
|
{
|
|
|
|
case TR_PEER_FROM_TRACKER:
|
|
|
|
[components addObject: NSLocalizedString(@"From: tracker", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
case TR_PEER_FROM_INCOMING:
|
|
|
|
[components addObject: NSLocalizedString(@"From: incoming connection", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
case TR_PEER_FROM_RESUME:
|
|
|
|
[components addObject: NSLocalizedString(@"From: cache", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
2010-05-08 08:54:45 +00:00
|
|
|
case TR_PEER_FROM_LPD:
|
2010-05-01 16:19:40 +00:00
|
|
|
[components addObject: NSLocalizedString(@"From: local peer discovery", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
2010-03-06 23:12:30 +00:00
|
|
|
case TR_PEER_FROM_PEX:
|
|
|
|
[components addObject: NSLocalizedString(@"From: peer exchange", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
case TR_PEER_FROM_DHT:
|
|
|
|
[components addObject: NSLocalizedString(@"From: distributed hash table", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
case TR_PEER_FROM_LTEP:
|
|
|
|
[components addObject: NSLocalizedString(@"From: libtorrent extension protocol handshake",
|
|
|
|
"Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-13 00:52:04 +00:00
|
|
|
NSAssert1(NO, @"Peer from unknown source: %ld", peerFrom);
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//determing status strings from flags
|
|
|
|
NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 6];
|
2017-07-08 14:38:47 +00:00
|
|
|
NSString * flags = peer[@"Flags"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([flags rangeOfString: @"D"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"d"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"U"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"u"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"K"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Peer is unchoking you, but you are not interested",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"?"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"You unchoked the peer, but the peer is not interested",
|
|
|
|
"Inspector -> peer -> status")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([statusArray count] > 0)
|
|
|
|
{
|
|
|
|
NSString * statusStrings = [statusArray componentsJoinedByString: @"\n\n"];
|
|
|
|
[components addObject: [@"\n" stringByAppendingString: statusStrings]];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return [components componentsJoinedByString: @"\n"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([fTorrents count] > 1)
|
2017-07-08 14:38:47 +00:00
|
|
|
return fWebSeeds[row][@"Name"];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2016-03-03 22:27:45 +00:00
|
|
|
- (void) animationDidStart: (CAAnimation *) animation
|
|
|
|
{
|
|
|
|
if (![[animation valueForKey: ANIMATION_ID_KEY] isEqualToString: WEB_SEED_ANIMATION_ID])
|
|
|
|
return;
|
|
|
|
|
|
|
|
[[fWebSeedTable enclosingScrollView] setHidden: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) animationDidStop: (CAAnimation *) animation finished: (BOOL) finished
|
|
|
|
{
|
|
|
|
if (![[animation valueForKey: ANIMATION_ID_KEY] isEqualToString: WEB_SEED_ANIMATION_ID])
|
|
|
|
return;
|
|
|
|
|
|
|
|
[[fWebSeedTable enclosingScrollView] setHidden: finished && fWebSeedTableTopConstraint.constant < 0];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoPeersViewController (Private)
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
- (void) setupInfo
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2012-04-29 00:53:34 +00:00
|
|
|
__block BOOL hasWebSeeds = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([fTorrents count] == 0)
|
|
|
|
{
|
|
|
|
fPeers = nil;
|
|
|
|
[fPeerTable reloadData];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fConnectedPeersField setStringValue: @""];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-29 00:53:34 +00:00
|
|
|
[fTorrents enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(Torrent * torrent, NSUInteger idx, BOOL *stop) {
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([torrent webSeedCount] > 0)
|
|
|
|
{
|
|
|
|
hasWebSeeds = YES;
|
2012-04-29 00:53:34 +00:00
|
|
|
*stop = YES;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2012-04-29 00:53:34 +00:00
|
|
|
}];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (!hasWebSeeds)
|
|
|
|
{
|
|
|
|
fWebSeeds = nil;
|
|
|
|
[fWebSeedTable reloadData];
|
|
|
|
}
|
2012-04-29 00:53:34 +00:00
|
|
|
else
|
|
|
|
[fWebSeedTable deselectAll: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
[self setWebSeedTableHidden: !hasWebSeeds animate: YES];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = YES;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate
|
|
|
|
{
|
|
|
|
if (animate && (![[self view] window] || ![[[self view] window] isVisible]))
|
|
|
|
animate = NO;
|
2016-02-27 20:29:57 +00:00
|
|
|
|
2016-03-03 22:27:45 +00:00
|
|
|
const CGFloat webSeedTableTopMargin = hide ? -NSHeight([[fWebSeedTable enclosingScrollView] frame]) : fViewTopMargin;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-03-03 22:27:45 +00:00
|
|
|
[(animate ? [fWebSeedTableTopConstraint animator] : fWebSeedTableTopConstraint) setConstant: webSeedTableTopMargin];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) peerSortDescriptors
|
|
|
|
{
|
|
|
|
NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
NSArray * oldDescriptors = [fPeerTable sortDescriptors];
|
|
|
|
BOOL useSecond = YES, asc = YES;
|
|
|
|
if ([oldDescriptors count] > 0)
|
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
NSSortDescriptor * descriptor = oldDescriptors[0];
|
2010-03-06 23:12:30 +00:00
|
|
|
[descriptors addObject: descriptor];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ((useSecond = ![[descriptor key] isEqualToString: @"IP"]))
|
|
|
|
asc = [descriptor ascending];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//sort by IP after primary sort
|
|
|
|
if (useSecond)
|
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
NSSortDescriptor * secondDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"IP" ascending: asc selector: @selector(compareNumeric:)];
|
2010-03-06 23:12:30 +00:00
|
|
|
[descriptors addObject: secondDescriptor];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return descriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|