2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2005-2012 Transmission authors and contributors
|
2007-09-16 01:02:06 +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 "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"
|
2009-08-30 18:38:56 +00:00
|
|
|
#import "NSApplicationAdditions.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"
|
|
|
|
#import "TorrentGroup.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-29 02:33:20 +00:00
|
|
|
#define MAX_GROUP 999999
|
2008-02-07 16:20:24 +00:00
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
//eliminate when Lion-only
|
2007-09-16 01:02:06 +00:00
|
|
|
#define ACTION_MENU_GLOBAL_TAG 101
|
|
|
|
#define ACTION_MENU_UNLIMITED_TAG 102
|
|
|
|
#define ACTION_MENU_LIMIT_TAG 103
|
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
#define ACTION_MENU_PRIORITY_HIGH_TAG 101
|
|
|
|
#define ACTION_MENU_PRIORITY_NORMAL_TAG 102
|
|
|
|
#define ACTION_MENU_PRIORITY_LOW_TAG 103
|
|
|
|
|
2008-06-18 16:25:30 +00:00
|
|
|
#define TOGGLE_PROGRESS_SECONDS 0.175
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface TorrentTableView (Private)
|
|
|
|
|
2008-02-28 02:17:17 +00:00
|
|
|
- (BOOL) pointInGroupStatusRect: (NSPoint) point;
|
|
|
|
|
2008-02-28 16:40:14 +00:00
|
|
|
- (void) setGroupStatusColumns;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentTableView
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder *) decoder
|
|
|
|
{
|
|
|
|
if ((self = [super initWithCoder: decoder]))
|
|
|
|
{
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-19 15:57:27 +00:00
|
|
|
fTorrentCell = [[TorrentCell alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-07 21:26:04 +00:00
|
|
|
NSData * groupData = [fDefaults dataForKey: @"CollapsedGroups"];
|
|
|
|
if (groupData)
|
2008-02-10 16:56:13 +00:00
|
|
|
fCollapsedGroups = [[NSUnarchiver unarchiveObjectWithData: groupData] mutableCopy];
|
2008-02-07 21:26:04 +00:00
|
|
|
else
|
|
|
|
fCollapsedGroups = [[NSMutableIndexSet alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
fMouseRow = -1;
|
2008-01-15 04:45:57 +00:00
|
|
|
fMouseControlRow = -1;
|
|
|
|
fMouseRevealRow = -1;
|
2008-01-15 23:48:03 +00:00
|
|
|
fMouseActionRow = -1;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-27 03:38:01 +00:00
|
|
|
fActionPopoverShown = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setDelegate: self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-02-15 14:56:14 +00:00
|
|
|
fPiecesBarPercent = [fDefaults boolForKey: @"PiecesBar"] ? 1.0 : 0.0;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2011-07-23 15:54:02 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-03-17 21:44:14 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
//set group columns to show ratio, needs to be in awakeFromNib to size columns correctly
|
|
|
|
[self setGroupStatusColumns];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-18 04:03:12 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(setNeedsDisplay) name: @"RefreshTorrentTable" object: nil];
|
2008-03-17 21:44:14 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 01:18:03 +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)
|
2008-02-07 16:20:24 +00:00
|
|
|
value = MAX_GROUP;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-07 16:20:24 +00:00
|
|
|
return [fCollapsedGroups containsIndex: value];
|
2008-02-07 01:26:12 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 01:18:03 +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)
|
2008-02-07 16:20:24 +00:00
|
|
|
value = MAX_GROUP;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-07 02:11:26 +00:00
|
|
|
[fCollapsedGroups removeIndex: value];
|
|
|
|
}
|
|
|
|
|
2008-02-07 02:15:24 +00:00
|
|
|
- (void) removeAllCollapsedGroups
|
|
|
|
{
|
|
|
|
[fCollapsedGroups removeAllIndexes];
|
|
|
|
}
|
|
|
|
|
2008-02-07 21:26:04 +00:00
|
|
|
- (void) saveCollapsedGroups
|
|
|
|
{
|
|
|
|
[fDefaults setObject: [NSArchiver archivedDataWithRootObject: fCollapsedGroups] forKey: @"CollapsedGroups"];
|
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (BOOL) outlineView: (NSOutlineView *) outlineView isGroupItem: (id) item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
return ![item isKindOfClass: [Torrent class]];
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (CGFloat) outlineView: (NSOutlineView *) outlineView heightOfRowByItem: (id) item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
return [item isKindOfClass: [Torrent class]] ? [self rowHeight] : GROUP_SEPARATOR_HEIGHT;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (NSCell *) outlineView: (NSOutlineView *) outlineView dataCellForTableColumn: (NSTableColumn *) tableColumn item: (id) item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2009-10-17 17:15:37 +00:00
|
|
|
const BOOL group = ![item isKindOfClass: [Torrent class]];
|
2008-02-18 20:53:10 +00:00
|
|
|
if (!tableColumn)
|
|
|
|
return !group ? fTorrentCell : nil;
|
|
|
|
else
|
|
|
|
return group ? [tableColumn dataCellForRow: [self rowForItem: item]] : nil;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn
|
|
|
|
item: (id) item
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-18 20:53:10 +00:00
|
|
|
if ([item isKindOfClass: [Torrent class]])
|
|
|
|
{
|
2011-07-21 02:35:03 +00:00
|
|
|
if (!tableColumn)
|
|
|
|
{
|
|
|
|
[cell setRepresentedObject: item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:35:03 +00:00
|
|
|
const NSInteger row = [self rowForItem: item];
|
|
|
|
[cell setHover: row == fMouseRow];
|
|
|
|
[cell setControlHover: row == fMouseControlRow];
|
|
|
|
[cell setRevealHover: row == fMouseRevealRow];
|
|
|
|
[cell setActionHover: row == fMouseActionRow];
|
|
|
|
}
|
2008-02-18 20:53:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-05 02:16:33 +00:00
|
|
|
NSString * ident = [tableColumn identifier];
|
|
|
|
if ([ident isEqualToString: @"UL Image"] || [ident isEqualToString: @"DL Image"])
|
2008-02-19 02:59:01 +00:00
|
|
|
{
|
2008-02-19 05:14:22 +00:00
|
|
|
//ensure arrows are white only when selected
|
2011-10-06 00:30:40 +00:00
|
|
|
[[cell image] setTemplate: [cell backgroundStyle] == NSBackgroundStyleLowered];
|
2008-02-19 02:59:01 +00:00
|
|
|
}
|
2008-02-18 20:53:10 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (NSRect) frameOfCellAtColumn: (NSInteger) column row: (NSInteger) row
|
2007-10-27 14:57:46 +00:00
|
|
|
{
|
2008-12-26 05:57:51 +00:00
|
|
|
if (column == -1)
|
2008-02-18 19:42:46 +00:00
|
|
|
return [self rectOfRow: row];
|
|
|
|
else
|
2008-02-19 02:10:20 +00:00
|
|
|
{
|
|
|
|
NSRect rect = [super frameOfCellAtColumn: column row: row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-19 02:10:20 +00:00
|
|
|
//adjust placement for proper vertical alignment
|
|
|
|
if (column == [self columnWithIdentifier: @"Group"])
|
2008-10-29 01:18:03 +00:00
|
|
|
rect.size.height -= 1.0f;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-19 02:10:20 +00:00
|
|
|
return rect;
|
|
|
|
}
|
2007-10-27 14:57:46 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (NSString *) outlineView: (NSOutlineView *) outlineView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn item: (id) item
|
2008-01-23 21:33:54 +00:00
|
|
|
{
|
2012-11-02 21:46:18 +00:00
|
|
|
if ([item isKindOfClass: [Torrent class]])
|
|
|
|
return [(Torrent *)item name];
|
|
|
|
else
|
|
|
|
return [[self dataSource] outlineView:outlineView objectValueForTableColumn:[self tableColumnWithIdentifier:@"Group"] byItem:item];
|
2008-01-23 21:33:54 +00:00
|
|
|
}
|
|
|
|
|
2011-10-23 17:45:05 +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
|
|
|
{
|
|
|
|
NSString * ident = [column identifier];
|
|
|
|
if ([ident isEqualToString: @"DL"] || [ident isEqualToString: @"DL Image"])
|
|
|
|
return NSLocalizedString(@"Download speed", "Torrent table -> group row -> tooltip");
|
|
|
|
else if ([ident isEqualToString: @"UL"] || [ident isEqualToString: @"UL Image"])
|
|
|
|
return [fDefaults boolForKey: @"DisplayGroupRowRatio"] ? 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)
|
|
|
|
{
|
2010-11-20 16:09:48 +00:00
|
|
|
NSUInteger count = [[item torrents] count];
|
2008-03-04 00:30:26 +00:00
|
|
|
if (count == 1)
|
|
|
|
return NSLocalizedString(@"1 transfer", "Torrent table -> group row -> tooltip");
|
|
|
|
else
|
2010-11-20 16:09:48 +00:00
|
|
|
return [NSString stringWithFormat: NSLocalizedString(@"%@ transfers", "Torrent table -> group row -> tooltip"),
|
|
|
|
[NSString formattedUInteger: count]];
|
2008-03-04 00:30:26 +00:00
|
|
|
}
|
2008-02-28 21:28:48 +00:00
|
|
|
else
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
- (void) updateTrackingAreas
|
|
|
|
{
|
|
|
|
[super updateTrackingAreas];
|
2010-03-20 03:27:17 +00:00
|
|
|
[self removeTrackingAreas];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 18:54:24 +00:00
|
|
|
const NSRange rows = [self rowsInRect: [self visibleRect]];
|
2008-02-06 23:45:44 +00:00
|
|
|
if (rows.length == 0)
|
2008-01-15 03:33:44 +00:00
|
|
|
return;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-07 17:21:12 +00:00
|
|
|
NSPoint mouseLocation = [self convertPoint: [[self window] mouseLocationOutsideOfEventStream] fromView: nil];
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSUInteger row = rows.location; row < NSMaxRange(rows); row++)
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
if (![[self itemAtRow: row] isKindOfClass: [Torrent class]])
|
|
|
|
continue;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-08 15:02:00 +00:00
|
|
|
NSDictionary * userInfo = @{@"Row": @(row)};
|
2008-02-18 19:42:46 +00:00
|
|
|
TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: -1 row: row];
|
2008-06-30 02:22:29 +00:00
|
|
|
[cell addTrackingAreasForView: self inRect: [self rectOfRow: row] withUserInfo: userInfo mouseLocation: mouseLocation];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
- (void) removeTrackingAreas
|
2008-01-15 16:19:16 +00:00
|
|
|
{
|
2010-03-20 03:27:17 +00:00
|
|
|
fMouseRow = -1;
|
2008-01-15 16:19:16 +00:00
|
|
|
fMouseControlRow = -1;
|
|
|
|
fMouseRevealRow = -1;
|
2008-01-15 23:48:03 +00:00
|
|
|
fMouseActionRow = -1;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (NSTrackingArea * area in [self trackingAreas])
|
2008-01-15 16:19:16 +00:00
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
if ([area owner] == self && [area userInfo][@"Row"])
|
2008-01-15 16:19:16 +00:00
|
|
|
[self removeTrackingArea: area];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
- (void) setRowHover: (NSInteger) row
|
|
|
|
{
|
2010-03-20 18:54:24 +00:00
|
|
|
NSAssert([fDefaults boolForKey: @"SmallView"], @"cannot set a hover row when not in compact view");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
fMouseRow = row;
|
2010-03-20 18:27:09 +00:00
|
|
|
if (row >= 0)
|
2010-03-20 03:27:17 +00:00
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
2008-10-29 01:18:03 +00:00
|
|
|
- (void) setControlButtonHover: (NSInteger) row
|
2008-01-15 19:48:19 +00:00
|
|
|
{
|
|
|
|
fMouseControlRow = row;
|
|
|
|
if (row >= 0)
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
2008-10-29 01:18:03 +00:00
|
|
|
- (void) setRevealButtonHover: (NSInteger) row
|
2008-01-15 19:48:19 +00:00
|
|
|
{
|
|
|
|
fMouseRevealRow = row;
|
|
|
|
if (row >= 0)
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
2008-10-29 01:18:03 +00:00
|
|
|
- (void) setActionButtonHover: (NSInteger) row
|
2008-01-15 23:48:03 +00:00
|
|
|
{
|
|
|
|
fMouseActionRow = row;
|
|
|
|
if (row >= 0)
|
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
- (void) mouseEntered: (NSEvent *) event
|
|
|
|
{
|
2008-01-15 04:45:57 +00:00
|
|
|
NSDictionary * dict = (NSDictionary *)[event userData];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
NSNumber * row;
|
2017-07-08 14:38:47 +00:00
|
|
|
if ((row = dict[@"Row"]))
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2009-12-23 02:02:11 +00:00
|
|
|
NSInteger rowVal = [row integerValue];
|
2017-07-08 14:38:47 +00:00
|
|
|
NSString * type = dict[@"Type"];
|
2008-01-20 18:51:53 +00:00
|
|
|
if ([type isEqualToString: @"Action"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseActionRow = rowVal;
|
2008-01-20 18:51:53 +00:00
|
|
|
else if ([type isEqualToString: @"Control"])
|
2008-01-15 04:45:57 +00:00
|
|
|
fMouseControlRow = rowVal;
|
2010-03-20 03:27:17 +00:00
|
|
|
else if ([type isEqualToString: @"Reveal"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseRevealRow = rowVal;
|
2010-03-20 03:27:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fMouseRow = rowVal;
|
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-15 04:45:57 +00:00
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: rowVal]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseExited: (NSEvent *) event
|
|
|
|
{
|
2008-01-16 06:48:12 +00:00
|
|
|
NSDictionary * dict = (NSDictionary *)[event userData];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
NSNumber * row;
|
2017-07-08 14:38:47 +00:00
|
|
|
if ((row = dict[@"Row"]))
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
NSString * type = dict[@"Type"];
|
2008-01-20 18:51:53 +00:00
|
|
|
if ([type isEqualToString: @"Action"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseActionRow = -1;
|
2008-01-20 18:51:53 +00:00
|
|
|
else if ([type isEqualToString: @"Control"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseControlRow = -1;
|
2010-03-20 03:27:17 +00:00
|
|
|
else if ([type isEqualToString: @"Reveal"])
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseRevealRow = -1;
|
2010-03-20 03:27:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fMouseRow = -1;
|
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-23 02:02:11 +00:00
|
|
|
[self setNeedsDisplayInRect: [self rectOfRow: [row integerValue]]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (void) outlineViewSelectionIsChanging: (NSNotification *) notification
|
2008-01-15 03:50:00 +00:00
|
|
|
{
|
2012-01-15 07:39:24 +00:00
|
|
|
#warning elliminate when view-based?
|
|
|
|
//if pushing a button, don't change the selected rows
|
2008-01-23 02:51:58 +00:00
|
|
|
if (fSelectedValues)
|
|
|
|
[self selectValues: fSelectedValues];
|
2008-01-15 03:50:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (void) outlineViewItemDidExpand: (NSNotification *) notification
|
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
NSInteger value = [[notification userInfo][@"NSObject"] groupIndex];
|
2008-05-11 21:38:40 +00:00
|
|
|
if (value < 0)
|
|
|
|
value = MAX_GROUP;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-11 21:38:40 +00:00
|
|
|
if ([fCollapsedGroups containsIndex: value])
|
|
|
|
{
|
|
|
|
[fCollapsedGroups removeIndex: value];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"OutlineExpandCollapse" object: self];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) outlineViewItemDidCollapse: (NSNotification *) notification
|
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
NSInteger value = [[notification userInfo][@"NSObject"] groupIndex];
|
2008-05-11 21:38:40 +00:00
|
|
|
if (value < 0)
|
|
|
|
value = MAX_GROUP;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-11 21:38:40 +00:00
|
|
|
[fCollapsedGroups addIndex: value];
|
2008-02-06 23:45:44 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"OutlineExpandCollapse" object: self];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) mouseDown: (NSEvent *) event
|
|
|
|
{
|
2008-01-15 03:50:00 +00:00
|
|
|
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
|
2008-11-17 03:20:15 +00:00
|
|
|
const NSInteger row = [self rowAtPoint: point];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-28 02:17:17 +00:00
|
|
|
//check to toggle group status before anything else
|
|
|
|
if ([self pointInGroupStatusRect: point])
|
|
|
|
{
|
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"DisplayGroupRowRatio"] forKey: @"DisplayGroupRowRatio"];
|
2008-02-28 16:40:14 +00:00
|
|
|
[self setGroupStatusColumns];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-28 02:17:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
const BOOL pushed = row != -1 && (fMouseActionRow == row || fMouseRevealRow == row || fMouseControlRow == row);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-17 04:20:52 +00:00
|
|
|
//if pushing a button, don't change the selected rows
|
2008-01-22 05:33:02 +00:00
|
|
|
if (pushed)
|
2017-07-29 16:14:22 +00:00
|
|
|
fSelectedValues = [self selectedValues];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-17 04:20:52 +00:00
|
|
|
[super mouseDown: event];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
fSelectedValues = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-17 04:20:52 +00:00
|
|
|
//avoid weird behavior when showing menu by doing this after mouse down
|
2008-12-26 05:57:51 +00:00
|
|
|
if (row != -1 && fMouseActionRow == row)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-07-21 02:35:03 +00:00
|
|
|
#warning maybe make appear on mouse down
|
|
|
|
[self displayTorrentActionPopoverForEvent: event];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-01-22 05:33:02 +00:00
|
|
|
else if (!pushed && [event clickCount] == 2) //double click
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2008-04-08 15:45:01 +00:00
|
|
|
id item = nil;
|
|
|
|
if (row != -1)
|
|
|
|
item = [self itemAtRow: row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-04-08 15:45:01 +00:00
|
|
|
if (!item || [item isKindOfClass: [Torrent class]])
|
2008-02-06 23:45:44 +00:00
|
|
|
[fController showInfo: nil];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([self isItemExpanded: item])
|
|
|
|
[self collapseItem: item];
|
|
|
|
else
|
|
|
|
[self expandItem: item];
|
|
|
|
}
|
|
|
|
}
|
2008-01-21 06:23:10 +00:00
|
|
|
else;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
- (void) selectValues: (NSArray *) values
|
2008-01-20 18:28:28 +00:00
|
|
|
{
|
2008-01-23 18:41:33 +00:00
|
|
|
NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (id item in values)
|
2008-01-20 20:38:51 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
if ([item isKindOfClass: [Torrent class]])
|
|
|
|
{
|
2009-12-23 02:02:11 +00:00
|
|
|
const NSInteger index = [self rowForItem: item];
|
2008-02-06 23:45:44 +00:00
|
|
|
if (index != -1)
|
|
|
|
[indexSet addIndex: index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-23 02:02:11 +00:00
|
|
|
const NSInteger group = [item groupIndex];
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSInteger i = 0; i < [self numberOfRows]; i++)
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
|
|
|
id tableItem = [self itemAtRow: i];
|
2009-12-23 02:02:11 +00:00
|
|
|
if ([tableItem isKindOfClass: [TorrentGroup class]] && group == [tableItem groupIndex])
|
2008-02-07 01:26:12 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
[indexSet addIndex: i];
|
2008-02-07 01:26:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-20 20:38:51 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-20 18:28:28 +00:00
|
|
|
[self selectRowIndexes: indexSet byExtendingSelection: NO];
|
|
|
|
}
|
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
- (NSArray *) selectedValues
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
NSIndexSet * selectedIndexes = [self selectedRowIndexes];
|
|
|
|
NSMutableArray * values = [NSMutableArray arrayWithCapacity: [selectedIndexes count]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSUInteger i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
|
2008-02-06 23:45:44 +00:00
|
|
|
[values addObject: [self itemAtRow: i]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
return values;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2008-01-22 23:48:14 +00:00
|
|
|
- (NSArray *) selectedTorrents
|
|
|
|
{
|
2008-01-23 02:51:58 +00:00
|
|
|
NSIndexSet * selectedIndexes = [self selectedRowIndexes];
|
2008-06-05 02:16:33 +00:00
|
|
|
NSMutableArray * torrents = [NSMutableArray arrayWithCapacity: [selectedIndexes count]]; //take a shot at guessing capacity
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSUInteger i = [selectedIndexes firstIndex]; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex: i])
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
id item = [self itemAtRow: i];
|
|
|
|
if ([item isKindOfClass: [Torrent class]])
|
2008-06-05 02:16:33 +00:00
|
|
|
[torrents addObject: item];
|
|
|
|
else
|
2008-01-23 03:12:06 +00:00
|
|
|
{
|
2008-07-01 01:28:19 +00:00
|
|
|
NSArray * groupTorrents = [item torrents];
|
2008-06-05 02:16:33 +00:00
|
|
|
[torrents addObjectsFromArray: groupTorrents];
|
2009-03-14 17:10:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSMenu *) menuForEvent: (NSEvent *) event
|
|
|
|
{
|
2008-10-29 01:18:03 +00:00
|
|
|
NSInteger row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (row >= 0)
|
|
|
|
{
|
|
|
|
if (![self isRowSelected: row])
|
|
|
|
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
|
|
|
return fContextRow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self deselectAll: self];
|
|
|
|
return fContextNoRow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-16 21:09:59 +00:00
|
|
|
//make sure that the pause buttons become orange when holding down the option key
|
2007-10-27 14:57:46 +00:00
|
|
|
- (void) flagsChanged: (NSEvent *) event
|
|
|
|
{
|
|
|
|
[self display];
|
|
|
|
[super flagsChanged: event];
|
|
|
|
}
|
|
|
|
|
2008-03-16 14:24:27 +00:00
|
|
|
//option-command-f will focus the filter bar's search field
|
|
|
|
- (void) keyDown: (NSEvent *) event
|
|
|
|
{
|
2008-11-04 00:34:13 +00:00
|
|
|
const unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-17 17:17:15 +00:00
|
|
|
if (firstChar == 'f' && [event modifierFlags] & NSAlternateKeyMask && [event modifierFlags] & NSCommandKeyMask)
|
2008-03-16 14:24:27 +00:00
|
|
|
[fController focusFilterField];
|
2009-09-04 04:10:46 +00:00
|
|
|
else if (firstChar == ' ')
|
2009-09-11 03:15:04 +00:00
|
|
|
[fController toggleQuickLook: nil];
|
2011-08-04 02:04:25 +00:00
|
|
|
else if ([event keyCode] == 53) //esc key
|
|
|
|
[self deselectAll: nil];
|
2008-03-16 14:24:27 +00:00
|
|
|
else
|
|
|
|
[super keyDown: event];
|
|
|
|
}
|
|
|
|
|
2008-10-29 01:18:03 +00:00
|
|
|
- (NSRect) iconRectForRow: (NSInteger) row
|
2008-05-21 22:09:05 +00:00
|
|
|
{
|
|
|
|
return [fTorrentCell iconRectForBounds: [self rectOfRow: row]];
|
|
|
|
}
|
|
|
|
|
2008-05-01 02:20:53 +00:00
|
|
|
- (void) paste: (id) sender
|
|
|
|
{
|
|
|
|
NSURL * url;
|
|
|
|
if ((url = [NSURL URLFromPasteboard: [NSPasteboard generalPasteboard]]))
|
2009-12-05 15:48:26 +00:00
|
|
|
[fController openURL: [url absoluteString]];
|
2016-01-06 11:05:37 +00:00
|
|
|
else
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2017-07-08 08:23:05 +00:00
|
|
|
NSArray * items = [[NSPasteboard generalPasteboard] readObjectsForClasses: @[[NSString class]] options: nil];
|
2011-12-26 02:33:13 +00:00
|
|
|
if (items)
|
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
NSDataDetector * detector = [NSDataDetector dataDetectorWithTypes: NSTextCheckingTypeLink error: nil];
|
2017-07-29 16:14:22 +00:00
|
|
|
for (__strong NSString * pbItem in items)
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2015-10-23 18:53:47 +00:00
|
|
|
pbItem = [pbItem stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
2011-12-27 23:19:14 +00:00
|
|
|
if ([pbItem rangeOfString: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
|
|
|
|
[fController openURL: pbItem];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#warning only accept full text?
|
|
|
|
for (NSTextCheckingResult * result in [detector matchesInString: pbItem options: 0 range: NSMakeRange(0, [pbItem length])])
|
|
|
|
[fController openURL: [[result URL] absoluteString]];
|
|
|
|
}
|
2011-12-26 02:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-01 02:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
if ([[[NSPasteboard generalPasteboard] types] containsObject: NSURLPboardType])
|
|
|
|
return YES;
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2017-07-08 08:23:05 +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
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
NSDataDetector * detector = [NSDataDetector dataDetectorWithTypes: NSTextCheckingTypeLink error: nil];
|
2017-07-29 16:14:22 +00:00
|
|
|
for (__strong NSString * pbItem in items)
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2016-01-06 11:05:37 +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])])
|
|
|
|
return YES;
|
2011-12-26 02:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +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;
|
|
|
|
}
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
- (void) toggleControlForTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
if ([torrent isActive])
|
2017-07-08 08:23:05 +00:00
|
|
|
[fController stopTorrents: @[torrent]];
|
2008-01-14 18:02:08 +00:00
|
|
|
else
|
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
if ([NSEvent modifierFlags] & NSAlternateKeyMask)
|
2017-07-08 08:23:05 +00:00
|
|
|
[fController resumeTorrentsNoWait: @[torrent]];
|
2008-01-14 18:02:08 +00:00
|
|
|
else if ([torrent waitingToStart])
|
2017-07-08 08:23:05 +00:00
|
|
|
[fController stopTorrents: @[torrent]];
|
2008-01-14 18:02:08 +00:00
|
|
|
else
|
2017-07-08 08:23:05 +00:00
|
|
|
[fController resumeTorrents: @[torrent]];
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 02:35:03 +00:00
|
|
|
- (void) displayTorrentActionPopoverForEvent: (NSEvent *) event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-04-20 03:36:35 +00:00
|
|
|
const NSInteger row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (row < 0)
|
|
|
|
return;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:35:03 +00:00
|
|
|
const NSRect rect = [fTorrentCell iconRectForBounds: [self rectOfRow: row]];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
if (fActionPopoverShown)
|
|
|
|
return;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +00:00
|
|
|
Torrent * torrent = [self itemAtRow: row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +00:00
|
|
|
NSPopover * popover = [[NSPopover alloc] init];
|
|
|
|
[popover setBehavior: NSPopoverBehaviorTransient];
|
|
|
|
InfoOptionsViewController * infoViewController = [[InfoOptionsViewController alloc] init];
|
|
|
|
[popover setContentViewController: infoViewController];
|
|
|
|
[popover setDelegate: self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +00:00
|
|
|
[popover showRelativeToRect: rect ofView: self preferredEdge: NSMaxYEdge];
|
2017-07-08 08:23:05 +00:00
|
|
|
[infoViewController setInfoForTorrents: @[torrent]];
|
2016-01-06 11:05:37 +00:00
|
|
|
[infoViewController updateInfo];
|
2017-01-24 17:53:16 +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
|
|
|
|
- (void) popoverWillShow: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
fActionPopoverShown = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) popoverWillClose: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
fActionPopoverShown = NO;
|
|
|
|
}
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
//eliminate when Lion-only, along with all the menu item instance variables
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) menuNeedsUpdate: (NSMenu *) menu
|
|
|
|
{
|
|
|
|
//this method seems to be called when it shouldn't be
|
|
|
|
if (!fMenuTorrent || ![menu supermenu])
|
|
|
|
return;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (menu == fUploadMenu || menu == fDownloadMenu)
|
|
|
|
{
|
2008-01-10 06:52:13 +00:00
|
|
|
NSMenuItem * item;
|
2009-03-05 01:33:51 +00:00
|
|
|
if ([menu numberOfItems] == 3)
|
2008-01-10 06:52:13 +00:00
|
|
|
{
|
2009-09-17 11:53:56 +00:00
|
|
|
const NSInteger speedLimitActionValue[] = { 0, 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500,
|
|
|
|
750, 1000, 1500, 2000, -1 };
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSInteger i = 0; speedLimitActionValue[i] != -1; i++)
|
2008-01-10 06:52:13 +00:00
|
|
|
{
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: NSLocalizedString(@"%d KB/s",
|
|
|
|
"Action menu -> upload/download limit"), speedLimitActionValue[i]] action: @selector(setQuickLimit:)
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
2017-07-07 10:34:27 +00:00
|
|
|
[item setRepresentedObject: @(speedLimitActionValue[i])];
|
2008-01-10 06:52:13 +00:00
|
|
|
[menu addItem: item];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-03-05 01:33:51 +00:00
|
|
|
const BOOL upload = menu == fUploadMenu;
|
|
|
|
const BOOL limit = [fMenuTorrent usesSpeedLimit: upload];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-10 06:52:13 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
|
2009-03-05 01:10:09 +00:00
|
|
|
[item setState: limit ? NSOnState : NSOffState];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
|
2008-02-06 23:45:44 +00:00
|
|
|
"torrent action menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
|
2009-03-05 01:33:51 +00:00
|
|
|
[item setState: !limit ? NSOnState : NSOffState];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else if (menu == fRatioMenu)
|
|
|
|
{
|
2008-01-10 06:52:13 +00:00
|
|
|
NSMenuItem * item;
|
|
|
|
if ([menu numberOfItems] == 4)
|
|
|
|
{
|
2010-11-14 15:16:39 +00:00
|
|
|
const float ratioLimitActionValue[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1.0 };
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-02-15 14:56:14 +00:00
|
|
|
for (NSInteger i = 0; ratioLimitActionValue[i] != -1.0; i++)
|
2008-01-10 06:52:13 +00:00
|
|
|
{
|
2008-03-24 00:06:54 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle: [NSString localizedStringWithFormat: @"%.2f", ratioLimitActionValue[i]]
|
2008-01-10 15:53:02 +00:00
|
|
|
action: @selector(setQuickRatio:) keyEquivalent: @""];
|
2008-01-10 06:52:13 +00:00
|
|
|
[item setTarget: self];
|
2017-07-07 10:34:27 +00:00
|
|
|
[item setRepresentedObject: @(ratioLimitActionValue[i])];
|
2008-01-10 06:52:13 +00:00
|
|
|
[menu addItem: item];
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-03-05 04:59:24 +00:00
|
|
|
const tr_ratiolimit mode = [fMenuTorrent ratioSetting];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-10 06:52:13 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
|
2009-02-24 00:34:46 +00:00
|
|
|
[item setState: mode == TR_RATIOLIMIT_SINGLE ? NSOnState : NSOffState];
|
2008-03-24 00:06:54 +00:00
|
|
|
[item setTitle: [NSString localizedStringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
|
|
|
|
"torrent action menu -> ratio stop"), [fMenuTorrent ratioLimit]]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
|
2009-02-24 00:34:46 +00:00
|
|
|
[item setState: mode == TR_RATIOLIMIT_UNLIMITED ? NSOnState : NSOffState];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
|
2009-02-24 00:34:46 +00:00
|
|
|
[item setState: mode == TR_RATIOLIMIT_GLOBAL ? NSOnState : NSOffState];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2009-04-20 03:36:35 +00:00
|
|
|
else if (menu == fPriorityMenu)
|
|
|
|
{
|
|
|
|
const tr_priority_t priority = [fMenuTorrent priority];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
NSMenuItem * item = [menu itemWithTag: ACTION_MENU_PRIORITY_HIGH_TAG];
|
|
|
|
[item setState: priority == TR_PRI_HIGH ? NSOnState : NSOffState];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_PRIORITY_NORMAL_TAG];
|
|
|
|
[item setState: priority == TR_PRI_NORMAL ? NSOnState : NSOffState];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
item = [menu itemWithTag: ACTION_MENU_PRIORITY_LOW_TAG];
|
|
|
|
[item setState: priority == TR_PRI_LOW ? NSOnState : NSOffState];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
//the following methods might not be needed when Lion-only
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) setQuickLimitMode: (id) sender
|
|
|
|
{
|
2009-03-05 01:10:09 +00:00
|
|
|
const BOOL limit = [sender tag] == ACTION_MENU_LIMIT_TAG;
|
|
|
|
[fMenuTorrent setUseSpeedLimit: limit upload: [sender menu] == fUploadMenu];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQuickLimit: (id) sender
|
|
|
|
{
|
2009-02-17 04:00:53 +00:00
|
|
|
const BOOL upload = [sender menu] == fUploadMenu;
|
2009-03-05 01:10:09 +00:00
|
|
|
[fMenuTorrent setUseSpeedLimit: YES upload: upload];
|
2008-01-10 06:52:13 +00:00
|
|
|
[fMenuTorrent setSpeedLimit: [[sender representedObject] intValue] upload: upload];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-03-05 22:48:01 +00:00
|
|
|
- (void) setGlobalLimit: (id) sender
|
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
[fMenuTorrent setUseGlobalSpeedLimit: [(NSButton *)sender state] != NSOnState];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-03-05 22:48:01 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) setQuickRatioMode: (id) sender
|
|
|
|
{
|
2009-02-24 00:34:46 +00:00
|
|
|
tr_ratiolimit mode;
|
2007-10-11 12:06:46 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case ACTION_MENU_UNLIMITED_TAG:
|
2009-02-24 00:34:46 +00:00
|
|
|
mode = TR_RATIOLIMIT_UNLIMITED;
|
2007-10-11 12:06:46 +00:00
|
|
|
break;
|
|
|
|
case ACTION_MENU_LIMIT_TAG:
|
2009-02-24 00:34:46 +00:00
|
|
|
mode = TR_RATIOLIMIT_SINGLE;
|
2007-10-11 12:06:46 +00:00
|
|
|
break;
|
|
|
|
case ACTION_MENU_GLOBAL_TAG:
|
2009-02-24 00:34:46 +00:00
|
|
|
mode = TR_RATIOLIMIT_GLOBAL;
|
2007-10-11 12:06:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fMenuTorrent setRatioSetting: mode];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQuickRatio: (id) sender
|
|
|
|
{
|
2009-02-24 00:34:46 +00:00
|
|
|
[fMenuTorrent setRatioSetting: TR_RATIOLIMIT_SINGLE];
|
2008-01-10 06:52:13 +00:00
|
|
|
[fMenuTorrent setRatioLimit: [[sender representedObject] floatValue]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
- (void) setPriority: (id) sender
|
|
|
|
{
|
|
|
|
tr_priority_t priority;
|
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case ACTION_MENU_PRIORITY_HIGH_TAG:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_PRIORITY_NORMAL_TAG:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_PRIORITY_LOW_TAG:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-13 00:52:04 +00:00
|
|
|
NSAssert1(NO, @"Unknown priority: %ld", [sender tag]);
|
2016-09-11 10:22:49 +00:00
|
|
|
priority = TR_PRI_NORMAL;
|
2009-04-20 03:36:35 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
[fMenuTorrent setPriority: priority];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
|
|
|
|
}
|
|
|
|
|
2008-01-16 19:30:12 +00:00
|
|
|
- (void) togglePiecesBar
|
2008-01-16 15:56:40 +00:00
|
|
|
{
|
2008-06-10 18:08:57 +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)
|
2017-07-07 10:34:27 +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
|
2008-06-18 16:25:30 +00:00
|
|
|
fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration: TOGGLE_PROGRESS_SECONDS animationCurve: NSAnimationEaseIn];
|
2008-06-10 05:09:30 +00:00
|
|
|
[fPiecesBarAnimation setAnimationBlockingMode: NSAnimationNonblocking];
|
|
|
|
[fPiecesBarAnimation setProgressMarks: progressMarks];
|
|
|
|
[fPiecesBarAnimation setDelegate: self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-10 05:09:30 +00:00
|
|
|
[fPiecesBarAnimation startAnimation];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) animationDidEnd: (NSAnimation *) animation
|
|
|
|
{
|
|
|
|
if (animation == fPiecesBarAnimation)
|
|
|
|
{
|
|
|
|
fPiecesBarAnimation = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) animation: (NSAnimation *) animation didReachProgressMark: (NSAnimationProgress) progress
|
|
|
|
{
|
|
|
|
if (animation == fPiecesBarAnimation)
|
2008-01-16 16:39:18 +00:00
|
|
|
{
|
2008-06-10 05:09:30 +00:00
|
|
|
if ([fDefaults boolForKey: @"PiecesBar"])
|
|
|
|
fPiecesBarPercent = progress;
|
|
|
|
else
|
2010-02-15 14:56:14 +00:00
|
|
|
fPiecesBarPercent = 1.0 - progress;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-18 04:03:12 +00:00
|
|
|
[self setNeedsDisplay: YES];
|
2008-01-16 16:39:18 +00:00
|
|
|
}
|
2008-01-16 15:56:40 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 01:18:03 +00:00
|
|
|
- (CGFloat) piecesBarPercent
|
2008-01-16 19:30:12 +00:00
|
|
|
{
|
|
|
|
return fPiecesBarPercent;
|
|
|
|
}
|
|
|
|
|
2016-03-03 17:57:08 +00:00
|
|
|
- (void) selectAndScrollToRow: (NSInteger) row
|
|
|
|
{
|
|
|
|
NSParameterAssert(row >= 0);
|
|
|
|
NSParameterAssert(row < [self numberOfRows]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-03-03 17:57:08 +00:00
|
|
|
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-03-03 17:57:08 +00:00
|
|
|
const NSRect rowRect = [self rectOfRow: row];
|
|
|
|
const NSRect viewRect = [[self superview] frame];
|
|
|
|
|
|
|
|
NSPoint scrollOrigin = rowRect.origin;
|
|
|
|
scrollOrigin.y += (rowRect.size.height - viewRect.size.height) / 2;
|
|
|
|
if (scrollOrigin.y < 0)
|
|
|
|
scrollOrigin.y = 0;
|
|
|
|
|
|
|
|
[[[self superview] animator] setBoundsOrigin: scrollOrigin];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentTableView (Private)
|
|
|
|
|
2008-02-28 02:17:17 +00:00
|
|
|
- (BOOL) pointInGroupStatusRect: (NSPoint) point
|
|
|
|
{
|
2008-10-29 01:18:03 +00:00
|
|
|
NSInteger row = [self rowAtPoint: point];
|
2008-02-28 02:17:17 +00:00
|
|
|
if (row < 0 || [[self itemAtRow: row] isKindOfClass: [Torrent class]])
|
|
|
|
return NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-08 09:16:01 +00:00
|
|
|
NSString * ident = [[self tableColumns][[self columnAtPoint: point]] identifier];
|
2008-02-28 02:17:17 +00:00
|
|
|
return [ident isEqualToString: @"UL"] || [ident isEqualToString: @"UL Image"]
|
2008-02-28 16:55:28 +00:00
|
|
|
|| [ident isEqualToString: @"DL"] || [ident isEqualToString: @"DL Image"];
|
2008-02-28 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 16:40:14 +00:00
|
|
|
- (void) setGroupStatusColumns
|
|
|
|
{
|
2009-09-18 02:18:22 +00:00
|
|
|
const BOOL ratio = [fDefaults boolForKey: @"DisplayGroupRowRatio"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-03-18 03:20:27 +00:00
|
|
|
[[self tableColumnWithIdentifier: @"DL"] setHidden: ratio];
|
2008-02-28 16:40:14 +00:00
|
|
|
[[self tableColumnWithIdentifier: @"DL Image"] setHidden: ratio];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|