mirror of
https://github.com/transmission/transmission.git
synced 2025-12-25 04:45:56 +00:00
Merge from branches/new_api:r161
This commit is contained in:
@@ -1,31 +1,49 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
#import "TorrentTableView.h"
|
||||
#import "Controller.h"
|
||||
#import "Torrent.h"
|
||||
|
||||
@implementation TorrentTableView
|
||||
|
||||
- (void) updateUI: (tr_stat_t *) stat
|
||||
- (void) setTorrents: (NSArray *) torrents
|
||||
{
|
||||
fStat = stat;
|
||||
[self reloadData];
|
||||
fTorrents = torrents;
|
||||
}
|
||||
|
||||
- (void) pauseOrResume: (int) row
|
||||
{
|
||||
if( fStat[row].status & TR_STATUS_PAUSE )
|
||||
Torrent * torrent = [fTorrents objectAtIndex: row];
|
||||
|
||||
if( [torrent isPaused] )
|
||||
{
|
||||
[fController resumeTorrentWithIndex: row];
|
||||
}
|
||||
else if( fStat[row].status & ( TR_STATUS_CHECK |
|
||||
TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
|
||||
else if( [torrent isActive] )
|
||||
{
|
||||
[fController stopTorrentWithIndex: row];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent *) e
|
||||
{
|
||||
fClickPoint = [self convertPoint: [e locationInWindow] fromView: NULL];
|
||||
[self display];
|
||||
}
|
||||
else;
|
||||
}
|
||||
|
||||
- (NSRect) pauseRectForRow: (int) row
|
||||
@@ -33,11 +51,10 @@
|
||||
int col;
|
||||
NSRect cellRect, rect;
|
||||
|
||||
col = [self columnWithIdentifier: @"Name"];
|
||||
col = [self columnWithIdentifier: @"Torrent"];
|
||||
cellRect = [self frameOfCellAtColumn: col row: row];
|
||||
rect = NSMakeRect( cellRect.origin.x + cellRect.size.width - 19,
|
||||
cellRect.origin.y + cellRect.size.height - 38,
|
||||
14, 14 );
|
||||
rect = NSMakeRect( cellRect.origin.x + cellRect.size.width - 39,
|
||||
cellRect.origin.y + 3, 14, 14 );
|
||||
|
||||
return rect;
|
||||
}
|
||||
@@ -47,11 +64,10 @@
|
||||
int col;
|
||||
NSRect cellRect, rect;
|
||||
|
||||
col = [self columnWithIdentifier: @"Name"];
|
||||
col = [self columnWithIdentifier: @"Torrent"];
|
||||
cellRect = [self frameOfCellAtColumn: col row: row];
|
||||
rect = NSMakeRect( cellRect.origin.x + cellRect.size.width - 19,
|
||||
cellRect.origin.y + cellRect.size.height - 19,
|
||||
14, 14 );
|
||||
rect = NSMakeRect( cellRect.origin.x + cellRect.size.width - 20,
|
||||
cellRect.origin.y + 3, 14, 14 );
|
||||
|
||||
return rect;
|
||||
}
|
||||
@@ -68,41 +84,60 @@
|
||||
[self rowAtPoint: point]] );
|
||||
}
|
||||
|
||||
|
||||
- (void) mouseDown: (NSEvent *) e
|
||||
{
|
||||
fClickPoint = [self convertPoint: [e locationInWindow] fromView: nil];
|
||||
int row = [self rowAtPoint: fClickPoint];
|
||||
|
||||
if( [e modifierFlags] & NSAlternateKeyMask )
|
||||
{
|
||||
[fController advancedChanged: self];
|
||||
fClickPoint = NSMakePoint( 0, 0 );
|
||||
}
|
||||
else if( ![self pointInPauseRect: fClickPoint] &&
|
||||
![self pointInRevealRect: fClickPoint] )
|
||||
{
|
||||
if( row >= 0 )
|
||||
{
|
||||
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
|
||||
byExtendingSelection: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self deselectAll: self];
|
||||
}
|
||||
}
|
||||
else;
|
||||
|
||||
[self display];
|
||||
}
|
||||
|
||||
- (void) mouseUp: (NSEvent *) e
|
||||
{
|
||||
NSPoint point;
|
||||
int row, col;
|
||||
int row;
|
||||
bool sameRow;
|
||||
Torrent * torrent;
|
||||
|
||||
point = [self convertPoint: [e locationInWindow] fromView: NULL];
|
||||
point = [self convertPoint: [e locationInWindow] fromView: nil];
|
||||
row = [self rowAtPoint: point];
|
||||
col = [self columnAtPoint: point];
|
||||
|
||||
if( row < 0 )
|
||||
{
|
||||
[self deselectAll: NULL];
|
||||
}
|
||||
else if( [self pointInPauseRect: point] )
|
||||
sameRow = row == [self rowAtPoint: fClickPoint];
|
||||
|
||||
if( sameRow && [self pointInPauseRect: point]
|
||||
&& [self pointInPauseRect: fClickPoint] )
|
||||
{
|
||||
[self pauseOrResume: row];
|
||||
}
|
||||
else if( [self pointInRevealRect: point] )
|
||||
else if( sameRow && [self pointInRevealRect: point]
|
||||
&& [self pointInRevealRect: fClickPoint] )
|
||||
{
|
||||
[fController finderReveal: [NSString stringWithFormat:
|
||||
@"%@/%@", [NSString stringWithUTF8String: fStat[row].folder],
|
||||
[NSString stringWithUTF8String: fStat[row].info.name]]];
|
||||
[self display];
|
||||
}
|
||||
else if( row >= 0 && col == [self columnWithIdentifier: @"Progress"]
|
||||
&& ( [e modifierFlags] & NSAlternateKeyMask ) )
|
||||
{
|
||||
[fController advancedChanged: NULL];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
|
||||
byExtendingSelection: NO];
|
||||
torrent = [fTorrents objectAtIndex: row];
|
||||
[torrent reveal];
|
||||
}
|
||||
else;
|
||||
|
||||
[self display];
|
||||
fClickPoint = NSMakePoint( 0, 0 );
|
||||
}
|
||||
|
||||
@@ -111,52 +146,67 @@
|
||||
NSPoint point;
|
||||
int row;
|
||||
|
||||
point = [self convertPoint: [e locationInWindow] fromView: NULL];
|
||||
point = [self convertPoint: [e locationInWindow] fromView: nil];
|
||||
row = [self rowAtPoint: point];
|
||||
|
||||
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
||||
|
||||
return row >= 0 ? fContextRow : fContextNoRow;
|
||||
if( row >= 0 )
|
||||
{
|
||||
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
|
||||
byExtendingSelection: NO];
|
||||
return fContextRow;
|
||||
}
|
||||
else
|
||||
{
|
||||
[self deselectAll: self];
|
||||
return fContextNoRow;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawRect: (NSRect) r
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
NSRect rect;
|
||||
NSPoint point;
|
||||
NSImage * image;
|
||||
Torrent * torrent;
|
||||
|
||||
[super drawRect: r];
|
||||
|
||||
for( i = 0; i < [self numberOfRows]; i++ )
|
||||
for( i = 0; i < [fTorrents count]; i++ )
|
||||
{
|
||||
torrent = [fTorrents objectAtIndex: i];
|
||||
rect = [self pauseRectForRow: i];
|
||||
image = NULL;
|
||||
if( fStat[i].status & TR_STATUS_PAUSE )
|
||||
image = nil;
|
||||
|
||||
if( [torrent isPaused] )
|
||||
{
|
||||
image = NSPointInRect( fClickPoint, rect ) ?
|
||||
[NSImage imageNamed: @"ResumeOn.png"] :
|
||||
[NSImage imageNamed: @"ResumeOff.png"];
|
||||
}
|
||||
else if( fStat[i].status &
|
||||
( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
|
||||
else if( [torrent isActive] )
|
||||
{
|
||||
image = NSPointInRect( fClickPoint, rect ) ?
|
||||
[NSImage imageNamed: @"PauseOn.png"] :
|
||||
[NSImage imageNamed: @"PauseOff.png"];
|
||||
}
|
||||
else;
|
||||
|
||||
if( image )
|
||||
{
|
||||
point = NSMakePoint( rect.origin.x, rect.origin.y + 14 );
|
||||
[image compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
[image setFlipped: YES];
|
||||
[image drawAtPoint: rect.origin fromRect:
|
||||
NSMakeRect( 0, 0, 14, 14 ) operation:
|
||||
NSCompositeSourceOver fraction: 1.0];
|
||||
}
|
||||
|
||||
rect = [self revealRectForRow: i];
|
||||
image = NSPointInRect( fClickPoint, rect ) ?
|
||||
[NSImage imageNamed: @"RevealOn.png"] :
|
||||
[NSImage imageNamed: @"RevealOff.png"];
|
||||
point = NSMakePoint( rect.origin.x, rect.origin.y + 14 );
|
||||
[image compositeToPoint: point operation: NSCompositeSourceOver];
|
||||
[image setFlipped: YES];
|
||||
[image drawAtPoint: rect.origin fromRect:
|
||||
NSMakeRect( 0, 0, 14, 14 ) operation:
|
||||
NSCompositeSourceOver fraction: 1.0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user