2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2009-01-10 23:37:37 +00:00
|
|
|
* Copyright (c) 2006-2009 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"
|
|
|
|
#import "TorrentTableView.h"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2008-10-31 00:13:50 +00:00
|
|
|
#import "ProgressGradients.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
#define BAR_HEIGHT 12.0f
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
#define IMAGE_SIZE_REG 32.0f
|
|
|
|
#define IMAGE_SIZE_MIN 16.0f
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
#define NORMAL_BUTTON_WIDTH 14.0f
|
|
|
|
#define ACTION_BUTTON_WIDTH 16.0f
|
2008-01-14 18:02:08 +00:00
|
|
|
|
|
|
|
//ends up being larger than font height
|
2008-10-25 21:34:30 +00:00
|
|
|
#define HEIGHT_TITLE 16.0f
|
|
|
|
#define HEIGHT_STATUS 12.0f
|
|
|
|
|
|
|
|
#define PADDING_HORIZONTAL 3.0f
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0f
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0f
|
|
|
|
#define PADDING_ABOVE_TITLE 4.0f
|
|
|
|
#define PADDING_ABOVE_MIN_STATUS 4.0f
|
|
|
|
#define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 2.0f
|
|
|
|
#define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0f
|
|
|
|
#define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0f
|
|
|
|
#define PADDING_BETWEEN_TITLE_AND_BAR_MIN 3.0f
|
|
|
|
#define PADDING_BETWEEN_BAR_AND_STATUS 2.0f
|
|
|
|
|
|
|
|
#define PIECES_TOTAL_PERCENT 0.6f
|
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;
|
|
|
|
- (NSRect) rectForTitleWithString: (NSAttributedString *) string basedOnMinimalStatusRect: (NSRect) statusRect
|
|
|
|
inBounds: (NSRect) bounds;
|
|
|
|
- (NSRect) rectForProgressWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
|
|
|
|
- (NSRect) rectForStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
|
|
|
|
|
|
|
|
- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color;
|
|
|
|
- (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color;
|
|
|
|
|
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
|
|
|
|
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];
|
|
|
|
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
|
|
|
|
|
|
|
|
fTitleAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
2008-10-25 21:34:30 +00:00
|
|
|
[NSFont messageFontOfSize: 12.0f], NSFontAttributeName,
|
2007-09-16 01:02:06 +00:00
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
|
|
|
fStatusAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
2008-10-25 21:34:30 +00:00
|
|
|
[NSFont messageFontOfSize: 9.0f], NSFontAttributeName,
|
2007-09-16 01:02:06 +00:00
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
|
|
|
[paragraphStyle release];
|
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
fBluePieceColor = [[NSColor colorWithCalibratedRed: 0.0f green: 0.4f blue: 0.8f alpha: 1.0f] retain];
|
2008-11-15 19:47:57 +00:00
|
|
|
fBarBorderColor = [[NSColor colorWithCalibratedWhite: 0.0f alpha: 0.2f] retain];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) iconRectForBounds: (NSRect) bounds
|
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
CGFloat imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
|
2008-01-16 06:22:47 +00:00
|
|
|
|
2008-01-16 06:48:12 +00:00
|
|
|
NSRect result = bounds;
|
2008-01-14 18:02:08 +00:00
|
|
|
result.origin.x += PADDING_HORIZONTAL;
|
2008-10-25 21:34:30 +00:00
|
|
|
result.origin.y += floorf((result.size.height - imageSize) * 0.5f);
|
2008-01-16 06:22:47 +00:00
|
|
|
result.size = NSMakeSize(imageSize, imageSize);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) titleRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
return [self rectForTitleWithString: [self attributedTitleWithColor: nil]
|
|
|
|
basedOnMinimalStatusRect: [self minimalStatusRectForBounds: bounds] inBounds: bounds];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) minimalStatusRectForBounds: (NSRect) bounds
|
|
|
|
{
|
2008-05-27 06:05:05 +00:00
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
|
|
|
return NSZeroRect;
|
|
|
|
|
2008-01-15 21:20:16 +00:00
|
|
|
return [self rectForMinimalStatusWithString: [self attributedStatusString: [self minimalStatusString] withColor: nil]
|
|
|
|
inBounds: bounds];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) progressRectForBounds: (NSRect) bounds
|
|
|
|
{
|
2008-05-27 06:05:05 +00:00
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
return NSZeroRect;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return [self rectForProgressWithString: [self attributedStatusString: [[self representedObject] progressString] withColor: nil]
|
2008-02-06 23:45:44 +00:00
|
|
|
inBounds: bounds];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) barRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
BOOL minimal = [fDefaults boolForKey: @"SmallView"];
|
|
|
|
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.size.height = BAR_HEIGHT;
|
2008-02-04 13:48:55 +00:00
|
|
|
result.origin.x += (minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG) + PADDING_BETWEEN_IMAGE_AND_BAR;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE;
|
|
|
|
if (minimal)
|
|
|
|
result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN;
|
|
|
|
else
|
|
|
|
result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
result.size.width = round(NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL - 2.0f * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH));
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) statusRectForBounds: (NSRect) bounds
|
|
|
|
{
|
2008-05-27 06:05:05 +00:00
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
return NSZeroRect;
|
|
|
|
|
2008-01-15 21:09:51 +00:00
|
|
|
return [self rectForStatusWithString: [self attributedStatusString: [self statusString] withColor: nil] inBounds: bounds];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
- (NSRect) controlButtonRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.size.height = NORMAL_BUTTON_WIDTH;
|
|
|
|
result.size.width = NORMAL_BUTTON_WIDTH;
|
2008-10-25 21:34:30 +00:00
|
|
|
result.origin.x = NSMaxX(bounds) - 2.0f * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
|
2008-01-14 18:02:08 +00:00
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f;
|
2008-01-14 18:02:08 +00:00
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN;
|
|
|
|
else
|
|
|
|
result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) revealButtonRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.size.height = NORMAL_BUTTON_WIDTH;
|
|
|
|
result.size.width = NORMAL_BUTTON_WIDTH;
|
|
|
|
result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH);
|
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f;
|
2008-01-14 18:02:08 +00:00
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN;
|
|
|
|
else
|
|
|
|
result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-01-14 19:12:26 +00:00
|
|
|
- (NSRect) actionButtonRectForBounds: (NSRect) bounds
|
|
|
|
{
|
2008-03-23 18:47:35 +00:00
|
|
|
NSRect result = [self iconRectForBounds: bounds];
|
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
result.origin.x += (result.size.width - ACTION_BUTTON_WIDTH) * 0.5f;
|
|
|
|
result.origin.y += (result.size.height - ACTION_BUTTON_WIDTH) * 0.5f;
|
2008-03-23 18:47:35 +00:00
|
|
|
result.size.width = ACTION_BUTTON_WIDTH;
|
|
|
|
result.size.height = ACTION_BUTTON_WIDTH;
|
|
|
|
}
|
2008-01-16 06:22:47 +00:00
|
|
|
|
2008-01-14 19:12:26 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
NSRect controlRect= [self controlButtonRectForBounds: cellFrame];
|
|
|
|
BOOL checkControl = NSMouseInRect(point, controlRect, [controlView isFlipped]);
|
|
|
|
|
|
|
|
NSRect revealRect = [self revealButtonRectForBounds: cellFrame];
|
|
|
|
BOOL checkReveal = NSMouseInRect(point, revealRect, [controlView isFlipped]);
|
|
|
|
|
2008-01-15 16:19:16 +00:00
|
|
|
[(TorrentTableView *)controlView removeButtonTrackingAreas];
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
while ([event type] != NSLeftMouseUp)
|
|
|
|
{
|
|
|
|
point = [controlView convertPoint: [event locationInWindow] fromView: nil];
|
|
|
|
|
|
|
|
if (checkControl)
|
|
|
|
{
|
|
|
|
BOOL inControlButton = NSMouseInRect(point, controlRect, [controlView isFlipped]);
|
|
|
|
if (fMouseDownControlButton != inControlButton)
|
|
|
|
{
|
|
|
|
fMouseDownControlButton = inControlButton;
|
|
|
|
[controlView setNeedsDisplayInRect: cellFrame];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (checkReveal)
|
|
|
|
{
|
|
|
|
BOOL inRevealButton = NSMouseInRect(point, revealRect, [controlView isFlipped]);
|
|
|
|
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];
|
|
|
|
|
|
|
|
[[self representedObject] revealData];
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
|
|
|
NSTrackingAreaOptions options = NSTrackingEnabledDuringMouseDrag | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
|
|
|
|
|
|
|
|
//control button
|
|
|
|
NSRect controlButtonRect = [self controlButtonRectForBounds: cellFrame];
|
|
|
|
NSTrackingAreaOptions controlOptions = options;
|
|
|
|
if (NSMouseInRect(mouseLocation, controlButtonRect, [controlView isFlipped]))
|
|
|
|
{
|
|
|
|
controlOptions |= NSTrackingAssumeInside;
|
2008-01-15 19:48:19 +00:00
|
|
|
[(TorrentTableView *)controlView setControlButtonHover: [[userInfo objectForKey: @"Row"] intValue]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary * controlInfo = [userInfo mutableCopy];
|
|
|
|
[controlInfo setObject: @"Control" forKey: @"Type"];
|
|
|
|
NSTrackingArea * area = [[NSTrackingArea alloc] initWithRect: controlButtonRect options: controlOptions owner: controlView
|
|
|
|
userInfo: controlInfo];
|
|
|
|
[controlView addTrackingArea: area];
|
|
|
|
[controlInfo release];
|
|
|
|
[area release];
|
|
|
|
|
|
|
|
//reveal button
|
|
|
|
NSRect revealButtonRect = [self revealButtonRectForBounds: cellFrame];
|
|
|
|
NSTrackingAreaOptions revealOptions = options;
|
|
|
|
if (NSMouseInRect(mouseLocation, revealButtonRect, [controlView isFlipped]))
|
|
|
|
{
|
|
|
|
revealOptions |= NSTrackingAssumeInside;
|
2008-01-15 19:48:19 +00:00
|
|
|
[(TorrentTableView *)controlView setRevealButtonHover: [[userInfo objectForKey: @"Row"] intValue]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary * revealInfo = [userInfo mutableCopy];
|
|
|
|
[revealInfo setObject: @"Reveal" forKey: @"Type"];
|
|
|
|
area = [[NSTrackingArea alloc] initWithRect: revealButtonRect options: revealOptions owner: controlView userInfo: revealInfo];
|
|
|
|
[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;
|
|
|
|
[(TorrentTableView *)controlView setActionButtonHover: [[userInfo objectForKey: @"Row"] intValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-12-18 17:05:49 +00:00
|
|
|
//group coloring
|
|
|
|
NSRect iconRect = [self iconRectForBounds: cellFrame];
|
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
NSInteger groupValue = [torrent groupValue];
|
2007-12-18 01:44:37 +00:00
|
|
|
if (groupValue != -1)
|
2007-12-18 21:32:55 +00:00
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
NSRect groupRect = NSInsetRect(iconRect, -1.0f, -2.0f);
|
2007-12-18 21:32:55 +00:00
|
|
|
if (!minimal)
|
|
|
|
{
|
|
|
|
groupRect.size.height--;
|
|
|
|
groupRect.origin.y--;
|
|
|
|
}
|
2008-11-04 01:31:24 +00:00
|
|
|
const CGFloat radius = minimal ? 3.0f : 6.0f;
|
2007-12-18 21:32:55 +00:00
|
|
|
|
2008-05-27 16:07:12 +00:00
|
|
|
NSColor * groupColor = [[GroupsController groups] colorForIndex: groupValue],
|
2008-10-25 21:34:30 +00:00
|
|
|
* darkGroupColor = [groupColor blendedColorWithFraction: 0.2f 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];
|
2008-10-25 21:34:30 +00:00
|
|
|
[bp setLineWidth: 2.0f];
|
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];
|
|
|
|
NSGradient * gradient = [[NSGradient alloc] initWithStartingColor: [groupColor blendedColorWithFraction: 0.7f
|
2008-05-27 16:07:12 +00:00
|
|
|
ofColor: [NSColor whiteColor]] endingColor: darkGroupColor];
|
2008-12-26 05:57:51 +00:00
|
|
|
[gradient drawInBezierPath: bp angle: 90.0f];
|
|
|
|
[gradient release];
|
2007-12-18 21:32:55 +00:00
|
|
|
}
|
2007-12-18 01:44:37 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//error image
|
2008-12-21 02:45:55 +00:00
|
|
|
const BOOL error = [torrent isError];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (error && !fErrorImage)
|
|
|
|
{
|
2008-01-07 00:23:15 +00:00
|
|
|
fErrorImage = [NSImage imageNamed: @"Error.png"];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fErrorImage setFlipped: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
//icon
|
2008-01-16 06:26:52 +00:00
|
|
|
if (!minimal || !(!fTracking && fHoverAction)) //don't show in minimal mode when hovered over
|
|
|
|
{
|
2008-01-16 23:17:36 +00:00
|
|
|
NSImage * icon = (minimal && error) ? fErrorImage : [torrent icon];
|
2008-10-25 21:34:30 +00:00
|
|
|
[icon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0f];
|
2008-01-16 06:26:52 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (error && !minimal)
|
|
|
|
{
|
|
|
|
NSRect errorRect = NSMakeRect(NSMaxX(iconRect) - IMAGE_SIZE_MIN, NSMaxY(iconRect) - IMAGE_SIZE_MIN,
|
|
|
|
IMAGE_SIZE_MIN, IMAGE_SIZE_MIN);
|
2008-10-25 21:34:30 +00:00
|
|
|
[fErrorImage drawInRect: errorRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0f];
|
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
|
|
|
|
|
|
|
//minimal status
|
2008-05-10 19:34:17 +00:00
|
|
|
NSRect minimalStatusRect;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (minimal)
|
|
|
|
{
|
2008-01-15 21:20:16 +00:00
|
|
|
NSAttributedString * minimalString = [self attributedStatusString: [self minimalStatusString] withColor: statusColor];
|
2007-09-16 01:02:06 +00:00
|
|
|
minimalStatusRect = [self rectForMinimalStatusWithString: minimalString inBounds: cellFrame];
|
|
|
|
|
|
|
|
[minimalString drawInRect: minimalStatusRect];
|
|
|
|
}
|
|
|
|
|
|
|
|
//title
|
|
|
|
NSAttributedString * titleString = [self attributedTitleWithColor: titleColor];
|
|
|
|
NSRect titleRect = [self rectForTitleWithString: titleString basedOnMinimalStatusRect: minimalStatusRect inBounds: cellFrame];
|
|
|
|
[titleString drawInRect: titleRect];
|
|
|
|
|
|
|
|
//progress
|
|
|
|
if (!minimal)
|
|
|
|
{
|
|
|
|
NSAttributedString * progressString = [self attributedStatusString: [torrent progressString] withColor: statusColor];
|
2007-09-26 23:49:21 +00:00
|
|
|
NSRect progressRect = [self rectForProgressWithString: progressString inBounds: cellFrame];
|
2008-01-22 05:19:18 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[progressString drawInRect: progressRect];
|
|
|
|
}
|
|
|
|
|
|
|
|
//bar
|
2007-11-04 15:01:34 +00:00
|
|
|
[self drawBar: [self barRectForBounds: cellFrame]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
//control button
|
2008-01-15 19:52:17 +00:00
|
|
|
NSString * controlImageSuffix;
|
|
|
|
if (fMouseDownControlButton)
|
|
|
|
controlImageSuffix = @"On.png";
|
|
|
|
else if (!fTracking && fHoverControl)
|
2008-01-16 05:01:45 +00:00
|
|
|
controlImageSuffix = @"Hover.png";
|
2008-01-15 19:52:17 +00:00
|
|
|
else
|
|
|
|
controlImageSuffix = @"Off.png";
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
NSImage * controlImage;
|
|
|
|
if ([torrent isActive])
|
|
|
|
controlImage = [NSImage imageNamed: [@"Pause" stringByAppendingString: controlImageSuffix]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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]];
|
|
|
|
}
|
2008-01-15 04:45:57 +00:00
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
[controlImage setFlipped: YES];
|
|
|
|
[controlImage drawInRect: [self controlButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
|
2008-10-25 21:34:30 +00:00
|
|
|
fraction: 1.0f];
|
2008-01-14 18:02:08 +00:00
|
|
|
|
|
|
|
//reveal button
|
2008-05-27 04:49:08 +00:00
|
|
|
NSString * revealImageString;
|
2008-01-15 19:52:17 +00:00
|
|
|
if (fMouseDownRevealButton)
|
2008-05-27 04:49:08 +00:00
|
|
|
revealImageString = @"RevealOn.png";
|
2008-01-15 19:52:17 +00:00
|
|
|
else if (!fTracking && fHoverReveal)
|
2008-05-27 04:49:08 +00:00
|
|
|
revealImageString = @"RevealHover.png";
|
2008-01-15 19:52:17 +00:00
|
|
|
else
|
2008-05-27 04:49:08 +00:00
|
|
|
revealImageString = @"RevealOff.png";
|
2008-01-15 19:52:17 +00:00
|
|
|
|
2008-05-27 04:49:08 +00:00
|
|
|
NSImage * revealImage = [NSImage imageNamed: revealImageString];
|
2008-01-14 18:02:08 +00:00
|
|
|
[revealImage setFlipped: YES];
|
|
|
|
[revealImage drawInRect: [self revealButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
|
2008-10-25 21:34:30 +00:00
|
|
|
fraction: 1.0f];
|
2008-01-14 18:02:08 +00:00
|
|
|
|
2008-01-14 19:12:26 +00:00
|
|
|
//action button
|
2008-05-27 04:49:08 +00:00
|
|
|
NSString * actionImageString;
|
2008-01-16 19:49:10 +00:00
|
|
|
if (fMouseDownActionButton)
|
2008-05-27 04:49:08 +00:00
|
|
|
actionImageString = @"ActionOn.png";
|
2008-01-16 19:49:10 +00:00
|
|
|
else if (!fTracking && fHoverAction)
|
2008-05-27 04:49:08 +00:00
|
|
|
actionImageString = @"ActionHover.png";
|
2008-01-16 06:22:47 +00:00
|
|
|
else
|
2008-05-27 04:49:08 +00:00
|
|
|
actionImageString = nil;
|
2008-01-16 06:22:47 +00:00
|
|
|
|
2008-05-27 04:49:08 +00:00
|
|
|
if (actionImageString)
|
2008-01-15 05:09:46 +00:00
|
|
|
{
|
2008-05-27 04:49:08 +00:00
|
|
|
NSImage * actionImage = [NSImage imageNamed: actionImageString];
|
2008-01-15 05:09:46 +00:00
|
|
|
[actionImage setFlipped: YES];
|
|
|
|
[actionImage drawInRect: [self actionButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
|
2008-10-25 21:34:30 +00:00
|
|
|
fraction: 1.0f];
|
2008-01-15 05:09:46 +00:00
|
|
|
}
|
2008-01-14 19:12:26 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//status
|
|
|
|
if (!minimal)
|
|
|
|
{
|
2008-01-15 21:09:51 +00:00
|
|
|
NSAttributedString * statusString = [self attributedStatusString: [self statusString] withColor: statusColor];
|
2007-09-16 01:02:06 +00:00
|
|
|
[statusString drawInRect: [self rectForStatusWithString: statusString inBounds: cellFrame]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentCell (Private)
|
|
|
|
|
2007-09-26 19:36:25 +00:00
|
|
|
- (void) drawBar: (NSRect) barRect
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
CGFloat piecesBarPercent = [(TorrentTableView *)[self controlView] piecesBarPercent];
|
|
|
|
if (piecesBarPercent > 0.0f)
|
2007-11-04 15:01:34 +00:00
|
|
|
{
|
|
|
|
NSRect regularBarRect = barRect, piecesBarRect = barRect;
|
2008-01-16 19:30:12 +00:00
|
|
|
piecesBarRect.size.height *= PIECES_TOTAL_PERCENT * piecesBarPercent;
|
2008-01-16 15:56:40 +00:00
|
|
|
regularBarRect.size.height -= piecesBarRect.size.height;
|
|
|
|
piecesBarRect.origin.y += regularBarRect.size.height;
|
|
|
|
|
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
|
|
|
|
2008-05-27 16:07:12 +00:00
|
|
|
[fBarBorderColor set];
|
2008-10-25 21:34:30 +00:00
|
|
|
[NSBezierPath strokeRect: NSInsetRect(barRect, 0.5f, 0.5f)];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRegularBar: (NSRect) barRect
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
NSInteger leftWidth = barRect.size.width;
|
|
|
|
CGFloat progress = [torrent progress];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-25 21:34:30 +00:00
|
|
|
if (progress < 1.0f)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
CGFloat rightProgress = 1.0f - progress, progressLeft = [torrent progressLeft];
|
|
|
|
NSInteger rightWidth = leftWidth * rightProgress;
|
2007-09-26 17:30:54 +00:00
|
|
|
leftWidth -= rightWidth;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-09-26 17:42:45 +00:00
|
|
|
if (progressLeft < rightProgress)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
NSInteger rightNoIncludeWidth = rightWidth * ((rightProgress - progressLeft) / rightProgress);
|
2007-09-26 17:30:54 +00:00
|
|
|
rightWidth -= rightNoIncludeWidth;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSRect noIncludeRect = barRect;
|
2007-09-26 17:30:54 +00:00
|
|
|
noIncludeRect.origin.x += barRect.size.width - rightNoIncludeWidth;
|
|
|
|
noIncludeRect.size.width = rightNoIncludeWidth;
|
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressLightGrayGradient] drawInRect: noIncludeRect angle: 90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-09-26 17:30:54 +00:00
|
|
|
|
2007-09-26 18:53:11 +00:00
|
|
|
if (rightWidth > 0)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-05 23:36:25 +00:00
|
|
|
if ([torrent isActive] && ![torrent allDownloaded] && ![torrent isChecking]
|
|
|
|
&& [fDefaults boolForKey: @"DisplayProgressBarAvailable"])
|
2007-09-28 12:55:28 +00:00
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
NSInteger notAvailableWidth = ceil(rightWidth * [torrent notAvailableDesired]);
|
2007-11-11 16:59:32 +00:00
|
|
|
if (notAvailableWidth > 0)
|
2007-09-28 12:55:28 +00:00
|
|
|
{
|
2008-04-11 17:52:05 +00:00
|
|
|
rightWidth -= notAvailableWidth;
|
|
|
|
|
2007-11-11 16:59:32 +00:00
|
|
|
NSRect notAvailableRect = barRect;
|
|
|
|
notAvailableRect.origin.x += leftWidth + rightWidth;
|
|
|
|
notAvailableRect.size.width = notAvailableWidth;
|
2007-09-28 12:55:28 +00:00
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressRedGradient] drawInRect: notAvailableRect angle: 90];
|
2007-09-28 12:55:28 +00:00
|
|
|
}
|
2007-11-11 16:59:32 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-09-28 12:55:28 +00:00
|
|
|
if (rightWidth > 0)
|
|
|
|
{
|
|
|
|
NSRect includeRect = barRect;
|
2007-11-11 16:59:32 +00:00
|
|
|
includeRect.origin.x += leftWidth;
|
2007-09-28 12:55:28 +00:00
|
|
|
includeRect.size.width = rightWidth;
|
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressWhiteGradient] drawInRect: includeRect angle: 90];
|
2007-09-28 12:55:28 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-26 17:30:54 +00:00
|
|
|
|
|
|
|
if (leftWidth > 0)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
NSRect completeRect = barRect;
|
|
|
|
completeRect.size.width = leftWidth;
|
|
|
|
|
|
|
|
if ([torrent isActive])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if ([torrent isChecking])
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressYellowGradient] drawInRect: completeRect angle: 90];
|
2007-09-26 17:30:54 +00:00
|
|
|
else if ([torrent isSeeding])
|
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
NSInteger ratioLeftWidth = leftWidth * (1.0f - [torrent progressStopRatio]);
|
2007-09-26 17:42:45 +00:00
|
|
|
leftWidth -= ratioLeftWidth;
|
|
|
|
|
|
|
|
if (ratioLeftWidth > 0)
|
2007-09-26 17:30:54 +00:00
|
|
|
{
|
2007-09-26 17:42:45 +00:00
|
|
|
NSRect ratioLeftRect = barRect;
|
|
|
|
ratioLeftRect.origin.x += leftWidth;
|
|
|
|
ratioLeftRect.size.width = ratioLeftWidth;
|
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressLightGreenGradient] drawInRect: ratioLeftRect angle: 90];
|
2007-09-26 17:30:54 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 17:42:45 +00:00
|
|
|
if (leftWidth > 0)
|
|
|
|
{
|
|
|
|
completeRect.size.width = leftWidth;
|
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressGreenGradient] drawInRect: completeRect angle: 90];
|
2007-09-26 17:42:45 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressBlueGradient] drawInRect: completeRect angle: 90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if ([torrent waitingToStart])
|
|
|
|
{
|
2008-10-25 21:34:30 +00:00
|
|
|
if ([torrent progressLeft] <= 0.0f)
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressDarkGreenGradient] drawInRect: completeRect angle: 90];
|
2007-09-26 17:30:54 +00:00
|
|
|
else
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressDarkBlueGradient] drawInRect: completeRect angle: 90];
|
2007-09-26 17:30:54 +00:00
|
|
|
}
|
|
|
|
else
|
2008-12-26 05:57:51 +00:00
|
|
|
[[ProgressGradients progressGrayGradient] drawInRect: completeRect angle: 90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawPiecesBar: (NSRect) barRect
|
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
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
|
2008-05-27 05:08:09 +00:00
|
|
|
[bitmap drawInRect: barRect];
|
|
|
|
[bitmap release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForMinimalStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.size = [string size];
|
|
|
|
|
2008-01-14 18:02:08 +00:00
|
|
|
result.origin.x += bounds.size.width - result.size.width - PADDING_HORIZONTAL;
|
2007-09-16 01:02:06 +00:00
|
|
|
result.origin.y += PADDING_ABOVE_MIN_STATUS;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForTitleWithString: (NSAttributedString *) string basedOnMinimalStatusRect: (NSRect) statusRect
|
|
|
|
inBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
BOOL minimal = [fDefaults boolForKey: @"SmallView"];
|
|
|
|
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.origin.y += PADDING_ABOVE_TITLE;
|
2008-01-14 18:02:08 +00:00
|
|
|
result.origin.x += PADDING_HORIZONTAL + (minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG) + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
result.size = [string size];
|
2008-01-14 18:02:08 +00:00
|
|
|
result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL
|
2007-09-16 01:02:06 +00:00
|
|
|
- (minimal ? PADDING_BETWEEN_TITLE_AND_MIN_STATUS + statusRect.size.width : 0));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForProgressWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE + PADDING_BETWEEN_TITLE_AND_PROGRESS;
|
2008-01-14 18:02:08 +00:00
|
|
|
result.origin.x += PADDING_HORIZONTAL + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
result.size = [string size];
|
2008-01-14 18:02:08 +00:00
|
|
|
result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE + PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS
|
|
|
|
+ PADDING_BETWEEN_PROGRESS_AND_BAR + BAR_HEIGHT + PADDING_BETWEEN_BAR_AND_STATUS;
|
2008-01-14 18:02:08 +00:00
|
|
|
result.origin.x += PADDING_HORIZONTAL + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
result.size = [string size];
|
2008-01-14 18:02:08 +00:00
|
|
|
result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString *) attributedTitleWithColor: (NSColor *) color
|
|
|
|
{
|
|
|
|
if (color)
|
|
|
|
[fTitleAttributes setObject: color forKey: NSForegroundColorAttributeName];
|
|
|
|
|
|
|
|
NSString * title = [[self representedObject] name];
|
|
|
|
return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString *) attributedStatusString: (NSString *) string withColor: (NSColor *) color
|
|
|
|
{
|
|
|
|
if (color)
|
|
|
|
[fStatusAttributes setObject: color forKey: NSForegroundColorAttributeName];
|
|
|
|
|
|
|
|
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))
|
|
|
|
return NSLocalizedString(@"Reveal the data file in Finder", "Torrent cell -> button info");
|
|
|
|
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
|
|
|
|
{
|
|
|
|
NSString * buttonString;
|
|
|
|
if ((buttonString = [self buttonString]))
|
|
|
|
return buttonString;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
return [fDefaults boolForKey: @"DisplaySmallStatusRegular"] ? [torrent shortStatusString] : [torrent remainingTimeString];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|