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

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

Started to restore the start/resume/reveal buttons

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