2006-03-23 12:39:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2005-2006 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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2006-01-20 01:13:21 +00:00
|
|
|
#import "TorrentTableView.h"
|
|
|
|
#import "Controller.h"
|
2006-03-23 12:39:39 +00:00
|
|
|
#import "Torrent.h"
|
2006-04-03 19:29:09 +00:00
|
|
|
#import "Utils.h"
|
2006-01-12 18:29:20 +00:00
|
|
|
|
|
|
|
@implementation TorrentTableView
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
- (void) setTorrents: (NSArray *) torrents
|
2006-01-12 18:29:20 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
fTorrents = torrents;
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) pauseRectForRow: (int) row
|
|
|
|
{
|
|
|
|
int col;
|
|
|
|
NSRect cellRect, rect;
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
col = [self columnWithIdentifier: @"Torrent"];
|
2006-01-12 18:29:20 +00:00
|
|
|
cellRect = [self frameOfCellAtColumn: col row: row];
|
2006-03-23 12:39:39 +00:00
|
|
|
rect = NSMakeRect( cellRect.origin.x + cellRect.size.width - 39,
|
|
|
|
cellRect.origin.y + 3, 14, 14 );
|
2006-01-12 18:29:20 +00:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) revealRectForRow: (int) row
|
|
|
|
{
|
|
|
|
int col;
|
|
|
|
NSRect cellRect, rect;
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
col = [self columnWithIdentifier: @"Torrent"];
|
2006-01-12 18:29:20 +00:00
|
|
|
cellRect = [self frameOfCellAtColumn: col row: row];
|
2006-03-23 12:39:39 +00:00
|
|
|
rect = NSMakeRect( cellRect.origin.x + cellRect.size.width - 20,
|
|
|
|
cellRect.origin.y + 3, 14, 14 );
|
2006-01-12 18:29:20 +00:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) pointInPauseRect: (NSPoint) point
|
|
|
|
{
|
|
|
|
return NSPointInRect( point, [self pauseRectForRow:
|
|
|
|
[self rowAtPoint: point]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) pointInRevealRect: (NSPoint) point
|
|
|
|
{
|
|
|
|
return NSPointInRect( point, [self revealRectForRow:
|
|
|
|
[self rowAtPoint: point]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
- (void) mouseDown: (NSEvent *) e
|
|
|
|
{
|
|
|
|
fClickPoint = [self convertPoint: [e locationInWindow] fromView: nil];
|
|
|
|
int row = [self rowAtPoint: fClickPoint];
|
2006-01-12 18:29:20 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
if( [e modifierFlags] & NSAlternateKeyMask )
|
2006-01-12 18:29:20 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
[fController advancedChanged: self];
|
|
|
|
fClickPoint = NSMakePoint( 0, 0 );
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
else if( ![self pointInPauseRect: fClickPoint] &&
|
|
|
|
![self pointInRevealRect: fClickPoint] )
|
2006-01-12 18:29:20 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
[super mouseDown: e];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
else;
|
|
|
|
|
|
|
|
[self display];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseUp: (NSEvent *) e
|
|
|
|
{
|
|
|
|
NSPoint point;
|
|
|
|
int row;
|
|
|
|
bool sameRow;
|
|
|
|
Torrent * torrent;
|
|
|
|
|
|
|
|
point = [self convertPoint: [e locationInWindow] fromView: nil];
|
|
|
|
row = [self rowAtPoint: point];
|
|
|
|
sameRow = row == [self rowAtPoint: fClickPoint];
|
|
|
|
|
|
|
|
if( sameRow && [self pointInPauseRect: point]
|
|
|
|
&& [self pointInPauseRect: fClickPoint] )
|
2006-01-12 18:33:20 +00:00
|
|
|
{
|
2006-04-07 13:09:19 +00:00
|
|
|
torrent = [fTorrents objectAtIndex: row];
|
|
|
|
|
|
|
|
if( [torrent isPaused] )
|
|
|
|
[fController resumeTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
|
|
|
|
else if( [torrent isActive] )
|
|
|
|
[fController stopTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
|
|
|
|
else;
|
2006-01-12 18:33:20 +00:00
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
else if( sameRow && [self pointInRevealRect: point]
|
|
|
|
&& [self pointInRevealRect: fClickPoint] )
|
2006-01-12 18:29:20 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
torrent = [fTorrents objectAtIndex: row];
|
|
|
|
[torrent reveal];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
2006-04-07 13:09:19 +00:00
|
|
|
else;
|
|
|
|
|
|
|
|
[super mouseUp: e];
|
2006-01-12 18:29:20 +00:00
|
|
|
|
|
|
|
fClickPoint = NSMakePoint( 0, 0 );
|
2006-03-28 11:17:42 +00:00
|
|
|
[self display];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMenu *) menuForEvent: (NSEvent *) e
|
|
|
|
{
|
|
|
|
NSPoint point;
|
|
|
|
int row;
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
point = [self convertPoint: [e locationInWindow] fromView: nil];
|
2006-01-12 18:29:20 +00:00
|
|
|
row = [self rowAtPoint: point];
|
2006-01-12 18:57:23 +00:00
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
if( row >= 0 )
|
|
|
|
{
|
2006-05-01 00:15:18 +00:00
|
|
|
if (![self isRowSelected: row])
|
|
|
|
{
|
|
|
|
if( OSX_VERSION >= 10.3 )
|
|
|
|
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
|
|
|
|
byExtendingSelection: NO];
|
|
|
|
else
|
|
|
|
[self selectRow: row byExtendingSelection: NO];
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
return fContextRow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self deselectAll: self];
|
|
|
|
return fContextNoRow;
|
|
|
|
}
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRect: (NSRect) r
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
unsigned i;
|
2006-01-12 18:29:20 +00:00
|
|
|
NSRect rect;
|
|
|
|
NSImage * image;
|
2006-03-23 12:39:39 +00:00
|
|
|
Torrent * torrent;
|
2006-01-12 18:29:20 +00:00
|
|
|
|
|
|
|
[super drawRect: r];
|
|
|
|
|
2006-03-23 12:39:39 +00:00
|
|
|
for( i = 0; i < [fTorrents count]; i++ )
|
2006-01-12 18:29:20 +00:00
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
torrent = [fTorrents objectAtIndex: i];
|
2006-01-12 18:29:20 +00:00
|
|
|
rect = [self pauseRectForRow: i];
|
2006-03-23 12:39:39 +00:00
|
|
|
image = nil;
|
|
|
|
|
|
|
|
if( [torrent isPaused] )
|
2006-01-12 18:29:20 +00:00
|
|
|
{
|
|
|
|
image = NSPointInRect( fClickPoint, rect ) ?
|
|
|
|
[NSImage imageNamed: @"ResumeOn.png"] :
|
|
|
|
[NSImage imageNamed: @"ResumeOff.png"];
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
else if( [torrent isActive] )
|
2006-01-12 18:29:20 +00:00
|
|
|
{
|
|
|
|
image = NSPointInRect( fClickPoint, rect ) ?
|
|
|
|
[NSImage imageNamed: @"PauseOn.png"] :
|
|
|
|
[NSImage imageNamed: @"PauseOff.png"];
|
|
|
|
}
|
2006-03-23 12:39:39 +00:00
|
|
|
else;
|
|
|
|
|
2006-01-12 18:29:20 +00:00
|
|
|
if( image )
|
|
|
|
{
|
2006-03-23 12:39:39 +00:00
|
|
|
[image setFlipped: YES];
|
|
|
|
[image drawAtPoint: rect.origin fromRect:
|
|
|
|
NSMakeRect( 0, 0, 14, 14 ) operation:
|
|
|
|
NSCompositeSourceOver fraction: 1.0];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rect = [self revealRectForRow: i];
|
|
|
|
image = NSPointInRect( fClickPoint, rect ) ?
|
|
|
|
[NSImage imageNamed: @"RevealOn.png"] :
|
|
|
|
[NSImage imageNamed: @"RevealOff.png"];
|
2006-03-23 12:39:39 +00:00
|
|
|
[image setFlipped: YES];
|
|
|
|
[image drawAtPoint: rect.origin fromRect:
|
|
|
|
NSMakeRect( 0, 0, 14, 14 ) operation:
|
|
|
|
NSCompositeSourceOver fraction: 1.0];
|
2006-01-12 18:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|