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.
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-04-24 20:34:30 +00:00
|
|
|
#import "CocoaCompatibility.h"
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "TorrentTableView.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "Controller.h"
|
2008-05-22 20:00:22 +00:00
|
|
|
#import "FileListNode.h"
|
2011-07-21 02:35:03 +00:00
|
|
|
#import "InfoOptionsViewController.h"
|
2022-11-13 16:54:22 +00:00
|
|
|
#import "NSKeyedUnarchiverAdditions.h"
|
2010-11-21 14:45:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "Torrent.h"
|
|
|
|
#import "TorrentCell.h"
|
2023-06-27 19:40:44 +00:00
|
|
|
#import "SmallTorrentCell.h"
|
|
|
|
#import "GroupCell.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "TorrentGroup.h"
|
2023-06-27 19:40:44 +00:00
|
|
|
#import "GroupsController.h"
|
|
|
|
#import "NSImageAdditions.h"
|
|
|
|
#import "TorrentCellActionButton.h"
|
|
|
|
#import "TorrentCellControlButton.h"
|
|
|
|
#import "TorrentCellRevealButton.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
CGFloat const kGroupSeparatorHeight = 18.0;
|
|
|
|
|
|
|
|
static NSInteger const kMaxGroup = 999999;
|
2023-06-27 19:40:44 +00:00
|
|
|
static CGFloat const kErrorImageSize = 20.0;
|
2008-02-07 16:20:24 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
static NSTimeInterval const kToggleProgressSeconds = 0.175;
|
2008-06-18 16:25:30 +00:00
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface TorrentTableView ()
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@property(nonatomic) IBOutlet Controller* fController;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSUserDefaults* fDefaults;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSMutableIndexSet* fCollapsedGroups;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSMenu* fContextRow;
|
|
|
|
@property(nonatomic) IBOutlet NSMenu* fContextNoRow;
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
@property(nonatomic) NSIndexSet* fSelectedRowIndexes;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic) CGFloat piecesBarPercent;
|
|
|
|
@property(nonatomic) NSAnimation* fPiecesBarAnimation;
|
|
|
|
|
|
|
|
@property(nonatomic) BOOL fActionPopoverShown;
|
2022-06-15 18:53:23 +00:00
|
|
|
@property(nonatomic) NSView* fPositioningView;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
@property(nonatomic) NSDictionary* fHoverEventDict;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentTableView
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithCoder:(NSCoder*)decoder
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithCoder:decoder]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fDefaults = NSUserDefaults.standardUserDefaults;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-04-29 21:44:59 +00:00
|
|
|
NSData* groupData;
|
|
|
|
if ((groupData = [_fDefaults dataForKey:@"CollapsedGroupIndexes"]))
|
|
|
|
{
|
2022-06-18 14:26:45 +00:00
|
|
|
_fCollapsedGroups = [NSKeyedUnarchiver unarchivedObjectOfClass:NSMutableIndexSet.class fromData:groupData error:nil];
|
2022-04-29 21:44:59 +00:00
|
|
|
}
|
|
|
|
else if ((groupData = [_fDefaults dataForKey:@"CollapsedGroups"])) //handle old groups
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-11-13 16:54:22 +00:00
|
|
|
_fCollapsedGroups = [[NSKeyedUnarchiver deprecatedUnarchiveObjectWithData:groupData] mutableCopy];
|
2022-04-29 21:44:59 +00:00
|
|
|
[_fDefaults removeObjectForKey:@"CollapsedGroups"];
|
|
|
|
[self saveCollapsedGroups];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-04-29 21:44:59 +00:00
|
|
|
if (_fCollapsedGroups == nil)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fCollapsedGroups = [[NSMutableIndexSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fActionPopoverShown = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.delegate = self;
|
2023-06-27 19:40:44 +00:00
|
|
|
self.indentationPerLevel = 0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_piecesBarPercent = [_fDefaults boolForKey:@"PiecesBar"] ? 1.0 : 0.0;
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2024-08-22 20:07:17 +00:00
|
|
|
self.style = NSTableViewStyleFullWidth;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2008-03-17 21:44:14 +00:00
|
|
|
{
|
2023-11-05 20:35:22 +00:00
|
|
|
[super awakeFromNib];
|
2023-10-01 13:39:39 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(refreshTorrentTable) name:@"RefreshTorrentTable"
|
|
|
|
object:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)refreshTorrentTable
|
|
|
|
{
|
|
|
|
self.needsDisplay = YES;
|
2023-06-27 19:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//make sure we don't lose selection on manual reloads
|
|
|
|
- (void)reloadData
|
|
|
|
{
|
2023-09-11 02:39:01 +00:00
|
|
|
NSArray<Torrent*>* selectedTorrents = self.selectedTorrents;
|
2023-06-27 19:40:44 +00:00
|
|
|
[super reloadData];
|
2023-09-11 02:39:01 +00:00
|
|
|
self.selectedTorrents = selectedTorrents;
|
2023-06-27 19:40:44 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (void)reloadVisibleRows
|
|
|
|
{
|
|
|
|
NSRect visibleRect = self.visibleRect;
|
|
|
|
NSRange range = [self rowsInRect:visibleRect];
|
2022-12-09 19:06:00 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
//since we use floating group rows, we need some magic to find visible group rows
|
|
|
|
if ([self.fDefaults boolForKey:@"SortByGroup"])
|
|
|
|
{
|
|
|
|
NSInteger location = range.location;
|
|
|
|
NSInteger length = range.length;
|
|
|
|
NSRange fullRange = NSMakeRange(0, length + location);
|
|
|
|
NSIndexSet* fullIndexSet = [NSIndexSet indexSetWithIndexesInRange:fullRange];
|
|
|
|
NSMutableIndexSet* visibleIndexSet = [[NSMutableIndexSet alloc] init];
|
|
|
|
|
2024-03-15 05:16:26 +00:00
|
|
|
[fullIndexSet enumerateIndexesUsingBlock:^(NSUInteger row, BOOL*) {
|
2023-06-27 19:40:44 +00:00
|
|
|
id rowView = [self rowViewAtRow:row makeIfNecessary:NO];
|
|
|
|
if ([rowView isGroupRowStyle])
|
|
|
|
{
|
|
|
|
[visibleIndexSet addIndex:row];
|
|
|
|
}
|
|
|
|
else if (NSIntersectsRect(visibleRect, [self rectOfRow:row]))
|
|
|
|
{
|
|
|
|
[visibleIndexSet addIndex:row];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self reloadDataForRowIndexes:visibleIndexSet columnIndexes:[NSIndexSet indexSetWithIndex:0]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self reloadDataForRowIndexes:[NSIndexSet indexSetWithIndexesInRange:range] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
|
|
|
|
}
|
2023-06-18 18:32:34 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (void)reloadDataForRowIndexes:(NSIndexSet*)rowIndexes columnIndexes:(NSIndexSet*)columnIndexes
|
2023-06-18 18:32:34 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
[super reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndexes];
|
|
|
|
|
|
|
|
//redraw fControlButton
|
|
|
|
BOOL minimal = [self.fDefaults boolForKey:@"SmallView"];
|
2024-03-15 05:16:26 +00:00
|
|
|
[rowIndexes enumerateIndexesUsingBlock:^(NSUInteger row, BOOL*) {
|
2023-06-27 19:40:44 +00:00
|
|
|
id rowView = [self rowViewAtRow:row makeIfNecessary:NO];
|
|
|
|
if (![rowView isGroupRowStyle])
|
|
|
|
{
|
|
|
|
if (minimal)
|
|
|
|
{
|
|
|
|
SmallTorrentCell* smallCell = [self viewAtColumn:0 row:row makeIfNecessary:NO];
|
|
|
|
[(TorrentCellControlButton*)smallCell.fControlButton resetImage];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TorrentCell* torrentCell = [self viewAtColumn:0 row:row makeIfNecessary:NO];
|
|
|
|
[(TorrentCellControlButton*)torrentCell.fControlButton resetImage];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
2008-03-17 21:44:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isGroupCollapsed:(NSInteger)value
|
2008-02-07 01:26:12 +00:00
|
|
|
{
|
2008-06-11 03:28:14 +00:00
|
|
|
if (value == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
value = kMaxGroup;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.fCollapsedGroups containsIndex:value];
|
2008-02-07 01:26:12 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeCollapsedGroup:(NSInteger)value
|
2008-02-07 02:11:26 +00:00
|
|
|
{
|
2008-06-11 03:28:14 +00:00
|
|
|
if (value == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
value = kMaxGroup;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCollapsedGroups removeIndex:value];
|
2008-02-07 02:11:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeAllCollapsedGroups
|
2008-02-07 02:15:24 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCollapsedGroups removeAllIndexes];
|
2008-02-07 02:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)saveCollapsedGroups
|
2008-02-07 21:26:04 +00:00
|
|
|
{
|
2022-12-14 06:42:49 +00:00
|
|
|
[self.fDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:self.fCollapsedGroups requiringSecureCoding:YES error:nil]
|
|
|
|
forKey:@"CollapsedGroupIndexes"];
|
2008-02-07 21:26:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
return YES;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)outlineView:(NSOutlineView*)outlineView heightOfRowByItem:(id)item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
return [item isKindOfClass:[Torrent class]] ? self.rowHeight : kGroupSeparatorHeight;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (NSView*)outlineView:(NSOutlineView*)outlineView viewForTableColumn:(NSTableColumn*)tableColumn item:(id)item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
Torrent* torrent = (Torrent*)item;
|
|
|
|
BOOL const minimal = [self.fDefaults boolForKey:@"SmallView"];
|
|
|
|
BOOL const error = torrent.anyErrorOrWarning;
|
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
TorrentCell* torrentCell;
|
2023-06-27 19:40:44 +00:00
|
|
|
if (minimal)
|
2022-12-09 19:06:00 +00:00
|
|
|
{
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell = [outlineView makeViewWithIdentifier:@"SmallTorrentCell" owner:self];
|
2023-06-27 19:40:44 +00:00
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
// set torrent icon or error badge
|
|
|
|
torrentCell.fIconView.image = error ? [NSImage imageNamed:NSImageNameCaution] : torrent.icon;
|
2023-06-27 19:40:44 +00:00
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
// set torrent status
|
|
|
|
torrentCell.fTorrentStatusField.stringValue = [self.fDefaults boolForKey:@"DisplaySmallStatusRegular"] ?
|
2023-06-27 19:40:44 +00:00
|
|
|
torrent.shortStatusString :
|
|
|
|
torrent.remainingTimeString;
|
|
|
|
|
|
|
|
if (self.fHoverEventDict)
|
|
|
|
{
|
|
|
|
NSInteger row = [self rowForItem:item];
|
|
|
|
NSInteger hoverRow = [self.fHoverEventDict[@"row"] integerValue];
|
|
|
|
|
|
|
|
if (row == hoverRow)
|
|
|
|
{
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell.fTorrentStatusField.hidden = YES;
|
|
|
|
torrentCell.fControlButton.hidden = NO;
|
|
|
|
torrentCell.fRevealButton.hidden = NO;
|
2023-06-27 19:40:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell.fTorrentStatusField.hidden = NO;
|
|
|
|
torrentCell.fControlButton.hidden = YES;
|
|
|
|
torrentCell.fRevealButton.hidden = YES;
|
2023-06-27 19:40:44 +00:00
|
|
|
}
|
2022-12-09 19:06:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell = [outlineView makeViewWithIdentifier:@"TorrentCell" owner:self];
|
2023-06-27 19:40:44 +00:00
|
|
|
torrentCell.fTorrentProgressField.stringValue = torrent.progressString;
|
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
// set torrent icon and error badge
|
2023-06-27 19:40:44 +00:00
|
|
|
NSImage* fileImage = torrent.icon;
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
NSRect frame = torrentCell.fIconView.frame;
|
|
|
|
NSImage* resultImage = [[NSImage alloc] initWithSize:NSMakeSize(frame.size.height, frame.size.width)];
|
|
|
|
[resultImage lockFocus];
|
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
// draw fileImage
|
2023-06-27 19:40:44 +00:00
|
|
|
[fileImage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0];
|
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
// overlay error badge
|
2023-06-27 19:40:44 +00:00
|
|
|
NSImage* errorImage = [NSImage imageNamed:NSImageNameCaution];
|
|
|
|
NSRect const errorRect = NSMakeRect(frame.origin.x, 0, kErrorImageSize, kErrorImageSize);
|
|
|
|
[errorImage drawInRect:errorRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0
|
|
|
|
respectFlipped:YES
|
|
|
|
hints:nil];
|
|
|
|
|
|
|
|
[resultImage unlockFocus];
|
|
|
|
|
|
|
|
torrentCell.fIconView.image = resultImage;
|
|
|
|
}
|
|
|
|
else
|
2022-12-24 18:19:53 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
torrentCell.fIconView.image = fileImage;
|
|
|
|
}
|
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
// set torrent status
|
2023-06-27 19:40:44 +00:00
|
|
|
NSString* status;
|
|
|
|
if (self.fHoverEventDict)
|
|
|
|
{
|
|
|
|
NSInteger row = [self rowForItem:item];
|
|
|
|
NSInteger hoverRow = [self.fHoverEventDict[@"row"] integerValue];
|
|
|
|
|
|
|
|
if (row == hoverRow)
|
|
|
|
{
|
|
|
|
status = self.fHoverEventDict[@"string"];
|
|
|
|
}
|
2022-12-24 18:19:53 +00:00
|
|
|
}
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell.fTorrentStatusField.stringValue = status ?: torrent.statusString;
|
|
|
|
}
|
|
|
|
|
|
|
|
torrentCell.fTorrentTableView = self;
|
|
|
|
|
|
|
|
// set this so that we can draw bar in torrentCell drawRect
|
|
|
|
torrentCell.objectValue = torrent;
|
|
|
|
|
|
|
|
torrentCell.fTorrentTitleField.stringValue = torrent.name;
|
2023-06-27 19:40:44 +00:00
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell.fActionButton.action = @selector(displayTorrentActionPopover:);
|
|
|
|
|
|
|
|
NSInteger const groupValue = torrent.groupValue;
|
|
|
|
NSImage* groupImage;
|
|
|
|
if (groupValue != -1)
|
|
|
|
{
|
|
|
|
if (![self.fDefaults boolForKey:@"SortByGroup"])
|
2023-06-27 19:40:44 +00:00
|
|
|
{
|
2023-09-02 01:41:03 +00:00
|
|
|
NSColor* groupColor = [GroupsController.groups colorForIndex:groupValue];
|
|
|
|
groupImage = [NSImage discIconWithColor:groupColor insetFactor:0];
|
2023-06-27 19:40:44 +00:00
|
|
|
}
|
2023-09-02 01:41:03 +00:00
|
|
|
}
|
2023-06-27 19:40:44 +00:00
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell.fGroupIndicatorView.image = groupImage;
|
2023-06-27 19:40:44 +00:00
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
torrentCell.fControlButton.action = @selector(toggleControlForTorrent:);
|
|
|
|
torrentCell.fRevealButton.action = @selector(revealTorrentFile:);
|
2023-06-27 19:40:44 +00:00
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
// redraw buttons
|
2023-11-27 01:48:02 +00:00
|
|
|
torrentCell.fControlButton.needsDisplay = YES;
|
|
|
|
torrentCell.fRevealButton.needsDisplay = YES;
|
2023-06-27 19:40:44 +00:00
|
|
|
|
2023-09-02 01:41:03 +00:00
|
|
|
return torrentCell;
|
2008-02-18 20:53:10 +00:00
|
|
|
}
|
2023-02-15 19:01:24 +00:00
|
|
|
else
|
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
TorrentGroup* group = (TorrentGroup*)item;
|
|
|
|
GroupCell* groupCell = [outlineView makeViewWithIdentifier:@"GroupCell" owner:self];
|
2023-02-15 19:01:24 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
NSInteger groupIndex = group.groupIndex;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
NSColor* groupColor = groupIndex != -1 ? [GroupsController.groups colorForIndex:groupIndex] :
|
|
|
|
[NSColor colorWithWhite:1.0 alpha:0];
|
|
|
|
groupCell.fGroupIndicatorView.image = [NSImage discIconWithColor:groupColor insetFactor:0];
|
2022-12-09 19:06:00 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
NSString* groupName = groupIndex != -1 ? [GroupsController.groups nameForIndex:groupIndex] :
|
|
|
|
NSLocalizedString(@"No Group", "Group table row");
|
2022-12-09 19:06:00 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
NSInteger row = [self rowForItem:item];
|
|
|
|
if ([self isRowSelected:row])
|
2022-12-09 19:06:00 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
NSMutableAttributedString* string = [[NSMutableAttributedString alloc] initWithString:groupName];
|
|
|
|
NSDictionary* attributes = @{
|
|
|
|
NSFontAttributeName : [NSFont boldSystemFontOfSize:11.0],
|
|
|
|
NSForegroundColorAttributeName : [NSColor labelColor]
|
|
|
|
};
|
|
|
|
|
|
|
|
[string addAttributes:attributes range:NSMakeRange(0, string.length)];
|
|
|
|
groupCell.fGroupTitleField.attributedStringValue = string;
|
2022-12-09 19:06:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
groupCell.fGroupTitleField.stringValue = groupName;
|
2022-12-09 19:06:00 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
groupCell.fGroupDownloadField.stringValue = [NSString stringForSpeed:group.downloadRate];
|
|
|
|
groupCell.fGroupDownloadView.image = [NSImage imageNamed:@"DownArrowGroupTemplate"];
|
2022-12-09 19:06:00 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
BOOL displayGroupRowRatio = [self.fDefaults boolForKey:@"DisplayGroupRowRatio"];
|
|
|
|
groupCell.fGroupDownloadField.hidden = displayGroupRowRatio;
|
|
|
|
groupCell.fGroupDownloadView.hidden = displayGroupRowRatio;
|
2022-12-09 19:06:00 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
if (displayGroupRowRatio)
|
|
|
|
{
|
|
|
|
groupCell.fGroupUploadAndRatioView.image = [NSImage imageNamed:@"YingYangGroupTemplate"];
|
|
|
|
groupCell.fGroupUploadAndRatioView.image.accessibilityDescription = NSLocalizedString(@"Ratio", "Torrent -> status image");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
groupCell.fGroupUploadAndRatioField.stringValue = [NSString stringForRatio:group.ratio];
|
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
groupCell.fGroupUploadAndRatioView.image = [NSImage imageNamed:@"UpArrowGroupTemplate"];
|
|
|
|
groupCell.fGroupUploadAndRatioView.image.accessibilityDescription = NSLocalizedString(@"UL", "Torrent -> status image");
|
|
|
|
|
|
|
|
groupCell.fGroupUploadAndRatioField.stringValue = [NSString stringForSpeed:group.uploadRate];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
return groupCell;
|
2008-02-19 02:10:20 +00:00
|
|
|
}
|
2023-06-27 19:40:44 +00:00
|
|
|
return nil;
|
2007-10-27 14:57:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)outlineView:(NSOutlineView*)outlineView typeSelectStringForTableColumn:(NSTableColumn*)tableColumn item:(id)item
|
2008-01-23 21:33:54 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
|
|
|
return ((Torrent*)item).name;
|
|
|
|
}
|
2012-11-02 21:46:18 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return [self.dataSource outlineView:outlineView objectValueForTableColumn:[self tableColumnWithIdentifier:@"Group"]
|
|
|
|
byItem:item];
|
|
|
|
}
|
2008-01-23 21:33:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)outlineView:(NSOutlineView*)outlineView
|
|
|
|
toolTipForCell:(NSCell*)cell
|
|
|
|
rect:(NSRectPointer)rect
|
|
|
|
tableColumn:(NSTableColumn*)column
|
|
|
|
item:(id)item
|
|
|
|
mouseLocation:(NSPoint)mouseLocation
|
2008-02-28 21:28:48 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* ident = column.identifier;
|
|
|
|
if ([ident isEqualToString:@"DL"] || [ident isEqualToString:@"DL Image"])
|
|
|
|
{
|
2008-02-28 21:28:48 +00:00
|
|
|
return NSLocalizedString(@"Download speed", "Torrent table -> group row -> tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString:@"UL"] || [ident isEqualToString:@"UL Image"])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.fDefaults boolForKey:@"DisplayGroupRowRatio"] ?
|
2021-08-15 09:41:48 +00:00
|
|
|
NSLocalizedString(@"Ratio", "Torrent table -> group row -> tooltip") :
|
|
|
|
NSLocalizedString(@"Upload speed", "Torrent table -> group row -> tooltip");
|
|
|
|
}
|
2008-03-04 00:30:26 +00:00
|
|
|
else if (ident)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger count = ((TorrentGroup*)item).torrents.count;
|
2008-03-04 00:30:26 +00:00
|
|
|
if (count == 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-03-04 00:30:26 +00:00
|
|
|
return NSLocalizedString(@"1 transfer", "Torrent table -> group row -> tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-03-04 00:30:26 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-11-14 18:30:03 +00:00
|
|
|
return [NSString localizedStringWithFormat:NSLocalizedString(@"%lu transfers", "Torrent table -> group row -> tooltip"), count];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-03-04 00:30:26 +00:00
|
|
|
}
|
2008-02-28 21:28:48 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-28 21:28:48 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-02-28 21:28:48 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (void)outlineViewSelectionDidChange:(NSNotification*)notification
|
2008-01-15 23:48:03 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
self.fSelectedRowIndexes = self.selectedRowIndexes;
|
|
|
|
[self reloadVisibleRows];
|
2008-01-15 03:50:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineViewItemDidExpand:(NSNotification*)notification
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* group = notification.userInfo[@"NSObject"];
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger value = group.groupIndex;
|
2008-05-11 21:38:40 +00:00
|
|
|
if (value < 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
value = kMaxGroup;
|
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.fCollapsedGroups containsIndex:value])
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCollapsedGroups removeIndex:value];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"OutlineExpandCollapse" object:self];
|
2008-05-11 21:38:40 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineViewItemDidCollapse:(NSNotification*)notification
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* group = notification.userInfo[@"NSObject"];
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger value = group.groupIndex;
|
2008-05-11 21:38:40 +00:00
|
|
|
if (value < 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
value = kMaxGroup;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCollapsedGroups addIndex:value];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"OutlineExpandCollapse" object:self];
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)mouseDown:(NSEvent*)event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
|
|
NSInteger const row = [self rowAtPoint:point];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[super mouseDown:event];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
id item = nil;
|
|
|
|
if (row != -1)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
item = [self itemAtRow:row];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
if (event.clickCount == 2) //double click
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!item || [item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController showInfo:nil];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([self isItemExpanded:item])
|
|
|
|
{
|
|
|
|
[self collapseItem:item];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self expandItem:item];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-27 19:40:44 +00:00
|
|
|
else if ([self pointInGroupStatusRect:point])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
//we check for this here rather than in the GroupCell
|
|
|
|
//as using floating group rows causes all sorts of weirdness...
|
|
|
|
[self toggleGroupRowRatio];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (NSArray<Torrent*>*)selectedTorrents
|
2008-01-22 23:48:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* selectedIndexes = self.selectedRowIndexes;
|
|
|
|
NSMutableArray* torrents = [NSMutableArray arrayWithCapacity:selectedIndexes.count]; //take a shot at guessing capacity
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger i = selectedIndexes.firstIndex; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex:i])
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
id item = [self itemAtRow:i];
|
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
|
|
|
[torrents addObject:item];
|
|
|
|
}
|
2008-06-05 02:16:33 +00:00
|
|
|
else
|
2008-01-23 03:12:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* groupTorrents = ((TorrentGroup*)item).torrents;
|
|
|
|
[torrents addObjectsFromArray:groupTorrents];
|
|
|
|
if ([self isItemExpanded:item])
|
|
|
|
{
|
|
|
|
i += groupTorrents.count;
|
|
|
|
}
|
2008-01-23 03:12:06 +00:00
|
|
|
}
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
return torrents;
|
2008-01-22 23:48:14 +00:00
|
|
|
}
|
|
|
|
|
2023-09-11 02:39:01 +00:00
|
|
|
- (void)setSelectedTorrents:(NSArray<Torrent*>*)selectedTorrents
|
|
|
|
{
|
|
|
|
NSMutableIndexSet* selectedIndexes = [NSMutableIndexSet new];
|
|
|
|
for (Torrent* i in selectedTorrents)
|
|
|
|
{
|
|
|
|
[selectedIndexes addIndex:[self rowForItem:i]];
|
|
|
|
}
|
|
|
|
[self selectRowIndexes:selectedIndexes byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSMenu*)menuForEvent:(NSEvent*)event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger row = [self rowAtPoint:[self convertPoint:event.locationInWindow fromView:nil]];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (row >= 0)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![self isRowSelected:row])
|
|
|
|
{
|
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fContextRow;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self deselectAll:self];
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fContextNoRow;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-16 21:09:59 +00:00
|
|
|
//make sure that the pause buttons become orange when holding down the option key
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)flagsChanged:(NSEvent*)event
|
2007-10-27 14:57:46 +00:00
|
|
|
{
|
|
|
|
[self display];
|
2021-08-15 09:41:48 +00:00
|
|
|
[super flagsChanged:event];
|
2007-10-27 14:57:46 +00:00
|
|
|
}
|
|
|
|
|
2008-03-16 14:24:27 +00:00
|
|
|
//option-command-f will focus the filter bar's search field
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)keyDown:(NSEvent*)event
|
2008-03-16 14:24:27 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
unichar const firstChar = [event.charactersIgnoringModifiers characterAtIndex:0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
if (firstChar == 'f' && event.modifierFlags & NSEventModifierFlagOption && event.modifierFlags & NSEventModifierFlagCommand)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController focusFilterField];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-09-04 04:10:46 +00:00
|
|
|
else if (firstChar == ' ')
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController toggleQuickLook:nil];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (event.keyCode == 53) //esc key
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self deselectAll:nil];
|
|
|
|
}
|
2008-03-16 14:24:27 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[super keyDown:event];
|
|
|
|
}
|
2008-03-16 14:24:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)iconRectForRow:(NSInteger)row
|
2008-05-21 22:09:05 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
BOOL minimal = [self.fDefaults boolForKey:@"SmallView"];
|
|
|
|
NSRect rect;
|
|
|
|
|
|
|
|
if (minimal)
|
|
|
|
{
|
|
|
|
SmallTorrentCell* smallCell = [self viewAtColumn:0 row:row makeIfNecessary:NO];
|
|
|
|
rect = smallCell.fActionButton.frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TorrentCell* torrentCell = [self viewAtColumn:0 row:row makeIfNecessary:NO];
|
|
|
|
rect = torrentCell.fIconView.frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRect rowRect = [self rectOfRow:row];
|
|
|
|
rect.origin.y += rowRect.origin.y;
|
|
|
|
rect.origin.x += self.intercellSpacing.width;
|
|
|
|
return rect;
|
2008-05-21 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 21:03:07 +00:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
// add support to `copy:`
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)copy:(id)sender
|
|
|
|
{
|
|
|
|
NSArray<Torrent*>* selectedTorrents = self.selectedTorrents;
|
|
|
|
if (selectedTorrents.count == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSPasteboard* pasteBoard = NSPasteboard.generalPasteboard;
|
|
|
|
NSString* links = [[selectedTorrents valueForKeyPath:@"magnetLink"] componentsJoinedByString:@"\n"];
|
2023-11-03 05:22:45 +00:00
|
|
|
[pasteBoard declareTypes:@[ NSPasteboardTypeString ] owner:nil];
|
|
|
|
[pasteBoard setString:links forType:NSPasteboardTypeString];
|
2022-05-13 21:03:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)paste:(id)sender
|
2008-05-01 02:20:53 +00:00
|
|
|
{
|
2024-01-02 04:35:57 +00:00
|
|
|
[self.fController openPasteboard];
|
2008-05-01 02:20:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
|
2008-05-01 02:20:53 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
SEL action = menuItem.action;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-01 02:20:53 +00:00
|
|
|
if (action == @selector(paste:))
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2023-11-03 05:22:45 +00:00
|
|
|
if ([NSPasteboard.generalPasteboard.types containsObject:NSPasteboardTypeURL])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-12-26 02:33:13 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* items = [NSPasteboard.generalPasteboard readObjectsForClasses:@[ [NSString class] ] options:nil];
|
2016-01-06 11:05:37 +00:00
|
|
|
if (items)
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
|
|
|
|
for (__strong NSString* pbItem in items)
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
pbItem = [pbItem stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
|
|
if (([pbItem rangeOfString:@"magnet:" options:(NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound) ||
|
|
|
|
[detector firstMatchInString:pbItem options:0 range:NSMakeRange(0, pbItem.length)])
|
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-12-26 02:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return NO;
|
2011-12-26 02:33:13 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-01 02:20:53 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (void)hoverEventBeganForView:(id)view
|
|
|
|
{
|
|
|
|
NSInteger row = [self rowForView:view];
|
|
|
|
Torrent* torrent = [self itemAtRow:row];
|
|
|
|
|
|
|
|
BOOL minimal = [self.fDefaults boolForKey:@"SmallView"];
|
|
|
|
if (minimal)
|
|
|
|
{
|
|
|
|
if ([view isKindOfClass:[SmallTorrentCell class]])
|
|
|
|
{
|
|
|
|
self.fHoverEventDict = @{ @"row" : [NSNumber numberWithInteger:row] };
|
|
|
|
}
|
|
|
|
else if ([view isKindOfClass:[TorrentCellActionButton class]])
|
|
|
|
{
|
|
|
|
SmallTorrentCell* smallCell = [self viewAtColumn:0 row:row makeIfNecessary:NO];
|
|
|
|
smallCell.fIconView.hidden = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSString* statusString;
|
|
|
|
if ([view isKindOfClass:[TorrentCellRevealButton class]])
|
|
|
|
{
|
|
|
|
statusString = NSLocalizedString(@"Show the data file in Finder", "Torrent cell -> button info");
|
|
|
|
}
|
|
|
|
else if ([view isKindOfClass:[TorrentCellControlButton class]])
|
|
|
|
{
|
|
|
|
if (torrent.active)
|
|
|
|
statusString = NSLocalizedString(@"Pause the transfer", "Torrent Table -> tooltip");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NSApp.currentEvent.modifierFlags & NSEventModifierFlagOption)
|
|
|
|
{
|
|
|
|
statusString = NSLocalizedString(@"Resume the transfer right away", "Torrent cell -> button info");
|
|
|
|
}
|
|
|
|
else if (torrent.waitingToStart)
|
|
|
|
{
|
|
|
|
statusString = NSLocalizedString(@"Stop waiting to start", "Torrent cell -> button info");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusString = NSLocalizedString(@"Resume the transfer", "Torrent cell -> button info");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ([view isKindOfClass:[TorrentCellActionButton class]])
|
|
|
|
{
|
|
|
|
statusString = NSLocalizedString(@"Change transfer settings", "Torrent Table -> tooltip");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusString)
|
|
|
|
{
|
|
|
|
self.fHoverEventDict = @{ @"string" : statusString, @"row" : [NSNumber numberWithInteger:row] };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self reloadVisibleRows];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)hoverEventEndedForView:(id)view
|
|
|
|
{
|
|
|
|
NSInteger row = [self rowForView:[view superview]];
|
|
|
|
|
|
|
|
BOOL update = YES;
|
|
|
|
BOOL minimal = [self.fDefaults boolForKey:@"SmallView"];
|
|
|
|
if (minimal)
|
|
|
|
{
|
|
|
|
if (minimal && ![view isKindOfClass:[SmallTorrentCell class]])
|
|
|
|
{
|
|
|
|
if ([view isKindOfClass:[TorrentCellActionButton class]])
|
|
|
|
{
|
|
|
|
SmallTorrentCell* smallCell = [self viewAtColumn:0 row:row makeIfNecessary:NO];
|
|
|
|
smallCell.fIconView.hidden = NO;
|
|
|
|
}
|
|
|
|
update = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
{
|
|
|
|
self.fHoverEventDict = nil;
|
|
|
|
[self reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleGroupRowRatio
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
BOOL displayGroupRowRatio = [self.fDefaults boolForKey:@"DisplayGroupRowRatio"];
|
|
|
|
[self.fDefaults setBool:!displayGroupRowRatio forKey:@"DisplayGroupRowRatio"];
|
|
|
|
[self reloadVisibleRows];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)toggleControlForTorrent:(id)sender
|
|
|
|
{
|
|
|
|
Torrent* torrent = [self itemAtRow:[self rowForView:[sender superview]]];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController stopTorrents:@[ torrent ]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
else
|
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
if (NSEvent.modifierFlags & NSEventModifierFlagOption)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController resumeTorrentsNoWait:@[ torrent ]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController stopTorrents:@[ torrent ]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController resumeTorrents:@[ torrent ]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (IBAction)revealTorrentFile:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
Torrent* torrent = [self itemAtRow:[self rowForView:[sender superview]]];
|
|
|
|
NSString* location = torrent.dataLocation;
|
|
|
|
if (location)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
NSURL* file = [NSURL fileURLWithPath:location];
|
|
|
|
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[ file ]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2023-06-27 19:40:44 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
- (IBAction)displayTorrentActionPopover:(id)sender
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fActionPopoverShown)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
Torrent* torrent = [self itemAtRow:[self rowForView:[sender superview]]];
|
|
|
|
NSRect rect = [sender bounds];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPopover* popover = [[NSPopover alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
popover.behavior = NSPopoverBehaviorTransient;
|
2021-08-15 09:41:48 +00:00
|
|
|
InfoOptionsViewController* infoViewController = [[InfoOptionsViewController alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
popover.contentViewController = infoViewController;
|
|
|
|
popover.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
[popover showRelativeToRect:rect ofView:sender preferredEdge:NSMaxYEdge];
|
2021-08-15 09:41:48 +00:00
|
|
|
[infoViewController setInfoForTorrents:@[ torrent ]];
|
2016-01-06 11:05:37 +00:00
|
|
|
[infoViewController updateInfo];
|
2022-06-15 18:53:23 +00:00
|
|
|
|
|
|
|
CGFloat width = NSWidth(rect);
|
|
|
|
|
2023-12-16 15:22:06 +00:00
|
|
|
if (NSMinX(self.window.frame) < width || NSMaxX(self.window.screen.visibleFrame) - NSMinX(self.window.frame) < 72)
|
2022-06-15 18:53:23 +00:00
|
|
|
{
|
|
|
|
// Ugly hack to hide NSPopover arrow.
|
|
|
|
self.fPositioningView = [[NSView alloc] initWithFrame:rect];
|
|
|
|
self.fPositioningView.identifier = @"positioningView";
|
|
|
|
[self addSubview:self.fPositioningView];
|
|
|
|
[popover showRelativeToRect:self.fPositioningView.bounds ofView:self.fPositioningView preferredEdge:NSMaxYEdge];
|
|
|
|
self.fPositioningView.bounds = NSOffsetRect(self.fPositioningView.bounds, 0, NSHeight(self.fPositioningView.bounds));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-27 19:40:44 +00:00
|
|
|
[popover showRelativeToRect:rect ofView:sender preferredEdge:NSMaxYEdge];
|
2022-06-15 18:53:23 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2011-07-27 03:38:01 +00:00
|
|
|
//don't show multiple popovers when clicking the gear button repeatedly
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)popoverWillShow:(NSNotification*)notification
|
2011-07-27 03:38:01 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fActionPopoverShown = YES;
|
2011-07-27 03:38:01 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 18:53:23 +00:00
|
|
|
- (void)popoverDidClose:(NSNotification*)notification
|
2011-07-27 03:38:01 +00:00
|
|
|
{
|
2022-06-15 18:53:23 +00:00
|
|
|
[self.fPositioningView removeFromSuperview];
|
|
|
|
self.fPositioningView = nil;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fActionPopoverShown = NO;
|
2011-07-27 03:38:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)togglePiecesBar
|
2008-01-16 15:56:40 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* progressMarks = [NSMutableArray arrayWithCapacity:16];
|
2012-03-13 02:52:11 +00:00
|
|
|
for (NSAnimationProgress i = 0.0625; i <= 1.0; i += 0.0625)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[progressMarks addObject:@(i)];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-03-13 03:49:30 +00:00
|
|
|
//this stops a previous animation
|
2022-10-19 19:28:21 +00:00
|
|
|
self.fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration:kToggleProgressSeconds animationCurve:NSAnimationEaseIn];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPiecesBarAnimation.animationBlockingMode = NSAnimationNonblocking;
|
|
|
|
self.fPiecesBarAnimation.progressMarks = progressMarks;
|
|
|
|
self.fPiecesBarAnimation.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPiecesBarAnimation startAnimation];
|
2008-06-10 05:09:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)animationDidEnd:(NSAnimation*)animation
|
2008-06-10 05:09:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (animation == self.fPiecesBarAnimation)
|
2008-06-10 05:09:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPiecesBarAnimation = nil;
|
2008-06-10 05:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)animation:(NSAnimation*)animation didReachProgressMark:(NSAnimationProgress)progress
|
2008-06-10 05:09:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (animation == self.fPiecesBarAnimation)
|
2008-01-16 16:39:18 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"PiecesBar"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.piecesBarPercent = progress;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-10 05:09:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.piecesBarPercent = 1.0 - progress;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.needsDisplay = YES;
|
2008-01-16 16:39:18 +00:00
|
|
|
}
|
2008-01-16 15:56:40 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)selectAndScrollToRow:(NSInteger)row
|
2016-03-03 17:57:08 +00:00
|
|
|
{
|
|
|
|
NSParameterAssert(row >= 0);
|
2021-08-07 07:27:56 +00:00
|
|
|
NSParameterAssert(row < self.numberOfRows);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const rowRect = [self rectOfRow:row];
|
|
|
|
NSRect const viewRect = self.superview.frame;
|
2016-03-03 17:57:08 +00:00
|
|
|
|
|
|
|
NSPoint scrollOrigin = rowRect.origin;
|
|
|
|
scrollOrigin.y += (rowRect.size.height - viewRect.size.height) / 2;
|
|
|
|
if (scrollOrigin.y < 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-03-03 17:57:08 +00:00
|
|
|
scrollOrigin.y = 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-03-03 17:57:08 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[[self.superview animator] setBoundsOrigin:scrollOrigin];
|
2016-03-03 17:57:08 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)pointInGroupStatusRect:(NSPoint)point
|
2008-02-28 02:17:17 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger row = [self rowAtPoint:point];
|
2023-06-27 19:40:44 +00:00
|
|
|
if (![[self itemAtRow:row] isKindOfClass:[TorrentGroup class]])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-28 02:17:17 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
//check if click is within the status/ratio rect
|
|
|
|
GroupCell* groupCell = [self viewAtColumn:0 row:row makeIfNecessary:NO];
|
|
|
|
NSRect titleRect = groupCell.fGroupTitleField.frame;
|
|
|
|
CGFloat maxX = NSMaxX(titleRect);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-06-27 19:40:44 +00:00
|
|
|
return point.x > maxX;
|
2008-02-28 16:40:14 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|