2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2006-2022 Transmission authors and contributors.
|
|
|
|
// 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
|
|
|
|
|
|
|
#import "TorrentCell.h"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2011-10-22 20:45:20 +00:00
|
|
|
#import "NSImageAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2008-10-31 00:13:50 +00:00
|
|
|
#import "ProgressGradients.h"
|
2009-10-11 03:36:50 +00:00
|
|
|
#import "Torrent.h"
|
|
|
|
#import "TorrentTableView.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-12-20 21:02:58 +00:00
|
|
|
#define BAR_HEIGHT 12.0
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-12-20 21:02:58 +00:00
|
|
|
#define IMAGE_SIZE_REG 32.0
|
|
|
|
#define IMAGE_SIZE_MIN 16.0
|
|
|
|
#define ERROR_IMAGE_SIZE 20.0
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-06-13 01:56:12 +00:00
|
|
|
#define GROUP_IMAGE_SIZE_REG 10.0
|
|
|
|
#define GROUP_IMAGE_SIZE_MIN 6.0
|
2022-06-08 20:13:29 +00:00
|
|
|
#define GROUP_PADDING_REG 22.0
|
2022-06-13 01:56:12 +00:00
|
|
|
#define GROUP_PADDING_MIN 14.0
|
2022-06-08 20:13:29 +00:00
|
|
|
|
2009-12-20 21:02:58 +00:00
|
|
|
#define NORMAL_BUTTON_WIDTH 14.0
|
|
|
|
#define ACTION_BUTTON_WIDTH 16.0
|
2008-01-14 18:02:08 +00:00
|
|
|
|
2011-10-22 20:45:20 +00:00
|
|
|
#define PRIORITY_ICON_WIDTH 12.0
|
|
|
|
#define PRIORITY_ICON_HEIGHT 12.0
|
2009-04-20 02:45:27 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
//ends up being larger than font height
|
2009-12-20 21:02:58 +00:00
|
|
|
#define HEIGHT_TITLE 16.0
|
|
|
|
#define HEIGHT_STATUS 12.0
|
|
|
|
|
2011-09-06 23:31:23 +00:00
|
|
|
#define PADDING_HORIZONTAL 5.0
|
2011-09-07 01:24:43 +00:00
|
|
|
#define PADDING_BETWEEN_BUTTONS 3.0
|
2011-09-06 23:31:23 +00:00
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_TITLE (PADDING_HORIZONTAL + 1.0)
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_BAR PADDING_HORIZONTAL
|
2011-10-23 17:45:05 +00:00
|
|
|
#define PADDING_BETWEEN_TITLE_AND_PRIORITY 6.0
|
2009-12-20 21:02:58 +00:00
|
|
|
#define PADDING_ABOVE_TITLE 4.0
|
2010-03-21 14:59:46 +00:00
|
|
|
#define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 3.0
|
2009-12-20 21:02:58 +00:00
|
|
|
#define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0
|
|
|
|
#define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0
|
|
|
|
#define PADDING_BETWEEN_BAR_AND_STATUS 2.0
|
2010-03-21 15:16:11 +00:00
|
|
|
#define PADDING_BETWEEN_BAR_AND_EDGE_MIN 3.0
|
2011-10-23 17:45:05 +00:00
|
|
|
#define PADDING_EXPANSION_FRAME 2.0
|
2009-12-20 21:02:58 +00:00
|
|
|
|
|
|
|
#define PIECES_TOTAL_PERCENT 0.6
|
2008-06-09 21:20:01 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define MAX_PIECES (18 * 18)
|
2007-11-04 15:01:34 +00:00
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface TorrentCell ()
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)drawBar:(NSRect)barRect;
|
|
|
|
- (void)drawRegularBar:(NSRect)barRect;
|
|
|
|
- (void)drawPiecesBar:(NSRect)barRect;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)rectForMinimalStatusWithString:(NSAttributedString*)string inBounds:(NSRect)bounds;
|
2022-05-14 07:53:30 +00:00
|
|
|
- (NSRect)rectForTitleWithString:(NSAttributedString*)string
|
|
|
|
withRightBound:(CGFloat)rightBound
|
|
|
|
inBounds:(NSRect)bounds
|
|
|
|
minimal:(BOOL)minimal;
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)rectForProgressWithStringInBounds:(NSRect)bounds;
|
|
|
|
- (NSRect)rectForStatusWithStringInBounds:(NSRect)bounds;
|
|
|
|
- (NSRect)barRectRegForBounds:(NSRect)bounds;
|
|
|
|
- (NSRect)barRectMinForBounds:(NSRect)bounds;
|
2009-12-12 03:11:48 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)controlButtonRectForBounds:(NSRect)bounds;
|
|
|
|
- (NSRect)revealButtonRectForBounds:(NSRect)bounds;
|
|
|
|
- (NSRect)actionButtonRectForBounds:(NSRect)bounds;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@property(nonatomic, readonly) NSUserDefaults* fDefaults;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSMutableDictionary* fTitleAttributes;
|
|
|
|
@property(nonatomic, readonly) NSMutableDictionary* fStatusAttributes;
|
|
|
|
|
|
|
|
@property(nonatomic) BOOL fTracking;
|
|
|
|
@property(nonatomic) BOOL fMouseDownControlButton;
|
|
|
|
@property(nonatomic) BOOL fMouseDownRevealButton;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSColor* fBarBorderColor;
|
|
|
|
@property(nonatomic, readonly) NSColor* fBluePieceColor;
|
|
|
|
@property(nonatomic, readonly) NSColor* fBarMinimalBorderColor;
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
@property(nonatomic, readonly) NSAttributedString* attributedTitle;
|
|
|
|
- (NSAttributedString*)attributedStatusString:(NSString*)string;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
@property(nonatomic, readonly) NSString* buttonString;
|
|
|
|
@property(nonatomic, readonly) NSString* statusString;
|
|
|
|
@property(nonatomic, readonly) NSString* minimalStatusString;
|
2008-01-15 21:09:51 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentCell
|
|
|
|
|
2008-01-07 00:31:56 +00:00
|
|
|
//only called once and the main table is always needed, so don't worry about releasing
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)init
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
2017-01-24 17:53:16 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fDefaults = NSUserDefaults.standardUserDefaults;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableParagraphStyle* paragraphStyle = [NSParagraphStyle.defaultParagraphStyle mutableCopy];
|
2021-08-07 07:27:56 +00:00
|
|
|
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fTitleAttributes = [[NSMutableDictionary alloc] initWithCapacity:3];
|
|
|
|
_fTitleAttributes[NSFontAttributeName] = [NSFont messageFontOfSize:12.0];
|
|
|
|
_fTitleAttributes[NSParagraphStyleAttributeName] = paragraphStyle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fStatusAttributes = [[NSMutableDictionary alloc] initWithCapacity:3];
|
|
|
|
_fStatusAttributes[NSFontAttributeName] = [NSFont messageFontOfSize:9.0];
|
|
|
|
_fStatusAttributes[NSParagraphStyleAttributeName] = paragraphStyle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fBluePieceColor = [NSColor colorWithCalibratedRed:0.0 green:0.4 blue:0.8 alpha:1.0];
|
|
|
|
_fBarBorderColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.2];
|
|
|
|
_fBarMinimalBorderColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.015];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
return self;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)copyWithZone:(NSZone*)zone
|
2011-05-19 22:01:16 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
id value = [super copyWithZone:zone];
|
|
|
|
[value setRepresentedObject:self.representedObject];
|
2011-05-19 22:01:16 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)iconRectForBounds:(NSRect)bounds
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-06-13 01:56:12 +00:00
|
|
|
BOOL const minimal = [self.fDefaults boolForKey:@"SmallView"];
|
|
|
|
CGFloat const imageSize = minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
|
|
|
|
CGFloat const padding = minimal ? GROUP_PADDING_MIN : GROUP_PADDING_REG;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-13 01:56:12 +00:00
|
|
|
return NSMakeRect(NSMinX(bounds) + (padding * 0.5) + PADDING_HORIZONTAL, ceil(NSMidY(bounds) - imageSize * 0.5), imageSize, imageSize);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 20:13:29 +00:00
|
|
|
- (NSRect)actionRectForBounds:(NSRect)bounds
|
|
|
|
{
|
|
|
|
NSRect iconRect = [self iconRectForBounds:bounds];
|
2022-06-13 01:56:12 +00:00
|
|
|
NSRect actionRect = [self actionButtonRectForBounds:iconRect];
|
2022-06-08 20:13:29 +00:00
|
|
|
|
2022-06-13 01:56:12 +00:00
|
|
|
return actionRect;
|
2022-06-08 20:13:29 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSCellHitResult)hitTestForEvent:(NSEvent*)event inRect:(NSRect)cellFrame ofView:(NSView*)controlView
|
2007-10-31 17:23:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPoint point = [controlView convertPoint:event.locationInWindow fromView:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (NSMouseInRect(point, [self controlButtonRectForBounds:cellFrame], controlView.flipped) ||
|
|
|
|
NSMouseInRect(point, [self revealButtonRectForBounds:cellFrame], controlView.flipped))
|
|
|
|
{
|
2008-01-14 18:02:08 +00:00
|
|
|
return NSCellHitContentArea | NSCellHitTrackableArea;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-31 17:23:56 +00:00
|
|
|
return NSCellHitContentArea;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (BOOL)prefersTrackingUntilMouseUp
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)trackMouse:(NSEvent*)event inRect:(NSRect)cellFrame ofView:(NSView*)controlView untilMouseUp:(BOOL)flag
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTracking = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.controlView = controlView;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPoint point = [controlView convertPoint:event.locationInWindow fromView:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const controlRect = [self controlButtonRectForBounds:cellFrame];
|
|
|
|
BOOL const checkControl = NSMouseInRect(point, controlRect, controlView.flipped);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const revealRect = [self revealButtonRectForBounds:cellFrame];
|
|
|
|
BOOL const checkReveal = NSMouseInRect(point, revealRect, controlView.flipped);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[(TorrentTableView*)controlView removeTrackingAreas];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
while (event.type != NSEventTypeLeftMouseUp)
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
point = [controlView convertPoint:event.locationInWindow fromView:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
if (checkControl)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const inControlButton = NSMouseInRect(point, controlRect, controlView.flipped);
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fMouseDownControlButton != inControlButton)
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fMouseDownControlButton = inControlButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
[controlView setNeedsDisplayInRect:cellFrame];
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (checkReveal)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const inRevealButton = NSMouseInRect(point, revealRect, controlView.flipped);
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fMouseDownRevealButton != inRevealButton)
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fMouseDownRevealButton = inRevealButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
[controlView setNeedsDisplayInRect:cellFrame];
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
//send events to where necessary
|
2021-10-31 15:18:27 +00:00
|
|
|
if (event.type == NSEventTypeMouseEntered || event.type == NSEventTypeMouseExited)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
}
|
2022-03-30 21:52:23 +00:00
|
|
|
event = [controlView.window nextEventMatchingMask:(NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged |
|
|
|
|
NSEventMaskMouseEntered | NSEventMaskMouseExited)];
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTracking = NO;
|
2008-01-14 18:02:08 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fMouseDownControlButton)
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fMouseDownControlButton = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[(TorrentTableView*)controlView toggleControlForTorrent:self.representedObject];
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (self.fMouseDownRevealButton)
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fMouseDownRevealButton = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
[controlView setNeedsDisplayInRect:cellFrame];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = ((Torrent*)self.representedObject).dataLocation;
|
2011-10-06 00:30:40 +00:00
|
|
|
if (location)
|
2009-08-30 17:52:03 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSURL* file = [NSURL fileURLWithPath:location];
|
|
|
|
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[ file ]];
|
2009-10-21 13:01:14 +00:00
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[controlView updateTrackingAreas];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)addTrackingAreasForView:(NSView*)controlView
|
|
|
|
inRect:(NSRect)cellFrame
|
|
|
|
withUserInfo:(NSDictionary*)userInfo
|
|
|
|
mouseLocation:(NSPoint)mouseLocation
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSTrackingAreaOptions const options = NSTrackingEnabledDuringMouseDrag | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
//whole row
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"SmallView"])
|
2010-03-20 03:27:17 +00:00
|
|
|
{
|
2010-03-20 18:27:09 +00:00
|
|
|
NSTrackingAreaOptions rowOptions = options;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (NSMouseInRect(mouseLocation, cellFrame, controlView.flipped))
|
2010-03-20 18:27:09 +00:00
|
|
|
{
|
|
|
|
rowOptions |= NSTrackingAssumeInside;
|
2022-02-22 16:04:20 +00:00
|
|
|
((TorrentTableView*)controlView).hoverRow = [userInfo[@"Row"] integerValue];
|
2010-03-20 18:27:09 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* rowInfo = [userInfo mutableCopy];
|
2017-07-08 14:38:47 +00:00
|
|
|
rowInfo[@"Type"] = @"Row";
|
2021-08-15 09:41:48 +00:00
|
|
|
NSTrackingArea* area = [[NSTrackingArea alloc] initWithRect:cellFrame options:rowOptions owner:controlView userInfo:rowInfo];
|
|
|
|
[controlView addTrackingArea:area];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-04-02 18:14:46 +00:00
|
|
|
//control button
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect controlButtonRect = [self controlButtonRectForBounds:cellFrame];
|
2010-04-02 18:14:46 +00:00
|
|
|
NSTrackingAreaOptions controlOptions = options;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (NSMouseInRect(mouseLocation, controlButtonRect, controlView.flipped))
|
2010-04-02 18:14:46 +00:00
|
|
|
{
|
|
|
|
controlOptions |= NSTrackingAssumeInside;
|
2022-02-22 16:04:20 +00:00
|
|
|
((TorrentTableView*)controlView).controlButtonHoverRow = [userInfo[@"Row"] integerValue];
|
2010-04-02 18:14:46 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* controlInfo = [userInfo mutableCopy];
|
2017-07-08 14:38:47 +00:00
|
|
|
controlInfo[@"Type"] = @"Control";
|
2021-08-15 09:41:48 +00:00
|
|
|
NSTrackingArea* area = [[NSTrackingArea alloc] initWithRect:controlButtonRect options:controlOptions owner:controlView
|
|
|
|
userInfo:controlInfo];
|
|
|
|
[controlView addTrackingArea:area];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
//reveal button
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect revealButtonRect = [self revealButtonRectForBounds:cellFrame];
|
2008-01-15 03:33:44 +00:00
|
|
|
NSTrackingAreaOptions revealOptions = options;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (NSMouseInRect(mouseLocation, revealButtonRect, controlView.flipped))
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
|
|
|
revealOptions |= NSTrackingAssumeInside;
|
2022-02-22 16:04:20 +00:00
|
|
|
((TorrentTableView*)controlView).revealButtonHoverRow = [userInfo[@"Row"] integerValue];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* revealInfo = [userInfo mutableCopy];
|
2017-07-08 14:38:47 +00:00
|
|
|
revealInfo[@"Type"] = @"Reveal";
|
2021-08-15 09:41:48 +00:00
|
|
|
area = [[NSTrackingArea alloc] initWithRect:revealButtonRect options:revealOptions owner:controlView userInfo:revealInfo];
|
|
|
|
[controlView addTrackingArea:area];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-16 06:48:12 +00:00
|
|
|
//action button
|
2022-06-08 20:13:29 +00:00
|
|
|
NSRect actionButtonRect = [self actionRectForBounds:cellFrame];
|
2008-01-15 23:48:03 +00:00
|
|
|
NSTrackingAreaOptions actionOptions = options;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (NSMouseInRect(mouseLocation, actionButtonRect, controlView.flipped))
|
2008-01-15 23:48:03 +00:00
|
|
|
{
|
|
|
|
actionOptions |= NSTrackingAssumeInside;
|
2022-02-22 16:04:20 +00:00
|
|
|
((TorrentTableView*)controlView).actionButtonHoverRow = [userInfo[@"Row"] integerValue];
|
2008-01-15 23:48:03 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* actionInfo = [userInfo mutableCopy];
|
2017-07-08 14:38:47 +00:00
|
|
|
actionInfo[@"Type"] = @"Action";
|
2021-08-15 09:41:48 +00:00
|
|
|
area = [[NSTrackingArea alloc] initWithRect:actionButtonRect options:actionOptions owner:controlView userInfo:actionInfo];
|
|
|
|
[controlView addTrackingArea:area];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = self.representedObject;
|
2011-05-19 22:01:16 +00:00
|
|
|
NSAssert(torrent != nil, @"can't have a TorrentCell without a Torrent");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const minimal = [self.fDefaults boolForKey:@"SmallView"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 05:09:34 +00:00
|
|
|
//bar
|
2021-08-15 09:41:48 +00:00
|
|
|
[self drawBar:minimal ? [self barRectMinForBounds:cellFrame] : [self barRectRegForBounds:cellFrame]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-18 17:05:49 +00:00
|
|
|
//group coloring
|
2022-06-08 20:13:29 +00:00
|
|
|
NSRect const parentRect = [self iconRectForBounds:cellFrame];
|
|
|
|
NSRect iconRect = NSMakeRect(parentRect.origin.x, parentRect.origin.y, parentRect.size.width, parentRect.size.height);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const groupValue = torrent.groupValue;
|
2007-12-18 01:44:37 +00:00
|
|
|
if (groupValue != -1)
|
2007-12-18 21:32:55 +00:00
|
|
|
{
|
2022-06-13 01:56:12 +00:00
|
|
|
NSRect groupRect = [self groupIconRectForBounds:iconRect];
|
|
|
|
NSColor* groupColor = [GroupsController.groups colorForIndex:groupValue];
|
|
|
|
NSImage* icon = [NSImage discIconWithColor:groupColor insetFactor:0];
|
2022-06-18 14:26:45 +00:00
|
|
|
[icon drawInRect:groupRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0f];
|
2007-12-18 21:32:55 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const error = torrent.anyErrorOrWarning;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//icon
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!minimal || !(!self.fTracking && self.hoverAction)) //don't show in minimal mode when hovered over
|
2008-01-16 06:26:52 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* icon = (minimal && error) ? [NSImage imageNamed:NSImageNameCaution] : torrent.icon;
|
2022-03-30 21:52:23 +00:00
|
|
|
[icon drawInRect:iconRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0 respectFlipped:YES
|
|
|
|
hints:nil];
|
2008-01-16 06:26:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-03 14:10:52 +00:00
|
|
|
//error badge
|
2007-09-16 01:02:06 +00:00
|
|
|
if (error && !minimal)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* errorImage = [NSImage imageNamed:NSImageNameCaution];
|
|
|
|
NSRect const errorRect = NSMakeRect(NSMaxX(iconRect) - ERROR_IMAGE_SIZE, NSMaxY(iconRect) - ERROR_IMAGE_SIZE, ERROR_IMAGE_SIZE, ERROR_IMAGE_SIZE);
|
2022-03-30 21:52:23 +00:00
|
|
|
[errorImage drawInRect:errorRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0
|
|
|
|
respectFlipped:YES
|
2021-08-15 09:41:48 +00:00
|
|
|
hints:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//text color
|
2021-08-15 09:41:48 +00:00
|
|
|
NSColor *titleColor, *statusColor;
|
2021-10-31 15:18:27 +00:00
|
|
|
if (self.backgroundStyle == NSBackgroundStyleEmphasized)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
titleColor = statusColor = NSColor.whiteColor;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-12-18 01:44:37 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
titleColor = NSColor.labelColor;
|
|
|
|
statusColor = NSColor.secondaryLabelColor;
|
2007-12-18 01:44:37 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTitleAttributes[NSForegroundColorAttributeName] = titleColor;
|
|
|
|
self.fStatusAttributes[NSForegroundColorAttributeName] = statusColor;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 07:53:30 +00:00
|
|
|
CGFloat titleRightBound;
|
2007-09-16 01:02:06 +00:00
|
|
|
//minimal status
|
2010-03-20 22:24:54 +00:00
|
|
|
if (minimal)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* minimalString = [self attributedStatusString:self.minimalStatusString];
|
|
|
|
NSRect minimalStatusRect = [self rectForMinimalStatusWithString:minimalString inBounds:cellFrame];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.hover)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[minimalString drawInRect:minimalStatusRect];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 07:53:30 +00:00
|
|
|
titleRightBound = NSMinX(minimalStatusRect);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
//progress
|
2022-05-14 07:53:30 +00:00
|
|
|
else
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* progressString = [self attributedStatusString:torrent.progressString];
|
|
|
|
NSRect progressRect = [self rectForProgressWithStringInBounds:cellFrame];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[progressString drawInRect:progressRect];
|
2022-05-14 07:53:30 +00:00
|
|
|
titleRightBound = NSMaxX(cellFrame);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!minimal || self.hover)
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2010-03-20 03:27:17 +00:00
|
|
|
//control button
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* controlImageSuffix;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fMouseDownControlButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
controlImageSuffix = @"On";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (!self.fTracking && self.hoverControl)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
controlImageSuffix = @"Hover";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
controlImageSuffix = @"Off";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* controlImage;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"Pause" stringByAppendingString:controlImageSuffix]];
|
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
else
|
2010-03-20 03:27:17 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
if (NSApp.currentEvent.modifierFlags & NSEventModifierFlagOption)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"ResumeNoWait" stringByAppendingString:controlImageSuffix]];
|
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"Pause" stringByAppendingString:controlImageSuffix]];
|
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
controlImage = [NSImage imageNamed:[@"Resume" stringByAppendingString:controlImageSuffix]];
|
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const controlRect = [self controlButtonRectForBounds:cellFrame];
|
2022-03-30 21:52:23 +00:00
|
|
|
[controlImage drawInRect:controlRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0
|
|
|
|
respectFlipped:YES
|
2021-08-15 09:41:48 +00:00
|
|
|
hints:nil];
|
2022-05-14 07:53:30 +00:00
|
|
|
if (minimal)
|
|
|
|
{
|
|
|
|
titleRightBound = MIN(titleRightBound, NSMinX(controlRect));
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
//reveal button
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* revealImageString;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fMouseDownRevealButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
revealImageString = @"RevealOn";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (!self.fTracking && self.hoverReveal)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
revealImageString = @"RevealHover";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
revealImageString = @"RevealOff";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* revealImage = [NSImage imageNamed:revealImageString];
|
2022-03-30 21:52:23 +00:00
|
|
|
[revealImage drawInRect:[self revealButtonRectForBounds:cellFrame] fromRect:NSZeroRect
|
|
|
|
operation:NSCompositingOperationSourceOver
|
2021-08-15 09:41:48 +00:00
|
|
|
fraction:1.0
|
|
|
|
respectFlipped:YES
|
|
|
|
hints:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
//action button
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning image should use new gear
|
2022-05-14 07:53:30 +00:00
|
|
|
if (!self.fTracking && self.hoverAction)
|
2010-03-20 03:27:17 +00:00
|
|
|
{
|
2022-05-14 07:53:30 +00:00
|
|
|
NSImage* actionImage = [NSImage imageNamed:@"ActionHover"];
|
2022-06-13 01:56:12 +00:00
|
|
|
[actionImage drawInRect:[self actionButtonRectForBounds:iconRect] fromRect:NSZeroRect
|
2021-10-31 15:18:27 +00:00
|
|
|
operation:NSCompositingOperationSourceOver
|
2021-08-15 09:41:48 +00:00
|
|
|
fraction:1.0
|
|
|
|
respectFlipped:YES
|
|
|
|
hints:nil];
|
2010-03-20 03:27:17 +00:00
|
|
|
}
|
2008-01-15 05:09:46 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 18:54:24 +00:00
|
|
|
//title
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* titleString = self.attributedTitle;
|
2022-05-14 07:53:30 +00:00
|
|
|
NSRect titleRect = [self rectForTitleWithString:titleString withRightBound:titleRightBound inBounds:cellFrame minimal:minimal];
|
2021-08-15 09:41:48 +00:00
|
|
|
[titleString drawInRect:titleRect];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 18:54:24 +00:00
|
|
|
//priority icon
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.priority != TR_PRI_NORMAL)
|
2010-03-20 18:54:24 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const priorityRect = NSMakeRect(
|
|
|
|
NSMaxX(titleRect) + PADDING_BETWEEN_TITLE_AND_PRIORITY,
|
|
|
|
NSMidY(titleRect) - PRIORITY_ICON_HEIGHT * 0.5,
|
|
|
|
PRIORITY_ICON_WIDTH,
|
|
|
|
PRIORITY_ICON_HEIGHT);
|
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
NSColor* priorityColor = self.backgroundStyle == NSBackgroundStyleEmphasized ? NSColor.whiteColor : NSColor.labelColor;
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
NSImage* priorityImage = [[NSImage imageNamed:(torrent.priority == TR_PRI_HIGH ? @"PriorityHighTemplate" : @"PriorityLowTemplate")]
|
|
|
|
imageWithColor:priorityColor];
|
2021-10-31 15:18:27 +00:00
|
|
|
[priorityImage drawInRect:priorityRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0
|
2021-08-15 09:41:48 +00:00
|
|
|
respectFlipped:YES
|
|
|
|
hints:nil];
|
2010-03-20 18:54:24 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//status
|
|
|
|
if (!minimal)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* statusString = [self attributedStatusString:self.statusString];
|
|
|
|
[statusString drawInRect:[self rectForStatusWithStringInBounds:cellFrame]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView*)view
|
2011-10-23 17:45:05 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL minimal = [self.fDefaults boolForKey:@"SmallView"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-23 17:45:05 +00:00
|
|
|
//this code needs to match the code in drawInteriorWithFrame:withView:
|
2022-05-14 07:53:30 +00:00
|
|
|
CGFloat titleRightBound;
|
2011-10-23 17:45:05 +00:00
|
|
|
if (minimal)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* minimalString = [self attributedStatusString:self.minimalStatusString];
|
|
|
|
NSRect minimalStatusRect = [self rectForMinimalStatusWithString:minimalString inBounds:cellFrame];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 07:53:30 +00:00
|
|
|
titleRightBound = NSMinX(minimalStatusRect);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 07:53:30 +00:00
|
|
|
if (self.hover)
|
|
|
|
{
|
|
|
|
NSRect const controlRect = [self controlButtonRectForBounds:cellFrame];
|
|
|
|
titleRightBound = MIN(titleRightBound, NSMinX(controlRect));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-10-23 17:45:05 +00:00
|
|
|
{
|
2022-05-14 07:53:30 +00:00
|
|
|
titleRightBound = NSMaxX(cellFrame);
|
2011-10-23 17:45:05 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* titleString = self.attributedTitle;
|
2022-05-14 07:53:30 +00:00
|
|
|
NSRect realRect = [self rectForTitleWithString:titleString withRightBound:titleRightBound inBounds:cellFrame minimal:minimal];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-23 17:45:05 +00:00
|
|
|
NSAssert([titleString size].width >= NSWidth(realRect), @"Full rect width should not be less than the used title rect width!");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([titleString size].width > NSWidth(realRect) &&
|
|
|
|
NSMouseInRect([view convertPoint:view.window.mouseLocationOutsideOfEventStream fromView:nil], realRect, view.flipped))
|
2011-10-23 17:45:05 +00:00
|
|
|
{
|
|
|
|
realRect.size.width = [titleString size].width;
|
|
|
|
return NSInsetRect(realRect, -PADDING_EXPANSION_FRAME, -PADDING_EXPANSION_FRAME);
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-23 17:45:05 +00:00
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView*)view
|
2011-10-23 17:45:05 +00:00
|
|
|
{
|
|
|
|
cellFrame.origin.x += PADDING_EXPANSION_FRAME;
|
|
|
|
cellFrame.origin.y += PADDING_EXPANSION_FRAME;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTitleAttributes[NSForegroundColorAttributeName] = NSColor.labelColor;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* titleString = self.attributedTitle;
|
|
|
|
[titleString drawInRect:cellFrame];
|
2011-10-23 17:45:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)drawBar:(NSRect)barRect
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const minimal = [self.fDefaults boolForKey:@"SmallView"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const piecesBarPercent = ((TorrentTableView*)self.controlView).piecesBarPercent;
|
2011-10-06 00:30:40 +00:00
|
|
|
if (piecesBarPercent > 0.0)
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2009-09-07 06:05:48 +00:00
|
|
|
NSRect piecesBarRect, regularBarRect;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDivideRect(barRect, &piecesBarRect, ®ularBarRect, floor(NSHeight(barRect) * PIECES_TOTAL_PERCENT * piecesBarPercent), NSMaxYEdge);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self drawRegularBar:regularBarRect];
|
|
|
|
[self drawPiecesBar:piecesBarRect];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
else
|
2007-11-05 00:04:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
((Torrent*)self.representedObject).previousFinishedPieces = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self drawRegularBar:barRect];
|
2007-11-05 00:04:14 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSColor* borderColor = minimal ? self.fBarMinimalBorderColor : self.fBarBorderColor;
|
2010-03-20 18:09:45 +00:00
|
|
|
[borderColor set];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSBezierPath strokeRect:NSInsetRect(barRect, 0.5, 0.5)];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)drawRegularBar:(NSRect)barRect
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = self.representedObject;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-09-07 05:40:09 +00:00
|
|
|
NSRect haveRect, missingRect;
|
2021-08-07 07:27:56 +00:00
|
|
|
NSDivideRect(barRect, &haveRect, &missingRect, round(torrent.progress * NSWidth(barRect)), NSMinXEdge);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-09-07 05:40:09 +00:00
|
|
|
if (!NSIsEmptyRect(haveRect))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.checking)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[ProgressGradients.progressYellowGradient drawInRect:haveRect angle:90];
|
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (torrent.seeding)
|
2007-09-26 17:30:54 +00:00
|
|
|
{
|
2009-09-06 21:09:33 +00:00
|
|
|
NSRect ratioHaveRect, ratioRemainingRect;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDivideRect(haveRect, &ratioHaveRect, &ratioRemainingRect, round(torrent.progressStopRatio * NSWidth(haveRect)), NSMinXEdge);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[ProgressGradients.progressGreenGradient drawInRect:ratioHaveRect angle:90];
|
|
|
|
[ProgressGradients.progressLightGreenGradient drawInRect:ratioRemainingRect angle:90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[ProgressGradients.progressBlueGradient drawInRect:haveRect angle:90];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.waitingToStart)
|
2007-09-26 17:30:54 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.allDownloaded)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[ProgressGradients.progressDarkGreenGradient drawInRect:haveRect angle:90];
|
|
|
|
}
|
2007-09-26 17:30:54 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[ProgressGradients.progressDarkBlueGradient drawInRect:haveRect angle:90];
|
|
|
|
}
|
2007-09-26 17:30:54 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[ProgressGradients.progressGrayGradient drawInRect:haveRect angle:90];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.allDownloaded)
|
2009-09-07 05:40:09 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const widthRemaining = round(NSWidth(barRect) * torrent.progressLeft);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-07 04:08:42 +00:00
|
|
|
NSRect wantedRect;
|
|
|
|
NSDivideRect(missingRect, &wantedRect, &missingRect, widthRemaining, NSMinXEdge);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-07 04:08:42 +00:00
|
|
|
//not-available section
|
2022-02-22 16:04:20 +00:00
|
|
|
if (torrent.active && !torrent.checking && torrent.availableDesired < 1.0 && [self.fDefaults boolForKey:@"DisplayProgressBarAvailable"])
|
2009-09-07 05:40:09 +00:00
|
|
|
{
|
2009-11-07 04:08:42 +00:00
|
|
|
NSRect unavailableRect;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDivideRect(wantedRect, &wantedRect, &unavailableRect, round(NSWidth(wantedRect) * torrent.availableDesired), NSMinXEdge);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[ProgressGradients.progressRedGradient drawInRect:unavailableRect angle:90];
|
2009-09-07 05:40:09 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-07 04:08:42 +00:00
|
|
|
//remaining section
|
2021-08-15 09:41:48 +00:00
|
|
|
[ProgressGradients.progressWhiteGradient drawInRect:wantedRect angle:90];
|
2009-09-07 05:40:09 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-07 04:08:42 +00:00
|
|
|
//unwanted section
|
|
|
|
if (!NSIsEmptyRect(missingRect))
|
2009-11-26 16:58:44 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.magnet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[ProgressGradients.progressLightGrayGradient drawInRect:missingRect angle:90];
|
|
|
|
}
|
2009-11-26 16:58:44 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[ProgressGradients.progressRedGradient drawInRect:missingRect angle:90];
|
|
|
|
}
|
2009-11-26 16:58:44 +00:00
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)drawPiecesBar:(NSRect)barRect
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = self.representedObject;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-07 02:46:49 +00:00
|
|
|
//fill an all-white bar for magnet links
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.magnet)
|
2010-03-07 02:46:49 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[[NSColor colorWithCalibratedWhite:1.0 alpha:[self.fDefaults boolForKey:@"SmallView"] ? 0.25 : 1.0] set];
|
2021-10-31 15:18:27 +00:00
|
|
|
NSRectFillUsingOperation(barRect, NSCompositingOperationSourceOver);
|
2010-03-07 02:46:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger pieceCount = MIN(torrent.pieceCount, MAX_PIECES);
|
2021-09-24 12:56:57 +00:00
|
|
|
float* piecesPercent = static_cast<float*>(malloc(pieceCount * sizeof(float)));
|
2021-08-15 09:41:48 +00:00
|
|
|
[torrent getAmountFinished:piecesPercent size:pieceCount];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil pixelsWide:pieceCount pixelsHigh:1
|
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:4
|
|
|
|
hasAlpha:YES
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSCalibratedRGBColorSpace
|
|
|
|
bytesPerRow:0
|
|
|
|
bitsPerPixel:0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* previousFinishedIndexes = torrent.previousFinishedPieces;
|
|
|
|
NSMutableIndexSet* finishedIndexes = [NSMutableIndexSet indexSet];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSInteger i = 0; i < pieceCount; i++)
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSColor* pieceColor;
|
2008-10-25 21:34:30 +00:00
|
|
|
if (piecesPercent[i] == 1.0f)
|
2008-06-11 16:28:33 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (previousFinishedIndexes && ![previousFinishedIndexes containsIndex:i])
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
pieceColor = NSColor.orangeColor;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-11 16:28:33 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
pieceColor = self.fBluePieceColor;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
[finishedIndexes addIndex:i];
|
2008-06-11 16:28:33 +00:00
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
pieceColor = [NSColor.whiteColor blendedColorWithFraction:piecesPercent[i] ofColor:self.fBluePieceColor];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-27 04:49:08 +00:00
|
|
|
//it's faster to just set color instead of checking previous color
|
2021-08-15 09:41:48 +00:00
|
|
|
[bitmap setColor:pieceColor atX:i y:0];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-11 16:28:33 +00:00
|
|
|
free(piecesPercent);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.previousFinishedPieces = finishedIndexes.count > 0 ? finishedIndexes : nil; //don't bother saving if none are complete
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
//actually draw image
|
2021-10-31 15:18:27 +00:00
|
|
|
[bitmap drawInRect:barRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver
|
2022-02-22 16:04:20 +00:00
|
|
|
fraction:([self.fDefaults boolForKey:@"SmallView"] ? 0.25 : 1.0)respectFlipped:YES
|
2021-08-15 09:41:48 +00:00
|
|
|
hints:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)rectForMinimalStatusWithString:(NSAttributedString*)string inBounds:(NSRect)bounds
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-09 23:02:10 +00:00
|
|
|
NSRect result;
|
|
|
|
result.size = [string size];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-09-06 23:31:23 +00:00
|
|
|
result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NSWidth(result));
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = ceil(NSMidY(bounds) - NSHeight(result) * 0.5);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-05-14 07:53:30 +00:00
|
|
|
- (NSRect)rectForTitleWithString:(NSAttributedString*)string
|
|
|
|
withRightBound:(CGFloat)rightBound
|
|
|
|
inBounds:(NSRect)bounds
|
|
|
|
minimal:(BOOL)minimal
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-09 23:02:10 +00:00
|
|
|
NSRect result;
|
2021-08-15 09:41:48 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + (minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG) + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
2009-12-13 03:13:34 +00:00
|
|
|
result.size.height = HEIGHT_TITLE;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-13 21:42:45 +00:00
|
|
|
if (minimal)
|
2010-03-21 14:59:46 +00:00
|
|
|
{
|
2022-06-13 01:56:12 +00:00
|
|
|
result.origin.x += GROUP_PADDING_MIN;
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = ceil(NSMidY(bounds) - NSHeight(result) * 0.5);
|
2010-03-20 18:54:24 +00:00
|
|
|
result.size.width = rightBound - NSMinX(result) - PADDING_BETWEEN_TITLE_AND_MIN_STATUS;
|
2010-03-21 14:59:46 +00:00
|
|
|
}
|
2010-03-20 18:54:24 +00:00
|
|
|
else
|
2010-03-21 14:59:46 +00:00
|
|
|
{
|
2022-06-08 20:13:29 +00:00
|
|
|
result.origin.x += GROUP_PADDING_REG;
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE;
|
2022-05-14 07:53:30 +00:00
|
|
|
result.size.width = rightBound - NSMinX(result) - PADDING_HORIZONTAL;
|
2010-03-21 14:59:46 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (((Torrent*)self.representedObject).priority != TR_PRI_NORMAL)
|
|
|
|
{
|
2009-12-13 21:42:45 +00:00
|
|
|
result.size.width -= PRIORITY_ICON_WIDTH + PADDING_BETWEEN_TITLE_AND_PRIORITY;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-10-23 17:45:05 +00:00
|
|
|
result.size.width = MIN(NSWidth(result), [string size].width);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)rectForProgressWithStringInBounds:(NSRect)bounds
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-09 23:02:10 +00:00
|
|
|
NSRect result;
|
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE + PADDING_BETWEEN_TITLE_AND_PROGRESS;
|
2022-06-08 20:13:29 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + GROUP_PADDING_REG + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-13 03:13:34 +00:00
|
|
|
result.size.height = HEIGHT_STATUS;
|
|
|
|
result.size.width = NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONTAL;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)rectForStatusWithStringInBounds:(NSRect)bounds
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-09 23:02:10 +00:00
|
|
|
NSRect result;
|
2021-08-15 09:41:48 +00:00
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE + PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS +
|
|
|
|
PADDING_BETWEEN_PROGRESS_AND_BAR + BAR_HEIGHT + PADDING_BETWEEN_BAR_AND_STATUS;
|
2022-06-08 20:13:29 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + GROUP_PADDING_REG + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-13 03:13:34 +00:00
|
|
|
result.size.height = HEIGHT_STATUS;
|
|
|
|
result.size.width = NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONTAL;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)barRectRegForBounds:(NSRect)bounds
|
2009-12-12 03:11:48 +00:00
|
|
|
{
|
2010-03-20 18:09:45 +00:00
|
|
|
NSRect result;
|
2010-03-28 01:29:40 +00:00
|
|
|
result.size.height = BAR_HEIGHT;
|
2022-06-08 20:13:29 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + GROUP_PADDING_REG + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_BAR;
|
2021-08-15 09:41:48 +00:00
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE + PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS +
|
|
|
|
PADDING_BETWEEN_PROGRESS_AND_BAR;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
result.size.width = floor(NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONTAL - 2.0 * (PADDING_BETWEEN_BUTTONS + NORMAL_BUTTON_WIDTH));
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-28 01:29:40 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)barRectMinForBounds:(NSRect)bounds
|
2010-03-28 01:29:40 +00:00
|
|
|
{
|
|
|
|
NSRect result;
|
2022-06-13 01:56:12 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + IMAGE_SIZE_MIN + GROUP_PADDING_MIN + PADDING_BETWEEN_IMAGE_AND_BAR;
|
2010-03-28 01:29:40 +00:00
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_BETWEEN_BAR_AND_EDGE_MIN;
|
|
|
|
result.size.height = NSHeight(bounds) - 2.0 * PADDING_BETWEEN_BAR_AND_EDGE_MIN;
|
2011-09-06 23:31:23 +00:00
|
|
|
result.size.width = NSMaxX(bounds) - NSMinX(result) - PADDING_BETWEEN_BAR_AND_EDGE_MIN;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 18:09:45 +00:00
|
|
|
return result;
|
2009-12-12 03:11:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)controlButtonRectForBounds:(NSRect)bounds
|
2009-12-12 03:11:48 +00:00
|
|
|
{
|
2009-12-13 21:42:45 +00:00
|
|
|
NSRect result;
|
2009-12-12 03:11:48 +00:00
|
|
|
result.size.height = NORMAL_BUTTON_WIDTH;
|
|
|
|
result.size.width = NORMAL_BUTTON_WIDTH;
|
2011-09-06 23:31:23 +00:00
|
|
|
result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH + PADDING_BETWEEN_BUTTONS + NORMAL_BUTTON_WIDTH);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"SmallView"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5 +
|
|
|
|
PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
|
|
|
}
|
2010-03-20 18:09:45 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = ceil(NSMidY(bounds) - NSHeight(result) * 0.5);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-12 03:11:48 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)revealButtonRectForBounds:(NSRect)bounds
|
2009-12-12 03:11:48 +00:00
|
|
|
{
|
2009-12-13 21:42:45 +00:00
|
|
|
NSRect result;
|
2009-12-12 03:11:48 +00:00
|
|
|
result.size.height = NORMAL_BUTTON_WIDTH;
|
|
|
|
result.size.width = NORMAL_BUTTON_WIDTH;
|
|
|
|
result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fDefaults boolForKey:@"SmallView"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5 +
|
|
|
|
PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
|
|
|
}
|
2010-03-20 18:09:45 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = ceil(NSMidY(bounds) - NSHeight(result) * 0.5);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-12 03:11:48 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)actionButtonRectForBounds:(NSRect)bounds
|
2009-12-12 03:11:48 +00:00
|
|
|
{
|
2022-06-13 01:56:12 +00:00
|
|
|
return NSMakeRect(NSMidX(bounds) - ACTION_BUTTON_WIDTH * 0.5, NSMidY(bounds) - ACTION_BUTTON_WIDTH * 0.5, ACTION_BUTTON_WIDTH, ACTION_BUTTON_WIDTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)groupIconRectForBounds:(NSRect)bounds
|
|
|
|
{
|
|
|
|
BOOL const minimal = [self.fDefaults boolForKey:@"SmallView"];
|
|
|
|
CGFloat const imageSize = minimal ? GROUP_IMAGE_SIZE_MIN : GROUP_IMAGE_SIZE_REG;
|
|
|
|
CGFloat const padding = minimal ? GROUP_PADDING_MIN + 2 : GROUP_PADDING_REG + 1.5;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-13 01:56:12 +00:00
|
|
|
return NSMakeRect(NSMinX(bounds) - padding * 0.5, NSMidY(bounds) - imageSize * 0.5, imageSize, imageSize);
|
2009-12-12 03:11:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSAttributedString*)attributedTitle
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* title = ((Torrent*)self.representedObject).name;
|
2022-02-22 16:04:20 +00:00
|
|
|
return [[NSAttributedString alloc] initWithString:title attributes:self.fTitleAttributes];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSAttributedString*)attributedStatusString:(NSString*)string
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return [[NSAttributedString alloc] initWithString:string attributes:self.fStatusAttributes];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)buttonString
|
2008-01-15 21:09:51 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fMouseDownRevealButton || (!self.fTracking && self.hoverReveal))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-15 23:41:28 +00:00
|
|
|
return NSLocalizedString(@"Show the data file in Finder", "Torrent cell -> button info");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (self.fMouseDownControlButton || (!self.fTracking && self.hoverControl))
|
2008-01-15 21:09:51 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = self.representedObject;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2008-01-15 23:48:03 +00:00
|
|
|
return NSLocalizedString(@"Pause the transfer", "Torrent Table -> tooltip");
|
2008-01-15 21:09:51 +00:00
|
|
|
else
|
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
if (NSApp.currentEvent.modifierFlags & NSEventModifierFlagOption)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-15 21:09:51 +00:00
|
|
|
return NSLocalizedString(@"Resume the transfer right away", "Torrent cell -> button info");
|
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
|
|
|
{
|
2008-01-15 21:09:51 +00:00
|
|
|
return NSLocalizedString(@"Stop waiting to start", "Torrent cell -> button info");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-15 21:09:51 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-15 21:09:51 +00:00
|
|
|
return NSLocalizedString(@"Resume the transfer", "Torrent cell -> button info");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-15 21:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (!self.fTracking && self.hoverAction)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-15 23:48:03 +00:00
|
|
|
return NSLocalizedString(@"Change transfer settings", "Torrent Table -> tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-15 21:20:16 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-15 21:20:16 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-15 21:20:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)statusString
|
2008-01-15 21:20:16 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* buttonString;
|
2021-08-07 07:27:56 +00:00
|
|
|
if ((buttonString = self.buttonString))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-15 21:20:16 +00:00
|
|
|
return buttonString;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-15 21:09:51 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return ((Torrent*)self.representedObject).statusString;
|
|
|
|
}
|
2008-01-15 21:09:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)minimalStatusString
|
2008-01-15 21:20:16 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = self.representedObject;
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.fDefaults boolForKey:@"DisplaySmallStatusRegular"] ? torrent.shortStatusString : torrent.remainingTimeString;
|
2008-01-15 21:20:16 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|