2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
#import "InfoTrackersViewController.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
#import "TrackerCell.h"
|
|
|
|
#import "TrackerNode.h"
|
|
|
|
#import "TrackerTableView.h"
|
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
static CGFloat const kTrackerGroupSeparatorHeight = 14.0;
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
typedef NS_ENUM(NSInteger, TrackerSegmentTag) {
|
|
|
|
TrackerSegmentTagAdd = 0,
|
|
|
|
TrackerSegmentTagRemove = 1,
|
|
|
|
};
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface InfoTrackersViewController ()
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
@property(nonatomic, copy) NSArray<Torrent*>* fTorrents;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic) BOOL fSet;
|
|
|
|
|
|
|
|
@property(nonatomic) NSMutableArray* fTrackers;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet TrackerTableView* fTrackerTable;
|
|
|
|
@property(nonatomic, readonly) TrackerCell* fTrackerCell;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSSegmentedControl* fTrackerAddRemoveControl;
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoTrackersViewController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)init
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithNibName:@"InfoTrackersView" bundle:nil]))
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
self.title = NSLocalizedString(@"Trackers", "Inspector view -> title");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fTrackerCell = [[TrackerCell alloc] init];
|
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 self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2010-03-14 02:53:22 +00:00
|
|
|
{
|
2023-11-05 20:35:22 +00:00
|
|
|
[super awakeFromNib];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackerAddRemoveControl.cell setToolTip:NSLocalizedString(@"Add a tracker", "Inspector view -> tracker buttons")
|
2022-10-19 19:28:21 +00:00
|
|
|
forSegment:TrackerSegmentTagAdd];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackerAddRemoveControl.cell setToolTip:NSLocalizedString(@"Remove selected trackers", "Inspector view -> tracker buttons")
|
2022-10-19 19:28:21 +00:00
|
|
|
forSegment:TrackerSegmentTagRemove];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const height = [NSUserDefaults.standardUserDefaults floatForKey:@"InspectorContentHeightTracker"];
|
2010-03-14 02:53:22 +00:00
|
|
|
if (height != 0.0)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect viewRect = self.view.frame;
|
2010-03-14 02:53:22 +00:00
|
|
|
viewRect.size.height = height;
|
2021-08-07 07:27:56 +00:00
|
|
|
self.view.frame = viewRect;
|
2010-03-14 02:53:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)setInfoForTorrents:(NSArray<Torrent*>*)torrents
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTorrents = torrents;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSet = NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateInfo
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fSet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
[self setupInfo];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTorrents.count == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//get updated tracker stats
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTrackerTable.editedRow == -1)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* oldTrackers = self.fTrackers;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTorrents.count == 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-04-29 22:51:40 +00:00
|
|
|
self.fTrackers = self.fTorrents[0].allTrackerStats;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackers = [[NSMutableArray alloc] init];
|
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackers addObjectsFromArray:torrent.allTrackerStats];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.trackers = self.fTrackers;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (oldTrackers && [self.fTrackers isEqualToArray:oldTrackers])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.needsDisplay = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-01-14 02:28:54 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackerTable reloadData];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSAssert1(self.fTorrents.count == 1, @"Attempting to add tracker with %ld transfers selected", self.fTorrents.count);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* addedIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(self.fTrackers.count - 2, 2)];
|
|
|
|
NSArray* tierAndTrackerBeingAdded = [self.fTrackers objectsAtIndexes:addedIndexes];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
self.fTrackers = self.fTorrents[0].allTrackerStats;
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackers addObjectsFromArray:tierAndTrackerBeingAdded];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.trackers = self.fTrackers;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet *updateIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fTrackers.count - 2)],
|
|
|
|
*columnIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fTrackerTable.tableColumns.count)];
|
|
|
|
[self.fTrackerTable reloadDataForRowIndexes:updateIndexes columnIndexes:columnIndexes];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)saveViewSize
|
2010-03-14 02:53:22 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setFloat:NSHeight(self.view.frame) forKey:@"InspectorContentHeightTracker"];
|
2010-03-14 02:53:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)clearView
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackers = nil;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fTrackers ? self.fTrackers.count : 0;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)tableView:(NSTableView*)tableView objectValueForTableColumn:(NSTableColumn*)column row:(NSInteger)row
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
id item = self.fTrackers[row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[NSDictionary class]])
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const tier = [item[@"Tier"] integerValue];
|
|
|
|
NSString* tierString = tier == -1 ?
|
|
|
|
NSLocalizedString(@"New Tier", "Inspector -> tracker table") :
|
2022-05-14 05:31:24 +00:00
|
|
|
[NSString stringWithFormat:NSLocalizedString(@"Tier %ld", "Inspector -> tracker table"), tier];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTorrents.count > 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
tierString = [tierString stringByAppendingFormat:@" - %@", item[@"Name"]];
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
return tierString;
|
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return item; //TrackerNode or NSString
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSCell*)tableView:(NSTableView*)tableView dataCellForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const tracker = [self.fTrackers[row] isKindOfClass:[TrackerNode class]];
|
|
|
|
return tracker ? self.fTrackerCell : [tableColumn dataCellForRow:row];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)tableView:(NSTableView*)tableView heightOfRow:(NSInteger)row
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-04-21 14:28:38 +00:00
|
|
|
//check for NSDictionary instead of TrackerNode because of display issue when adding a row
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fTrackers[row] isKindOfClass:[NSDictionary class]])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
return kTrackerGroupSeparatorHeight;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return tableView.rowHeight;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)tableView:(NSTableView*)tableView shouldEditTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
|
2011-10-12 03:35:55 +00:00
|
|
|
{
|
2011-10-18 02:30:22 +00:00
|
|
|
//don't allow tier row to be edited by double-click
|
2011-10-12 03:35:55 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)tableViewSelectionDidChange:(NSNotification*)notification
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[self.fTrackerAddRemoveControl setEnabled:self.fTrackerTable.numberOfSelectedRows > 0 forSegment:TrackerSegmentTagRemove];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)tableView:(NSTableView*)tableView isGroupRow:(NSInteger)row
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-07-17 23:04:32 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableView:(NSTableView*)tableView shouldSelectRow:(NSInteger)row
|
|
|
|
{
|
|
|
|
id node = self.fTrackers[row];
|
|
|
|
if ([node isKindOfClass:[TrackerNode class]])
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)tableView:(NSTableView*)tableView
|
|
|
|
toolTipForCell:(NSCell*)cell
|
|
|
|
rect:(NSRectPointer)rect
|
|
|
|
tableColumn:(NSTableColumn*)column
|
|
|
|
row:(NSInteger)row
|
|
|
|
mouseLocation:(NSPoint)mouseLocation
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
id node = self.fTrackers[row];
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([node isKindOfClass:[TrackerNode class]])
|
|
|
|
{
|
|
|
|
return ((TrackerNode*)node).fullAnnounceAddress;
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)tableView:(NSTableView*)tableView
|
|
|
|
setObjectValue:(id)object
|
|
|
|
forTableColumn:(NSTableColumn*)tableColumn
|
|
|
|
row:(NSInteger)row
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
Torrent* torrent = self.fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
BOOL added = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSString* tracker in [object componentsSeparatedByString:@"\n"])
|
|
|
|
{
|
|
|
|
if ([torrent addTrackerToNewTier:tracker])
|
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
added = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (!added)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
NSBeep();
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//reset table with either new or old value
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackers = torrent.allTrackerStats;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.trackers = self.fTrackers;
|
|
|
|
[self.fTrackerTable reloadData];
|
|
|
|
[self.fTrackerTable deselectAll:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-04-29 19:00:35 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil]; //in case sort by tracker
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)addRemoveTracker:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
//don't allow add/remove when currently adding - it leads to weird results
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTrackerTable.editedRow != -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-03-24 00:56:36 +00:00
|
|
|
[self updateInfo];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([[sender cell] tagForSegment:[sender selectedSegment]] == TrackerSegmentTagRemove)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
[self removeTrackers];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
[self addTrackers];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setupInfo
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger const numberSelected = self.fTorrents.count;
|
2010-03-09 02:26:52 +00:00
|
|
|
if (numberSelected != 1)
|
|
|
|
{
|
|
|
|
if (numberSelected == 0)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackers = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.trackers = nil;
|
|
|
|
[self.fTrackerTable reloadData];
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.torrent = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
[self.fTrackerAddRemoveControl setEnabled:NO forSegment:TrackerSegmentTagAdd];
|
|
|
|
[self.fTrackerAddRemoveControl setEnabled:NO forSegment:TrackerSegmentTagRemove];
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.torrent = self.fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
[self.fTrackerAddRemoveControl setEnabled:YES forSegment:TrackerSegmentTagAdd];
|
|
|
|
[self.fTrackerAddRemoveControl setEnabled:NO forSegment:TrackerSegmentTagRemove];
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackerTable deselectAll:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSet = YES;
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
#warning doesn't like blank addresses
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)addTrackers
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[self.view.window makeKeyWindow];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSAssert1(self.fTorrents.count == 1, @"Attempting to add tracker with %ld transfers selected", self.fTorrents.count);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackers addObject:@{ @"Tier" : @-1 }];
|
|
|
|
[self.fTrackers addObject:@""];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.trackers = self.fTrackers;
|
|
|
|
[self.fTrackerTable reloadData];
|
|
|
|
[self.fTrackerTable selectRowIndexes:[NSIndexSet indexSetWithIndex:self.fTrackers.count - 1] byExtendingSelection:NO];
|
2022-03-30 21:52:23 +00:00
|
|
|
[self.fTrackerTable editColumn:[self.fTrackerTable columnWithIdentifier:@"Tracker"] row:self.fTrackers.count - 1
|
|
|
|
withEvent:nil
|
|
|
|
select:YES];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeTrackers
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableDictionary* removeIdentifiers = [NSMutableDictionary dictionaryWithCapacity:self.fTorrents.count];
|
2012-01-14 02:28:54 +00:00
|
|
|
NSUInteger removeTrackerCount = 0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* selectedIndexes = self.fTrackerTable.selectedRowIndexes;
|
2010-03-06 23:12:30 +00:00
|
|
|
BOOL groupSelected = NO;
|
2012-01-14 02:28:54 +00:00
|
|
|
NSUInteger groupRowIndex = NSNotFound;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* removeIndexes = [NSMutableIndexSet indexSet];
|
2022-02-22 16:04:20 +00:00
|
|
|
for (NSUInteger i = 0; i < self.fTrackers.count; ++i)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
id object = self.fTrackers[i];
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([object isKindOfClass:[TrackerNode class]])
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TrackerNode* node = (TrackerNode*)object;
|
|
|
|
if (groupSelected || [selectedIndexes containsIndex:i])
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = node.torrent;
|
|
|
|
NSMutableSet* removeSet;
|
2017-07-08 14:38:47 +00:00
|
|
|
if (!(removeSet = removeIdentifiers[torrent]))
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2011-04-05 23:03:33 +00:00
|
|
|
removeSet = [NSMutableSet set];
|
2017-07-08 14:38:47 +00:00
|
|
|
removeIdentifiers[torrent] = removeSet;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[removeSet addObject:node.fullAnnounceAddress];
|
2012-01-14 02:28:54 +00:00
|
|
|
++removeTrackerCount;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[removeIndexes addIndex:i];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2012-01-14 02:28:54 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-01-14 02:28:54 +00:00
|
|
|
groupRowIndex = NSNotFound; //don't remove the group row
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-14 02:28:54 +00:00
|
|
|
//mark the previous group row for removal, if necessary
|
|
|
|
if (groupRowIndex != NSNotFound)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[removeIndexes addIndex:groupRowIndex];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
groupSelected = [selectedIndexes containsIndex:i];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!groupSelected && i > selectedIndexes.lastIndex)
|
2012-01-14 02:28:54 +00:00
|
|
|
{
|
|
|
|
groupRowIndex = NSNotFound;
|
2010-03-06 23:12:30 +00:00
|
|
|
break;
|
2012-01-14 02:28:54 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-14 02:28:54 +00:00
|
|
|
groupRowIndex = i;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-14 02:28:54 +00:00
|
|
|
//mark the last group for removal, too
|
|
|
|
if (groupRowIndex != NSNotFound)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[removeIndexes addIndex:groupRowIndex];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAssert2(
|
|
|
|
removeTrackerCount <= removeIndexes.count,
|
|
|
|
@"Marked %ld trackers to remove, but only removing %ld rows",
|
|
|
|
removeTrackerCount,
|
|
|
|
removeIndexes.count);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
//we might have no trackers if remove right after a failed add (race condition ftw)
|
|
|
|
#warning look into having a failed add apply right away, so that this can become an assert
|
2012-01-14 02:28:54 +00:00
|
|
|
if (removeTrackerCount == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-03-24 00:56:36 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([NSUserDefaults.standardUserDefaults boolForKey:@"WarningRemoveTrackers"])
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-14 02:28:54 +00:00
|
|
|
if (removeTrackerCount > 1)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
alert.messageText = [NSString
|
2022-11-14 18:30:03 +00:00
|
|
|
localizedStringWithFormat:NSLocalizedString(@"Are you sure you want to remove %lu trackers?", "Remove trackers alert -> title"),
|
|
|
|
removeTrackerCount];
|
2021-08-15 09:41:48 +00:00
|
|
|
alert.informativeText = NSLocalizedString(
|
|
|
|
@"Once removed, Transmission will no longer attempt to contact them."
|
|
|
|
" This cannot be undone.",
|
|
|
|
"Remove trackers alert -> message");
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = NSLocalizedString(@"Are you sure you want to remove this tracker?", "Remove trackers alert -> title");
|
2021-08-15 09:41:48 +00:00
|
|
|
alert.informativeText = NSLocalizedString(
|
|
|
|
@"Once removed, Transmission will no longer attempt to contact it."
|
|
|
|
" This cannot be undone.",
|
|
|
|
"Remove trackers alert -> message");
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Remove", "Remove trackers alert -> button")];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Remove trackers alert -> button")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.showsSuppressionButton = YES;
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
NSInteger result = [alert runModal];
|
2021-10-31 15:18:27 +00:00
|
|
|
if (alert.suppressionButton.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"WarningRemoveTrackers"];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (result != NSAlertFirstButtonReturn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackerTable beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (Torrent* torrent in removeIdentifiers)
|
|
|
|
{
|
|
|
|
[torrent removeTrackers:removeIdentifiers[torrent]];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//reset table with either new or old value
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackers = [[NSMutableArray alloc] init];
|
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackers addObjectsFromArray:torrent.allTrackerStats];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackerTable removeRowsAtIndexes:removeIndexes withAnimation:NSTableViewAnimationSlideLeft];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTrackerTable.trackers = self.fTrackers;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTrackerTable endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-04-29 19:00:35 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil]; //in case sort by tracker
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|