source: trunk/macosx/TorrentTableView.m @ 3601

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

show the multiple document icon on Leopard when multiple files selected

  • Property svn:keywords set to Date Rev Author Id
File size: 22.4 KB
Line 
1/******************************************************************************
2 * $Id: TorrentTableView.m 3601 2007-10-27 18:40:43Z livings124 $
3 *
4 * Copyright (c) 2005-2007 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 "TorrentCell.h"
27#import "Controller.h"
28#import "Torrent.h"
29#import "NSApplicationAdditions.h"
30#import "NSMenuAdditions.h"
31
32#define PADDING 3.0
33
34#define BUTTON_TO_TOP_REGULAR 33.0
35#define BUTTON_TO_TOP_SMALL 20.0
36
37#define ACTION_BUTTON_TO_TOP 47.0
38
39#define ACTION_MENU_GLOBAL_TAG 101
40#define ACTION_MENU_UNLIMITED_TAG 102
41#define ACTION_MENU_LIMIT_TAG 103
42
43@interface TorrentTableView (Private)
44
45- (NSRect) pauseRectForRow: (int) row;
46- (NSRect) revealRectForRow: (int) row;
47- (NSRect) actionRectForRow: (int) row;
48
49- (BOOL) pointInIconRect: (NSPoint) point;
50- (BOOL) pointInProgressRect: (NSPoint) point;
51- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
52
53- (BOOL) pointInPauseRect: (NSPoint) point;
54- (BOOL) pointInRevealRect: (NSPoint) point;
55- (BOOL) pointInActionRect: (NSPoint) point;
56
57- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
58
59@end
60
61@implementation TorrentTableView
62
63- (id) initWithCoder: (NSCoder *) decoder
64{
65    if ((self = [super initWithCoder: decoder]))
66    {
67        fResumeOnIcon = [NSImage imageNamed: @"ResumeOn.png"];
68        fResumeOffIcon = [NSImage imageNamed: @"ResumeOff.png"];
69        fPauseOnIcon = [NSImage imageNamed: @"PauseOn.png"];
70        fPauseOffIcon = [NSImage imageNamed: @"PauseOff.png"];
71        fResumeNoWaitOnIcon = [NSImage imageNamed: @"ResumeNoWaitOn.png"];
72        fResumeNoWaitOffIcon = [NSImage imageNamed: @"ResumeNoWaitOff.png"];
73       
74        fRevealOnIcon = [NSImage imageNamed: @"RevealOn.png"];
75        fRevealOffIcon = [NSImage imageNamed: @"RevealOff.png"];
76       
77        fActionOnIcon = [NSImage imageNamed: @"ActionOn.png"];
78        fActionOffIcon = [NSImage imageNamed: @"ActionOff.png"];
79       
80        fClickPoint = NSZeroPoint;
81        fClickIn = NO;
82       
83        fDefaults = [NSUserDefaults standardUserDefaults];
84       
85        [self setDelegate: self];
86    }
87   
88    return self;
89}
90
91- (void) dealloc
92{
93    [fKeyStrokes release];
94    [fMenuTorrent release];
95   
96    [super dealloc];
97}
98
99- (void) setTorrents: (NSArray *) torrents
100{
101    fTorrents = torrents;
102}
103
104- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell
105        forTableColumn: (NSTableColumn *) tableColumn row: (int) row
106{
107    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
108}
109
110
111- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row
112{
113    return [[fTorrents objectAtIndex: row] name];
114}
115
116- (void) mouseDown: (NSEvent *) event
117{
118    //NSLog(@"down");
119    fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil];
120
121    if ([self pointInActionRect: fClickPoint])
122    {
123        int row = [self rowAtPoint: fClickPoint];
124        [self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
125       
126        [self displayTorrentMenuForEvent: event];
127       
128        fClickPoint = NSZeroPoint;
129        [self setNeedsDisplayInRect: [self rectOfRow: row]];
130    }
131    else if ([self pointInPauseRect: fClickPoint] || [self pointInRevealRect: fClickPoint])
132    {
133        fClickIn = YES;
134        [self setNeedsDisplayInRect: [self rectOfRow: [self rowAtPoint: fClickPoint]]];
135    }
136    else
137    {
138        if (/*[event modifierFlags] & NSAlternateKeyMask*/NO)
139        {
140            [fDefaults setBool: ![fDefaults boolForKey: @"UseAdvancedBar"] forKey: @"UseAdvancedBar"];
141            fClickPoint = NSZeroPoint;
142            [self reloadData];
143        }
144        else
145        {
146            if ([self pointInMinimalStatusRect: fClickPoint])
147            {
148                [fDefaults setBool: ![fDefaults boolForKey: @"DisplaySmallStatusRegular"] forKey: @"DisplaySmallStatusRegular"];
149                fClickPoint = NSZeroPoint;
150                [self reloadData];
151            }
152
153            [super mouseDown: event];
154        }
155    }
156}
157
158#warning not always working
159- (void) mouseUp: (NSEvent *) event
160{
161    //NSLog(@"up");
162    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
163    int row = [self rowAtPoint: point], oldRow = [self rowAtPoint: fClickPoint];
164   
165    if (row == oldRow && [self pointInPauseRect: point] && [self pointInPauseRect: fClickPoint])
166    {
167        Torrent * torrent = [fTorrents objectAtIndex: row];
168       
169        if ([torrent isActive])
170            [fController stopTorrents: [NSArray arrayWithObject: torrent]];
171        else
172        {
173            if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
174                [fController resumeTorrentsNoWait: [NSArray arrayWithObject: torrent]];
175            else if ([torrent waitingToStart])
176                [fController stopTorrents: [NSArray arrayWithObject: torrent]];
177            else
178                [fController resumeTorrents: [NSArray arrayWithObject: torrent]];
179        }
180    }
181    else if (row == oldRow && [self pointInRevealRect: point] && [self pointInRevealRect: fClickPoint])
182        [[fTorrents objectAtIndex: row] revealData];
183    else if ([event clickCount] == 2 && !NSEqualPoints(fClickPoint, NSZeroPoint))
184    {
185        if ([self pointInProgressRect: fClickPoint])
186        {
187            [fDefaults setBool: ![fDefaults boolForKey: @"DisplayStatusProgressSelected"] forKey: @"DisplayStatusProgressSelected"];
188            [self reloadData];
189        }
190        else if ([self pointInIconRect: point])
191            [[fTorrents objectAtIndex: row] revealData];
192        else if (![self pointInActionRect: point])
193            [fController showInfo: nil];
194        else;
195    }
196    else;
197   
198    [super mouseUp: event];
199
200    fClickPoint = NSZeroPoint;
201    fClickIn = NO;
202    [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
203}
204
205- (void) mouseDragged: (NSEvent *) event
206{
207    if (NSEqualPoints(fClickPoint, NSZeroPoint))
208    {
209        [super mouseDragged: event];
210        return;
211    }
212   
213    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
214    int oldRow = [self rowAtPoint: fClickPoint];
215   
216    BOOL inRect;
217    if ([self pointInRevealRect: fClickPoint])
218        inRect = oldRow == [self rowAtPoint: point] && [self pointInRevealRect: point];
219    else if ([self pointInPauseRect: fClickPoint])
220        inRect = oldRow == [self rowAtPoint: point] && [self pointInPauseRect: point];
221    else
222    {
223        [super mouseDragged: event];
224        return;
225    }
226   
227    if (inRect != fClickIn)
228    {
229        fClickIn = inRect;
230        [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
231    }
232}
233
234- (NSMenu *) menuForEvent: (NSEvent *) event
235{
236    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
237   
238    if (row >= 0)
239    {
240        if (![self isRowSelected: row])
241            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
242        return fContextRow;
243    }
244    else
245    {
246        [self deselectAll: self];
247        return fContextNoRow;
248    }
249}
250
251- (void) flagsChanged: (NSEvent *) event
252{
253    [self display];
254    [super flagsChanged: event];
255}
256
257- (void) keyDown: (NSEvent *) event
258{
259    //this is handled by the delegate in Leopard
260    if ([NSApp isOnLeopardOrBetter])
261    {
262        [super keyDown: event];
263        return;
264    }
265   
266    if (!fKeyStrokes)
267        fKeyStrokes = [[NSMutableArray alloc] init];
268   
269    unichar newChar = [[event characters] characterAtIndex: 0];
270    if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]
271        || [[NSCharacterSet symbolCharacterSet] characterIsMember: newChar]
272        || [[NSCharacterSet punctuationCharacterSet] characterIsMember: newChar])
273    {
274        if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
275            [fKeyStrokes removeAllObjects];
276        [fKeyStrokes addObject: event];
277   
278        [self interpretKeyEvents: fKeyStrokes];
279    }
280    else
281    {
282        [fKeyStrokes removeAllObjects];
283        [super keyDown: event];
284    }
285}
286
287- (void) insertText: (NSString *) text
288{
289    //this is handled by the delegate in Leopard
290    if ([NSApp isOnLeopardOrBetter])
291    {
292        [super insertText: text];
293        return;
294    }
295   
296    //sort torrents by name before finding closest match
297    NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES
298                                            selector: @selector(caseInsensitiveCompare:)] autorelease];
299    NSArray * descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
300
301    NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors];
302    [descriptors release];
303   
304    text = [text lowercaseString];
305   
306    //select torrent closest to text that isn't before text alphabetically
307    NSEnumerator * enumerator = [tempTorrents objectEnumerator];
308    Torrent * torrent;
309    while ((torrent = [enumerator nextObject]))
310        if ([[[torrent name] lowercaseString] hasPrefix: text])
311        {
312            int row = [fTorrents indexOfObject: torrent];
313            [self selectRow: row byExtendingSelection: NO];
314            [self scrollRowToVisible: row];
315            return;
316        }
317}
318
319- (void) displayTorrentMenuForEvent: (NSEvent *) event
320{
321    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
322    if (row < 0)
323        return;
324   
325    //get and update file menu
326    fMenuTorrent = [[fTorrents objectAtIndex: row] retain];
327    NSMenu * fileMenu = [fMenuTorrent fileMenu];
328    [self updateFileMenu: fileMenu forFiles: [fMenuTorrent fileList]];
329   
330    //add file menu items to action menu
331    NSRange range = NSMakeRange(0, [fileMenu numberOfItems]);
332    [fActionMenu appendItemsFromMenu: fileMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range]];
333   
334    //place menu below button
335    NSRect rect = [self actionRectForRow: row];
336    NSPoint location = rect.origin;
337    location.y += rect.size.height + 5.0;
338    location = [self convertPoint: location toView: nil];
339   
340    NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
341        modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
342        context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
343   
344    [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
345   
346    //move file menu items back to the torrent's file menu
347    range.location = [fActionMenu numberOfItems] - range.length;
348    [fileMenu appendItemsFromMenu: fActionMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range]];
349   
350    [fMenuTorrent release];
351    fMenuTorrent = nil;
352}
353
354- (void) menuNeedsUpdate: (NSMenu *) menu
355{
356    //this method seems to be called when it shouldn't be
357    if (!fMenuTorrent || ![menu supermenu])
358        return;
359   
360    if (menu == fUploadMenu || menu == fDownloadMenu)
361    {
362        BOOL upload = menu == fUploadMenu;
363        int mode = [fMenuTorrent speedMode: upload];
364       
365        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
366        [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
367        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
368                    "torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
369       
370        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
371        [item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
372       
373        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
374        [item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
375    }
376    else if (menu == fRatioMenu)
377    {
378        int mode = [fMenuTorrent ratioSetting];
379       
380        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
381        [item setState: mode == NSOnState ? NSOnState : NSOffState];
382        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
383                    "torrent action context menu -> ratio stop"), [fMenuTorrent ratioLimit]]];
384       
385        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
386        [item setState: mode == NSOffState ? NSOnState : NSOffState];
387       
388        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
389        [item setState: mode == NSMixedState ? NSOnState : NSOffState];
390    }
391    else if ([menu supermenu]) //assume the menu is part of the file list
392    {
393        NSMenu * supermenu = [menu supermenu];
394        [self updateFileMenu: menu forFiles: [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]]
395                                                    representedObject] objectForKey: @"Children"]];
396    }
397    else;
398}
399
400- (void) setQuickLimitMode: (id) sender
401{
402    int mode;
403    switch ([sender tag])
404    {
405        case ACTION_MENU_UNLIMITED_TAG:
406            mode = TR_SPEEDLIMIT_UNLIMITED;
407            break;
408        case ACTION_MENU_LIMIT_TAG:
409            mode = TR_SPEEDLIMIT_SINGLE;
410            break;
411        case ACTION_MENU_GLOBAL_TAG:
412            mode = TR_SPEEDLIMIT_GLOBAL;
413            break;
414        default:
415            return;
416    }
417   
418    [fMenuTorrent setSpeedMode: mode upload: [sender menu] == fUploadMenu];
419   
420    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
421}
422
423- (void) setQuickLimit: (id) sender
424{
425    BOOL upload = [sender menu] == fUploadMenu;
426    [fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload];
427    [fMenuTorrent setSpeedLimit: [[sender title] intValue] upload: upload];
428   
429    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
430}
431
432- (void) setQuickRatioMode: (id) sender
433{
434    int mode;
435    switch ([sender tag])
436    {
437        case ACTION_MENU_UNLIMITED_TAG:
438            mode = NSOffState;
439            break;
440        case ACTION_MENU_LIMIT_TAG:
441            mode = NSOnState;
442            break;
443        case ACTION_MENU_GLOBAL_TAG:
444            mode = NSMixedState;
445            break;
446        default:
447            return;
448    }
449   
450    [fMenuTorrent setRatioSetting: mode];
451   
452    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
453}
454
455- (void) setQuickRatio: (id) sender
456{
457    [fMenuTorrent setRatioSetting: NSOnState];
458    [fMenuTorrent setRatioLimit: [[sender title] floatValue]];
459   
460    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
461}
462
463- (void) checkFile: (id) sender
464{
465    NSIndexSet * indexSet = [[sender representedObject] objectForKey: @"Indexes"];
466    [fMenuTorrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexSet];
467   
468    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
469}
470
471- (void) drawRow: (int) row clipRect: (NSRect) rect
472{
473    [super drawRow: row clipRect: rect];
474   
475    Torrent * torrent = [fTorrents objectAtIndex: row];
476   
477    //pause/resume icon
478    NSImage * pauseImage = nil;
479    NSRect pauseRect  = [self pauseRectForRow: row];
480    if ([torrent isActive])
481        pauseImage = fClickIn && NSPointInRect(fClickPoint, pauseRect) ? fPauseOnIcon : fPauseOffIcon;
482    else
483    {
484        BOOL inPauseRect = fClickIn && NSPointInRect(fClickPoint, pauseRect);
485        if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask && [fDefaults boolForKey: @"Queue"])
486            pauseImage = inPauseRect ? fResumeNoWaitOnIcon : fResumeNoWaitOffIcon;
487        else if ([torrent waitingToStart])
488            pauseImage = inPauseRect ? fPauseOnIcon : fPauseOffIcon;
489        else
490            pauseImage = inPauseRect ? fResumeOnIcon : fResumeOffIcon;
491    }
492   
493    if (pauseImage)
494        [pauseImage compositeToPoint: NSMakePoint(pauseRect.origin.x, NSMaxY(pauseRect)) operation: NSCompositeSourceOver];
495   
496    //reveal icon
497    NSRect revealRect = [self revealRectForRow: row];
498    NSImage * revealImage = fClickIn && NSPointInRect(fClickPoint, revealRect) ? fRevealOnIcon : fRevealOffIcon;
499    [revealImage compositeToPoint: NSMakePoint(revealRect.origin.x, NSMaxY(revealRect)) operation: NSCompositeSourceOver];
500   
501    //action icon
502    if (![fDefaults boolForKey: @"SmallView"])
503    {
504        NSRect actionRect = [self actionRectForRow: row];
505        NSImage * actionImage = NSPointInRect(fClickPoint, actionRect) ? fActionOnIcon : fActionOffIcon;
506        [actionImage compositeToPoint: NSMakePoint(actionRect.origin.x, NSMaxY(actionRect)) operation: NSCompositeSourceOver];
507    }
508}
509
510@end
511
512@implementation TorrentTableView (Private)
513
514- (NSRect) pauseRectForRow: (int) row
515{
516    if (row < 0)
517        return NSZeroRect;
518   
519    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
520   
521    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
522   
523    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH - PADDING - BUTTON_WIDTH,
524                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
525}
526
527- (NSRect) revealRectForRow: (int) row
528{
529    if (row < 0)
530        return NSZeroRect;
531   
532    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
533   
534    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
535   
536    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH,
537                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
538}
539
540- (NSRect) actionRectForRow: (int) row
541{
542    if (row < 0)
543        return NSZeroRect;
544   
545    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
546    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row],
547            iconRect = [cell iconRectForBounds: cellRect];
548   
549    if ([fDefaults boolForKey: @"SmallView"])
550        return iconRect;
551    else
552        return NSMakeRect(iconRect.origin.x + (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5,
553                        cellRect.origin.y + ACTION_BUTTON_TO_TOP, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT);
554}
555
556- (BOOL) pointInIconRect: (NSPoint) point
557{
558    int row = [self rowAtPoint: point];
559    if (row < 0)
560        return NO;
561   
562    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
563    return NSPointInRect(point, [cell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
564}
565
566- (BOOL) pointInProgressRect: (NSPoint) point
567{
568    int row = [self rowAtPoint: point];
569    if (row < 0 || [fDefaults boolForKey: @"SmallView"])
570        return NO;
571   
572    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
573    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
574    return NSPointInRect(point, [cell progressRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
575}
576
577- (BOOL) pointInMinimalStatusRect: (NSPoint) point
578{
579    int row = [self rowAtPoint: point];
580    if (row < 0 || ![fDefaults boolForKey: @"SmallView"])
581        return NO;
582   
583    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
584    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
585    return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
586}
587
588- (BOOL) pointInPauseRect: (NSPoint) point
589{
590    int row = [self rowAtPoint: point];
591    if (row < 0)
592        return NO;
593   
594    return NSPointInRect(point, [self pauseRectForRow: row]);
595}
596
597- (BOOL) pointInRevealRect: (NSPoint) point
598{
599    int row = [self rowAtPoint: point];
600    if (row < 0)
601        return NO;
602   
603    return NSPointInRect(point, [self revealRectForRow: row]);
604}
605
606- (BOOL) pointInActionRect: (NSPoint) point
607{
608    int row = [self rowAtPoint: point];
609    if (row < 0)
610        return NO;
611   
612    return NSPointInRect(point, [self actionRectForRow: row]);
613}
614
615- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
616{
617    BOOL create = [menu numberOfItems] <= 0;
618   
619    NSEnumerator * enumerator = [files objectEnumerator];
620    NSDictionary * dict;
621    NSMenuItem * item;
622    while ((dict = [enumerator nextObject]))
623    {
624        NSString * name = [dict objectForKey: @"Name"];
625       
626        if (create)
627        {
628            item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""];
629           
630            NSImage * icon;
631            if (![[dict objectForKey: @"IsFolder"] boolValue])
632            {
633                icon = [[dict objectForKey: @"Icon"] copy];
634                [icon setFlipped: NO];
635            }
636            else
637            {
638                NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
639                [itemMenu setAutoenablesItems: NO];
640                [item setSubmenu: itemMenu];
641                [itemMenu setDelegate: self];
642                [itemMenu release];
643               
644                icon = [[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')] copy];
645            }
646           
647            [item setRepresentedObject: dict];
648           
649            [icon setScalesWhenResized: YES];
650            [icon setSize: NSMakeSize(16.0, 16.0)];
651            [item setImage: icon];
652            [icon release];
653           
654            [item setAction: @selector(checkFile:)];
655           
656            [menu addItem: item];
657            [item release];
658        }
659        else
660            item = [menu itemWithTitle: name];
661       
662        NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
663        [item setState: [fMenuTorrent checkForFiles: indexSet]];
664        [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]];
665    }
666}
667
668@end
Note: See TracBrowser for help on using the repository browser.