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
|
|
|
|
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
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface TorrentCell (Private)
|
|
|
|
|
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;
|
|
|
|
- (NSRect)rectForTitleWithString:(NSAttributedString*)string withRightBound:(CGFloat)rightBound inBounds:(NSRect)bounds;
|
|
|
|
- (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
|
|
|
|
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
|
|
|
{
|
2021-08-07 07:27:56 +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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fTitleAttributes = [[NSMutableDictionary alloc] initWithCapacity:3];
|
|
|
|
fTitleAttributes[NSFontAttributeName] = [NSFont messageFontOfSize:12.0];
|
2017-07-08 14:38:47 +00:00
|
|
|
fTitleAttributes[NSParagraphStyleAttributeName] = paragraphStyle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fStatusAttributes = [[NSMutableDictionary alloc] initWithCapacity:3];
|
|
|
|
fStatusAttributes[NSFontAttributeName] = [NSFont messageFontOfSize:9.0];
|
2017-07-08 14:38:47 +00:00
|
|
|
fStatusAttributes[NSParagraphStyleAttributeName] = paragraphStyle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const imageSize = [fDefaults boolForKey:@"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return NSMakeRect(NSMinX(bounds) + PADDING_HORIZONTAL, ceil(NSMidY(bounds) - imageSize * 0.5), imageSize, imageSize);
|
2007-09-16 01:02:06 +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
|
|
|
{
|
2008-01-15 04:52:40 +00:00
|
|
|
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);
|
2008-01-14 18:02:08 +00:00
|
|
|
if (fMouseDownControlButton != inControlButton)
|
|
|
|
{
|
|
|
|
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);
|
2008-01-14 18:02:08 +00:00
|
|
|
if (fMouseDownRevealButton != inRevealButton)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
2021-10-31 15:18:27 +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
|
|
|
|
2008-01-15 04:52:40 +00:00
|
|
|
fTracking = NO;
|
2008-01-14 18:02:08 +00:00
|
|
|
|
|
|
|
if (fMouseDownControlButton)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
else if (fMouseDownRevealButton)
|
|
|
|
{
|
|
|
|
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
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([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;
|
2021-08-15 09:41:48 +00:00
|
|
|
[(TorrentTableView*)controlView setRowHover:[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;
|
2021-08-15 09:41:48 +00:00
|
|
|
[(TorrentTableView*)controlView setControlButtonHover:[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;
|
2021-08-15 09:41:48 +00:00
|
|
|
[(TorrentTableView*)controlView setRevealButtonHover:[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
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect actionButtonRect = [self iconRectForBounds:cellFrame]; //use the whole icon
|
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;
|
2021-08-15 09:41:48 +00:00
|
|
|
[(TorrentTableView*)controlView setActionButtonHover:[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)setHover:(BOOL)hover
|
2010-03-20 03:27:17 +00:00
|
|
|
{
|
|
|
|
fHover = hover;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setControlHover:(BOOL)hover
|
2008-01-15 04:45:57 +00:00
|
|
|
{
|
2008-03-23 18:47:35 +00:00
|
|
|
fHoverControl = hover;
|
2008-01-15 04:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRevealHover:(BOOL)hover
|
2008-01-15 04:45:57 +00:00
|
|
|
{
|
2008-03-23 18:47:35 +00:00
|
|
|
fHoverReveal = hover;
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setActionHover:(BOOL)hover
|
2008-01-15 23:48:03 +00:00
|
|
|
{
|
2008-03-23 18:47:35 +00:00
|
|
|
fHoverAction = hover;
|
2008-01-15 23:48:03 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setActionPushed:(BOOL)pushed
|
2008-01-16 19:49:10 +00:00
|
|
|
{
|
|
|
|
fMouseDownActionButton = pushed;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const minimal = [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
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const iconRect = [self iconRectForBounds:cellFrame];
|
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
|
|
|
{
|
2009-12-20 21:02:58 +00:00
|
|
|
NSRect groupRect = NSInsetRect(iconRect, -1.0, -2.0);
|
2007-12-18 21:32:55 +00:00
|
|
|
if (!minimal)
|
|
|
|
{
|
2009-12-20 21:02:58 +00:00
|
|
|
groupRect.size.height -= 1.0;
|
|
|
|
groupRect.origin.y -= 1.0;
|
2007-12-18 21:32:55 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const radius = minimal ? 3.0 : 6.0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSColor *groupColor = [GroupsController.groups colorForIndex:groupValue],
|
|
|
|
*darkGroupColor = [groupColor blendedColorWithFraction:0.2 ofColor:NSColor.whiteColor];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-14 21:35:37 +00:00
|
|
|
//border
|
2021-08-15 09:41:48 +00:00
|
|
|
NSBezierPath* bp = [NSBezierPath bezierPathWithRoundedRect:groupRect xRadius:radius yRadius:radius];
|
2008-05-27 16:07:12 +00:00
|
|
|
[darkGroupColor set];
|
2021-08-07 07:27:56 +00:00
|
|
|
bp.lineWidth = 2.0;
|
2008-05-27 16:07:12 +00:00
|
|
|
[bp stroke];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-14 21:35:37 +00:00
|
|
|
//inside
|
2021-08-15 09:41:48 +00:00
|
|
|
bp = [NSBezierPath bezierPathWithRoundedRect:groupRect xRadius:radius yRadius:radius];
|
|
|
|
NSGradient* gradient = [[NSGradient alloc] initWithStartingColor:[groupColor blendedColorWithFraction:0.7
|
|
|
|
ofColor:NSColor.whiteColor]
|
|
|
|
endingColor:darkGroupColor];
|
|
|
|
[gradient drawInBezierPath:bp angle:90.0];
|
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
|
2008-01-16 06:26:52 +00:00
|
|
|
if (!minimal || !(!fTracking && fHoverAction)) //don't show in minimal mode when hovered over
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* icon = (minimal && error) ? [NSImage imageNamed:NSImageNameCaution] : torrent.icon;
|
2021-10-31 15:18:27 +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);
|
2021-10-31 15:18:27 +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
|
|
|
|
2017-07-08 14:38:47 +00:00
|
|
|
fTitleAttributes[NSForegroundColorAttributeName] = titleColor;
|
|
|
|
fStatusAttributes[NSForegroundColorAttributeName] = statusColor;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//minimal status
|
2010-03-20 22:24:54 +00:00
|
|
|
CGFloat minimalTitleRightBound;
|
|
|
|
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
|
|
|
|
2010-03-20 22:24:54 +00:00
|
|
|
if (!fHover)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[minimalString drawInRect:minimalStatusRect];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 22:24:54 +00:00
|
|
|
minimalTitleRightBound = NSMinX(minimalStatusRect);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//progress
|
|
|
|
if (!minimal)
|
|
|
|
{
|
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];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
if (!minimal || fHover)
|
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;
|
2010-03-20 03:27:17 +00:00
|
|
|
if (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
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else if (!fTracking && fHoverControl)
|
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];
|
2021-10-31 15:18:27 +00:00
|
|
|
[controlImage drawInRect:controlRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0 respectFlipped:YES
|
2021-08-15 09:41:48 +00:00
|
|
|
hints:nil];
|
2010-03-20 22:24:54 +00:00
|
|
|
minimalTitleRightBound = MIN(minimalTitleRightBound, 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;
|
2010-03-20 03:27:17 +00:00
|
|
|
if (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
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else if (!fTracking && fHoverReveal)
|
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];
|
2021-10-31 15:18:27 +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
|
|
|
|
NSString* actionImageString;
|
2010-03-20 03:27:17 +00:00
|
|
|
if (fMouseDownActionButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
#warning we can get rid of this on 10.7
|
2012-06-10 02:35:58 +00:00
|
|
|
actionImageString = @"ActionOn";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else if (!fTracking && fHoverAction)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-06-10 02:35:58 +00:00
|
|
|
actionImageString = @"ActionHover";
|
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
|
|
|
{
|
2010-03-20 03:27:17 +00:00
|
|
|
actionImageString = nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
if (actionImageString)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* actionImage = [NSImage imageNamed:actionImageString];
|
|
|
|
[actionImage drawInRect:[self actionButtonRectForBounds:cellFrame] 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;
|
|
|
|
NSRect titleRect = [self rectForTitleWithString:titleString withRightBound:minimalTitleRightBound inBounds:cellFrame];
|
|
|
|
[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);
|
|
|
|
|
2021-10-31 15:18:27 +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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL minimal = [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:
|
|
|
|
CGFloat minimalTitleRightBound;
|
|
|
|
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
|
|
|
|
2011-10-23 17:45:05 +00:00
|
|
|
minimalTitleRightBound = NSMinX(minimalStatusRect);
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-23 17:45:05 +00:00
|
|
|
if (!minimal || fHover)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const controlRect = [self controlButtonRectForBounds:cellFrame];
|
2011-10-23 17:45:05 +00:00
|
|
|
minimalTitleRightBound = MIN(minimalTitleRightBound, NSMinX(controlRect));
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAttributedString* titleString = self.attributedTitle;
|
|
|
|
NSRect realRect = [self rectForTitleWithString:titleString withRightBound:minimalTitleRightBound inBounds:cellFrame];
|
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
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentCell (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)drawBar:(NSRect)barRect
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const minimal = [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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSColor* borderColor = minimal ? fBarMinimalBorderColor : 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
|
2021-08-15 09:41:48 +00:00
|
|
|
if (torrent.active && !torrent.checking && torrent.availableDesired < 1.0 && [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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[[NSColor colorWithCalibratedWhite:1.0 alpha:[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
|
|
|
{
|
2008-06-11 16:28:33 +00:00
|
|
|
pieceColor = 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
|
|
|
{
|
|
|
|
pieceColor = [NSColor.whiteColor blendedColorWithFraction:piecesPercent[i] ofColor:fBluePieceColor];
|
|
|
|
}
|
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
|
2021-08-15 09:41:48 +00:00
|
|
|
fraction:([fDefaults boolForKey:@"SmallView"] ? 0.25 : 1.0)respectFlipped:YES
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)rectForTitleWithString:(NSAttributedString*)string withRightBound:(CGFloat)rightBound inBounds:(NSRect)bounds
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const minimal = [fDefaults boolForKey:@"SmallView"];
|
2017-01-24 17:53:16 +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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE;
|
2010-03-20 18:54:24 +00:00
|
|
|
result.size.width = NSMaxX(bounds) - 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;
|
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + 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;
|
2009-10-09 23:02:10 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + 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;
|
2011-09-06 02:56:55 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + 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;
|
2011-09-06 02:56:55 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONTAL + IMAGE_SIZE_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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![fDefaults boolForKey:@"SmallView"])
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![fDefaults boolForKey:@"SmallView"])
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const iconRect = [self iconRectForBounds:bounds];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-20 21:02:58 +00:00
|
|
|
//in minimal view the rect will be the icon rect, but avoid the extra defaults lookup with some cheap math
|
2021-08-15 09:41:48 +00:00
|
|
|
return NSMakeRect(NSMidX(iconRect) - ACTION_BUTTON_WIDTH * 0.5, NSMidY(iconRect) - ACTION_BUTTON_WIDTH * 0.5, ACTION_BUTTON_WIDTH, ACTION_BUTTON_WIDTH);
|
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;
|
|
|
|
return [[NSAttributedString alloc] initWithString:title attributes: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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [[NSAttributedString alloc] initWithString:string attributes: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
|
|
|
{
|
|
|
|
if (fMouseDownRevealButton || (!fTracking && fHoverReveal))
|
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
|
|
|
}
|
2008-01-15 21:09:51 +00:00
|
|
|
else if (fMouseDownControlButton || (!fTracking && fHoverControl))
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
2008-01-15 23:48:03 +00:00
|
|
|
else if (!fTracking && fHoverAction)
|
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;
|
|
|
|
return [fDefaults boolForKey:@"DisplaySmallStatusRegular"] ? torrent.shortStatusString : torrent.remainingTimeString;
|
2008-01-15 21:20:16 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|