source: branches/new_api/macosx/TorrentTableView.m @ 151

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

Moved 'reveal in finder' to the Torrent class, and do it in a PathFinder?-
compatible way (fixes #6)

File size: 5.6 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
27@implementation TorrentTableView
28
29- (void) setTorrents: (NSArray *) torrents
30{
31    fTorrents = torrents;
32}
33
34- (void) pauseOrResume: (int) row
35{
36#if 0
37    if( fStat[row].status & TR_STATUS_PAUSE )
38    {
39        [fController resumeTorrentWithIndex: row];
40    }
41    else if( fStat[row].status & ( TR_STATUS_CHECK |
42              TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
43    {
44        [fController stopTorrentWithIndex: row];
45    }                                                                   
46#endif
47}
48
49- (void) mouseDown: (NSEvent *) e
50{
51    fClickPoint = [self convertPoint: [e locationInWindow] fromView: NULL];
52    [self display];
53}
54
55- (NSRect) pauseRectForRow: (int) row
56{
57    int col;
58    NSRect cellRect, rect;
59
60    col      = [self columnWithIdentifier: @"Torrent"];
61    cellRect = [self frameOfCellAtColumn: col row: row];
62    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 39,
63                           cellRect.origin.y + 3, 14, 14 );
64
65    return rect;
66}
67
68- (NSRect) revealRectForRow: (int) row
69{
70    int col;
71    NSRect cellRect, rect;
72
73    col      = [self columnWithIdentifier: @"Torrent"];
74    cellRect = [self frameOfCellAtColumn: col row: row];
75    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 20,
76                           cellRect.origin.y + 3, 14, 14 );
77
78    return rect;
79}
80
81- (BOOL) pointInPauseRect: (NSPoint) point
82{
83    return NSPointInRect( point, [self pauseRectForRow:
84                                    [self rowAtPoint: point]] );
85}
86
87- (BOOL) pointInRevealRect: (NSPoint) point
88{
89    return NSPointInRect( point, [self revealRectForRow:
90                                    [self rowAtPoint: point]] );
91}
92
93- (void) mouseUp: (NSEvent *) e
94{
95    NSPoint point;
96    int row, col;
97    Torrent * torrent;
98
99    point = [self convertPoint: [e locationInWindow] fromView: NULL];
100    row   = [self rowAtPoint: point];
101    col   = [self columnAtPoint: point];
102
103    if( row < 0 )
104    {
105        [self deselectAll: NULL];
106    }
107    else if( [self pointInPauseRect: point] )
108    {
109        [self pauseOrResume: row];
110    }
111    else if( [self pointInRevealRect: point] )
112    {
113        torrent = [fTorrents objectAtIndex: row];
114        [torrent reveal];
115        [self display];
116    }
117    else if( row >= 0 && ( [e modifierFlags] & NSAlternateKeyMask ) )
118    {
119        [fController advancedChanged: self];
120    }
121    else
122    {
123        [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
124            byExtendingSelection: NO];
125    }
126
127    fClickPoint = NSMakePoint( 0, 0 );
128}
129
130- (NSMenu *) menuForEvent: (NSEvent *) e
131{
132    NSPoint point;
133    int row;
134
135    point = [self convertPoint: [e locationInWindow] fromView: NULL];
136    row = [self rowAtPoint: point];
137   
138    [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
139
140    return row >= 0 ? fContextRow : fContextNoRow;
141}
142
143- (void) drawRect: (NSRect) r
144{
145    int i;
146    NSRect rect;
147    NSPoint point;
148    NSImage * image;
149
150    [super drawRect: r];
151
152    for( i = 0; i < [self numberOfRows]; i++ )
153    {
154        rect  = [self pauseRectForRow: i];
155        image = NULL;
156#if 0
157        if( fStat[i].status & TR_STATUS_PAUSE )
158        {
159#endif
160            image = NSPointInRect( fClickPoint, rect ) ?
161                [NSImage imageNamed: @"ResumeOn.png"] :
162                [NSImage imageNamed: @"ResumeOff.png"];
163#if 0
164        }
165        else if( fStat[i].status &
166                 ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
167        {
168            image = NSPointInRect( fClickPoint, rect ) ?
169                [NSImage imageNamed: @"PauseOn.png"] :
170                [NSImage imageNamed: @"PauseOff.png"];
171        }
172#endif
173        if( image )
174        {
175            [image setFlipped: YES];
176            [image drawAtPoint: rect.origin fromRect:
177                NSMakeRect( 0, 0, 14, 14 ) operation:
178                NSCompositeSourceOver fraction: 1.0];
179        }
180
181        rect  = [self revealRectForRow: i];
182        image = NSPointInRect( fClickPoint, rect ) ?
183            [NSImage imageNamed: @"RevealOn.png"] :
184            [NSImage imageNamed: @"RevealOff.png"];
185        [image setFlipped: YES];
186        [image drawAtPoint: rect.origin fromRect:
187            NSMakeRect( 0, 0, 14, 14 ) operation:
188            NSCompositeSourceOver fraction: 1.0];
189    }
190}
191
192@end
Note: See TracBrowser for help on using the repository browser.