2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2010-01-01 21:12:04 +00:00
|
|
|
* Copyright (c) 2006-2010 Transmission authors and contributors
|
2007-09-16 01:02:06 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "TorrentCell.h"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2009-08-29 20:28:52 +00:00
|
|
|
#import "NSApplicationAdditions.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
|
|
|
|
2009-12-20 21:02:58 +00:00
|
|
|
#define PRIORITY_ICON_WIDTH 14.0
|
|
|
|
#define PRIORITY_ICON_HEIGHT 14.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
|
|
|
|
|
|
|
|
#define PADDING_HORIZONTAL 3.0
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0
|
2010-03-21 14:59:46 +00:00
|
|
|
#define PADDING_BETWEEN_TITLE_AND_PRIORITY 3.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
|
2009-12-20 21:02:58 +00:00
|
|
|
|
|
|
|
#define PIECES_TOTAL_PERCENT 0.6
|
2008-06-09 21:20:01 +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)
|
|
|
|
|
2007-09-26 19:36:25 +00:00
|
|
|
- (void) drawBar: (NSRect) barRect;
|
2007-11-04 15:01:34 +00:00
|
|
|
- (void) drawRegularBar: (NSRect) barRect;
|
|
|
|
- (void) drawPiecesBar: (NSRect) barRect;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
- (NSRect) rectForMinimalStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
|
2010-03-20 18:54:24 +00:00
|
|
|
- (NSRect) rectForTitleWithString: (NSAttributedString *) string withRightBound: (CGFloat) rightBound inBounds: (NSRect) bounds;
|
2009-12-13 03:13:34 +00:00
|
|
|
- (NSRect) rectForProgressWithStringInBounds: (NSRect) bounds;
|
|
|
|
- (NSRect) rectForStatusWithStringInBounds: (NSRect) bounds;
|
2010-03-28 01:29:40 +00:00
|
|
|
- (NSRect) barRectRegForBounds: (NSRect) bounds;
|
|
|
|
- (NSRect) barRectMinForBounds: (NSRect) bounds;
|
2009-12-12 03:11:48 +00:00
|
|
|
|
|
|
|
- (NSRect) controlButtonRectForBounds: (NSRect) bounds;
|
|
|
|
- (NSRect) revealButtonRectForBounds: (NSRect) bounds;
|
|
|
|
- (NSRect) actionButtonRectForBounds: (NSRect) bounds;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-09-28 17:42:24 +00:00
|
|
|
- (NSAttributedString *) attributedTitle;
|
|
|
|
- (NSAttributedString *) attributedStatusString: (NSString *) string;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-15 21:20:16 +00:00
|
|
|
- (NSString *) buttonString;
|
2008-01-15 21:09:51 +00:00
|
|
|
- (NSString *) statusString;
|
2008-01-15 21:20:16 +00:00
|
|
|
- (NSString *) minimalStatusString;
|
2008-01-15 21:09:51 +00:00
|
|
|
|
2009-08-29 20:28:52 +00:00
|
|
|
- (void) drawImage: (NSImage *) image inRect: (NSRect) rect; //use until 10.5 dropped
|
|
|
|
|
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
|
2007-09-16 01:02:06 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
2010-04-01 02:34:29 +00:00
|
|
|
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingMiddle];
|
2009-12-20 21:02:58 +00:00
|
|
|
|
|
|
|
fTitleAttributes = [[NSMutableDictionary alloc] initWithCapacity: 3];
|
|
|
|
[fTitleAttributes setObject: [NSFont messageFontOfSize: 12.0] forKey: NSFontAttributeName];
|
|
|
|
[fTitleAttributes setObject: paragraphStyle forKey: NSParagraphStyleAttributeName];
|
|
|
|
|
|
|
|
fStatusAttributes = [[NSMutableDictionary alloc] initWithCapacity: 3];
|
|
|
|
[fStatusAttributes setObject: [NSFont messageFontOfSize: 9.0] forKey: NSFontAttributeName];
|
|
|
|
[fStatusAttributes setObject: paragraphStyle forKey: NSParagraphStyleAttributeName];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[paragraphStyle release];
|
|
|
|
|
2009-12-20 21:02:58 +00:00
|
|
|
fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain];
|
2010-03-20 03:30:04 +00:00
|
|
|
fBarBorderColor = [[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.2] retain];
|
2010-03-20 18:09:45 +00:00
|
|
|
fBarMinimalBorderColor = [[NSColor colorWithCalibratedWhite: 0.0 alpha: 0.015] retain];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) iconRectForBounds: (NSRect) bounds
|
|
|
|
{
|
2009-12-12 03:11:48 +00:00
|
|
|
const CGFloat imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
|
2008-01-16 06:22:47 +00:00
|
|
|
|
2010-03-21 14:59:46 +00:00
|
|
|
return NSMakeRect(NSMinX(bounds) + PADDING_HORIZONTAL, ceil(NSMidY(bounds) - imageSize * 0.5),
|
2009-12-20 21:02:58 +00:00
|
|
|
imageSize, imageSize);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-10-31 17:23:56 +00:00
|
|
|
- (NSUInteger) hitTestForEvent: (NSEvent *) event inRect: (NSRect) cellFrame ofView: (NSView *) controlView
|
|
|
|
{
|
2008-01-14 18:02:08 +00:00
|
|
|
NSPoint point = [controlView convertPoint: [event locationInWindow] fromView: nil];
|
|
|
|
|
|
|
|
if (NSMouseInRect(point, [self controlButtonRectForBounds: cellFrame], [controlView isFlipped])
|
2008-05-27 06:05:05 +00:00
|
|
|
|| NSMouseInRect(point, [self revealButtonRectForBounds: cellFrame], [controlView isFlipped]))
|
2008-01-14 18:02:08 +00:00
|
|
|
return NSCellHitContentArea | NSCellHitTrackableArea;
|
|
|
|
|
2007-10-31 17:23:56 +00:00
|
|
|
return NSCellHitContentArea;
|
|
|
|
}
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
+ (BOOL) prefersTrackingUntilMouseUp
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) trackMouse: (NSEvent *) event inRect: (NSRect) cellFrame ofView: (NSView *) controlView untilMouseUp: (BOOL) flag
|
|
|
|
{
|
2008-01-15 04:52:40 +00:00
|
|
|
fTracking = YES;
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
[self setControlView: controlView];
|
|
|
|
|
|
|
|
NSPoint point = [controlView convertPoint: [event locationInWindow] fromView: nil];
|
|
|
|
|
2009-11-02 01:40:39 +00:00
|
|
|
const NSRect controlRect= [self controlButtonRectForBounds: cellFrame];
|
|
|
|
const BOOL checkControl = NSMouseInRect(point, controlRect, [controlView isFlipped]);
|
2008-01-14 18:02:08 +00:00
|
|
|
|
2009-11-02 01:40:39 +00:00
|
|
|
const NSRect revealRect = [self revealButtonRectForBounds: cellFrame];
|
|
|
|
const BOOL checkReveal = NSMouseInRect(point, revealRect, [controlView isFlipped]);
|
2008-01-14 18:02:08 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
[(TorrentTableView *)controlView removeTrackingAreas];
|
2008-01-15 16:19:16 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
while ([event type] != NSLeftMouseUp)
|
|
|
|
{
|
|
|
|
point = [controlView convertPoint: [event locationInWindow] fromView: nil];
|
|
|
|
|
|
|
|
if (checkControl)
|
|
|
|
{
|
2009-11-02 01:40:39 +00:00
|
|
|
const BOOL inControlButton = NSMouseInRect(point, controlRect, [controlView isFlipped]);
|
2008-01-14 18:02:08 +00:00
|
|
|
if (fMouseDownControlButton != inControlButton)
|
|
|
|
{
|
|
|
|
fMouseDownControlButton = inControlButton;
|
|
|
|
[controlView setNeedsDisplayInRect: cellFrame];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (checkReveal)
|
|
|
|
{
|
2009-11-02 01:40:39 +00:00
|
|
|
const BOOL inRevealButton = NSMouseInRect(point, revealRect, [controlView isFlipped]);
|
2008-01-14 18:02:08 +00:00
|
|
|
if (fMouseDownRevealButton != inRevealButton)
|
|
|
|
{
|
|
|
|
fMouseDownRevealButton = inRevealButton;
|
|
|
|
[controlView setNeedsDisplayInRect: cellFrame];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else;
|
|
|
|
|
|
|
|
//send events to where necessary
|
|
|
|
if ([event type] == NSMouseEntered || [event type] == NSMouseExited)
|
|
|
|
[NSApp sendEvent: event];
|
|
|
|
event = [[controlView window] nextEventMatchingMask:
|
|
|
|
(NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSMouseEnteredMask | NSMouseExitedMask)];
|
|
|
|
}
|
2008-01-15 04:52:40 +00:00
|
|
|
|
|
|
|
fTracking = NO;
|
2008-01-14 18:02:08 +00:00
|
|
|
|
|
|
|
if (fMouseDownControlButton)
|
|
|
|
{
|
|
|
|
fMouseDownControlButton = NO;
|
|
|
|
|
|
|
|
[(TorrentTableView *)controlView toggleControlForTorrent: [self representedObject]];
|
|
|
|
}
|
|
|
|
else if (fMouseDownRevealButton)
|
|
|
|
{
|
|
|
|
fMouseDownRevealButton = NO;
|
|
|
|
[controlView setNeedsDisplayInRect: cellFrame];
|
|
|
|
|
2009-08-30 17:52:03 +00:00
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
NSString * location = [[self representedObject] dataLocation];
|
|
|
|
if (location)
|
|
|
|
{
|
|
|
|
NSURL * file = [NSURL fileURLWithPath: location];
|
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
|
|
|
|
}
|
2009-08-30 17:52:03 +00:00
|
|
|
}
|
|
|
|
else
|
2009-10-21 13:01:14 +00:00
|
|
|
{
|
|
|
|
NSString * location = [[self representedObject] dataLocation];
|
|
|
|
if (location)
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil];
|
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
|
|
|
else;
|
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[controlView updateTrackingAreas];
|
2008-01-15 16:19:16 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2008-01-15 03:33:44 +00:00
|
|
|
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
|
|
|
mouseLocation: (NSPoint) mouseLocation
|
|
|
|
{
|
2010-03-20 18:27:09 +00:00
|
|
|
const NSTrackingAreaOptions options = NSTrackingEnabledDuringMouseDrag | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
|
2008-01-15 03:33:44 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
//whole row
|
2010-03-20 18:27:09 +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;
|
|
|
|
if (NSMouseInRect(mouseLocation, cellFrame, [controlView isFlipped]))
|
|
|
|
{
|
|
|
|
rowOptions |= NSTrackingAssumeInside;
|
|
|
|
[(TorrentTableView *)controlView setRowHover: [[userInfo objectForKey: @"Row"] integerValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary * rowInfo = [userInfo mutableCopy];
|
|
|
|
[rowInfo setObject: @"Row" forKey: @"Type"];
|
|
|
|
NSTrackingArea * area = [[NSTrackingArea alloc] initWithRect: cellFrame options: rowOptions owner: controlView userInfo: rowInfo];
|
|
|
|
[controlView addTrackingArea: area];
|
|
|
|
[rowInfo release];
|
|
|
|
[area release];
|
|
|
|
|
|
|
|
//control button
|
|
|
|
NSRect controlButtonRect = [self controlButtonRectForBounds: cellFrame];
|
|
|
|
NSTrackingAreaOptions controlOptions = options;
|
|
|
|
if (NSMouseInRect(mouseLocation, controlButtonRect, [controlView isFlipped]))
|
|
|
|
{
|
|
|
|
controlOptions |= NSTrackingAssumeInside;
|
|
|
|
[(TorrentTableView *)controlView setControlButtonHover: [[userInfo objectForKey: @"Row"] integerValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary * controlInfo = [userInfo mutableCopy];
|
|
|
|
[controlInfo setObject: @"Control" forKey: @"Type"];
|
|
|
|
area = [[NSTrackingArea alloc] initWithRect: controlButtonRect options: controlOptions owner: controlView
|
|
|
|
userInfo: controlInfo];
|
|
|
|
[controlView addTrackingArea: area];
|
|
|
|
[controlInfo release];
|
|
|
|
[area release];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//reveal button
|
|
|
|
NSRect revealButtonRect = [self revealButtonRectForBounds: cellFrame];
|
|
|
|
NSTrackingAreaOptions revealOptions = options;
|
|
|
|
if (NSMouseInRect(mouseLocation, revealButtonRect, [controlView isFlipped]))
|
|
|
|
{
|
|
|
|
revealOptions |= NSTrackingAssumeInside;
|
2009-12-20 21:02:58 +00:00
|
|
|
[(TorrentTableView *)controlView setRevealButtonHover: [[userInfo objectForKey: @"Row"] integerValue]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary * revealInfo = [userInfo mutableCopy];
|
|
|
|
[revealInfo setObject: @"Reveal" forKey: @"Type"];
|
2010-03-20 18:54:24 +00:00
|
|
|
NSTrackingArea * area = [[NSTrackingArea alloc] initWithRect: revealButtonRect options: revealOptions owner: controlView
|
|
|
|
userInfo: revealInfo];
|
2008-01-15 03:33:44 +00:00
|
|
|
[controlView addTrackingArea: area];
|
|
|
|
[revealInfo release];
|
|
|
|
[area release];
|
2008-01-15 23:48:03 +00:00
|
|
|
|
2008-01-16 06:48:12 +00:00
|
|
|
//action button
|
2008-01-20 18:51:53 +00:00
|
|
|
NSRect actionButtonRect = [self iconRectForBounds: cellFrame]; //use the whole icon
|
2008-01-15 23:48:03 +00:00
|
|
|
NSTrackingAreaOptions actionOptions = options;
|
|
|
|
if (NSMouseInRect(mouseLocation, actionButtonRect, [controlView isFlipped]))
|
|
|
|
{
|
|
|
|
actionOptions |= NSTrackingAssumeInside;
|
2009-12-20 21:02:58 +00:00
|
|
|
[(TorrentTableView *)controlView setActionButtonHover: [[userInfo objectForKey: @"Row"] integerValue]];
|
2008-01-15 23:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary * actionInfo = [userInfo mutableCopy];
|
|
|
|
[actionInfo setObject: @"Action" forKey: @"Type"];
|
|
|
|
area = [[NSTrackingArea alloc] initWithRect: actionButtonRect options: actionOptions owner: controlView userInfo: actionInfo];
|
|
|
|
[controlView addTrackingArea: area];
|
|
|
|
[actionInfo release];
|
|
|
|
[area release];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
- (void) setHover: (BOOL) hover
|
|
|
|
{
|
|
|
|
fHover = hover;
|
|
|
|
}
|
|
|
|
|
2008-01-15 04:45:57 +00:00
|
|
|
- (void) setControlHover: (BOOL) hover
|
|
|
|
{
|
2008-03-23 18:47:35 +00:00
|
|
|
fHoverControl = hover;
|
2008-01-15 04:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRevealHover: (BOOL) hover
|
|
|
|
{
|
2008-03-23 18:47:35 +00:00
|
|
|
fHoverReveal = hover;
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 23:48:03 +00:00
|
|
|
- (void) setActionHover: (BOOL) hover
|
|
|
|
{
|
2008-03-23 18:47:35 +00:00
|
|
|
fHoverAction = hover;
|
2008-01-15 23:48:03 +00:00
|
|
|
}
|
|
|
|
|
2008-01-16 19:49:10 +00:00
|
|
|
- (void) setActionPushed: (BOOL) pushed
|
|
|
|
{
|
|
|
|
fMouseDownActionButton = pushed;
|
|
|
|
}
|
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
- (void) drawInteriorWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
2008-12-21 02:45:55 +00:00
|
|
|
const BOOL minimal = [fDefaults boolForKey: @"SmallView"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2010-03-20 05:09:34 +00:00
|
|
|
//bar
|
2010-03-28 01:29:40 +00:00
|
|
|
[self drawBar: minimal ? [self barRectMinForBounds: cellFrame] : [self barRectRegForBounds: cellFrame]];
|
2010-03-20 05:09:34 +00:00
|
|
|
|
2007-12-18 17:05:49 +00:00
|
|
|
//group coloring
|
2009-12-20 21:02:58 +00:00
|
|
|
const NSRect iconRect = [self iconRectForBounds: cellFrame];
|
2007-12-18 17:05:49 +00:00
|
|
|
|
2009-12-20 21:02:58 +00:00
|
|
|
const NSInteger 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
|
|
|
}
|
2009-12-20 21:02:58 +00:00
|
|
|
const CGFloat radius = minimal ? 3.0 : 6.0;
|
2007-12-18 21:32:55 +00:00
|
|
|
|
2008-05-27 16:07:12 +00:00
|
|
|
NSColor * groupColor = [[GroupsController groups] colorForIndex: groupValue],
|
2009-12-20 21:02:58 +00:00
|
|
|
* darkGroupColor = [groupColor blendedColorWithFraction: 0.2 ofColor: [NSColor whiteColor]];
|
2008-05-14 21:35:37 +00:00
|
|
|
|
|
|
|
//border
|
2008-12-26 05:57:51 +00:00
|
|
|
NSBezierPath * bp = [NSBezierPath bezierPathWithRoundedRect: groupRect xRadius: radius yRadius: radius];
|
2008-05-27 16:07:12 +00:00
|
|
|
[darkGroupColor set];
|
2009-12-20 21:02:58 +00:00
|
|
|
[bp setLineWidth: 2.0];
|
2008-05-27 16:07:12 +00:00
|
|
|
[bp stroke];
|
2008-05-14 21:35:37 +00:00
|
|
|
|
|
|
|
//inside
|
2008-12-26 05:57:51 +00:00
|
|
|
bp = [NSBezierPath bezierPathWithRoundedRect: groupRect xRadius: radius yRadius: radius];
|
2009-12-20 21:02:58 +00:00
|
|
|
NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: [groupColor blendedColorWithFraction: 0.7
|
2008-05-27 16:07:12 +00:00
|
|
|
ofColor: [NSColor whiteColor]] endingColor: darkGroupColor];
|
2009-12-20 21:02:58 +00:00
|
|
|
[gradient drawInBezierPath: bp angle: 90.0];
|
2008-12-26 05:57:51 +00:00
|
|
|
[gradient release];
|
2007-12-18 21:32:55 +00:00
|
|
|
}
|
2007-12-18 01:44:37 +00:00
|
|
|
|
2009-10-17 17:15:37 +00:00
|
|
|
const BOOL error = [torrent isAnyErrorOrWarning];
|
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
|
|
|
|
{
|
2009-10-03 14:10:52 +00:00
|
|
|
NSImage * icon = (minimal && error) ? [NSImage imageNamed: [NSApp isOnSnowLeopardOrBetter] ? NSImageNameCaution : @"Error.png"]
|
|
|
|
: [torrent icon];
|
2009-08-29 20:28:52 +00:00
|
|
|
[self drawImage: icon inRect: iconRect];
|
2008-01-16 06:26:52 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-03 14:10:52 +00:00
|
|
|
//error badge
|
2007-09-16 01:02:06 +00:00
|
|
|
if (error && !minimal)
|
|
|
|
{
|
2009-08-29 20:37:29 +00:00
|
|
|
NSRect errorRect = NSMakeRect(NSMaxX(iconRect) - ERROR_IMAGE_SIZE, NSMaxY(iconRect) - ERROR_IMAGE_SIZE,
|
|
|
|
ERROR_IMAGE_SIZE, ERROR_IMAGE_SIZE);
|
2009-10-03 14:10:52 +00:00
|
|
|
[self drawImage: [NSImage imageNamed: [NSApp isOnSnowLeopardOrBetter] ? NSImageNameCaution : @"Error.png"] inRect: errorRect];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//text color
|
2007-12-18 01:44:37 +00:00
|
|
|
NSColor * titleColor, * statusColor;
|
2009-01-02 01:10:54 +00:00
|
|
|
if ([self backgroundStyle] == NSBackgroundStyleDark)
|
2009-01-02 02:41:54 +00:00
|
|
|
titleColor = statusColor = [NSColor whiteColor];
|
2007-12-18 01:44:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
titleColor = [NSColor controlTextColor];
|
|
|
|
statusColor = [NSColor darkGrayColor];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-09-28 17:42:24 +00:00
|
|
|
[fTitleAttributes setObject: titleColor forKey: NSForegroundColorAttributeName];
|
|
|
|
[fStatusAttributes setObject: statusColor forKey: NSForegroundColorAttributeName];
|
|
|
|
|
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
|
|
|
{
|
2009-09-28 17:42:24 +00:00
|
|
|
NSAttributedString * minimalString = [self attributedStatusString: [self minimalStatusString]];
|
2010-03-20 22:24:54 +00:00
|
|
|
NSRect minimalStatusRect = [self rectForMinimalStatusWithString: minimalString inBounds: cellFrame];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2010-03-20 22:24:54 +00:00
|
|
|
if (!fHover)
|
|
|
|
[minimalString drawInRect: minimalStatusRect];
|
|
|
|
|
|
|
|
minimalTitleRightBound = NSMinX(minimalStatusRect);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//progress
|
|
|
|
if (!minimal)
|
|
|
|
{
|
2009-09-28 17:42:24 +00:00
|
|
|
NSAttributedString * progressString = [self attributedStatusString: [torrent progressString]];
|
2009-12-13 03:13:34 +00:00
|
|
|
NSRect progressRect = [self rectForProgressWithStringInBounds: cellFrame];
|
2008-01-22 05:19:18 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[progressString drawInRect: progressRect];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
NSString * controlImageSuffix;
|
|
|
|
if (fMouseDownControlButton)
|
|
|
|
controlImageSuffix = @"On.png";
|
|
|
|
else if (!fTracking && fHoverControl)
|
|
|
|
controlImageSuffix = @"Hover.png";
|
|
|
|
else
|
|
|
|
controlImageSuffix = @"Off.png";
|
|
|
|
|
|
|
|
NSImage * controlImage;
|
|
|
|
if ([torrent isActive])
|
2008-01-14 18:02:08 +00:00
|
|
|
controlImage = [NSImage imageNamed: [@"Pause" stringByAppendingString: controlImageSuffix]];
|
|
|
|
else
|
2010-03-20 03:27:17 +00:00
|
|
|
{
|
|
|
|
if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
|
|
|
|
controlImage = [NSImage imageNamed: [@"ResumeNoWait" stringByAppendingString: controlImageSuffix]];
|
|
|
|
else if ([torrent waitingToStart])
|
|
|
|
controlImage = [NSImage imageNamed: [@"Pause" stringByAppendingString: controlImageSuffix]];
|
|
|
|
else
|
|
|
|
controlImage = [NSImage imageNamed: [@"Resume" stringByAppendingString: controlImageSuffix]];
|
|
|
|
}
|
|
|
|
|
2010-03-20 18:54:24 +00:00
|
|
|
const NSRect controlRect = [self controlButtonRectForBounds: cellFrame];
|
|
|
|
[self drawImage: controlImage inRect: controlRect];
|
2010-03-20 22:24:54 +00:00
|
|
|
minimalTitleRightBound = MIN(minimalTitleRightBound, NSMinX(controlRect));
|
2010-03-20 03:27:17 +00:00
|
|
|
|
|
|
|
//reveal button
|
|
|
|
NSString * revealImageString;
|
|
|
|
if (fMouseDownRevealButton)
|
|
|
|
revealImageString = @"RevealOn.png";
|
|
|
|
else if (!fTracking && fHoverReveal)
|
|
|
|
revealImageString = @"RevealHover.png";
|
|
|
|
else
|
|
|
|
revealImageString = @"RevealOff.png";
|
|
|
|
|
|
|
|
NSImage * revealImage = [NSImage imageNamed: revealImageString];
|
|
|
|
[self drawImage: revealImage inRect: [self revealButtonRectForBounds: cellFrame]];
|
|
|
|
|
|
|
|
//action button
|
|
|
|
NSString * actionImageString;
|
|
|
|
if (fMouseDownActionButton)
|
|
|
|
actionImageString = @"ActionOn.png";
|
|
|
|
else if (!fTracking && fHoverAction)
|
|
|
|
actionImageString = @"ActionHover.png";
|
|
|
|
else
|
|
|
|
actionImageString = nil;
|
|
|
|
|
|
|
|
if (actionImageString)
|
|
|
|
{
|
|
|
|
NSImage * actionImage = [NSImage imageNamed: actionImageString];
|
|
|
|
[self drawImage: actionImage inRect: [self actionButtonRectForBounds: cellFrame]];
|
|
|
|
}
|
2008-01-15 05:09:46 +00:00
|
|
|
}
|
2008-01-14 19:12:26 +00:00
|
|
|
|
2010-03-20 18:54:24 +00:00
|
|
|
//title
|
|
|
|
NSAttributedString * titleString = [self attributedTitle];
|
2010-03-20 22:24:54 +00:00
|
|
|
NSRect titleRect = [self rectForTitleWithString: titleString withRightBound: minimalTitleRightBound inBounds: cellFrame];
|
2010-03-20 18:54:24 +00:00
|
|
|
[titleString drawInRect: titleRect];
|
|
|
|
|
|
|
|
//priority icon
|
|
|
|
if ([torrent priority] != TR_PRI_NORMAL)
|
|
|
|
{
|
|
|
|
NSImage * priorityImage = [torrent priority] == TR_PRI_HIGH ? [NSImage imageNamed: @"PriorityHigh.png"]
|
|
|
|
: [NSImage imageNamed: @"PriorityLow.png"];
|
|
|
|
//take line out completely when 10.6-only
|
|
|
|
priorityImage = [NSApp isOnSnowLeopardOrBetter] ? [priorityImage retain] : [priorityImage copy];
|
|
|
|
|
|
|
|
NSRect priorityRect = NSMakeRect(NSMaxX(titleRect) + PADDING_BETWEEN_TITLE_AND_PRIORITY,
|
|
|
|
NSMidY(titleRect) - PRIORITY_ICON_HEIGHT * 0.5,
|
|
|
|
PRIORITY_ICON_WIDTH, PRIORITY_ICON_HEIGHT);
|
|
|
|
|
|
|
|
[self drawImage: priorityImage inRect: priorityRect];
|
|
|
|
[priorityImage release];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//status
|
|
|
|
if (!minimal)
|
|
|
|
{
|
2009-09-28 17:42:24 +00:00
|
|
|
NSAttributedString * statusString = [self attributedStatusString: [self statusString]];
|
2009-12-13 03:13:34 +00:00
|
|
|
[statusString drawInRect: [self rectForStatusWithStringInBounds: cellFrame]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentCell (Private)
|
|
|
|
|
2007-09-26 19:36:25 +00:00
|
|
|
- (void) drawBar: (NSRect) barRect
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2010-03-20 03:51:29 +00:00
|
|
|
const BOOL minimal = [fDefaults boolForKey: @"SmallView"];
|
|
|
|
|
2009-09-07 06:05:48 +00:00
|
|
|
const CGFloat piecesBarPercent = [(TorrentTableView *)[self controlView] piecesBarPercent];
|
2010-03-20 18:09:45 +00:00
|
|
|
if (piecesBarPercent > 0.0 && (!minimal || [NSApp isOnSnowLeopardOrBetter]))
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2009-09-07 06:05:48 +00:00
|
|
|
NSRect piecesBarRect, regularBarRect;
|
2009-11-07 23:20:41 +00:00
|
|
|
NSDivideRect(barRect, &piecesBarRect, ®ularBarRect, floor(NSHeight(barRect) * PIECES_TOTAL_PERCENT * piecesBarPercent),
|
2009-09-07 06:05:48 +00:00
|
|
|
NSMaxYEdge);
|
2008-01-16 15:56:40 +00:00
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
[self drawRegularBar: regularBarRect];
|
|
|
|
[self drawPiecesBar: piecesBarRect];
|
|
|
|
}
|
|
|
|
else
|
2007-11-05 00:04:14 +00:00
|
|
|
{
|
2008-06-11 16:28:33 +00:00
|
|
|
[[self representedObject] setPreviousFinishedPieces: nil];
|
2007-11-05 00:04:14 +00:00
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
[self drawRegularBar: barRect];
|
2007-11-05 00:04:14 +00:00
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
|
2010-03-20 18:09:45 +00:00
|
|
|
NSColor * borderColor = minimal ? fBarMinimalBorderColor : fBarBorderColor;
|
|
|
|
[borderColor set];
|
|
|
|
[NSBezierPath strokeRect: NSInsetRect(barRect, 0.5, 0.5)];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRegularBar: (NSRect) barRect
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
2009-09-07 05:40:09 +00:00
|
|
|
NSRect haveRect, missingRect;
|
2009-11-07 23:20:41 +00:00
|
|
|
NSDivideRect(barRect, &haveRect, &missingRect, round([torrent progress] * NSWidth(barRect)), NSMinXEdge);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-09-07 05:40:09 +00:00
|
|
|
if (!NSIsEmptyRect(haveRect))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if ([torrent isActive])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if ([torrent isChecking])
|
2009-09-07 05:40:09 +00:00
|
|
|
[[ProgressGradients progressYellowGradient] drawInRect: haveRect angle: 90];
|
2007-09-26 17:30:54 +00:00
|
|
|
else if ([torrent isSeeding])
|
|
|
|
{
|
2009-09-06 21:09:33 +00:00
|
|
|
NSRect ratioHaveRect, ratioRemainingRect;
|
2009-11-07 23:20:41 +00:00
|
|
|
NSDivideRect(haveRect, &ratioHaveRect, &ratioRemainingRect, round([torrent progressStopRatio] * NSWidth(haveRect)),
|
2009-09-07 05:40:09 +00:00
|
|
|
NSMinXEdge);
|
2007-09-26 17:30:54 +00:00
|
|
|
|
2009-09-06 21:09:33 +00:00
|
|
|
[[ProgressGradients progressGreenGradient] drawInRect: ratioHaveRect angle: 90];
|
|
|
|
[[ProgressGradients progressLightGreenGradient] drawInRect: ratioRemainingRect angle: 90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
2009-09-07 05:40:09 +00:00
|
|
|
[[ProgressGradients progressBlueGradient] drawInRect: haveRect angle: 90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if ([torrent waitingToStart])
|
|
|
|
{
|
2009-09-07 05:40:09 +00:00
|
|
|
if ([torrent allDownloaded])
|
|
|
|
[[ProgressGradients progressDarkGreenGradient] drawInRect: haveRect angle: 90];
|
2007-09-26 17:30:54 +00:00
|
|
|
else
|
2009-09-07 05:40:09 +00:00
|
|
|
[[ProgressGradients progressDarkBlueGradient] drawInRect: haveRect angle: 90];
|
2007-09-26 17:30:54 +00:00
|
|
|
}
|
|
|
|
else
|
2009-09-07 05:40:09 +00:00
|
|
|
[[ProgressGradients progressGrayGradient] drawInRect: haveRect angle: 90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-07 05:40:09 +00:00
|
|
|
|
2009-11-27 03:20:19 +00:00
|
|
|
if (![torrent allDownloaded])
|
2009-09-07 05:40:09 +00:00
|
|
|
{
|
2009-11-07 23:20:41 +00:00
|
|
|
const CGFloat widthRemaining = round(NSWidth(barRect) * [torrent progressLeft]);
|
2009-11-07 04:08:42 +00:00
|
|
|
|
|
|
|
NSRect wantedRect;
|
|
|
|
NSDivideRect(missingRect, &wantedRect, &missingRect, widthRemaining, NSMinXEdge);
|
|
|
|
|
|
|
|
//not-available section
|
2009-12-12 04:39:43 +00:00
|
|
|
if ([torrent isActive] && ![torrent isChecking] && [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;
|
2009-11-07 23:20:41 +00:00
|
|
|
NSDivideRect(wantedRect, &wantedRect, &unavailableRect, round(NSWidth(wantedRect) * [torrent availableDesired]),
|
2009-11-07 04:08:42 +00:00
|
|
|
NSMinXEdge);
|
2009-09-07 05:40:09 +00:00
|
|
|
|
2009-11-07 04:08:42 +00:00
|
|
|
[[ProgressGradients progressRedGradient] drawInRect: unavailableRect angle: 90];
|
2009-09-07 05:40:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-07 04:08:42 +00:00
|
|
|
//remaining section
|
|
|
|
[[ProgressGradients progressWhiteGradient] drawInRect: wantedRect angle: 90];
|
2009-09-07 05:40:09 +00:00
|
|
|
}
|
2009-11-07 04:08:42 +00:00
|
|
|
|
|
|
|
//unwanted section
|
|
|
|
if (!NSIsEmptyRect(missingRect))
|
2009-11-26 16:58:44 +00:00
|
|
|
{
|
|
|
|
if (![torrent isMagnet])
|
|
|
|
[[ProgressGradients progressLightGrayGradient] drawInRect: missingRect angle: 90];
|
|
|
|
else
|
|
|
|
[[ProgressGradients progressRedGradient] drawInRect: missingRect angle: 90];
|
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawPiecesBar: (NSRect) barRect
|
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
2010-03-07 02:46:49 +00:00
|
|
|
//fill an all-white bar for magnet links
|
|
|
|
if ([torrent isMagnet])
|
|
|
|
{
|
|
|
|
[[NSColor whiteColor] set];
|
|
|
|
NSRectFill(barRect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
NSInteger pieceCount = MIN([torrent pieceCount], MAX_PIECES);
|
2008-11-02 14:04:57 +00:00
|
|
|
float * piecesPercent = malloc(pieceCount * sizeof(float));
|
2008-06-10 21:13:33 +00:00
|
|
|
[torrent getAmountFinished: piecesPercent size: pieceCount];
|
2007-11-04 15:01:34 +00:00
|
|
|
|
2008-05-27 05:27:42 +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];
|
|
|
|
|
2008-06-11 16:28:33 +00:00
|
|
|
NSIndexSet * previousFinishedIndexes = [torrent previousFinishedPieces];
|
|
|
|
NSMutableIndexSet * finishedIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSInteger i = 0; i < pieceCount; i++)
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2008-05-27 05:27:42 +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
|
|
|
{
|
|
|
|
if (previousFinishedIndexes && ![previousFinishedIndexes containsIndex: i])
|
|
|
|
pieceColor = [NSColor orangeColor];
|
|
|
|
else
|
|
|
|
pieceColor = fBluePieceColor;
|
|
|
|
[finishedIndexes addIndex: i];
|
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
else
|
2008-06-10 21:13:33 +00:00
|
|
|
pieceColor = [[NSColor whiteColor] blendedColorWithFraction: piecesPercent[i] ofColor: fBluePieceColor];
|
2007-11-04 15:01:34 +00:00
|
|
|
|
2008-05-27 04:49:08 +00:00
|
|
|
//it's faster to just set color instead of checking previous color
|
2008-05-27 05:08:09 +00:00
|
|
|
[bitmap setColor: pieceColor atX: i y: 0];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
2008-06-11 16:28:33 +00:00
|
|
|
free(piecesPercent);
|
|
|
|
|
|
|
|
[torrent setPreviousFinishedPieces: [finishedIndexes count] > 0 ? finishedIndexes : nil]; //don't bother saving if none are complete
|
2007-11-04 15:01:34 +00:00
|
|
|
|
|
|
|
//actually draw image
|
2010-03-20 03:51:29 +00:00
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
|
|
|
[bitmap drawInRect: barRect fromRect: NSZeroRect operation: NSCompositeSourceOver
|
|
|
|
fraction: ([fDefaults boolForKey: @"SmallView"] ? 0.125 : 1.0) respectFlipped: YES hints: nil];
|
|
|
|
else
|
|
|
|
[bitmap drawInRect: barRect];
|
|
|
|
|
2008-05-27 05:08:09 +00:00
|
|
|
[bitmap release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForMinimalStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
2009-10-09 23:02:10 +00:00
|
|
|
NSRect result;
|
|
|
|
result.size = [string size];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2010-03-20 18:09:45 +00:00
|
|
|
result.origin.x = NSMaxX(bounds) - (NSWidth(result) + PADDING_HORIZONTAL * 2.0);
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = ceil(NSMidY(bounds) - NSHeight(result) * 0.5);
|
2009-10-09 23:44:18 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-03-20 18:54:24 +00:00
|
|
|
- (NSRect) rectForTitleWithString: (NSAttributedString *) string withRightBound: (CGFloat) rightBound inBounds: (NSRect) bounds
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-04-20 02:45:27 +00:00
|
|
|
const BOOL minimal = [fDefaults boolForKey: @"SmallView"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-09 23:02:10 +00:00
|
|
|
NSRect result;
|
|
|
|
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;
|
2010-03-21 14:59:46 +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
|
|
|
}
|
2010-03-20 18:54:24 +00:00
|
|
|
|
2009-12-13 21:42:45 +00:00
|
|
|
if ([[self representedObject] priority] != TR_PRI_NORMAL)
|
2009-12-14 23:47:15 +00:00
|
|
|
{
|
2009-12-13 21:42:45 +00:00
|
|
|
result.size.width -= PRIORITY_ICON_WIDTH + PADDING_BETWEEN_TITLE_AND_PRIORITY;
|
2009-12-20 21:02:58 +00:00
|
|
|
result.size.width = MIN(NSWidth(result), [string size].width); //only need to force it smaller for the priority icon
|
2009-12-14 23:47:15 +00:00
|
|
|
}
|
2009-12-14 13:20:36 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-12-13 03:13:34 +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;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-12-13 03:13:34 +00:00
|
|
|
result.size.height = HEIGHT_STATUS;
|
|
|
|
result.size.width = NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONTAL;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-12-13 03:13:34 +00:00
|
|
|
- (NSRect) rectForStatusWithStringInBounds: (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 + HEIGHT_STATUS
|
2007-09-16 01:02:06 +00:00
|
|
|
+ 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;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-12-13 03:13:34 +00:00
|
|
|
result.size.height = HEIGHT_STATUS;
|
|
|
|
result.size.width = NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONTAL;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-03-28 01:29:40 +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;
|
|
|
|
result.origin.x = NSMinX(bounds) + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_BAR;
|
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE + PADDING_BETWEEN_TITLE_AND_PROGRESS
|
|
|
|
+ HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
2009-12-12 03:11:48 +00:00
|
|
|
|
2010-03-28 01:29:40 +00:00
|
|
|
result.size.width = floor(NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONTAL
|
|
|
|
- 2.0 * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) barRectMinForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result;
|
|
|
|
result.origin.x = NSMinX(bounds) + IMAGE_SIZE_MIN + PADDING_BETWEEN_IMAGE_AND_BAR;
|
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_BETWEEN_BAR_AND_EDGE_MIN;
|
|
|
|
result.size.height = NSHeight(bounds) - 2.0 * PADDING_BETWEEN_BAR_AND_EDGE_MIN;
|
|
|
|
result.size.width = NSMaxX(bounds) - NSMinX(result) - PADDING_HORIZONTAL;
|
2010-03-20 18:09:45 +00:00
|
|
|
|
|
|
|
return result;
|
2009-12-12 03:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) controlButtonRectForBounds: (NSRect) bounds
|
|
|
|
{
|
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;
|
2009-12-20 21:02:58 +00:00
|
|
|
result.origin.x = NSMaxX(bounds) - 2.0 * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
|
2009-12-12 03:11:48 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
2010-03-20 18:09:45 +00:00
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5
|
2010-03-20 03:27:17 +00:00
|
|
|
+ PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
2010-03-20 18:09:45 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = ceil(NSMidY(bounds) - NSHeight(result) * 0.5);
|
2010-03-20 18:09:45 +00:00
|
|
|
result.origin.x -= PADDING_HORIZONTAL;
|
|
|
|
}
|
2009-12-12 03:11:48 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) revealButtonRectForBounds: (NSRect) bounds
|
|
|
|
{
|
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);
|
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
2010-03-20 18:09:45 +00:00
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5
|
2010-03-20 03:27:17 +00:00
|
|
|
+ PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
2010-03-20 18:09:45 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-21 14:59:46 +00:00
|
|
|
result.origin.y = ceil(NSMidY(bounds) - NSHeight(result) * 0.5);
|
2010-03-20 18:09:45 +00:00
|
|
|
result.origin.x -= PADDING_HORIZONTAL;
|
|
|
|
}
|
2009-12-12 03:11:48 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) actionButtonRectForBounds: (NSRect) bounds
|
|
|
|
{
|
2009-12-20 21:02:58 +00:00
|
|
|
const NSRect iconRect = [self iconRectForBounds: bounds];
|
2009-12-12 03:11:48 +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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-28 17:42:24 +00:00
|
|
|
- (NSAttributedString *) attributedTitle
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSString * title = [[self representedObject] name];
|
|
|
|
return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
|
|
|
|
}
|
|
|
|
|
2009-09-28 17:42:24 +00:00
|
|
|
- (NSAttributedString *) attributedStatusString: (NSString *) string
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return [[[NSAttributedString alloc] initWithString: string attributes: fStatusAttributes] autorelease];
|
|
|
|
}
|
|
|
|
|
2008-01-15 21:20:16 +00:00
|
|
|
- (NSString *) buttonString
|
2008-01-15 21:09:51 +00:00
|
|
|
{
|
|
|
|
if (fMouseDownRevealButton || (!fTracking && fHoverReveal))
|
2009-10-15 23:41:28 +00:00
|
|
|
return NSLocalizedString(@"Show the data file in Finder", "Torrent cell -> button info");
|
2008-01-15 21:09:51 +00:00
|
|
|
else if (fMouseDownControlButton || (!fTracking && fHoverControl))
|
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
if ([torrent isActive])
|
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
|
|
|
|
{
|
2008-12-21 02:45:55 +00:00
|
|
|
if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
|
2008-01-15 21:09:51 +00:00
|
|
|
return NSLocalizedString(@"Resume the transfer right away", "Torrent cell -> button info");
|
|
|
|
else if ([torrent waitingToStart])
|
|
|
|
return NSLocalizedString(@"Stop waiting to start", "Torrent cell -> button info");
|
|
|
|
else
|
|
|
|
return NSLocalizedString(@"Resume the transfer", "Torrent cell -> button info");
|
|
|
|
}
|
|
|
|
}
|
2008-01-15 23:48:03 +00:00
|
|
|
else if (!fTracking && fHoverAction)
|
|
|
|
return NSLocalizedString(@"Change transfer settings", "Torrent Table -> tooltip");
|
2008-01-15 21:20:16 +00:00
|
|
|
else
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) statusString
|
|
|
|
{
|
|
|
|
NSString * buttonString;
|
|
|
|
if ((buttonString = [self buttonString]))
|
|
|
|
return buttonString;
|
2008-01-15 21:09:51 +00:00
|
|
|
else
|
|
|
|
return [[self representedObject] statusString];
|
|
|
|
}
|
|
|
|
|
2008-01-15 21:20:16 +00:00
|
|
|
- (NSString *) minimalStatusString
|
|
|
|
{
|
2010-03-20 22:42:33 +00:00
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
return [fDefaults boolForKey: @"DisplaySmallStatusRegular"] ? [torrent shortStatusString] : [torrent remainingTimeString];
|
2008-01-15 21:20:16 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 20:28:52 +00:00
|
|
|
- (void) drawImage: (NSImage *) image inRect: (NSRect) rect
|
|
|
|
{
|
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
|
|
|
[image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0 respectFlipped: YES hints: nil];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[image setFlipped: YES];
|
|
|
|
[image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|