2008-01-04 04:45:31 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2008-2012 Transmission authors and contributors
|
2008-01-04 04:45:31 +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 "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
|
|
|
|
2008-11-01 22:08:02 +00:00
|
|
|
#define UPDATE_SECONDS 1.0
|
2008-01-09 19:52:11 +00:00
|
|
|
|
2010-02-11 01:34:32 +00:00
|
|
|
#define POPUP_PRIORITY_HIGH 0
|
|
|
|
#define POPUP_PRIORITY_NORMAL 1
|
|
|
|
#define POPUP_PRIORITY_LOW 2
|
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
@interface AddWindowController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateFiles;
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setDestinationPath:(NSString*)destination determinationType:(TorrentDeterminationType)determinationType;
|
2008-12-08 03:26:28 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGroupsMenu;
|
|
|
|
- (void)changeGroupValue:(id)sender;
|
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
|
|
|
{
|
|
|
|
fTorrent = torrent;
|
2021-08-07 07:27:56 +00:00
|
|
|
fDestination = path.stringByExpandingTildeInPath;
|
2008-12-13 22:10:11 +00:00
|
|
|
fLockDestination = lockDestination;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
fController = controller;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fTorrentFile = torrentFile.stringByExpandingTildeInPath;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-08-05 03:48:13 +00:00
|
|
|
fDeleteTorrentEnableInitially = deleteTorrent;
|
|
|
|
fCanToggleDelete = canToggleDelete;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fGroupValue = torrent.groupValue;
|
2012-10-30 00:22:10 +00:00
|
|
|
fGroupValueDetermination = TorrentDeterminationAutomatic;
|
|
|
|
|
2021-08-07 07:27:56 +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"
|
|
|
|
object:fTorrent];
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileController setTorrent:fTorrent];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* name = fTorrent.name;
|
2021-08-07 07:27:56 +00:00
|
|
|
self.window.title = name;
|
|
|
|
fNameField.stringValue = name;
|
|
|
|
fNameField.toolTip = name;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fIconView.image = fTorrent.icon;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!fTorrent.folder)
|
2012-05-28 20:16:43 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fFileFilterField.hidden = YES;
|
|
|
|
fCheckAllButton.hidden = YES;
|
|
|
|
fUncheckAllButton.hidden = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect scrollFrame = fFileScrollView.frame;
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const diff = NSMinY(fFileScrollView.frame) - NSMinY(fFileFilterField.frame);
|
2012-05-28 20:16:43 +00:00
|
|
|
scrollFrame.origin.y -= diff;
|
|
|
|
scrollFrame.size.height += diff;
|
2021-08-07 07:27:56 +00:00
|
|
|
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];
|
2021-08-15 09:41:48 +00:00
|
|
|
[fGroupPopUp selectItemWithTag:fGroupValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-02-25 01:56:56 +00:00
|
|
|
NSInteger priorityIndex;
|
2021-08-07 07:27:56 +00:00
|
|
|
switch (fTorrent.priority)
|
2010-02-11 01:34:32 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_PRI_HIGH:
|
|
|
|
priorityIndex = POPUP_PRIORITY_HIGH;
|
|
|
|
break;
|
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
priorityIndex = POPUP_PRIORITY_NORMAL;
|
|
|
|
break;
|
|
|
|
case TR_PRI_LOW:
|
|
|
|
priorityIndex = POPUP_PRIORITY_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown priority for adding torrent: %d", fTorrent.priority);
|
|
|
|
priorityIndex = POPUP_PRIORITY_NORMAL;
|
2010-02-11 01:34:32 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
[fPriorityPopUp selectItemAtIndex:priorityIndex];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
fStartCheck.state = [NSUserDefaults.standardUserDefaults boolForKey:@"AutoStartDownload"] ? NSControlStateValueOn
|
|
|
|
: NSControlStateValueOff;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
fDeleteCheck.state = fDeleteTorrentEnableInitially ? NSControlStateValueOn : NSControlStateValueOff;
|
2021-08-07 07:27:56 +00:00
|
|
|
fDeleteCheck.enabled = fCanToggleDelete;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
if (fDestination)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setDestinationPath:fDestination
|
|
|
|
determinationType:(fLockDestination ? TorrentDeterminationUserSpecified : TorrentDeterminationAutomatic)];
|
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fLocationField.stringValue = @"";
|
|
|
|
fLocationImageView.image = nil;
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fTimer = [NSTimer scheduledTimerWithTimeInterval:UPDATE_SECONDS target:self selector:@selector(updateFiles) 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
|
|
|
|
if (!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
|
|
|
|
2008-01-09 19:52:11 +00:00
|
|
|
[fTimer invalidate];
|
2008-01-04 04:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (Torrent*)torrent
|
2008-01-05 21:31:05 +00:00
|
|
|
{
|
|
|
|
return fTorrent;
|
|
|
|
}
|
|
|
|
|
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"),
|
|
|
|
fTorrent.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
|
|
|
{
|
2012-10-30 00:22:10 +00:00
|
|
|
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
|
|
|
|
{
|
|
|
|
if (!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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fDestination.lastPathComponent isEqualToString:fTorrent.name] &&
|
|
|
|
[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
|
|
|
|
2020-11-22 13:02:29 +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
|
|
|
{
|
2008-01-09 19:52:11 +00:00
|
|
|
[fTimer invalidate];
|
|
|
|
fTimer = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileController setTorrent:nil]; //avoid a crash when window tries to update
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileController setFilterText:[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
|
|
|
{
|
|
|
|
[fFileController checkAll];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)uncheckAll:(id)sender
|
2012-05-20 00:19:55 +00:00
|
|
|
{
|
|
|
|
[fFileController uncheckAll];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)verifyLocalData:(id)sender
|
2008-01-09 19:52:11 +00:00
|
|
|
{
|
|
|
|
[fTorrent 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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case POPUP_PRIORITY_HIGH:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
case POPUP_PRIORITY_NORMAL:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case POPUP_PRIORITY_LOW:
|
|
|
|
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
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
fTorrent.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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* statusString = [NSString stringForFileSize:fTorrent.size];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (fTorrent.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
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const filesCheckState = [fTorrent
|
|
|
|
checkForFiles:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, fTorrent.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 = !fTorrent.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;
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger count = fTorrent.fileCount;
|
2008-02-27 19:34:55 +00:00
|
|
|
if (count != 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
fileString = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"%@ files", "Add torrent -> info"), [NSString formattedUInteger:count]];
|
|
|
|
}
|
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"),
|
|
|
|
[NSString stringForFileSize:fTorrent.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
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
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];
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![fGroupPopUp selectItemWithTag:fGroupValue])
|
2008-01-05 22:32:34 +00:00
|
|
|
{
|
|
|
|
fGroupValue = -1;
|
2017-01-24 17:53:16 +00:00
|
|
|
fGroupValueDetermination = TorrentDeterminationAutomatic;
|
2021-08-15 09:41:48 +00:00
|
|
|
[fGroupPopUp selectItemWithTag:fGroupValue];
|
2008-01-05 22:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-04 04:45:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AddWindowController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateFiles
|
2010-01-31 23:36:48 +00:00
|
|
|
{
|
|
|
|
[fTorrent update];
|
2017-01-24 17:53:16 +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
|
|
|
[self updateCheckButtons:nil]; //call in case button state changed by checking
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (fTorrent.checking)
|
2011-08-16 02:33:18 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const waiting = fTorrent.checkingWaiting;
|
2021-08-07 07:27:56 +00:00
|
|
|
fVerifyIndicator.indeterminate = waiting;
|
2011-08-16 02:33:18 +00:00
|
|
|
if (waiting)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[fVerifyIndicator startAnimation:self];
|
|
|
|
}
|
2011-08-16 02:33:18 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fVerifyIndicator.doubleValue = fTorrent.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
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fVerifyIndicator.indeterminate = YES; //we want to hide when stopped, which only applies when indeterminate
|
2021-08-15 09:41:48 +00:00
|
|
|
[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
|
|
|
{
|
|
|
|
[fTimer invalidate];
|
|
|
|
fTimer = nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
[fTorrent setGroupValue:fGroupValue determinationType:fGroupValueDetermination];
|
2012-10-30 00:22:10 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
if (fTorrentFile && fCanToggleDelete && fDeleteCheck.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[Torrent trashFile:fTorrentFile error:nil];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
if (fStartCheck.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-08-02 12:43:26 +00:00
|
|
|
[fTorrent startTransfer];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileController setTorrent: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];
|
2021-08-15 09:41:48 +00:00
|
|
|
[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;
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!fDestination || ![fDestination isEqualToString:destination])
|
2017-01-24 17:53:16 +00:00
|
|
|
{
|
2017-07-29 16:14:22 +00:00
|
|
|
fDestination = destination;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fTorrent changeDownloadFolderBeforeUsing:fDestination determinationType:determinationType];
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fLocationField.stringValue = fDestination.stringByAbbreviatingWithTildeInPath;
|
|
|
|
fLocationField.toolTip = fDestination;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
ExpandedPathToIconTransformer* iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
|
|
|
|
fLocationImageView.image = [iconTransformer transformedValue: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];
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2008-11-30 21:23:59 +00:00
|
|
|
NSInteger previousGroup = fGroupValue;
|
2008-01-05 22:32:34 +00:00
|
|
|
fGroupValue = [sender tag];
|
2012-10-30 00:22:10 +00:00
|
|
|
fGroupValueDetermination = TorrentDeterminationUserSpecified;
|
|
|
|
|
2008-12-13 22:10:11 +00:00
|
|
|
if (!fLockDestination)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([GroupsController.groups usesCustomDownloadLocationForIndex:fGroupValue])
|
|
|
|
{
|
|
|
|
[self setDestinationPath:[GroupsController.groups customDownloadLocationForIndex:fGroupValue]
|
|
|
|
determinationType:TorrentDeterminationAutomatic];
|
|
|
|
}
|
|
|
|
else if ([fDestination isEqualToString:[GroupsController.groups customDownloadLocationForIndex:previousGroup]])
|
|
|
|
{
|
|
|
|
[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
|