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)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setupInfo;
|
2010-03-09 02:26:52 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)canQuickLookFile:(FileListNode*)item;
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoFileViewController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)init
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithNibName:@"InfoFileView" bundle:nil]))
|
2010-03-14 03:09:12 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
self.title = NSLocalizedString(@"Files", "Inspector view -> title");
|
2010-03-14 03:09:12 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const height = [NSUserDefaults.standardUserDefaults floatForKey:@"InspectorContentHeightFiles"];
|
2010-03-14 02:53:22 +00:00
|
|
|
if (height != 0.0)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect viewRect = self.view.frame;
|
2010-03-14 02:53:22 +00:00
|
|
|
viewRect.size.height = height;
|
2021-08-07 07:27:56 +00:00
|
|
|
self.view.frame = viewRect;
|
2010-03-14 02:53:22 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +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
|
2021-08-07 07:27:56 +00:00
|
|
|
fCheckAllButton.title = NSLocalizedString(@"All", "inspector -> check all");
|
|
|
|
fUncheckAllButton.title = NSLocalizedString(@"None", "inspector -> check all");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect checkAllFrame = fCheckAllButton.frame;
|
|
|
|
NSRect uncheckAllFrame = fUncheckAllButton.frame;
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const oldAllWidth = checkAllFrame.size.width;
|
|
|
|
CGFloat const oldNoneWidth = uncheckAllFrame.size.width;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:24:39 +00:00
|
|
|
[fCheckAllButton sizeToFit];
|
|
|
|
[fUncheckAllButton sizeToFit];
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const newWidth = MAX(fCheckAllButton.bounds.size.width, fUncheckAllButton.bounds.size.width);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const uncheckAllChange = newWidth - oldNoneWidth;
|
2012-05-14 00:24:39 +00:00
|
|
|
uncheckAllFrame.size.width = newWidth;
|
|
|
|
uncheckAllFrame.origin.x -= uncheckAllChange;
|
2021-08-07 07:27:56 +00:00
|
|
|
fUncheckAllButton.frame = uncheckAllFrame;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const checkAllChange = newWidth - oldAllWidth;
|
2012-05-14 00:24:39 +00:00
|
|
|
checkAllFrame.size.width = newWidth;
|
|
|
|
checkAllFrame.origin.x -= (checkAllChange + uncheckAllChange);
|
2021-08-07 07:27:56 +00:00
|
|
|
fCheckAllButton.frame = checkAllFrame;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setInfoForTorrents:(NSArray*)torrents
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2017-07-29 16:14:22 +00:00
|
|
|
fTorrents = torrents;
|
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
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateInfo
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
if (!fSet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
[self setupInfo];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning use TorrentFileCheckChange notification as well
|
|
|
|
Torrent* torrent = fTorrents[0];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.folder)
|
2012-05-14 00:00:19 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const filesCheckState = [torrent
|
|
|
|
checkForFiles:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, torrent.fileCount)]];
|
2021-10-31 15:18:27 +00:00
|
|
|
fCheckAllButton.enabled = filesCheckState != NSControlStateValueOn; //if anything is unchecked
|
2021-08-07 07:27:56 +00:00
|
|
|
fUncheckAllButton.enabled = !torrent.allDownloaded; //if there are any checked files that aren't finished
|
2012-05-14 00:00:19 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)saveViewSize
|
2010-03-14 02:53:22 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setFloat:NSHeight(self.view.frame) forKey:@"InspectorContentHeightFiles"];
|
2010-03-14 02:53:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setFileFilterText:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileController setFilterText:[sender stringValue]];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)checkAll:(id)sender
|
2012-05-14 00:00:19 +00:00
|
|
|
{
|
|
|
|
[fFileController checkAll];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)uncheckAll:(id)sender
|
2012-05-14 00:00:19 +00:00
|
|
|
{
|
|
|
|
[fFileController uncheckAll];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)quickLookURLs
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileOutlineView* fileOutlineView = fFileController.outlineView;
|
|
|
|
Torrent* torrent = fTorrents[0];
|
|
|
|
NSIndexSet* indexes = fileOutlineView.selectedRowIndexes;
|
|
|
|
NSMutableArray* urlArray = [NSMutableArray arrayWithCapacity:indexes.count];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger i = indexes.firstIndex; i != NSNotFound; i = [indexes indexGreaterThanIndex:i])
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* item = [fileOutlineView itemAtRow:i];
|
|
|
|
if ([self canQuickLookFile:item])
|
|
|
|
{
|
|
|
|
[urlArray addObject:[NSURL fileURLWithPath:[torrent fileLocation:item]]];
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return urlArray;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)canQuickLook
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (fTorrents.count != 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = fTorrents[0];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.folder)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
FileOutlineView* fileOutlineView = fFileController.outlineView;
|
|
|
|
NSIndexSet* indexes = fileOutlineView.selectedRowIndexes;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger i = indexes.firstIndex; i != NSNotFound; i = [indexes indexGreaterThanIndex:i])
|
|
|
|
{
|
|
|
|
if ([self canQuickLookFile:[fileOutlineView itemAtRow:i]])
|
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)quickLookSourceFrameForPreviewItem:(id<QLPreviewItem>)item
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileOutlineView* fileOutlineView = fFileController.outlineView;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* fullPath = ((NSURL*)item).path;
|
|
|
|
Torrent* torrent = fTorrents[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++)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* rowItem = [fileOutlineView itemAtRow:row];
|
|
|
|
if ([[torrent fileLocation:rowItem] isEqualToString:fullPath])
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect frame = [fileOutlineView iconRectForRow:row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!NSIntersectsRect(fileOutlineView.visibleRect, frame))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return NSZeroRect;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
frame.origin = [fileOutlineView convertPoint:frame.origin toView:nil];
|
|
|
|
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)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setupInfo
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fFileFilterField.stringValue = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (fTorrents.count == 1)
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileController setTorrent:torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const isFolder = torrent.folder;
|
2021-08-07 07:27:56 +00:00
|
|
|
fFileFilterField.enabled = isFolder;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-14 00:00:19 +00:00
|
|
|
if (!isFolder)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fCheckAllButton.enabled = NO;
|
|
|
|
fUncheckAllButton.enabled = NO;
|
2012-05-14 00:00:19 +00:00
|
|
|
}
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileController setTorrent:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fFileFilterField.enabled = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fCheckAllButton.enabled = NO;
|
|
|
|
fUncheckAllButton.enabled = 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;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)canQuickLookFile:(FileListNode*)item
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = fTorrents[0];
|
|
|
|
return (item.isFolder || [torrent fileProgress:item] >= 1.0) && [torrent fileLocation:item];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|