2010-03-06 23:12:30 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2010-2012 Transmission authors and contributors
|
2010-03-06 23:12:30 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "InfoFileViewController.h"
|
|
|
|
#import "FileListNode.h"
|
|
|
|
#import "FileOutlineController.h"
|
|
|
|
#import "FileOutlineView.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
|
|
|
|
@interface InfoFileViewController (Private)
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
- (void) setupInfo;
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (BOOL) canQuickLookFile: (FileListNode *) item;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoFileViewController
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2010-03-14 03:09:12 +00:00
|
|
|
if ((self = [super initWithNibName: @"InfoFileView" bundle: nil]))
|
|
|
|
{
|
|
|
|
[self setTitle: NSLocalizedString(@"Files", "Inspector view -> title")];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2010-03-14 02:53:22 +00:00
|
|
|
const CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: @"InspectorContentHeightFiles"];
|
|
|
|
if (height != 0.0)
|
|
|
|
{
|
|
|
|
NSRect viewRect = [[self view] frame];
|
|
|
|
viewRect.size.height = height;
|
|
|
|
[[self view] setFrame: viewRect];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:56:44 +00:00
|
|
|
[[fFileFilterField cell] setPlaceholderString: NSLocalizedString(@"Filter", "inspector -> file filter")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:24:39 +00:00
|
|
|
//localize and place all and none buttons
|
|
|
|
[fCheckAllButton setTitle: NSLocalizedString(@"All", "inspector -> check all")];
|
|
|
|
[fUncheckAllButton setTitle: NSLocalizedString(@"None", "inspector -> check all")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:27:40 +00:00
|
|
|
NSRect checkAllFrame = [fCheckAllButton frame];
|
|
|
|
NSRect uncheckAllFrame = [fUncheckAllButton frame];
|
2012-05-14 00:24:39 +00:00
|
|
|
const CGFloat oldAllWidth = checkAllFrame.size.width;
|
|
|
|
const CGFloat oldNoneWidth = uncheckAllFrame.size.width;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:24:39 +00:00
|
|
|
[fCheckAllButton sizeToFit];
|
|
|
|
[fUncheckAllButton sizeToFit];
|
|
|
|
const CGFloat newWidth = MAX([fCheckAllButton bounds].size.width, [fUncheckAllButton bounds].size.width);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:24:39 +00:00
|
|
|
const CGFloat uncheckAllChange = newWidth - oldNoneWidth;
|
|
|
|
uncheckAllFrame.size.width = newWidth;
|
|
|
|
uncheckAllFrame.origin.x -= uncheckAllChange;
|
|
|
|
[fUncheckAllButton setFrame: uncheckAllFrame];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:24:39 +00:00
|
|
|
const CGFloat checkAllChange = newWidth - oldAllWidth;
|
|
|
|
checkAllFrame.size.width = newWidth;
|
|
|
|
checkAllFrame.origin.x -= (checkAllChange + uncheckAllChange);
|
|
|
|
[fCheckAllButton setFrame: checkAllFrame];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fTorrents release];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
- (void) setInfoForTorrents: (NSArray *) torrents
|
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2012-03-13 02:52:11 +00:00
|
|
|
[fTorrents release];
|
|
|
|
fTorrents = [torrents retain];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfo
|
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
if (!fSet)
|
|
|
|
[self setupInfo];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([fTorrents count] == 1)
|
2012-05-14 00:00:19 +00:00
|
|
|
{
|
2012-01-04 00:36:21 +00:00
|
|
|
[fFileController refresh];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-20 00:19:55 +00:00
|
|
|
#warning use TorrentFileCheckChange notification as well
|
2012-05-14 00:00:19 +00:00
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
if ([torrent isFolder])
|
|
|
|
{
|
|
|
|
const NSInteger filesCheckState = [torrent checkForFiles: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [torrent fileCount])]];
|
|
|
|
[fCheckAllButton setEnabled: filesCheckState != NSOnState]; //if anything is unchecked
|
|
|
|
[fUncheckAllButton setEnabled: ![torrent allDownloaded]]; //if there are any checked files that aren't finished
|
|
|
|
}
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 02:53:22 +00:00
|
|
|
- (void) saveViewSize
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setFloat: NSHeight([[self view] frame]) forKey: @"InspectorContentHeightFiles"];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (void) setFileFilterText: (id) sender
|
|
|
|
{
|
|
|
|
[fFileController setFilterText: [sender stringValue]];
|
|
|
|
}
|
|
|
|
|
2012-05-14 00:00:19 +00:00
|
|
|
- (IBAction) checkAll: (id) sender
|
|
|
|
{
|
|
|
|
[fFileController checkAll];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) uncheckAll: (id) sender
|
|
|
|
{
|
|
|
|
[fFileController uncheckAll];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (NSArray *) quickLookURLs
|
|
|
|
{
|
|
|
|
FileOutlineView * fileOutlineView = [fFileController outlineView];
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
|
|
|
|
NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
|
|
|
{
|
|
|
|
FileListNode * item = [fileOutlineView itemAtRow: i];
|
|
|
|
if ([self canQuickLookFile: item])
|
|
|
|
[urlArray addObject: [NSURL fileURLWithPath: [torrent fileLocation: item]]];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return urlArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canQuickLook
|
|
|
|
{
|
|
|
|
if ([fTorrents count] != 1)
|
|
|
|
return NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
if (![torrent isFolder])
|
|
|
|
return NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
FileOutlineView * fileOutlineView = [fFileController outlineView];
|
|
|
|
NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
|
|
|
if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]])
|
|
|
|
return YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
- (NSRect) quickLookSourceFrameForPreviewItem: (id <QLPreviewItem>) item
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
FileOutlineView * fileOutlineView = [fFileController outlineView];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
NSString * fullPath = [(NSURL *)item path];
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
for (NSUInteger row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
|
|
|
|
{
|
|
|
|
FileListNode * rowItem = [fileOutlineView itemAtRow: row];
|
|
|
|
if ([[torrent fileLocation: rowItem] isEqualToString: fullPath])
|
|
|
|
{
|
|
|
|
NSRect frame = [fileOutlineView iconRectForRow: row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (!NSIntersectsRect([fileOutlineView visibleRect], frame))
|
|
|
|
return NSZeroRect;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil];
|
2016-01-08 10:05:19 +00:00
|
|
|
frame = [[[self view] window] convertRectToScreen: frame];
|
2010-03-06 23:12:30 +00:00
|
|
|
frame.origin.y -= frame.size.height;
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoFileViewController (Private)
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
- (void) setupInfo
|
|
|
|
{
|
|
|
|
[fFileFilterField setStringValue: @""];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
if ([fTorrents count] == 1)
|
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
[fFileController setTorrent: torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:00:19 +00:00
|
|
|
const BOOL isFolder = [torrent isFolder];
|
|
|
|
[fFileFilterField setEnabled: isFolder];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:00:19 +00:00
|
|
|
if (!isFolder)
|
|
|
|
{
|
|
|
|
[fCheckAllButton setEnabled: NO];
|
|
|
|
[fUncheckAllButton setEnabled: NO];
|
|
|
|
}
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fFileController setTorrent: nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
[fFileFilterField setEnabled: NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:00:19 +00:00
|
|
|
[fCheckAllButton setEnabled: NO];
|
|
|
|
[fUncheckAllButton setEnabled: NO];
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = YES;
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (BOOL) canQuickLookFile: (FileListNode *) item
|
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
return ([item isFolder] || [torrent fileProgress: item] >= 1.0) && [torrent fileLocation: item];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|