2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2008-2023 Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2008-01-04 04:45:31 +00:00
|
|
|
|
|
|
|
#import "AddWindowController.h"
|
|
|
|
#import "Controller.h"
|
2009-10-11 03:36:50 +00:00
|
|
|
#import "ExpandedPathToIconTransformer.h"
|
|
|
|
#import "FileOutlineController.h"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2008-01-04 04:45:31 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-10-11 03:36:50 +00:00
|
|
|
#import "Torrent.h"
|
2008-01-04 04:45:31 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
static NSTimeInterval const kUpdateSeconds = 1.0;
|
2008-01-09 19:52:11 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
typedef NS_ENUM(NSUInteger, PopupPriority) {
|
|
|
|
PopupPriorityHigh = 0,
|
|
|
|
PopupPriorityNormal = 1,
|
|
|
|
PopupPriorityLow = 2,
|
|
|
|
};
|
2010-02-11 01:34:32 +00:00
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface AddWindowController ()
|
2008-01-04 04:45:31 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@property(nonatomic) IBOutlet NSImageView* fIconView;
|
|
|
|
@property(nonatomic) IBOutlet NSImageView* fLocationImageView;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fNameField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fStatusField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fLocationField;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fStartCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fDeleteCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSPopUpButton* fGroupPopUp;
|
|
|
|
@property(nonatomic) IBOutlet NSPopUpButton* fPriorityPopUp;
|
|
|
|
@property(nonatomic) IBOutlet NSProgressIndicator* fVerifyIndicator;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fFileFilterField;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fCheckAllButton;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fUncheckAllButton;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet FileOutlineController* fFileController;
|
|
|
|
@property(nonatomic) IBOutlet NSScrollView* fFileScrollView;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) Controller* fController;
|
|
|
|
|
|
|
|
@property(nonatomic, copy) NSString* fDestination;
|
|
|
|
@property(nonatomic, readonly) NSString* fTorrentFile;
|
|
|
|
@property(nonatomic) BOOL fLockDestination;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) BOOL fDeleteTorrentEnableInitially;
|
|
|
|
@property(nonatomic, readonly) BOOL fCanToggleDelete;
|
|
|
|
@property(nonatomic) NSInteger fGroupValue;
|
|
|
|
|
|
|
|
@property(nonatomic, weak) NSTimer* fTimer;
|
|
|
|
|
|
|
|
@property(nonatomic) TorrentDeterminationType fGroupValueDetermination;
|
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AddWindowController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithTorrent:(Torrent*)torrent
|
|
|
|
destination:(NSString*)path
|
|
|
|
lockDestination:(BOOL)lockDestination
|
|
|
|
controller:(Controller*)controller
|
|
|
|
torrentFile:(NSString*)torrentFile
|
|
|
|
deleteTorrentCheckEnableInitially:(BOOL)deleteTorrent
|
|
|
|
canToggleDelete:(BOOL)canToggleDelete
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithWindowNibName:@"AddWindow"]))
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_torrent = torrent;
|
|
|
|
_fDestination = path.stringByExpandingTildeInPath;
|
|
|
|
_fLockDestination = lockDestination;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fController = controller;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fTorrentFile = torrentFile.stringByExpandingTildeInPath;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fDeleteTorrentEnableInitially = deleteTorrent;
|
|
|
|
_fCanToggleDelete = canToggleDelete;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fGroupValue = torrent.groupValue;
|
|
|
|
_fGroupValueDetermination = TorrentDeterminationAutomatic;
|
2012-10-30 00:22:10 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fVerifyIndicator.usesThreadedAnimation = YES;
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateCheckButtons:) name:@"TorrentFileCheckChange"
|
2022-02-22 16:04:20 +00:00
|
|
|
object:self.torrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateGroupMenu:) name:@"UpdateGroups" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fFileController.torrent = self.torrent;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* name = self.torrent.name;
|
2021-08-07 07:27:56 +00:00
|
|
|
self.window.title = name;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fNameField.stringValue = name;
|
|
|
|
self.fNameField.toolTip = name;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-16 17:55:33 +00:00
|
|
|
//disable fullscreen support
|
2022-06-29 04:20:42 +00:00
|
|
|
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenNone;
|
2022-06-08 19:15:51 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIconView.image = self.torrent.icon;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.torrent.folder)
|
2012-05-28 20:16:43 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fFileFilterField.hidden = YES;
|
|
|
|
self.fCheckAllButton.hidden = YES;
|
|
|
|
self.fUncheckAllButton.hidden = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSRect scrollFrame = self.fFileScrollView.frame;
|
|
|
|
CGFloat const diff = NSMinY(self.fFileScrollView.frame) - NSMinY(self.fFileFilterField.frame);
|
2012-05-28 20:16:43 +00:00
|
|
|
scrollFrame.origin.y -= diff;
|
|
|
|
scrollFrame.size.height += diff;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fFileScrollView.frame = scrollFrame;
|
2012-05-28 20:16:43 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self updateCheckButtons:nil];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-05 22:32:34 +00:00
|
|
|
[self setGroupsMenu];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fGroupPopUp selectItemWithTag:self.fGroupValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
PopupPriority priorityIndex;
|
2022-02-22 16:04:20 +00:00
|
|
|
switch (self.torrent.priority)
|
2010-02-11 01:34:32 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_PRI_HIGH:
|
2022-10-19 19:28:21 +00:00
|
|
|
priorityIndex = PopupPriorityHigh;
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
|
|
|
case TR_PRI_NORMAL:
|
2022-10-19 19:28:21 +00:00
|
|
|
priorityIndex = PopupPriorityNormal;
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
|
|
|
case TR_PRI_LOW:
|
2022-10-19 19:28:21 +00:00
|
|
|
priorityIndex = PopupPriorityLow;
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2022-02-22 16:04:20 +00:00
|
|
|
NSAssert1(NO, @"Unknown priority for adding torrent: %d", self.torrent.priority);
|
2022-10-19 19:28:21 +00:00
|
|
|
priorityIndex = PopupPriorityNormal;
|
2010-02-11 01:34:32 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPriorityPopUp selectItemAtIndex:priorityIndex];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
self.fStartCheck.state = [NSUserDefaults.standardUserDefaults boolForKey:@"AutoStartDownload"] ? NSControlStateValueOn :
|
|
|
|
NSControlStateValueOff;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDeleteCheck.state = self.fDeleteTorrentEnableInitially ? NSControlStateValueOn : NSControlStateValueOff;
|
|
|
|
self.fDeleteCheck.enabled = self.fCanToggleDelete;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fDestination)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self setDestinationPath:self.fDestination
|
|
|
|
determinationType:(self.fLockDestination ? TorrentDeterminationUserSpecified : TorrentDeterminationAutomatic)];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fLocationField.stringValue = @"";
|
|
|
|
self.fLocationImageView.image = nil;
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
self.fTimer = [NSTimer scheduledTimerWithTimeInterval:kUpdateSeconds target:self selector:@selector(updateFiles)
|
2022-03-30 21:52:23 +00:00
|
|
|
userInfo:nil
|
|
|
|
repeats:YES];
|
2010-01-31 23:36:48 +00:00
|
|
|
[self updateFiles];
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)windowDidLoad
|
2008-01-05 03:06:20 +00:00
|
|
|
{
|
|
|
|
//if there is no destination, prompt for one right away
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fDestination)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setDestination:nil];
|
|
|
|
}
|
2008-01-05 03:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)dealloc
|
2008-01-09 21:08:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[_fTimer invalidate];
|
2008-01-05 21:31:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setDestination:(id)sender
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2008-01-04 04:45:31 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.prompt = NSLocalizedString(@"Select", "Open torrent -> prompt");
|
|
|
|
panel.allowsMultipleSelection = NO;
|
|
|
|
panel.canChooseFiles = NO;
|
|
|
|
panel.canChooseDirectories = YES;
|
|
|
|
panel.canCreateDirectories = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
panel.message = [NSString stringWithFormat:NSLocalizedString(@"Select the download folder for \"%@\"", "Add -> select destination folder"),
|
2022-02-22 16:04:20 +00:00
|
|
|
self.torrent.name];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
2021-10-31 15:18:27 +00:00
|
|
|
if (result == NSModalResponseOK)
|
2011-12-11 22:31:01 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fLockDestination = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setDestinationPath:panel.URLs[0].path determinationType:TorrentDeterminationUserSpecified];
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fDestination)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self performSelectorOnMainThread:@selector(cancelAdd:) withObject:nil waitUntilDone:NO];
|
|
|
|
}
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
|
|
|
}];
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)add:(id)sender
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDestination.lastPathComponent isEqualToString:self.torrent.name] &&
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults boolForKey:@"WarningFolderDataSameName"])
|
2008-01-11 19:54:08 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
alert.messageText = NSLocalizedString(@"The destination directory and root data directory have the same name.", "Add torrent -> same name -> title");
|
|
|
|
alert.informativeText = NSLocalizedString(
|
|
|
|
@"If you are attempting to use already existing data,"
|
|
|
|
" the root data directory should be inside the destination directory.",
|
|
|
|
"Add torrent -> same name -> message");
|
2021-10-31 15:18:27 +00:00
|
|
|
alert.alertStyle = NSAlertStyleWarning;
|
2021-08-15 09:41:48 +00:00
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Add torrent -> same name -> button")];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Add", "Add torrent -> same name -> button")];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.showsSuppressionButton = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-06-29 04:20:42 +00:00
|
|
|
[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
|
2021-10-31 15:18:27 +00:00
|
|
|
if (alert.suppressionButton.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"WarningFolderDataSameName"];
|
|
|
|
}
|
2020-11-22 13:02:29 +00:00
|
|
|
|
|
|
|
if (returnCode == NSAlertSecondButtonReturn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self performSelectorOnMainThread:@selector(confirmAdd) withObject:nil waitUntilDone:NO];
|
|
|
|
}
|
2020-11-22 13:02:29 +00:00
|
|
|
}];
|
2008-01-11 19:54:08 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-11 19:54:08 +00:00
|
|
|
[self confirmAdd];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)cancelAdd:(id)sender
|
2008-01-16 23:17:36 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self.window performClose:sender];
|
2008-01-16 23:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//only called on cancel
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)windowShouldClose:(id)window
|
2008-01-04 04:45:31 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTimer invalidate];
|
|
|
|
self.fTimer = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fFileController.torrent = nil; //avoid a crash when window tries to update
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController askOpenConfirmed:self add:NO];
|
2008-02-13 19:33:04 +00:00
|
|
|
return YES;
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setFileFilterText:(id)sender
|
2012-05-20 00:19:55 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fFileController.filterText = [sender stringValue];
|
2012-05-20 00:19:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)checkAll:(id)sender
|
2012-05-20 00:19:55 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFileController checkAll];
|
2012-05-20 00:19:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)uncheckAll:(id)sender
|
2012-05-20 00:19:55 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFileController uncheckAll];
|
2012-05-20 00:19:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)verifyLocalData:(id)sender
|
2008-01-09 19:52:11 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent resetCache];
|
2010-01-31 23:36:48 +00:00
|
|
|
[self updateFiles];
|
2008-01-09 19:52:11 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)changePriority:(id)sender
|
2010-02-11 01:34:32 +00:00
|
|
|
{
|
|
|
|
tr_priority_t priority;
|
2010-02-25 01:56:56 +00:00
|
|
|
switch ([sender indexOfSelectedItem])
|
2010-02-11 01:34:32 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
case PopupPriorityHigh:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case PopupPriorityNormal:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case PopupPriorityLow:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown priority tag for adding torrent: %ld", [sender tag]);
|
|
|
|
priority = TR_PRI_NORMAL;
|
2010-02-11 01:34:32 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.torrent.priority = priority;
|
2010-02-11 01:34:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateCheckButtons:(NSNotification*)notification
|
2008-02-27 19:34:55 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* statusString = [NSString stringForFileSize:self.torrent.size];
|
|
|
|
if (self.torrent.folder)
|
2008-02-27 19:34:55 +00:00
|
|
|
{
|
2012-05-20 00:19:55 +00:00
|
|
|
//check buttons
|
|
|
|
//keep synced with identical code in InfoFileViewController.m
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger const filesCheckState = [self.torrent
|
|
|
|
checkForFiles:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.torrent.fileCount)]];
|
|
|
|
self.fCheckAllButton.enabled = filesCheckState != NSControlStateValueOn; //if anything is unchecked
|
|
|
|
self.fUncheckAllButton.enabled = !self.torrent.allDownloaded; //if there are any checked files that aren't finished
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-05-20 00:19:55 +00:00
|
|
|
//status field
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* fileString;
|
2022-05-14 05:31:24 +00:00
|
|
|
NSUInteger count = self.torrent.fileCount;
|
2008-02-27 19:34:55 +00:00
|
|
|
if (count != 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-11-14 18:30:03 +00:00
|
|
|
fileString = [NSString localizedStringWithFormat:NSLocalizedString(@"%lu files", "Add torrent -> info"), count];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-02-27 19:34:55 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-04-07 13:29:46 +00:00
|
|
|
fileString = NSLocalizedString(@"1 file", "Add torrent -> info");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* selectedString = [NSString stringWithFormat:NSLocalizedString(@"%@ selected", "Add torrent -> info"),
|
2022-02-22 16:04:20 +00:00
|
|
|
[NSString stringForFileSize:self.torrent.totalSizeSelected]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
statusString = [NSString stringWithFormat:@"%@, %@ (%@)", fileString, statusString, selectedString];
|
2008-02-27 19:34:55 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStatusField.stringValue = statusString;
|
2008-02-27 19:34:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateGroupMenu:(NSNotification*)notification
|
2008-01-04 14:56:29 +00:00
|
|
|
{
|
2008-01-05 22:32:34 +00:00
|
|
|
[self setGroupsMenu];
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.fGroupPopUp selectItemWithTag:self.fGroupValue])
|
2008-01-05 22:32:34 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fGroupValue = -1;
|
|
|
|
self.fGroupValueDetermination = TorrentDeterminationAutomatic;
|
|
|
|
[self.fGroupPopUp selectItemWithTag:self.fGroupValue];
|
2008-01-05 22:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateFiles
|
2010-01-31 23:36:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent update];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFileController refresh];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self updateCheckButtons:nil]; //call in case button state changed by checking
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.torrent.checking)
|
2011-08-16 02:33:18 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const waiting = self.torrent.checkingWaiting;
|
|
|
|
self.fVerifyIndicator.indeterminate = waiting;
|
2011-08-16 02:33:18 +00:00
|
|
|
if (waiting)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fVerifyIndicator startAnimation:self];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-08-16 02:33:18 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fVerifyIndicator.doubleValue = self.torrent.checkingProgress;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-01-31 23:36:48 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fVerifyIndicator.indeterminate = YES; //we want to hide when stopped, which only applies when indeterminate
|
|
|
|
[self.fVerifyIndicator stopAnimation:self];
|
2011-08-16 02:31:53 +00:00
|
|
|
}
|
2010-01-31 23:36:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)confirmAdd
|
2008-01-11 19:54:08 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTimer invalidate];
|
|
|
|
self.fTimer = nil;
|
|
|
|
[self.torrent setGroupValue:self.fGroupValue determinationType:self.fGroupValueDetermination];
|
2012-10-30 00:22:10 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTorrentFile && self.fCanToggleDelete && self.fDeleteCheck.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[Torrent trashFile:self.fTorrentFile error:nil];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fStartCheck.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent startTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fFileController.torrent = nil; //avoid a crash when window tries to update
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-13 19:33:04 +00:00
|
|
|
[self close];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fController askOpenConfirmed:self add:YES];
|
2008-01-11 19:54:08 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setDestinationPath:(NSString*)destination determinationType:(TorrentDeterminationType)determinationType
|
2008-11-30 19:23:15 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
destination = destination.stringByExpandingTildeInPath;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fDestination || ![self.fDestination isEqualToString:destination])
|
2017-01-24 17:53:16 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDestination = destination;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent changeDownloadFolderBeforeUsing:self.fDestination determinationType:determinationType];
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fLocationField.stringValue = self.fDestination.stringByAbbreviatingWithTildeInPath;
|
|
|
|
self.fLocationField.toolTip = self.fDestination;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
ExpandedPathToIconTransformer* iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fLocationImageView.image = [iconTransformer transformedValue:self.fDestination];
|
2008-11-30 19:23:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGroupsMenu
|
2008-01-05 22:32:34 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenu* groupMenu = [GroupsController.groups groupMenuWithTarget:self action:@selector(changeGroupValue:) isSmall:NO];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fGroupPopUp.menu = groupMenu;
|
2008-01-05 22:32:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)changeGroupValue:(id)sender
|
2008-01-05 22:32:34 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger previousGroup = self.fGroupValue;
|
|
|
|
self.fGroupValue = [sender tag];
|
|
|
|
self.fGroupValueDetermination = TorrentDeterminationUserSpecified;
|
2012-10-30 00:22:10 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fLockDestination)
|
2008-12-13 22:10:11 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([GroupsController.groups usesCustomDownloadLocationForIndex:self.fGroupValue])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self setDestinationPath:[GroupsController.groups customDownloadLocationForIndex:self.fGroupValue]
|
2021-08-15 09:41:48 +00:00
|
|
|
determinationType:TorrentDeterminationAutomatic];
|
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if ([self.fDestination isEqualToString:[GroupsController.groups customDownloadLocationForIndex:previousGroup]])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setDestinationPath:[NSUserDefaults.standardUserDefaults stringForKey:@"DownloadFolder"]
|
|
|
|
determinationType:TorrentDeterminationAutomatic];
|
|
|
|
}
|
2008-12-13 22:10:11 +00:00
|
|
|
}
|
2008-01-05 22:32:34 +00:00
|
|
|
}
|
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
@end
|