2006-07-16 19:39:23 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-04-03 02:22:25 +00:00
|
|
|
* Copyright (c) 2006-2007 Transmission authors and contributors
|
2006-07-16 19:39:23 +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"
|
|
|
|
#import "StringAdditions.h"
|
2007-05-23 21:34:14 +00:00
|
|
|
#import "CTGradientAdditions.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-09-12 00:08:30 +00:00
|
|
|
//also defined in Torrent.m
|
2006-07-16 19:39:23 +00:00
|
|
|
#define BAR_HEIGHT 12.0
|
|
|
|
|
|
|
|
@interface TorrentCell (Private)
|
|
|
|
|
|
|
|
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point;
|
|
|
|
- (void) buildSimpleBar: (float) width point: (NSPoint) point;
|
2006-10-02 05:21:10 +00:00
|
|
|
- (void) buildAdvancedBar: (float) widthFloat point: (NSPoint) point;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentCell
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2007-05-24 06:46:59 +00:00
|
|
|
if ((self = [super init]))
|
2007-05-23 21:34:14 +00:00
|
|
|
{
|
2006-07-16 19:39:23 +00:00
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
2006-08-29 00:09:49 +00:00
|
|
|
|
2007-05-24 06:46:59 +00:00
|
|
|
fWhiteGradient = [[CTGradient aquaNormalGradient] retain];
|
|
|
|
fGrayGradient = [[CTGradient progressGrayGradient] retain];
|
2007-05-23 21:34:14 +00:00
|
|
|
fBlueGradient = [[CTGradient progressBlueGradient] retain];
|
2007-05-24 06:46:59 +00:00
|
|
|
fGreenGradient = [[CTGradient progressGreenGradient] retain];
|
|
|
|
fLightGreenGradient = [[CTGradient progressLightGreenGradient] retain];
|
2007-05-23 21:34:14 +00:00
|
|
|
fTransparentGradient = [[CTGradient progressTransparentGradient] retain];
|
2007-03-22 04:30:08 +00:00
|
|
|
|
2007-05-24 06:46:59 +00:00
|
|
|
fErrorImage = [[NSImage imageNamed: @"Error"] copy];
|
|
|
|
[fErrorImage setFlipped: YES];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2007-05-23 21:34:14 +00:00
|
|
|
return self;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) placeBar: (NSImage *) barImage width: (float) width point: (NSPoint) point
|
|
|
|
{
|
2007-03-24 17:31:10 +00:00
|
|
|
if (width <= 0.0)
|
|
|
|
return;
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
if ([barImage size].width < width)
|
2006-09-05 02:12:07 +00:00
|
|
|
[barImage setSize: NSMakeSize(width * 2.0, BAR_HEIGHT)];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-08-30 21:40:36 +00:00
|
|
|
[barImage compositeToPoint: point fromRect: NSMakeRect(0, 0, width, BAR_HEIGHT) operation: NSCompositeSourceOver];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) buildSimpleBar: (float) width point: (NSPoint) point
|
|
|
|
{
|
2006-09-11 23:52:03 +00:00
|
|
|
NSDictionary * info = [self objectValue];
|
2007-03-22 04:30:08 +00:00
|
|
|
|
2007-05-23 21:34:14 +00:00
|
|
|
NSRect barBounds, completeBounds;
|
|
|
|
if([[self controlView] isFlipped])
|
|
|
|
barBounds = NSMakeRect(point.x, point.y, width, BAR_HEIGHT);
|
|
|
|
else
|
|
|
|
barBounds = NSMakeRect(point.x, point.y - BAR_HEIGHT, width, BAR_HEIGHT);
|
|
|
|
completeBounds = barBounds;
|
|
|
|
|
2007-04-06 15:15:53 +00:00
|
|
|
if ([[info objectForKey: @"Seeding"] boolValue])
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-03-22 04:30:08 +00:00
|
|
|
float stopRatio, ratio;
|
|
|
|
if ((stopRatio = [[info objectForKey: @"StopRatio"] floatValue]) != INVALID
|
2007-05-28 03:17:23 +00:00
|
|
|
&& (ratio = [[info objectForKey: @"Ratio"] floatValue]) < stopRatio
|
|
|
|
&& stopRatio != 0)
|
2007-05-23 21:34:14 +00:00
|
|
|
{
|
|
|
|
if (ratio < 0)
|
|
|
|
ratio = 0;
|
|
|
|
completeBounds.size.width = width * ratio / stopRatio;
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-05-23 21:34:14 +00:00
|
|
|
if (completeBounds.size.width < barBounds.size.width)
|
|
|
|
[fLightGreenGradient fillRect: barBounds angle: -90];
|
|
|
|
[fGreenGradient fillRect: completeBounds angle: -90];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-23 21:34:14 +00:00
|
|
|
completeBounds.size.width = [[info objectForKey: @"Progress"] floatValue] * width;
|
|
|
|
if (completeBounds.size.width < barBounds.size.width)
|
|
|
|
[fWhiteGradient fillRect: barBounds angle: -90];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-05-23 21:34:14 +00:00
|
|
|
if ([[info objectForKey: @"Active"] boolValue])
|
|
|
|
[fBlueGradient fillRect: completeBounds angle: -90];
|
2006-07-16 19:39:23 +00:00
|
|
|
else
|
2007-05-24 06:46:59 +00:00
|
|
|
[fGrayGradient fillRect: completeBounds angle: -90];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2007-05-23 21:34:14 +00:00
|
|
|
[[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] set];
|
|
|
|
[NSBezierPath strokeRect: NSInsetRect(barBounds, 0.5, 0.5)];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-05-23 21:34:14 +00:00
|
|
|
- (void) buildAdvancedBar: (float) width point: (NSPoint) point
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2006-09-12 00:08:30 +00:00
|
|
|
NSDictionary * info = [self objectValue];
|
|
|
|
|
2006-09-12 00:51:11 +00:00
|
|
|
//place actual advanced bar
|
2006-10-02 05:21:10 +00:00
|
|
|
NSImage * image = [info objectForKey: @"AdvancedBar"];
|
2007-05-23 21:34:14 +00:00
|
|
|
[image setSize: NSMakeSize(width, BAR_HEIGHT)];
|
2006-10-02 05:21:10 +00:00
|
|
|
[image compositeToPoint: point operation: NSCompositeSourceOver];
|
2006-09-12 00:51:11 +00:00
|
|
|
|
2007-05-23 21:34:14 +00:00
|
|
|
NSRect barBounds;
|
2007-05-24 06:46:59 +00:00
|
|
|
if ([[self controlView] isFlipped])
|
|
|
|
barBounds = NSMakeRect(point.x, point.y, width, BAR_HEIGHT);
|
2007-05-23 21:34:14 +00:00
|
|
|
else
|
|
|
|
barBounds = NSMakeRect(point.x, point.y - BAR_HEIGHT, width, BAR_HEIGHT);
|
|
|
|
[fTransparentGradient fillRect: barBounds angle: -90];
|
|
|
|
[[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] set];
|
|
|
|
[NSBezierPath strokeRect: NSInsetRect(barBounds, 0.5, 0.5)];
|
2006-09-12 00:08:30 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-07-25 00:59:14 +00:00
|
|
|
- (void) toggleMinimalStatus
|
|
|
|
{
|
2007-04-06 15:25:15 +00:00
|
|
|
[fDefaults setBool: ![fDefaults boolForKey: @"SmallStatusRegular"] forKey: @"SmallStatusRegular"];
|
2006-07-25 00:59:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view
|
|
|
|
{
|
|
|
|
BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: view]
|
|
|
|
isEqual: [NSColor alternateSelectedControlColor]];
|
2007-01-18 06:22:15 +00:00
|
|
|
|
|
|
|
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
NSDictionary * nameAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
2006-07-18 23:40:37 +00:00
|
|
|
highlighted ? [NSColor whiteColor] : [NSColor controlTextColor], NSForegroundColorAttributeName,
|
2007-01-18 06:22:15 +00:00
|
|
|
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
|
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
2006-07-16 19:39:23 +00:00
|
|
|
NSDictionary * statusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
|
|
|
highlighted ? [NSColor whiteColor] : [NSColor darkGrayColor], NSForegroundColorAttributeName,
|
2007-01-18 06:22:15 +00:00
|
|
|
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
|
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
|
|
|
[paragraphStyle release];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
NSPoint pen = cellFrame.origin;
|
|
|
|
const float PADDING = 3.0, LINE_PADDING = 2.0, EXTRA_NAME_SHIFT = 1.0;
|
2006-09-11 23:52:03 +00:00
|
|
|
|
|
|
|
NSDictionary * info = [self objectValue];
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
if (![fDefaults boolForKey: @"SmallView"]) //regular size
|
|
|
|
{
|
|
|
|
//icon
|
2006-09-11 23:52:03 +00:00
|
|
|
NSImage * icon = [info objectForKey: @"Icon"];
|
2006-07-16 19:39:23 +00:00
|
|
|
NSSize iconSize = [icon size];
|
|
|
|
|
|
|
|
pen.x += PADDING;
|
|
|
|
pen.y += (cellFrame.size.height - iconSize.height) * 0.5;
|
|
|
|
|
|
|
|
[icon drawAtPoint: pen fromRect: NSMakeRect(0, 0, iconSize.width, iconSize.height)
|
|
|
|
operation: NSCompositeSourceOver fraction: 1.0];
|
2006-08-29 00:09:49 +00:00
|
|
|
|
|
|
|
//error badge
|
2006-09-11 23:52:03 +00:00
|
|
|
if ([[info objectForKey: @"Error"] boolValue])
|
2006-08-29 00:09:49 +00:00
|
|
|
{
|
|
|
|
NSSize errorIconSize = [fErrorImage size];
|
|
|
|
[fErrorImage drawAtPoint: NSMakePoint(pen.x + iconSize.width - errorIconSize.width,
|
|
|
|
pen.y + iconSize.height - errorIconSize.height)
|
|
|
|
fromRect: NSMakeRect(0, 0, errorIconSize.width, errorIconSize.height)
|
|
|
|
operation: NSCompositeSourceOver fraction: 1.0];
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
float mainWidth = cellFrame.size.width - iconSize.width - 3.0 * PADDING - EXTRA_NAME_SHIFT;
|
|
|
|
|
|
|
|
//name string
|
|
|
|
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
|
|
|
|
pen.y = cellFrame.origin.y + PADDING;
|
2007-01-18 06:22:15 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
NSString * nameString = [info objectForKey: @"Name"];
|
|
|
|
NSSize nameSize = [nameString sizeWithAttributes: nameAttributes];
|
|
|
|
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, nameSize.height) withAttributes: nameAttributes];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
//progress string
|
2007-01-19 02:06:12 +00:00
|
|
|
pen.y += nameSize.height + LINE_PADDING - 1.0;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
NSString * progressString = [info objectForKey: @"ProgressString"];
|
|
|
|
NSSize progressSize = [progressString sizeWithAttributes: statusAttributes];
|
|
|
|
[progressString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, progressSize.height) withAttributes: statusAttributes];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
//progress bar
|
|
|
|
pen.x -= EXTRA_NAME_SHIFT;
|
2007-01-19 02:06:12 +00:00
|
|
|
pen.y += progressSize.height + LINE_PADDING + BAR_HEIGHT;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
|
|
|
|
|
2006-09-12 00:08:30 +00:00
|
|
|
if ([fDefaults boolForKey: @"UseAdvancedBar"])
|
2006-07-16 19:39:23 +00:00
|
|
|
[self buildAdvancedBar: barWidth point: pen];
|
2006-09-12 00:08:30 +00:00
|
|
|
else
|
2006-07-16 19:39:23 +00:00
|
|
|
[self buildSimpleBar: barWidth point: pen];
|
|
|
|
|
|
|
|
//status string
|
|
|
|
pen.x += EXTRA_NAME_SHIFT;
|
|
|
|
pen.y += LINE_PADDING;
|
2007-01-18 06:22:15 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
NSString * statusString = [info objectForKey: @"StatusString"];
|
|
|
|
NSSize statusSize = [statusString sizeWithAttributes: statusAttributes];
|
|
|
|
[statusString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, statusSize.height) withAttributes: statusAttributes];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else //small size
|
|
|
|
{
|
|
|
|
//icon
|
2006-09-11 23:52:03 +00:00
|
|
|
NSImage * icon = ![[info objectForKey: @"Error"] boolValue] ? [info objectForKey: @"Icon"] : fErrorImage;
|
2006-07-16 19:39:23 +00:00
|
|
|
NSSize iconSize = [icon size];
|
|
|
|
|
|
|
|
pen.x += PADDING;
|
|
|
|
pen.y += (cellFrame.size.height - iconSize.height) * 0.5;
|
|
|
|
|
|
|
|
[icon drawAtPoint: pen fromRect: NSMakeRect(0, 0, iconSize.width, iconSize.height)
|
|
|
|
operation: NSCompositeSourceOver fraction: 1.0];
|
|
|
|
|
|
|
|
//name and status string
|
|
|
|
float mainWidth = cellFrame.size.width - iconSize.width - 3.0 * PADDING - EXTRA_NAME_SHIFT;
|
|
|
|
|
|
|
|
//place name string
|
|
|
|
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
|
|
|
|
pen.y = cellFrame.origin.y + LINE_PADDING;
|
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
NSString * nameString = [info objectForKey: @"Name"];
|
|
|
|
NSSize nameSize = [nameString sizeWithAttributes: nameAttributes];
|
|
|
|
|
2007-04-06 15:25:15 +00:00
|
|
|
NSString * statusString = ![fDefaults boolForKey: @"SmallStatusRegular"] && [[info objectForKey: @"Active"] boolValue]
|
2007-01-19 02:06:12 +00:00
|
|
|
? [info objectForKey: @"RemainingTimeString"]
|
|
|
|
: [info objectForKey: @"ShortStatusString"];
|
|
|
|
NSSize statusSize = [statusString sizeWithAttributes: statusAttributes];
|
|
|
|
|
|
|
|
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth - statusSize.width - 2.0 * LINE_PADDING, nameSize.height)
|
|
|
|
withAttributes: nameAttributes];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
//place status string
|
2007-01-19 02:06:12 +00:00
|
|
|
pen.x = NSMaxX(cellFrame) - PADDING - statusSize.width;
|
|
|
|
pen.y += (nameSize.height - statusSize.height) * 0.5;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
[statusString drawInRect: NSMakeRect(pen.x, pen.y, statusSize.width, statusSize.height)
|
|
|
|
withAttributes: statusAttributes];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
//progress bar
|
|
|
|
pen.x = cellFrame.origin.x + iconSize.width + 2.0 * PADDING;
|
2007-01-19 02:06:12 +00:00
|
|
|
pen.y = cellFrame.origin.y + nameSize.height + LINE_PADDING + PADDING + BAR_HEIGHT;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
|
|
|
|
|
2006-09-12 00:08:30 +00:00
|
|
|
if ([fDefaults boolForKey: @"UseAdvancedBar"])
|
2006-07-16 19:39:23 +00:00
|
|
|
[self buildAdvancedBar: barWidth point: pen];
|
2006-09-12 00:08:30 +00:00
|
|
|
else
|
2006-07-16 19:39:23 +00:00
|
|
|
[self buildSimpleBar: barWidth point: pen];
|
|
|
|
}
|
|
|
|
|
|
|
|
[nameAttributes release];
|
|
|
|
[statusAttributes release];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|