2007-06-23 22:00:09 +00:00
|
|
|
#import "FilePriorityCell.h"
|
2007-06-29 01:49:41 +00:00
|
|
|
#import "InfoWindowController.h"
|
2007-06-23 22:00:09 +00:00
|
|
|
#import "Torrent.h"
|
|
|
|
|
|
|
|
@implementation FilePriorityCell
|
|
|
|
|
2007-06-24 15:02:29 +00:00
|
|
|
- (id) init
|
2007-06-23 22:00:09 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
[self setTrackingMode: NSSegmentSwitchTrackingSelectAny];
|
|
|
|
[self setControlSize: NSMiniControlSize];
|
|
|
|
[self setSegmentCount: 3];
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < [self segmentCount]; i++)
|
|
|
|
{
|
|
|
|
[self setLabel: @"" forSegment: i];
|
|
|
|
[self setWidth: 6.0 forSegment: i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setItem: (NSMutableDictionary *) item
|
|
|
|
{
|
|
|
|
fItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSelected: (BOOL) flag forSegment: (int) segment
|
|
|
|
{
|
|
|
|
[super setSelected: flag forSegment: segment];
|
|
|
|
|
|
|
|
//only for when clicking manually
|
2007-06-29 01:49:41 +00:00
|
|
|
Torrent * torrent = [[[[self controlView] window] windowController] selectedTorrent];
|
2007-06-24 04:03:43 +00:00
|
|
|
NSIndexSet * indexes = [fItem objectForKey: @"Indexes"];
|
|
|
|
if (![torrent canChangeDownloadCheckForFiles: indexes])
|
2007-06-23 22:00:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int priority = segment, actualPriority;
|
|
|
|
if (priority == 0)
|
|
|
|
actualPriority = PRIORITY_LOW;
|
|
|
|
else if (priority == 2)
|
|
|
|
actualPriority = PRIORITY_HIGH;
|
|
|
|
else
|
|
|
|
actualPriority = PRIORITY_NORMAL;
|
|
|
|
|
2007-06-24 04:03:43 +00:00
|
|
|
[torrent setFilePriority: actualPriority forIndexes: indexes];
|
2007-06-24 15:02:29 +00:00
|
|
|
[(FileOutlineView *)[self controlView] reloadData];
|
2007-06-23 22:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
|
|
|
|
{
|
2007-06-29 01:49:41 +00:00
|
|
|
Torrent * torrent = [(InfoWindowController *)[[[self controlView] window] windowController] selectedTorrent];
|
2007-06-23 22:00:09 +00:00
|
|
|
NSIndexSet * indexSet = [fItem objectForKey: @"Indexes"];
|
|
|
|
|
|
|
|
if (![torrent canChangeDownloadCheckForFiles: indexSet])
|
|
|
|
return;
|
|
|
|
|
|
|
|
BOOL low = [torrent hasFilePriority: PRIORITY_LOW forIndexes: indexSet],
|
|
|
|
normal = [torrent hasFilePriority: PRIORITY_NORMAL forIndexes: indexSet],
|
|
|
|
high = [torrent hasFilePriority: PRIORITY_HIGH forIndexes: indexSet];
|
|
|
|
|
2007-06-24 15:02:29 +00:00
|
|
|
FileOutlineView * view = (FileOutlineView *)[self controlView];
|
|
|
|
int row = [view hoverRow];
|
|
|
|
if (row != -1 && [view itemAtRow: row] == fItem)
|
2007-06-23 22:00:09 +00:00
|
|
|
{
|
|
|
|
[super setSelected: low forSegment: 0];
|
|
|
|
[super setSelected: normal forSegment: 1];
|
|
|
|
[super setSelected: high forSegment: 2];
|
|
|
|
|
|
|
|
[super drawWithFrame: cellFrame inView: controlView];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (high || low)
|
|
|
|
{
|
|
|
|
BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: controlView]
|
|
|
|
isEqual: [NSColor alternateSelectedControlColor]];
|
|
|
|
NSDictionary * attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
|
|
|
highlighted ? [NSColor whiteColor] : [NSColor controlTextColor], NSForegroundColorAttributeName,
|
|
|
|
[NSFont messageFontOfSize: 18.0], NSFontAttributeName, nil];
|
|
|
|
|
|
|
|
NSString * text;
|
|
|
|
if (low && !normal && !high)
|
|
|
|
text = @"-";
|
|
|
|
else if (!low && !normal && high)
|
|
|
|
text = @"+";
|
|
|
|
else
|
|
|
|
text = @"*";
|
|
|
|
|
|
|
|
NSSize textSize = [text sizeWithAttributes: attributes];
|
|
|
|
NSRect textRect = NSMakeRect(cellFrame.origin.x + (cellFrame.size.width - textSize.width) * 0.5,
|
|
|
|
cellFrame.origin.y + (cellFrame.size.height - textSize.height) * 0.5,
|
|
|
|
textSize.width, textSize.height);
|
|
|
|
|
|
|
|
[text drawInRect: textRect withAttributes: attributes];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|