source: trunk/macosx/TorrentTableView.m @ 256

Last change on this file since 256 was 256, checked in by titer, 16 years ago

Merged Mitchell's changes, this includes:
Adds stop at ratio,
Adds sorting by name, date or state,
Seperates Info window into its own nib,
Adds option to enable or disabled autostarting downloads,
Seperates Network / Transfers in the Preferences

File size: 5.8 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2005-2006 Transmission authors and contributors
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *****************************************************************************/
22
23#import "TorrentTableView.h"
24#import "Controller.h"
25#import "Torrent.h"
26#import "Utils.h"
27
28@implementation TorrentTableView
29
30- (void) setTorrents: (NSArray *) torrents
31{
32    fTorrents = torrents;
33}
34
35- (NSRect) pauseRectForRow: (int) row
36{
37    int col;
38    NSRect cellRect, rect;
39
40    col      = [self columnWithIdentifier: @"Torrent"];
41    cellRect = [self frameOfCellAtColumn: col row: row];
42    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 39,
43                           cellRect.origin.y + 3, 14, 14 );
44
45    return rect;
46}
47
48- (NSRect) revealRectForRow: (int) row
49{
50    int col;
51    NSRect cellRect, rect;
52
53    col      = [self columnWithIdentifier: @"Torrent"];
54    cellRect = [self frameOfCellAtColumn: col row: row];
55    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 20,
56                           cellRect.origin.y + 3, 14, 14 );
57
58    return rect;
59}
60
61- (BOOL) pointInPauseRect: (NSPoint) point
62{
63    return NSPointInRect( point, [self pauseRectForRow:
64                                    [self rowAtPoint: point]] );
65}
66
67- (BOOL) pointInRevealRect: (NSPoint) point
68{
69    return NSPointInRect( point, [self revealRectForRow:
70                                    [self rowAtPoint: point]] );
71}
72
73- (void) mouseDown: (NSEvent *) e
74{
75    fClickPoint = [self convertPoint: [e locationInWindow] fromView: nil];
76    int row = [self rowAtPoint: fClickPoint];
77
78    if( [e modifierFlags] & NSAlternateKeyMask )
79    {
80        [fController advancedChanged: self];
81        fClickPoint = NSMakePoint( 0, 0 );
82    }
83    else if( ![self pointInPauseRect: fClickPoint] &&
84             ![self pointInRevealRect: fClickPoint] )
85    {
86        [super mouseDown: e];
87    }
88    else;
89
90    [self display];
91}
92
93- (void) mouseUp: (NSEvent *) e
94{
95    NSPoint point;
96    int row;
97    bool sameRow;
98    Torrent * torrent;
99
100    point = [self convertPoint: [e locationInWindow] fromView: nil];
101    row   = [self rowAtPoint: point];
102    sameRow = row == [self rowAtPoint: fClickPoint];
103   
104    if( sameRow && [self pointInPauseRect: point]
105            && [self pointInPauseRect: fClickPoint] )
106    {
107        torrent = [fTorrents objectAtIndex: row];
108
109                if( [torrent isPaused] )
110                        [fController resumeTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
111                else if( [torrent isActive] )
112                        [fController stopTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
113                else;
114    }
115    else if( sameRow && [self pointInRevealRect: point]
116                && [self pointInRevealRect: fClickPoint] )
117    {
118        torrent = [fTorrents objectAtIndex: row];
119        [torrent reveal];
120    }
121        else;
122   
123        [super mouseUp: e];
124
125    fClickPoint = NSMakePoint( 0, 0 );
126    [self display];
127}
128
129- (NSMenu *) menuForEvent: (NSEvent *) e
130{
131    NSPoint point;
132    int row;
133
134    point = [self convertPoint: [e locationInWindow] fromView: nil];
135    row = [self rowAtPoint: point];
136   
137    if( row >= 0 )
138    {
139        if (![self isRowSelected: row])
140            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
141                byExtendingSelection: NO];
142               
143        return fContextRow;
144    }
145    else
146    {
147        [self deselectAll: self];
148        return fContextNoRow;
149    }
150}
151
152- (void) drawRect: (NSRect) r
153{
154    unsigned i;
155    NSRect rect;
156    NSImage * image;
157    Torrent * torrent;
158
159    [super drawRect: r];
160
161    for( i = 0; i < [fTorrents count]; i++ )
162    {
163        torrent = [fTorrents objectAtIndex: i];
164        rect  = [self pauseRectForRow: i];
165        image = nil;
166
167        if( [torrent isPaused] )
168        {
169            image = NSPointInRect( fClickPoint, rect ) ?
170                [NSImage imageNamed: @"ResumeOn.png"] :
171                [NSImage imageNamed: @"ResumeOff.png"];
172        }
173        else if( [torrent isActive] )
174        {
175            image = NSPointInRect( fClickPoint, rect ) ?
176                [NSImage imageNamed: @"PauseOn.png"] :
177                [NSImage imageNamed: @"PauseOff.png"];
178        }
179        else;
180
181        if( image )
182        {
183            [image setFlipped: YES];
184            [image drawAtPoint: rect.origin fromRect:
185                NSMakeRect( 0, 0, 14, 14 ) operation:
186                NSCompositeSourceOver fraction: 1.0];
187        }
188
189        rect  = [self revealRectForRow: i];
190        image = NSPointInRect( fClickPoint, rect ) ?
191            [NSImage imageNamed: @"RevealOn.png"] :
192            [NSImage imageNamed: @"RevealOff.png"];
193        [image setFlipped: YES];
194        [image drawAtPoint: rect.origin fromRect:
195            NSMakeRect( 0, 0, 14, 14 ) operation:
196            NSCompositeSourceOver fraction: 1.0];
197    }
198}
199
200@end
Note: See TracBrowser for help on using the repository browser.