source: trunk/macosx/FileOutlineView.m @ 2335

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

use new functions for setting multiple file dl/priorities

File size: 5.4 KB
Line 
1/******************************************************************************
2 * $Id$
3 *
4 * Copyright (c) 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 "FileOutlineView.h"
26#import "FileBrowserCell.h"
27#import "InfoWindowController.h"
28#import "Torrent.h"
29
30@implementation FileOutlineView
31
32- (void) awakeFromNib
33{
34    NSBrowserCell * browserCell = [[[FileBrowserCell alloc] init] autorelease];
35    [[self tableColumnWithIdentifier: @"Name"] setDataCell: browserCell];
36   
37    [self setAutoresizesOutlineColumn: NO];
38    [self setIndentationPerLevel: 14.0];
39   
40    fNormalColor = [self backgroundColor];
41    fHighPriorityColor = [[NSColor colorWithCalibratedRed: 0.678 green: 0.937 blue: 0.451 alpha: 1.0] retain];
42    fLowPriorityColor = [[NSColor colorWithCalibratedRed: 0.984 green: 0.878 blue: 0.431 alpha: 1.0] retain];
43   
44    fHoverRow = -1;
45}
46
47- (void) dealloc
48{
49    [fHighPriorityColor release];
50    [fLowPriorityColor release];
51   
52    [super dealloc];
53}
54
55- (void) mouseDown: (NSEvent *) event
56{
57    [[self window] makeKeyWindow];
58    [super mouseDown: event];
59}
60
61- (NSMenu *) menuForEvent: (NSEvent *) event
62{
63    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
64   
65    if (row >= 0)
66    {
67        if (![self isRowSelected: row])
68            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
69    }
70    else
71        [self deselectAll: self];
72   
73    return [self menu];
74}
75
76- (void) setHoverRowForEvent: (NSEvent *) event
77{
78    int row = -1;
79    if (event)
80    {
81        NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
82        if ([self columnAtPoint: point] == [self columnWithIdentifier: @"Priority"])
83            row = [self rowAtPoint: point];
84    }
85   
86    if (row != fHoverRow)
87    {
88        if (fHoverRow != -1)
89            [self reloadItem: [self itemAtRow: fHoverRow]];
90        fHoverRow = row;
91        if (fHoverRow != -1)
92            [self reloadItem: [self itemAtRow: fHoverRow]];
93    }
94}
95
96- (int) hoverRow
97{
98    return fHoverRow;
99}
100
101- (void) drawRow: (int) row clipRect: (NSRect) clipRect
102{
103    if (![self isRowSelected: row])
104    {
105        NSDictionary * item = [self itemAtRow: row];
106        Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent];
107       
108        NSIndexSet * indexSet = [item objectForKey: @"Indexes"];
109        if ([[item objectForKey: @"IsFolder"] boolValue] || ![torrent canChangeDownloadCheckForFiles: indexSet])
110            [fNormalColor set];
111        else
112        {
113            if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet])
114                [fHighPriorityColor set];
115            else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet])
116                [fLowPriorityColor set];
117            else
118                [fNormalColor set];
119        }
120       
121        NSRect rect = [self rectOfRow: row];
122        rect.size.height -= 1.0;
123       
124        NSRectFill(rect);
125    }
126   
127    [super drawRow: row clipRect: clipRect];
128}
129
130- (void) drawRect: (NSRect) r
131{
132    [super drawRect: r];
133
134    NSDictionary * item;
135    NSIndexSet * indexSet;
136    int i, priority;
137    Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent];
138    for (i = 0; i < [self numberOfRows]; i++)
139    {
140        if ([self isRowSelected: i])
141        {
142            item = [self itemAtRow: i];
143            if ([[item objectForKey: @"IsFolder"] boolValue])
144                continue;
145           
146            indexSet = [item objectForKey: @"Indexes"];
147            if ([torrent canChangeDownloadCheckForFiles: indexSet])
148            {
149                if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet])
150                    [fHighPriorityColor set];
151                else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet])
152                    [fLowPriorityColor set];
153                else
154                    continue;
155               
156                NSRect rect = [self rectOfRow: i];
157                float width = 14.0;
158                rect.origin.y += (rect.size.height - width) * 0.5;
159                rect.origin.x += 3.0;
160                rect.size.width = width;
161                rect.size.height = width;
162               
163                [[NSBezierPath bezierPathWithOvalInRect: rect] fill];
164            }
165        }
166    }
167}
168
169@end
Note: See TracBrowser for help on using the repository browser.