source: trunk/macosx/InfoFileViewController.m @ 13251

Last change on this file since 13251 was 13251, checked in by livings124, 9 years ago

reverse r13248-r13250, since ARC doesn't support 32-bit.

  • Property svn:keywords set to Date Rev Author Id
File size: 5.7 KB
Line 
1/******************************************************************************
2 * $Id: InfoFileViewController.m 13251 2012-03-13 02:52:11Z livings124 $
3 *
4 * Copyright (c) 2010-2012 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 "InfoFileViewController.h"
26#import "FileListNode.h"
27#import "FileOutlineController.h"
28#import "FileOutlineView.h"
29#import "Torrent.h"
30
31@interface InfoFileViewController (Private)
32
33- (void) setupInfo;
34
35- (BOOL) canQuickLookFile: (FileListNode *) item;
36
37@end
38
39@implementation InfoFileViewController
40
41- (id) init
42{
43    if ((self = [super initWithNibName: @"InfoFileView" bundle: nil]))
44    {
45        [self setTitle: NSLocalizedString(@"Files", "Inspector view -> title")];
46    }
47   
48    return self;
49}
50
51- (void) awakeFromNib
52{
53    const CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: @"InspectorContentHeightFiles"];
54    if (height != 0.0)
55    {
56        NSRect viewRect = [[self view] frame];
57        viewRect.size.height = height;
58        [[self view] setFrame: viewRect];
59    }
60   
61    [[fFileFilterField cell] setPlaceholderString: NSLocalizedString(@"Filter", "inspector -> file filter")];
62}
63
64- (void) dealloc
65{
66    [fTorrents release];
67   
68    [super dealloc];
69}
70
71- (void) setInfoForTorrents: (NSArray *) torrents
72{
73    //don't check if it's the same in case the metadata changed
74    [fTorrents release];
75    fTorrents = [torrents retain];
76   
77    fSet = NO;
78}
79
80- (void) updateInfo
81{
82    if (!fSet)
83        [self setupInfo];
84   
85    if ([fTorrents count] == 1)
86        [fFileController refresh];
87}
88
89- (void) saveViewSize
90{
91    [[NSUserDefaults standardUserDefaults] setFloat: NSHeight([[self view] frame]) forKey: @"InspectorContentHeightFiles"];
92}
93
94- (void) setFileFilterText: (id) sender
95{
96    [fFileController setFilterText: [sender stringValue]];
97}
98
99- (NSArray *) quickLookURLs
100{
101    FileOutlineView * fileOutlineView = [fFileController outlineView];
102    Torrent * torrent = [fTorrents objectAtIndex: 0];
103    NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
104    NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]];
105   
106    for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
107    {
108        FileListNode * item = [fileOutlineView itemAtRow: i];
109        if ([self canQuickLookFile: item])
110            [urlArray addObject: [NSURL fileURLWithPath: [torrent fileLocation: item]]];
111    }
112   
113    return urlArray;
114}
115
116- (BOOL) canQuickLook
117{
118    if ([fTorrents count] != 1)
119        return NO;
120   
121    Torrent * torrent = [fTorrents objectAtIndex: 0];
122    if (![torrent isFolder])
123        return NO;
124   
125    FileOutlineView * fileOutlineView = [fFileController outlineView];
126    NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
127   
128    for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
129        if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]])
130            return YES;
131   
132    return NO;
133}
134
135- (NSRect) quickLookSourceFrameForPreviewItem: (id <QLPreviewItem>) item
136{
137    FileOutlineView * fileOutlineView = [fFileController outlineView];
138   
139    NSString * fullPath = [(NSURL *)item path];
140    Torrent * torrent = [fTorrents objectAtIndex: 0];
141    NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]];
142   
143    for (NSUInteger row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
144    {
145        FileListNode * rowItem = [fileOutlineView itemAtRow: row];
146        if ([[torrent fileLocation: rowItem] isEqualToString: fullPath])
147        {
148            NSRect frame = [fileOutlineView iconRectForRow: row];
149           
150            if (!NSIntersectsRect([fileOutlineView visibleRect], frame))
151                return NSZeroRect;
152           
153            frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil];
154            frame.origin = [[[self view] window] convertBaseToScreen: frame.origin];
155            frame.origin.y -= frame.size.height;
156            return frame;
157        }
158    }
159   
160    return NSZeroRect;
161}
162
163@end
164
165@implementation InfoFileViewController (Private)
166
167- (void) setupInfo
168{
169    [fFileFilterField setStringValue: @""];
170   
171    if ([fTorrents count] == 1)
172    {
173        Torrent * torrent = [fTorrents objectAtIndex: 0];
174       
175        [fFileController setTorrent: torrent];
176        [fFileFilterField setEnabled: [torrent isFolder]];
177    }
178    else
179    {
180        [fFileController setTorrent: nil];
181        [fFileFilterField setEnabled: NO];
182    }
183   
184    fSet = YES;
185}
186
187- (BOOL) canQuickLookFile: (FileListNode *) item
188{
189    Torrent * torrent = [fTorrents objectAtIndex: 0];
190    return ([item isFolder] || [torrent fileProgress: item] >= 1.0) && [torrent fileLocation: item];
191}
192
193@end
Note: See TracBrowser for help on using the repository browser.