2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006-2007 Transmission authors and contributors
|
|
|
|
*
|
|
|
|
* 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"
|
2007-12-17 16:06:20 +00:00
|
|
|
#import "GroupsWindowController.h"
|
2007-12-12 05:01:31 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2007-12-17 16:06:20 +00:00
|
|
|
#import "NSBezierPathAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "CTGradientAdditions.h"
|
|
|
|
|
|
|
|
#define BAR_HEIGHT 12.0
|
|
|
|
|
|
|
|
#define IMAGE_SIZE_REG 32.0
|
|
|
|
#define IMAGE_SIZE_MIN 16.0
|
|
|
|
|
|
|
|
//end up being larger than font height
|
|
|
|
#define HEIGHT_TITLE 16.0
|
|
|
|
#define HEIGHT_STATUS 12.0
|
|
|
|
|
|
|
|
#define PADDING_HORIZONAL 2.0
|
|
|
|
#define PADDING_ABOVE_IMAGE_REG 9.0
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0
|
|
|
|
#define PADDING_ABOVE_TITLE 3.0
|
|
|
|
#define PADDING_ABOVE_MIN_STATUS 4.0
|
|
|
|
#define PADDING_BETWEEN_TITLE_AND_MIN_STATUS 2.0
|
|
|
|
#define PADDING_BETWEEN_TITLE_AND_PROGRESS 1.0
|
|
|
|
#define PADDING_BETWEEN_PROGRESS_AND_BAR 2.0
|
|
|
|
#define PADDING_BETWEEN_TITLE_AND_BAR_MIN 3.0
|
|
|
|
#define PADDING_BETWEEN_BAR_AND_STATUS 2.0
|
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
#define GROUP_BORDER_X -4.0
|
|
|
|
#define GROUP_BORDER_Y -1.0
|
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
#define MAX_PIECES 324
|
|
|
|
#define BLANK_PIECE -99
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentCell
|
|
|
|
|
|
|
|
//only called one, so don't worry about release
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
|
|
|
|
|
|
|
|
fTitleAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
|
|
|
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
|
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
|
|
|
fStatusAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
|
|
|
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
|
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
|
|
|
[paragraphStyle release];
|
|
|
|
|
2007-11-06 04:53:06 +00:00
|
|
|
//store box colors
|
|
|
|
fGrayColor = [[NSColor colorWithCalibratedRed: 0.9 green: 0.9 blue: 0.9 alpha: 1.0] retain];
|
|
|
|
fBlue1Color = [[NSColor colorWithCalibratedRed: 0.8 green: 1.0 blue: 1.0 alpha: 1.0] retain];
|
|
|
|
fBlue2Color = [[NSColor colorWithCalibratedRed: 0.6 green: 1.0 blue: 1.0 alpha: 1.0] retain];
|
|
|
|
fBlue3Color = [[NSColor colorWithCalibratedRed: 0.6 green: 0.8 blue: 1.0 alpha: 1.0] retain];
|
|
|
|
fBlue4Color = [[NSColor colorWithCalibratedRed: 0.4 green: 0.6 blue: 1.0 alpha: 1.0] retain];
|
|
|
|
fBlueColor = [[NSColor colorWithCalibratedRed: 0.0 green: 0.4 blue: 0.8 alpha: 1.0] retain];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
fBarOverlayColor = [[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] retain];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
- (id) copyWithZone: (NSZone *) zone
|
|
|
|
{
|
|
|
|
TorrentCell * copy = [super copyWithZone: zone];
|
|
|
|
|
|
|
|
copy->fBitmap = nil;
|
|
|
|
copy->fPieces = NULL;
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fBitmap release];
|
|
|
|
if (fPieces)
|
|
|
|
free(fPieces);
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSRect) iconRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result = bounds;
|
|
|
|
|
|
|
|
result.origin.x += PADDING_HORIZONAL;
|
|
|
|
|
|
|
|
float imageSize;
|
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
{
|
|
|
|
imageSize = IMAGE_SIZE_MIN;
|
|
|
|
result.origin.y += (result.size.height - imageSize) * 0.5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imageSize = IMAGE_SIZE_REG;
|
|
|
|
result.origin.y += PADDING_ABOVE_IMAGE_REG;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.size = NSMakeSize(imageSize, imageSize);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) titleRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
return [self rectForTitleWithString: [self attributedTitleWithColor: nil]
|
|
|
|
basedOnMinimalStatusRect: [self minimalStatusRectForBounds: bounds] inBounds: bounds];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) minimalStatusRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
2007-09-30 13:41:26 +00:00
|
|
|
NSString * string = [fDefaults boolForKey: @"DisplaySmallStatusRegular"]
|
|
|
|
? [torrent shortStatusString] : [torrent remainingTimeString];
|
2007-09-16 01:02:06 +00:00
|
|
|
return [self rectForMinimalStatusWithString: [self attributedStatusString: string withColor: nil] inBounds: bounds];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) progressRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
return [self rectForProgressWithString: [self attributedStatusString: [[self representedObject] progressString] withColor: nil]
|
|
|
|
inBounds: bounds];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) barRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
BOOL minimal = [fDefaults boolForKey: @"SmallView"];
|
|
|
|
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.size.height = BAR_HEIGHT;
|
2007-09-26 04:12:57 +00:00
|
|
|
result.origin.x = PADDING_HORIZONAL + (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;
|
|
|
|
|
2007-09-26 17:30:54 +00:00
|
|
|
result.size.width = round(NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL - BUTTONS_TOTAL_WIDTH);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) statusRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
return [self rectForStatusWithString: [self attributedStatusString: [[self representedObject] statusString] withColor: nil]
|
|
|
|
inBounds: bounds];
|
|
|
|
}
|
|
|
|
|
2007-10-31 17:23:56 +00:00
|
|
|
- (NSUInteger) hitTestForEvent: (NSEvent *) event inRect: (NSRect) cellFrame ofView: (NSView *) controlView
|
|
|
|
{
|
|
|
|
return NSCellHitContentArea;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) drawInteriorWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
|
|
|
|
{
|
|
|
|
[super drawInteriorWithFrame: cellFrame inView: controlView];
|
|
|
|
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
|
|
|
BOOL minimal = [fDefaults boolForKey: @"SmallView"];
|
|
|
|
|
|
|
|
//error image
|
|
|
|
BOOL error = [torrent isError];
|
|
|
|
if (error && !fErrorImage)
|
|
|
|
{
|
|
|
|
fErrorImage = [[NSImage imageNamed: @"Error.png"] copy];
|
|
|
|
[fErrorImage setFlipped: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
//icon
|
|
|
|
NSImage * icon = minimal && error ? fErrorImage : [torrent icon];
|
|
|
|
NSRect iconRect = [self iconRectForBounds: cellFrame];
|
|
|
|
[icon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
|
|
|
|
|
|
|
if (error && !minimal)
|
|
|
|
{
|
|
|
|
NSRect errorRect = NSMakeRect(NSMaxX(iconRect) - IMAGE_SIZE_MIN, NSMaxY(iconRect) - IMAGE_SIZE_MIN,
|
|
|
|
IMAGE_SIZE_MIN, IMAGE_SIZE_MIN);
|
|
|
|
[fErrorImage drawInRect: errorRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
|
|
|
}
|
|
|
|
|
|
|
|
//text color
|
2007-12-17 16:06:20 +00:00
|
|
|
BOOL selected = [NSApp isOnLeopardOrBetter] ? [self backgroundStyle] == NSBackgroundStyleDark : [self isHighlighted]
|
|
|
|
&& [[self highlightColorWithFrame: cellFrame inView: controlView] isEqual: [NSColor alternateSelectedControlColor]];
|
|
|
|
int groupIndex = [torrent groupValue];
|
|
|
|
|
|
|
|
NSColor * titleColor = selected && groupIndex == -1 ? [NSColor whiteColor] : [NSColor controlTextColor],
|
|
|
|
* statusColor = selected ? [NSColor whiteColor] : [NSColor darkGrayColor];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//minimal status
|
|
|
|
NSRect minimalStatusRect;
|
|
|
|
if (minimal)
|
|
|
|
{
|
2007-09-30 13:41:26 +00:00
|
|
|
NSString * string = [fDefaults boolForKey: @"DisplaySmallStatusRegular"]
|
|
|
|
? [torrent shortStatusString] : [torrent remainingTimeString];
|
2007-09-16 01:02:06 +00:00
|
|
|
NSAttributedString * minimalString = [self attributedStatusString: string withColor: statusColor];
|
|
|
|
minimalStatusRect = [self rectForMinimalStatusWithString: minimalString inBounds: cellFrame];
|
|
|
|
|
|
|
|
[minimalString drawInRect: minimalStatusRect];
|
|
|
|
}
|
|
|
|
|
|
|
|
//title
|
|
|
|
NSAttributedString * titleString = [self attributedTitleWithColor: titleColor];
|
|
|
|
NSRect titleRect = [self rectForTitleWithString: titleString basedOnMinimalStatusRect: minimalStatusRect inBounds: cellFrame];
|
2007-12-17 16:06:20 +00:00
|
|
|
|
|
|
|
if (groupIndex != -1)
|
|
|
|
[[[GroupsWindowController groupsController] gradientForIndex: [torrent groupValue]] fillBezierPath:
|
|
|
|
[NSBezierPath bezierPathWithRoundedRect: NSInsetRect(titleRect, GROUP_BORDER_X, GROUP_BORDER_Y) radius: 7.0] angle: 90];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[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];
|
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
|
|
|
|
|
|
|
//status
|
|
|
|
if (!minimal)
|
|
|
|
{
|
|
|
|
NSAttributedString * statusString = [self attributedStatusString: [torrent statusString] withColor: statusColor];
|
|
|
|
[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
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"PiecesBar"])
|
|
|
|
{
|
|
|
|
NSRect regularBarRect = barRect, piecesBarRect = barRect;
|
2007-11-11 06:36:32 +00:00
|
|
|
regularBarRect.size.height /= 2.5;
|
2007-11-04 15:01:34 +00:00
|
|
|
piecesBarRect.origin.y += regularBarRect.size.height;
|
|
|
|
piecesBarRect.size.height -= regularBarRect.size.height;
|
|
|
|
|
|
|
|
[self drawRegularBar: regularBarRect];
|
|
|
|
[self drawPiecesBar: piecesBarRect];
|
|
|
|
}
|
|
|
|
else
|
2007-11-05 00:04:14 +00:00
|
|
|
{
|
|
|
|
if (fPieces)
|
|
|
|
{
|
|
|
|
free(fPieces);
|
|
|
|
fPieces = NULL;
|
|
|
|
[fBitmap release];
|
|
|
|
fBitmap = nil;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
[fBarOverlayColor set];
|
|
|
|
[NSBezierPath strokeRect: NSInsetRect(barRect, 0.5, 0.5)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRegularBar: (NSRect) barRect
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
2007-09-26 17:30:54 +00:00
|
|
|
int leftWidth = barRect.size.width;
|
2007-09-26 17:42:45 +00:00
|
|
|
float progress = [torrent progress];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (progress < 1.0)
|
|
|
|
{
|
2007-09-26 18:53:11 +00:00
|
|
|
float rightProgress = 1.0 - progress, progressLeft = [torrent progressLeft];
|
|
|
|
int 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
|
|
|
{
|
2007-09-26 17:42:45 +00:00
|
|
|
int 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;
|
|
|
|
|
|
|
|
if (!fLightGrayGradient)
|
|
|
|
fLightGrayGradient = [[CTGradient progressLightGrayGradient] retain];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fLightGrayGradient fillRect: noIncludeRect angle: -90];
|
|
|
|
}
|
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
|
|
|
{
|
2007-11-20 13:16:24 +00:00
|
|
|
if ([torrent isActive] && ![torrent allDownloaded] && [fDefaults boolForKey: @"DisplayProgressBarAvailable"])
|
2007-09-28 12:55:28 +00:00
|
|
|
{
|
2007-11-11 16:59:32 +00:00
|
|
|
int notAvailableWidth = MIN(barRect.size.width * [torrent notAvailableDesired], rightWidth);
|
|
|
|
rightWidth -= notAvailableWidth;
|
2007-09-28 12:55:28 +00:00
|
|
|
|
2007-11-11 16:59:32 +00:00
|
|
|
if (notAvailableWidth > 0)
|
2007-09-28 12:55:28 +00:00
|
|
|
{
|
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
|
|
|
|
2007-11-11 21:45:27 +00:00
|
|
|
if (!fRedGradient)
|
|
|
|
fRedGradient = [[CTGradient progressRedGradient] retain];
|
|
|
|
[fRedGradient fillRect: 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;
|
|
|
|
|
|
|
|
if (!fWhiteGradient)
|
|
|
|
fWhiteGradient = [[CTGradient progressWhiteGradient] retain];
|
|
|
|
[fWhiteGradient fillRect: includeRect angle: -90];
|
|
|
|
}
|
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])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if (!fYellowGradient)
|
|
|
|
fYellowGradient = [[CTGradient progressYellowGradient] retain];
|
|
|
|
[fYellowGradient fillRect: completeRect angle: -90];
|
|
|
|
}
|
|
|
|
else if ([torrent isSeeding])
|
|
|
|
{
|
2007-09-26 17:42:45 +00:00
|
|
|
int ratioLeftWidth = leftWidth * (1.0 - [torrent progressStopRatio]);
|
|
|
|
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;
|
|
|
|
|
2007-09-26 17:30:54 +00:00
|
|
|
if (!fLightGreenGradient)
|
|
|
|
fLightGreenGradient = [[CTGradient progressLightGreenGradient] retain];
|
2007-09-26 17:42:45 +00:00
|
|
|
[fLightGreenGradient fillRect: 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;
|
|
|
|
|
|
|
|
if (!fGreenGradient)
|
|
|
|
fGreenGradient = [[CTGradient progressGreenGradient] retain];
|
|
|
|
[fGreenGradient fillRect: completeRect angle: -90];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if (!fBlueGradient)
|
|
|
|
fBlueGradient = [[CTGradient progressBlueGradient] retain];
|
|
|
|
[fBlueGradient fillRect: completeRect angle: -90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-26 17:30:54 +00:00
|
|
|
if ([torrent waitingToStart])
|
|
|
|
{
|
2007-09-26 17:42:45 +00:00
|
|
|
if ([torrent progressLeft] <= 0.0)
|
2007-09-26 17:30:54 +00:00
|
|
|
{
|
|
|
|
if (!fDarkGreenGradient)
|
|
|
|
fDarkGreenGradient = [[CTGradient progressDarkGreenGradient] retain];
|
|
|
|
[fDarkGreenGradient fillRect: completeRect angle: -90];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!fDarkBlueGradient)
|
|
|
|
fDarkBlueGradient = [[CTGradient progressDarkBlueGradient] retain];
|
|
|
|
[fDarkBlueGradient fillRect: completeRect angle: -90];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!fGrayGradient)
|
|
|
|
fGrayGradient = [[CTGradient progressGrayGradient] retain];
|
|
|
|
[fGrayGradient fillRect: completeRect angle: -90];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawPiecesBar: (NSRect) barRect
|
|
|
|
{
|
|
|
|
if (!fBitmap)
|
|
|
|
fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
|
|
|
|
pixelsWide: MAX_PIECES pixelsHigh: barRect.size.height bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
|
|
|
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
if (!fPieces)
|
|
|
|
{
|
|
|
|
fPieces = malloc(MAX_PIECES);
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_PIECES; i++)
|
|
|
|
fPieces[i] = BLANK_PIECE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#warning add flashing orange
|
|
|
|
|
|
|
|
Torrent * torrent = [self representedObject];
|
|
|
|
|
2007-11-05 19:15:45 +00:00
|
|
|
int pieceCount = MIN([torrent pieceCount], MAX_PIECES);
|
2007-11-04 15:01:34 +00:00
|
|
|
float * piecePercent = malloc(pieceCount * sizeof(float));
|
|
|
|
[torrent getAmountFinished: piecePercent size: pieceCount];
|
|
|
|
|
2007-11-05 19:15:45 +00:00
|
|
|
int i, h, index;
|
|
|
|
float increment = (float)pieceCount / MAX_PIECES;
|
2007-11-06 04:53:06 +00:00
|
|
|
NSColor * pieceColor;
|
2007-11-04 15:01:34 +00:00
|
|
|
for (i = 0; i < MAX_PIECES; i++)
|
|
|
|
{
|
2007-11-05 19:15:45 +00:00
|
|
|
index = i * increment;
|
2007-11-06 04:53:06 +00:00
|
|
|
pieceColor = nil;
|
2007-11-05 19:15:45 +00:00
|
|
|
|
2007-11-04 15:01:34 +00:00
|
|
|
if (piecePercent[index] >= 1.0)
|
|
|
|
{
|
|
|
|
if (fPieces[i] != -1)
|
|
|
|
{
|
2007-11-06 04:53:06 +00:00
|
|
|
pieceColor = fBlueColor;
|
2007-11-04 15:01:34 +00:00
|
|
|
fPieces[i] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (piecePercent[index] <= 0.0)
|
|
|
|
{
|
|
|
|
if (fPieces[i] != 0)
|
|
|
|
{
|
2007-11-06 04:53:06 +00:00
|
|
|
pieceColor = fGrayColor;
|
2007-11-04 15:01:34 +00:00
|
|
|
fPieces[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (piecePercent[index] <= 0.25)
|
|
|
|
{
|
|
|
|
if (fPieces[i] != 1)
|
|
|
|
{
|
2007-11-06 04:53:06 +00:00
|
|
|
pieceColor = fBlue1Color;
|
2007-11-04 15:01:34 +00:00
|
|
|
fPieces[i] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (piecePercent[index] <= 0.5)
|
|
|
|
{
|
|
|
|
if (fPieces[i] != 2)
|
|
|
|
{
|
2007-11-06 04:53:06 +00:00
|
|
|
pieceColor = fBlue2Color;
|
2007-11-04 15:01:34 +00:00
|
|
|
fPieces[i] = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (piecePercent[index] <= 0.75)
|
|
|
|
{
|
|
|
|
if (fPieces[i] != 3)
|
|
|
|
{
|
2007-11-06 04:53:06 +00:00
|
|
|
pieceColor = fBlue3Color;
|
2007-11-04 15:01:34 +00:00
|
|
|
fPieces[i] = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fPieces[i] != 4)
|
|
|
|
{
|
2007-11-06 04:53:06 +00:00
|
|
|
pieceColor = fBlue4Color;
|
2007-11-04 15:01:34 +00:00
|
|
|
fPieces[i] = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-06 04:53:06 +00:00
|
|
|
if (pieceColor)
|
2007-11-04 15:01:34 +00:00
|
|
|
for (h = 0; h < barRect.size.height; h++)
|
2007-11-06 04:53:06 +00:00
|
|
|
[fBitmap setColor: pieceColor atX: i y: h];
|
2007-11-04 15:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(piecePercent);
|
|
|
|
|
|
|
|
//actually draw image
|
2007-11-06 04:53:06 +00:00
|
|
|
[fBitmap drawInRect: barRect];
|
2007-11-04 15:01:34 +00:00
|
|
|
|
|
|
|
if (!fTransparentGradient)
|
|
|
|
fTransparentGradient = [[CTGradient progressTransparentGradient] retain];
|
|
|
|
[fTransparentGradient fillRect: barRect angle: -90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForMinimalStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
|
|
|
return NSZeroRect;
|
|
|
|
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.size = [string size];
|
|
|
|
|
|
|
|
result.origin.x += bounds.size.width - result.size.width - PADDING_HORIZONAL;
|
|
|
|
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;
|
|
|
|
result.origin.x += PADDING_HORIZONAL + (minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG) + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
|
|
|
|
|
|
|
result.size = [string size];
|
|
|
|
result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL
|
|
|
|
- (minimal ? PADDING_BETWEEN_TITLE_AND_MIN_STATUS + statusRect.size.width : 0));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForProgressWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
return NSZeroRect;
|
|
|
|
|
|
|
|
NSRect result = bounds;
|
|
|
|
result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE + PADDING_BETWEEN_TITLE_AND_PROGRESS;
|
|
|
|
result.origin.x += PADDING_HORIZONAL + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
|
|
|
|
|
|
|
result.size = [string size];
|
|
|
|
result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) rectForStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"SmallView"])
|
|
|
|
return NSZeroRect;
|
|
|
|
|
|
|
|
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;
|
|
|
|
result.origin.x += PADDING_HORIZONAL + IMAGE_SIZE_REG + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
|
|
|
|
|
|
|
result.size = [string size];
|
|
|
|
result.size.width = MIN(result.size.width, NSMaxX(bounds) - result.origin.x - PADDING_HORIZONAL);
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|