2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2007-2012 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 "FileNameCell.h"
|
2007-10-20 19:25:14 +00:00
|
|
|
#import "FileOutlineView.h"
|
2007-10-20 19:13:52 +00:00
|
|
|
#import "Torrent.h"
|
2008-05-22 18:39:49 +00:00
|
|
|
#import "FileListNode.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
|
2010-05-31 14:06:54 +00:00
|
|
|
#import "transmission.h" // required by utils.h
|
|
|
|
#import "utils.h"
|
|
|
|
|
2009-12-31 03:19:54 +00:00
|
|
|
#define PADDING_HORIZONAL 2.0
|
|
|
|
#define IMAGE_FOLDER_SIZE 16.0
|
|
|
|
#define IMAGE_ICON_SIZE 32.0
|
|
|
|
#define PADDING_BETWEEN_IMAGE_AND_TITLE 4.0
|
|
|
|
#define PADDING_ABOVE_TITLE_FILE 2.0
|
|
|
|
#define PADDING_BELOW_STATUS_FILE 2.0
|
|
|
|
#define PADDING_BETWEEN_NAME_AND_FOLDER_STATUS 4.0
|
2012-10-29 22:17:08 +00:00
|
|
|
#define PADDING_EXPANSION_FRAME 2.0
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
@interface FileNameCell (Private)
|
|
|
|
|
|
|
|
- (NSRect) rectForTitleWithString: (NSAttributedString *) string inBounds: (NSRect) bounds;
|
2008-10-12 13:22:13 +00:00
|
|
|
- (NSRect) rectForStatusWithString: (NSAttributedString *) string withTitleRect: (NSRect) titleRect inBounds: (NSRect) bounds;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-09-28 17:42:24 +00:00
|
|
|
- (NSAttributedString *) attributedTitle;
|
|
|
|
- (NSAttributedString *) attributedStatus;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FileNameCell
|
|
|
|
|
2008-01-07 00:07:03 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
2010-04-01 02:34:29 +00:00
|
|
|
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingMiddle];
|
2008-01-07 00:07:03 +00:00
|
|
|
|
|
|
|
fTitleAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
2009-12-31 03:19:54 +00:00
|
|
|
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
|
2008-01-07 00:07:03 +00:00
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
|
|
|
|
2010-07-08 01:49:41 +00:00
|
|
|
NSMutableParagraphStyle * statusParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
[statusParagraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
|
|
|
|
|
2008-01-07 00:07:03 +00:00
|
|
|
fStatusAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
2009-12-31 03:19:54 +00:00
|
|
|
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
|
2010-07-08 01:49:41 +00:00
|
|
|
statusParagraphStyle, NSParagraphStyleAttributeName, nil];
|
2008-01-07 00:07:03 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[paragraphStyle release];
|
|
|
|
[statusParagraphStyle release];
|
2008-01-07 00:07:03 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fTitleAttributes release];
|
|
|
|
[fStatusAttributes release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) copyWithZone: (NSZone *) zone
|
|
|
|
{
|
|
|
|
FileNameCell * copy = [super copyWithZone: zone];
|
|
|
|
|
|
|
|
copy->fTitleAttributes = [fTitleAttributes retain];
|
|
|
|
copy->fStatusAttributes = [fStatusAttributes retain];
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSImage *) image
|
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
FileListNode * node = (FileListNode *)[self objectValue];
|
2009-12-27 19:30:20 +00:00
|
|
|
return [node icon];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) imageRectForBounds: (NSRect) bounds
|
|
|
|
{
|
|
|
|
NSRect result = bounds;
|
|
|
|
|
|
|
|
result.origin.x += PADDING_HORIZONAL;
|
|
|
|
|
2008-11-01 14:26:51 +00:00
|
|
|
const CGFloat IMAGE_SIZE = [(FileListNode *)[self objectValue] isFolder] ? IMAGE_FOLDER_SIZE : IMAGE_ICON_SIZE;
|
2009-12-31 03:19:54 +00:00
|
|
|
result.origin.y += (result.size.height - IMAGE_SIZE) * 0.5;
|
2007-09-16 01:02:06 +00:00
|
|
|
result.size = NSMakeSize(IMAGE_SIZE, IMAGE_SIZE);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
|
|
|
|
{
|
|
|
|
//icon
|
2011-10-06 00:30:40 +00:00
|
|
|
[[self image] drawInRect: [self imageRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0 respectFlipped: YES hints: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-01-02 01:10:54 +00:00
|
|
|
NSColor * titleColor, * statusColor;
|
|
|
|
if ([self backgroundStyle] == NSBackgroundStyleDark)
|
|
|
|
titleColor = statusColor = [NSColor whiteColor];
|
2011-05-31 22:26:04 +00:00
|
|
|
else if ([[(FileListNode *)[self objectValue] torrent] checkForFiles: [(FileListNode *)[self objectValue] indexes]] == NSOffState)
|
2009-01-02 01:10:54 +00:00
|
|
|
titleColor = statusColor = [NSColor disabledControlTextColor];
|
|
|
|
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];
|
|
|
|
|
2009-01-02 01:10:54 +00:00
|
|
|
//title
|
2009-09-28 17:42:24 +00:00
|
|
|
NSAttributedString * titleString = [self attributedTitle];
|
2007-09-16 01:02:06 +00:00
|
|
|
NSRect titleRect = [self rectForTitleWithString: titleString inBounds: cellFrame];
|
|
|
|
[titleString drawInRect: titleRect];
|
|
|
|
|
|
|
|
//status
|
2009-09-28 17:42:24 +00:00
|
|
|
NSAttributedString * statusString = [self attributedStatus];
|
2008-10-12 13:22:13 +00:00
|
|
|
NSRect statusRect = [self rectForStatusWithString: statusString withTitleRect: titleRect inBounds: cellFrame];
|
|
|
|
[statusString drawInRect: statusRect];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 22:17:08 +00:00
|
|
|
- (NSRect) expansionFrameWithFrame: (NSRect) cellFrame inView: (NSView *) view
|
|
|
|
{
|
|
|
|
NSAttributedString * titleString = [self attributedTitle];
|
|
|
|
NSRect realRect = [self rectForTitleWithString: titleString inBounds: cellFrame];
|
|
|
|
|
|
|
|
if ([titleString size].width > NSWidth(realRect)
|
|
|
|
&& NSMouseInRect([view convertPoint: [[view window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil], realRect, [view isFlipped]))
|
|
|
|
{
|
|
|
|
realRect.size.width = [titleString size].width;
|
|
|
|
return NSInsetRect(realRect, -PADDING_EXPANSION_FRAME, -PADDING_EXPANSION_FRAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawWithExpansionFrame: (NSRect) cellFrame inView: (NSView *)view
|
|
|
|
{
|
|
|
|
cellFrame.origin.x += PADDING_EXPANSION_FRAME;
|
|
|
|
cellFrame.origin.y += PADDING_EXPANSION_FRAME;
|
|
|
|
|
|
|
|
[fTitleAttributes setObject: [NSColor controlTextColor] forKey: NSForegroundColorAttributeName];
|
|
|
|
NSAttributedString * titleString = [self attributedTitle];
|
|
|
|
[titleString drawInRect: cellFrame];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FileNameCell (Private)
|
|
|
|
|
|
|
|
- (NSRect) rectForTitleWithString: (NSAttributedString *) string inBounds: (NSRect) bounds
|
|
|
|
{
|
2009-12-31 03:19:54 +00:00
|
|
|
const NSSize titleSize = [string size];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2012-10-29 00:04:18 +00:00
|
|
|
//no right padding, so that there's not too much space between this and the priority image
|
2009-12-31 03:19:54 +00:00
|
|
|
NSRect result;
|
2008-05-22 18:39:49 +00:00
|
|
|
if (![(FileListNode *)[self objectValue] isFolder])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-12-31 03:19:54 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONAL + IMAGE_ICON_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
|
|
|
result.origin.y = NSMinY(bounds) + PADDING_ABOVE_TITLE_FILE;
|
2012-10-29 00:04:18 +00:00
|
|
|
result.size.width = NSMaxX(bounds) - NSMinX(result);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-31 03:19:54 +00:00
|
|
|
result.origin.x = NSMinX(bounds) + PADDING_HORIZONAL + IMAGE_FOLDER_SIZE + PADDING_BETWEEN_IMAGE_AND_TITLE;
|
|
|
|
result.origin.y = NSMidY(bounds) - titleSize.height * 0.5;
|
2012-10-29 00:04:18 +00:00
|
|
|
result.size.width = MIN(titleSize.width, NSMaxX(bounds) - NSMinX(result));
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2009-12-31 03:19:54 +00:00
|
|
|
result.size.height = titleSize.height;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-10-12 13:22:13 +00:00
|
|
|
- (NSRect) rectForStatusWithString: (NSAttributedString *) string withTitleRect: (NSRect) titleRect inBounds: (NSRect) bounds;
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-12-31 03:19:54 +00:00
|
|
|
const NSSize statusSize = [string size];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-12 13:22:13 +00:00
|
|
|
NSRect result;
|
|
|
|
if (![(FileListNode *)[self objectValue] isFolder])
|
|
|
|
{
|
2010-07-08 01:49:41 +00:00
|
|
|
result.origin.x = NSMinX(titleRect);
|
2008-11-01 17:52:25 +00:00
|
|
|
result.origin.y = NSMaxY(bounds) - PADDING_BELOW_STATUS_FILE - statusSize.height;
|
2010-07-08 01:49:41 +00:00
|
|
|
result.size.width = NSWidth(titleRect);
|
2008-10-12 13:22:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.origin.x = NSMaxX(titleRect) + PADDING_BETWEEN_NAME_AND_FOLDER_STATUS;
|
2009-12-31 03:19:54 +00:00
|
|
|
result.origin.y = NSMaxY(titleRect) - statusSize.height - 1.0;
|
2012-10-29 00:04:18 +00:00
|
|
|
result.size.width = NSMaxX(bounds) - NSMaxX(titleRect);
|
2008-10-12 13:22:13 +00:00
|
|
|
}
|
2009-12-31 03:19:54 +00:00
|
|
|
result.size.height = statusSize.height;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-09-28 17:42:24 +00:00
|
|
|
- (NSAttributedString *) attributedTitle
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
NSString * title = [(FileListNode *)[self objectValue] name];
|
2012-03-13 02:52:11 +00:00
|
|
|
return [[[NSAttributedString alloc] initWithString: title attributes: fTitleAttributes] autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-28 17:42:24 +00:00
|
|
|
- (NSAttributedString *) attributedStatus
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
FileListNode * node = (FileListNode *)[self objectValue];
|
2011-05-31 22:26:04 +00:00
|
|
|
Torrent * torrent = [node torrent];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-12-31 03:19:54 +00:00
|
|
|
const CGFloat progress = [torrent fileProgress: node];
|
2010-07-06 03:57:23 +00:00
|
|
|
NSString * percentString = [NSString percentString: progress longDecimals: YES];
|
2008-10-12 13:22:13 +00:00
|
|
|
|
2009-09-28 03:12:58 +00:00
|
|
|
NSString * status = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@",
|
2008-10-12 13:22:13 +00:00
|
|
|
"Inspector -> Files tab -> file status string"), percentString, [NSString stringForFileSize: [node size]]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
return [[[NSAttributedString alloc] initWithString: status attributes: fStatusAttributes] autorelease];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|