1 /******************************************************************************
2 * $Id: InfoFileViewController.m 10494 2010-04-17 18:44:34Z livings124 $
4 * Copyright (c) 2010 Transmission authors and contributors
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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 *****************************************************************************/
25 #import "InfoFileViewController.h"
26 #import "FileListNode.h"
27 #import "FileOutlineController.h"
28 #import "FileOutlineView.h"
31 @interface InfoFileViewController (Private)
35 - (BOOL) canQuickLookFile: (FileListNode *) item;
39 @implementation InfoFileViewController
43 if ((self = [super initWithNibName: @"InfoFileView" bundle: nil]))
45 [self setTitle: NSLocalizedString(@"Files", "Inspector view -> title")];
53 const CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: @"InspectorContentHeightFiles"];
56 NSRect viewRect = [[self view] frame];
57 viewRect.size.height = height;
58 [[self view] setFrame: viewRect];
61 [[fFileFilterField cell] setPlaceholderString: NSLocalizedString(@"Filter", "inspector -> file filter")];
71 - (void) setInfoForTorrents: (NSArray *) torrents
73 //don't check if it's the same in case the metadata changed
75 fTorrents = [torrents retain];
85 if ([fTorrents count] == 1)
86 [fFileController reloadData];
91 [[NSUserDefaults standardUserDefaults] setFloat: NSHeight([[self view] frame]) forKey: @"InspectorContentHeightFiles"];
94 - (void) setFileFilterText: (id) sender
96 [fFileController setFilterText: [sender stringValue]];
99 - (NSArray *) quickLookURLs
101 FileOutlineView * fileOutlineView = [fFileController outlineView];
102 Torrent * torrent = [fTorrents objectAtIndex: 0];
103 NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
104 NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]];
106 for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
108 FileListNode * item = [fileOutlineView itemAtRow: i];
109 if ([self canQuickLookFile: item])
110 [urlArray addObject: [NSURL fileURLWithPath: [torrent fileLocation: item]]];
116 - (BOOL) canQuickLook
118 if ([fTorrents count] != 1)
121 Torrent * torrent = [fTorrents objectAtIndex: 0];
122 if (![torrent isFolder])
125 FileOutlineView * fileOutlineView = [fFileController outlineView];
126 NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
128 for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
129 if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]])
135 #warning uncomment (in header too)
136 - (NSRect) quickLookSourceFrameForPreviewItem: (id /*<QLPreviewItem>*/) item
138 FileOutlineView * fileOutlineView = [fFileController outlineView];
140 NSString * fullPath = [(NSURL *)item path];
141 Torrent * torrent = [fTorrents objectAtIndex: 0];
142 NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]];
144 for (NSUInteger row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
146 FileListNode * rowItem = [fileOutlineView itemAtRow: row];
147 if ([[torrent fileLocation: rowItem] isEqualToString: fullPath])
149 NSRect frame = [fileOutlineView iconRectForRow: row];
151 if (!NSIntersectsRect([fileOutlineView visibleRect], frame))
154 frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil];
155 frame.origin = [[[self view] window] convertBaseToScreen: frame.origin];
156 frame.origin.y -= frame.size.height;
166 @implementation InfoFileViewController (Private)
170 [fFileFilterField setStringValue: @""];
172 if ([fTorrents count] == 1)
174 Torrent * torrent = [fTorrents objectAtIndex: 0];
176 [fFileController setTorrent: torrent];
177 [fFileFilterField setEnabled: [torrent isFolder]];
181 [fFileController setTorrent: nil];
182 [fFileFilterField setEnabled: NO];
188 - (BOOL) canQuickLookFile: (FileListNode *) item
190 Torrent * torrent = [fTorrents objectAtIndex: 0];
191 return ([item isFolder] || [torrent fileProgress: item] >= 1.0) && [torrent fileLocation: item];