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 | if ([[item objectForKey: @"IsFolder"] boolValue] |
---|
109 | || ![torrent canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]) |
---|
110 | [fNormalColor set]; |
---|
111 | else |
---|
112 | { |
---|
113 | NSIndexSet * indexSet = [item objectForKey: @"Indexes"]; |
---|
114 | if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet]) |
---|
115 | [fHighPriorityColor set]; |
---|
116 | else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet]) |
---|
117 | [fLowPriorityColor set]; |
---|
118 | else |
---|
119 | [fNormalColor set]; |
---|
120 | } |
---|
121 | |
---|
122 | NSRect rect = [self rectOfRow: row]; |
---|
123 | rect.size.height -= 1.0; |
---|
124 | |
---|
125 | NSRectFill(rect); |
---|
126 | } |
---|
127 | |
---|
128 | [super drawRow: row clipRect: clipRect]; |
---|
129 | } |
---|
130 | |
---|
131 | - (void) drawRect: (NSRect) r |
---|
132 | { |
---|
133 | [super drawRect: r]; |
---|
134 | |
---|
135 | NSDictionary * item; |
---|
136 | NSIndexSet * indexSet; |
---|
137 | int i, priority; |
---|
138 | Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent]; |
---|
139 | for (i = 0; i < [self numberOfRows]; i++) |
---|
140 | { |
---|
141 | if ([self isRowSelected: i]) |
---|
142 | { |
---|
143 | item = [self itemAtRow: i]; |
---|
144 | if ([[item objectForKey: @"IsFolder"] boolValue]) |
---|
145 | continue; |
---|
146 | |
---|
147 | indexSet = [item objectForKey: @"Indexes"]; |
---|
148 | if ([torrent canChangeDownloadCheckForFiles: indexSet]) |
---|
149 | { |
---|
150 | if ([torrent hasFilePriority: TR_PRI_HIGH forIndexes: indexSet]) |
---|
151 | [fHighPriorityColor set]; |
---|
152 | else if ([torrent hasFilePriority: TR_PRI_LOW forIndexes: indexSet]) |
---|
153 | [fLowPriorityColor set]; |
---|
154 | else |
---|
155 | continue; |
---|
156 | |
---|
157 | NSRect rect = [self rectOfRow: i]; |
---|
158 | float width = 14.0; |
---|
159 | rect.origin.y += (rect.size.height - width) * 0.5; |
---|
160 | rect.origin.x += 3.0; |
---|
161 | rect.size.width = width; |
---|
162 | rect.size.height = width; |
---|
163 | |
---|
164 | [[NSBezierPath bezierPathWithOvalInRect: rect] fill]; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | @end |
---|