source: trunk/macosx/TorrentTableView.m @ 272

Last change on this file since 272 was 272, checked in by livings124, 15 years ago

First commit on my own 8-)

Sorting by progress, sorting no longer causes crashes.
New look for the table.
Info is now inspector: can set individual and multiple ratio limits, shows listing of files, more info in general, resizes when changing tabs, can change tabs with cmd-left and cmd-right.
Menu items moved to "Transfers" menu.
Sliding status bar in its own view.
Prefs moved into their own nib.
Toolbar items for pause and resume selected (many wanted this, but it needs better icons)
New icons for Transfers and General.
A lot of tweaking of main window to fix alignment etc.
Sparkle used for updated (still needs to be added to website to work).

And a lot more tweaking and changes that I'm too lazy to list.

...now let's hope I commit this right

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