2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
2019-01-11 18:36:19 +00:00
|
|
|
* Copyright (c) 2005-2019 Transmission authors and contributors
|
2007-09-16 01:02:06 +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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-09-30 10:37:30 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
#import <Sparkle/Sparkle.h>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
|
|
|
|
#import "VDKQueue.h"
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "PrefsController.h"
|
2008-08-31 19:47:11 +00:00
|
|
|
#import "BlocklistDownloaderViewController.h"
|
2008-09-01 15:46:00 +00:00
|
|
|
#import "BlocklistScheduler.h"
|
2012-05-28 17:26:15 +00:00
|
|
|
#import "Controller.h"
|
2008-11-01 15:22:32 +00:00
|
|
|
#import "PortChecker.h"
|
2008-12-06 01:18:25 +00:00
|
|
|
#import "BonjourController.h"
|
2012-06-18 01:33:27 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-01-11 16:58:14 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define DOWNLOAD_FOLDER 0
|
|
|
|
#define DOWNLOAD_TORRENT 2
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define RPC_IP_ADD_TAG 0
|
|
|
|
#define RPC_IP_REMOVE_TAG 1
|
2008-06-04 04:48:17 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define TOOLBAR_GENERAL @"TOOLBAR_GENERAL"
|
|
|
|
#define TOOLBAR_TRANSFERS @"TOOLBAR_TRANSFERS"
|
|
|
|
#define TOOLBAR_GROUPS @"TOOLBAR_GROUPS"
|
|
|
|
#define TOOLBAR_BANDWIDTH @"TOOLBAR_BANDWIDTH"
|
|
|
|
#define TOOLBAR_PEERS @"TOOLBAR_PEERS"
|
|
|
|
#define TOOLBAR_NETWORK @"TOOLBAR_NETWORK"
|
|
|
|
#define TOOLBAR_REMOTE @"TOOLBAR_REMOTE"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define RPC_KEYCHAIN_SERVICE "Transmission:Remote"
|
|
|
|
#define RPC_KEYCHAIN_NAME "Remote"
|
2008-06-13 19:56:09 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define WEBUI_URL @"http://localhost:%ld/"
|
2008-07-19 13:40:23 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface PrefsController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPrefView:(id)sender;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setKeychainPassword:(char const*)password forService:(char const*)service username:(char const*)username;
|
2008-06-13 18:47:38 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PrefsController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithHandle:(tr_session*)handle
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithWindowNibName:@"PrefsWindow"]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2012-05-29 01:03:21 +00:00
|
|
|
fHandle = handle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fDefaults = NSUserDefaults.standardUserDefaults;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-04 19:45:51 +00:00
|
|
|
//check for old version download location (before 1.1)
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* choice;
|
|
|
|
if ((choice = [fDefaults stringForKey:@"DownloadChoice"]))
|
2008-01-05 01:48:55 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setBool:[choice isEqualToString:@"Constant"] forKey:@"DownloadLocationConstant"];
|
|
|
|
[fDefaults setBool:YES forKey:@"DownloadAsk"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults removeObjectForKey:@"DownloadChoice"];
|
2008-01-05 01:48:55 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-11-01 00:06:40 +00:00
|
|
|
//check for old version blocklist (before 2.12)
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDate* blocklistDate;
|
|
|
|
if ((blocklistDate = [fDefaults objectForKey:@"BlocklistLastUpdate"]))
|
2010-11-01 00:06:40 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setObject:blocklistDate forKey:@"BlocklistNewLastUpdateSuccess"];
|
|
|
|
[fDefaults setObject:blocklistDate forKey:@"BlocklistNewLastUpdate"];
|
|
|
|
[fDefaults removeObjectForKey:@"BlocklistLastUpdate"];
|
|
|
|
|
|
|
|
NSURL* blocklistDir = [[NSFileManager.defaultManager URLsForDirectory:NSApplicationDirectory inDomains:NSUserDomainMask][0]
|
|
|
|
URLByAppendingPathComponent:@"Transmission/blocklists/"];
|
|
|
|
[NSFileManager.defaultManager moveItemAtURL:[blocklistDir URLByAppendingPathComponent:@"level1.bin"]
|
|
|
|
toURL:[blocklistDir URLByAppendingPathComponent:@DEFAULT_BLOCKLIST_FILENAME]
|
|
|
|
error:nil];
|
2010-11-01 00:06:40 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-11 04:41:23 +00:00
|
|
|
//save a new random port
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fDefaults boolForKey:@"RandomPort"])
|
|
|
|
{
|
|
|
|
[fDefaults setInteger:tr_sessionGetPeerPort(fHandle) forKey:@"BindPort"];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set auto import
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* autoPath;
|
|
|
|
VDKQueue* x = [(Controller*)[NSApp delegate] fileWatcherQueue];
|
|
|
|
if ([fDefaults boolForKey:@"AutoImport"] && (autoPath = [fDefaults stringForKey:@"AutoImportDirectory"]))
|
|
|
|
{
|
|
|
|
[((Controller*)NSApp.delegate).fileWatcherQueue addPath:autoPath.stringByExpandingTildeInPath
|
|
|
|
notifyingAbout:VDKQueueNotifyAboutWrite];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-08-10 02:29:12 +00:00
|
|
|
//set special-handling of magnet link add window checkbox
|
|
|
|
[self updateShowAddMagnetWindowField];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-09-01 15:46:00 +00:00
|
|
|
//set blocklist scheduler
|
2021-08-07 07:27:56 +00:00
|
|
|
[BlocklistScheduler.scheduler updateSchedule];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-20 11:46:30 +00:00
|
|
|
//set encryption
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setEncryptionMode:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-01 22:17:25 +00:00
|
|
|
//update rpc whitelist
|
2008-06-13 19:56:09 +00:00
|
|
|
[self updateRPCPassword];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fRPCWhitelistArray = [[fDefaults arrayForKey:@"RPCWhitelist"] mutableCopy];
|
2008-10-01 22:17:25 +00:00
|
|
|
if (!fRPCWhitelistArray)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
fRPCWhitelistArray = [NSMutableArray arrayWithObject:@"127.0.0.1"];
|
|
|
|
}
|
2008-10-01 22:17:25 +00:00
|
|
|
[self updateRPCWhitelist];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-01-11 16:58:14 +00:00
|
|
|
//reset old Sparkle settings from previous versions
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults removeObjectForKey:@"SUScheduledCheckInterval"];
|
|
|
|
if ([fDefaults objectForKey:@"CheckForUpdates"])
|
2009-01-11 16:58:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[[SUUpdater sharedUpdater] setAutomaticallyChecksForUpdates:[fDefaults boolForKey:@"CheckForUpdates"]];
|
|
|
|
[fDefaults removeObjectForKey:@"CheckForUpdates"];
|
2009-01-11 16:58:14 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setAutoUpdateToBeta:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)dealloc
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-12 03:59:55 +00:00
|
|
|
[fPortStatusTimer invalidate];
|
2007-12-18 20:59:55 +00:00
|
|
|
if (fPortChecker)
|
|
|
|
{
|
2007-12-25 19:14:45 +00:00
|
|
|
[fPortChecker cancelProbe];
|
2007-12-18 20:59:55 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
fHasLoaded = YES;
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.window.restorationClass = [self class];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSToolbar* toolbar = [[NSToolbar alloc] initWithIdentifier:@"Preferences Toolbar"];
|
2021-08-07 07:27:56 +00:00
|
|
|
toolbar.delegate = self;
|
|
|
|
toolbar.allowsUserCustomization = NO;
|
|
|
|
toolbar.displayMode = NSToolbarDisplayModeIconAndLabel;
|
|
|
|
toolbar.sizeMode = NSToolbarSizeModeRegular;
|
|
|
|
toolbar.selectedItemIdentifier = TOOLBAR_GENERAL;
|
|
|
|
self.window.toolbar = toolbar;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setPrefView:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set download folder
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFolderPopUp selectItemAtIndex:[fDefaults boolForKey:@"DownloadLocationConstant"] ? DOWNLOAD_FOLDER : DOWNLOAD_TORRENT];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set stop ratio
|
2021-08-15 09:41:48 +00:00
|
|
|
fRatioStopField.floatValue = [fDefaults floatForKey:@"RatioLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
//set idle seeding minutes
|
2021-08-15 09:41:48 +00:00
|
|
|
fIdleStopField.integerValue = [fDefaults integerForKey:@"IdleLimitMinutes"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set limits
|
|
|
|
[self updateLimitFields];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set speed limit
|
2021-08-15 09:41:48 +00:00
|
|
|
fSpeedLimitUploadField.intValue = [fDefaults integerForKey:@"SpeedLimitUploadLimit"];
|
|
|
|
fSpeedLimitDownloadField.intValue = [fDefaults integerForKey:@"SpeedLimitDownloadLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set port
|
2021-08-15 09:41:48 +00:00
|
|
|
fPortField.intValue = [fDefaults integerForKey:@"BindPort"];
|
2007-09-16 01:02:06 +00:00
|
|
|
fNatStatus = -1;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updatePortStatus];
|
2021-08-15 09:41:48 +00:00
|
|
|
fPortStatusTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(updatePortStatus) userInfo:nil
|
|
|
|
repeats:YES];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-21 05:56:34 +00:00
|
|
|
//set peer connections
|
2021-08-15 09:41:48 +00:00
|
|
|
fPeersGlobalField.intValue = [fDefaults integerForKey:@"PeersTotal"];
|
|
|
|
fPeersTorrentField.intValue = [fDefaults integerForKey:@"PeersTorrent"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set queue values
|
2021-08-15 09:41:48 +00:00
|
|
|
fQueueDownloadField.intValue = [fDefaults integerForKey:@"QueueDownloadNumber"];
|
|
|
|
fQueueSeedField.intValue = [fDefaults integerForKey:@"QueueSeedNumber"];
|
|
|
|
fStalledField.intValue = [fDefaults integerForKey:@"StalledMinutes"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-03-29 23:38:38 +00:00
|
|
|
//set blocklist
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* blocklistURL = [fDefaults stringForKey:@"BlocklistURL"];
|
2010-11-15 00:25:18 +00:00
|
|
|
if (blocklistURL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fBlocklistURLField.stringValue = blocklistURL;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-11-15 00:25:18 +00:00
|
|
|
[self updateBlocklistButton];
|
2008-03-29 23:38:38 +00:00
|
|
|
[self updateBlocklistFields];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateLimitFields)
|
|
|
|
name:@"UpdateSpeedLimitValuesOutsidePrefs"
|
|
|
|
object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateRatioStopField)
|
|
|
|
name:@"UpdateRatioStopValueOutsidePrefs"
|
|
|
|
object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateLimitStopField)
|
|
|
|
name:@"UpdateIdleStopValueOutsidePrefs"
|
|
|
|
object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateBlocklistFields) name:@"BlocklistUpdated"
|
|
|
|
object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateBlocklistURLField)
|
|
|
|
name:NSControlTextDidChangeNotification
|
|
|
|
object:fBlocklistURLField];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 19:11:43 +00:00
|
|
|
//set rpc port
|
2021-08-15 09:41:48 +00:00
|
|
|
fRPCPortField.intValue = [fDefaults integerForKey:@"RPCPort"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-03-14 15:53:13 +00:00
|
|
|
//set rpc password
|
|
|
|
if (fRPCPassword)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fRPCPasswordField.stringValue = fRPCPassword;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar itemForItemIdentifier:(NSString*)ident willBeInsertedIntoToolbar:(BOOL)flag
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:ident];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([ident isEqualToString:TOOLBAR_GENERAL])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"General", "Preferences -> toolbar item title");
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageWithSystemSymbolName:@"gearshape" accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageNamed:NSImageNamePreferencesGeneral];
|
2020-11-21 13:27:38 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(setPrefView:);
|
|
|
|
item.autovalidates = NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_TRANSFERS])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Transfers", "Preferences -> toolbar item title");
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageWithSystemSymbolName:@"arrow.up.arrow.down" accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageNamed:@"Transfers"];
|
2020-11-21 13:27:38 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(setPrefView:);
|
|
|
|
item.autovalidates = NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_GROUPS])
|
2008-11-29 22:50:04 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Groups", "Preferences -> toolbar item title");
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageWithSystemSymbolName:@"pin" accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageNamed:@"Groups"];
|
2020-11-21 13:27:38 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(setPrefView:);
|
|
|
|
item.autovalidates = NO;
|
2008-11-29 22:50:04 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_BANDWIDTH])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Bandwidth", "Preferences -> toolbar item title");
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageWithSystemSymbolName:@"speedometer" accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageNamed:@"Bandwidth"];
|
2020-11-21 13:27:38 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(setPrefView:);
|
|
|
|
item.autovalidates = NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_PEERS])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Peers", "Preferences -> toolbar item title");
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageWithSystemSymbolName:@"person.2" accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageNamed:NSImageNameUserGroup];
|
2020-11-21 13:27:38 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(setPrefView:);
|
|
|
|
item.autovalidates = NO;
|
2008-04-06 03:06:26 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_NETWORK])
|
2008-04-06 03:06:26 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Network", "Preferences -> toolbar item title");
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageWithSystemSymbolName:@"network" accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageNamed:NSImageNameNetwork];
|
2020-11-21 13:27:38 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(setPrefView:);
|
|
|
|
item.autovalidates = NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:TOOLBAR_REMOTE])
|
2008-06-03 19:11:43 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
item.label = NSLocalizedString(@"Remote", "Preferences -> toolbar item title");
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageWithSystemSymbolName:@"antenna.radiowaves.left.and.right" accessibilityDescription:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.image = [NSImage imageNamed:@"Remote"];
|
2020-11-21 13:27:38 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.action = @selector(setPrefView:);
|
|
|
|
item.autovalidates = NO;
|
2008-06-03 19:11:43 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
return item;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return @[
|
|
|
|
TOOLBAR_GENERAL,
|
|
|
|
TOOLBAR_TRANSFERS,
|
|
|
|
TOOLBAR_GROUPS,
|
|
|
|
TOOLBAR_BANDWIDTH,
|
|
|
|
TOOLBAR_PEERS,
|
|
|
|
TOOLBAR_NETWORK,
|
|
|
|
TOOLBAR_REMOTE
|
|
|
|
];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [self toolbarAllowedItemIdentifiers:toolbar];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [self toolbarAllowedItemIdentifiers:toolbar];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (void)restoreWindowWithIdentifier:(NSString*)identifier
|
|
|
|
state:(NSCoder*)state
|
|
|
|
completionHandler:(void (^)(NSWindow*, NSError*))completionHandler
|
2012-05-28 17:26:15 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSWindow* window = ((Controller*)NSApp.delegate).prefsController.window;
|
2012-05-28 17:26:15 +00:00
|
|
|
completionHandler(window, nil);
|
|
|
|
}
|
|
|
|
|
2009-01-11 16:58:14 +00:00
|
|
|
//for a beta release, always use the beta appcast
|
2009-01-16 22:26:16 +00:00
|
|
|
#if defined(TR_BETA_RELEASE)
|
2009-01-13 04:51:11 +00:00
|
|
|
#define SPARKLE_TAG YES
|
2009-01-11 16:58:14 +00:00
|
|
|
#else
|
2021-08-15 09:41:48 +00:00
|
|
|
#define SPARKLE_TAG [fDefaults boolForKey:@"AutoUpdateBeta"]
|
2009-01-11 16:58:14 +00:00
|
|
|
#endif
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setAutoUpdateToBeta:(id)sender
|
2009-01-11 16:58:14 +00:00
|
|
|
{
|
2018-10-04 20:17:29 +00:00
|
|
|
// TODO: Support beta releases (if/when necessary)
|
2009-01-11 16:58:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPort:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_port const port = [sender intValue];
|
|
|
|
[fDefaults setInteger:port forKey:@"BindPort"];
|
2008-05-23 16:18:58 +00:00
|
|
|
tr_sessionSetPeerPort(fHandle, port);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-23 16:18:58 +00:00
|
|
|
fPeerPort = -1;
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updatePortStatus];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)randomPort:(id)sender
|
2008-12-11 04:41:23 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_port const port = tr_sessionSetPeerPortRandom(fHandle);
|
|
|
|
[fDefaults setInteger:port forKey:@"BindPort"];
|
2021-08-07 07:27:56 +00:00
|
|
|
fPortField.intValue = port;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-01-29 00:50:55 +00:00
|
|
|
fPeerPort = -1;
|
|
|
|
[self updatePortStatus];
|
2008-12-11 04:41:23 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRandomPortOnStart:(id)sender
|
2009-04-03 04:29:27 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
tr_sessionSetPeerPortRandomOnStart(fHandle, ((NSButton*)sender).state == NSControlStateValueOn);
|
2009-04-03 04:29:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setNat:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetPortForwardingEnabled(fHandle, [fDefaults boolForKey:@"NatTraversal"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-18 20:59:55 +00:00
|
|
|
fNatStatus = -1;
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updatePortStatus];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updatePortStatus
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_port_forwarding const fwd = tr_sessionGetPortForwarding(fHandle);
|
|
|
|
int const port = tr_sessionGetPeerPort(fHandle);
|
2008-09-07 20:33:10 +00:00
|
|
|
BOOL natStatusChanged = (fNatStatus != fwd);
|
|
|
|
BOOL peerPortChanged = (fPeerPort != port);
|
2008-05-22 12:31:47 +00:00
|
|
|
|
2008-09-07 20:33:10 +00:00
|
|
|
if (natStatusChanged || peerPortChanged)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-22 12:31:47 +00:00
|
|
|
fNatStatus = fwd;
|
2008-05-23 16:18:58 +00:00
|
|
|
fPeerPort = port;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fPortStatusField.stringValue = @"";
|
|
|
|
fPortStatusImage.image = nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
[fPortStatusProgress startAnimation:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-18 20:02:49 +00:00
|
|
|
if (fPortChecker)
|
|
|
|
{
|
2007-12-25 19:14:45 +00:00
|
|
|
[fPortChecker cancelProbe];
|
2007-12-18 20:02:49 +00:00
|
|
|
}
|
2008-09-07 20:33:10 +00:00
|
|
|
BOOL delay = natStatusChanged || tr_sessionIsPortForwardingEnabled(fHandle);
|
2021-08-15 09:41:48 +00:00
|
|
|
fPortChecker = [[PortChecker alloc] initForPort:fPeerPort delay:delay withDelegate:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)portCheckerDidFinishProbing:(PortChecker*)portChecker
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fPortStatusProgress stopAnimation:self];
|
2021-08-07 07:27:56 +00:00
|
|
|
switch (fPortChecker.status)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case PORT_STATUS_OPEN:
|
|
|
|
fPortStatusField.stringValue = NSLocalizedString(@"Port is open", "Preferences -> Network -> port status");
|
|
|
|
fPortStatusImage.image = [NSImage imageNamed:NSImageNameStatusAvailable];
|
|
|
|
break;
|
|
|
|
case PORT_STATUS_CLOSED:
|
|
|
|
fPortStatusField.stringValue = NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status");
|
|
|
|
fPortStatusImage.image = [NSImage imageNamed:NSImageNameStatusUnavailable];
|
|
|
|
break;
|
|
|
|
case PORT_STATUS_ERROR:
|
|
|
|
fPortStatusField.stringValue = NSLocalizedString(@"Port check site is down", "Preferences -> Network -> port status");
|
|
|
|
fPortStatusImage.image = [NSImage imageNamed:NSImageNameStatusPartiallyAvailable];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Port checker returned invalid status: %d", fPortChecker.status);
|
|
|
|
break;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-12-18 20:02:49 +00:00
|
|
|
fPortChecker = nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)sounds
|
2007-09-17 00:01:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* sounds = [NSMutableArray array];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* directories = NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, NSUserDomainMask | NSLocalDomainMask | NSSystemDomainMask, YES);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (__strong NSString* directory in directories)
|
2008-12-26 07:25:17 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
directory = [directory stringByAppendingPathComponent:@"Sounds"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 07:25:17 +00:00
|
|
|
BOOL isDirectory;
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([NSFileManager.defaultManager fileExistsAtPath:directory isDirectory:&isDirectory] && isDirectory)
|
2007-09-17 00:01:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* directoryContents = [NSFileManager.defaultManager contentsOfDirectoryAtPath:directory error:NULL];
|
|
|
|
for (__strong NSString* sound in directoryContents)
|
2008-04-10 16:03:12 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
sound = sound.stringByDeletingPathExtension;
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([NSSound soundNamed:sound])
|
|
|
|
{
|
|
|
|
[sounds addObject:sound];
|
|
|
|
}
|
2008-04-10 16:03:12 +00:00
|
|
|
}
|
2007-09-17 00:01:57 +00:00
|
|
|
}
|
2008-12-26 07:25:17 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-17 00:01:57 +00:00
|
|
|
return sounds;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSound:(id)sender
|
2007-09-17 00:01:57 +00:00
|
|
|
{
|
|
|
|
//play sound when selecting
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSound* sound;
|
|
|
|
if ((sound = [NSSound soundNamed:[sender titleOfSelectedItem]]))
|
|
|
|
{
|
2007-09-17 00:01:57 +00:00
|
|
|
[sound play];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-17 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setUTP:(id)sender
|
2011-02-18 03:50:19 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetUTPEnabled(fHandle, [fDefaults boolForKey:@"UTPGlobal"]);
|
2011-02-18 03:50:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPeersGlobal:(id)sender
|
2007-12-21 05:56:34 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
int const count = [sender intValue];
|
|
|
|
[fDefaults setInteger:count forKey:@"PeersTotal"];
|
2008-05-12 16:39:32 +00:00
|
|
|
tr_sessionSetPeerLimit(fHandle, count);
|
2007-12-21 05:56:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPeersTorrent:(id)sender
|
2007-12-22 04:15:35 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
int const count = [sender intValue];
|
|
|
|
[fDefaults setInteger:count forKey:@"PeersTorrent"];
|
2009-08-17 02:10:14 +00:00
|
|
|
tr_sessionSetPeerLimitPerTorrent(fHandle, count);
|
2007-12-22 04:15:35 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPEX:(id)sender
|
2007-12-24 05:05:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetPexEnabled(fHandle, [fDefaults boolForKey:@"PEXGlobal"]);
|
2007-12-24 05:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setDHT:(id)sender
|
2009-05-21 04:35:40 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetDHTEnabled(fHandle, [fDefaults boolForKey:@"DHTGlobal"]);
|
2009-05-21 04:35:40 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setLPD:(id)sender
|
2010-05-01 16:31:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetLPDEnabled(fHandle, [fDefaults boolForKey:@"LocalPeerDiscoveryGlobal"]);
|
2010-05-01 16:31:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setEncryptionMode:(id)sender
|
2007-09-20 11:46:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_encryption_mode const mode = [fDefaults boolForKey:@"EncryptionPrefer"] ?
|
|
|
|
([fDefaults boolForKey:@"EncryptionRequire"] ? TR_ENCRYPTION_REQUIRED : TR_ENCRYPTION_PREFERRED) :
|
|
|
|
TR_CLEAR_PREFERRED;
|
2009-01-06 02:07:55 +00:00
|
|
|
tr_sessionSetEncryption(fHandle, mode);
|
2007-09-20 11:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setBlocklistEnabled:(id)sender
|
2008-03-29 23:38:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_blocklistSetEnabled(fHandle, [fDefaults boolForKey:@"BlocklistNew"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[BlocklistScheduler.scheduler updateSchedule];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-11-15 00:25:18 +00:00
|
|
|
[self updateBlocklistButton];
|
2010-10-31 19:05:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateBlocklist:(id)sender
|
2008-03-29 23:38:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[BlocklistDownloaderViewController downloadWithPrefsController:self];
|
2008-03-29 23:38:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setBlocklistAutoUpdate:(id)sender
|
2008-09-01 15:46:00 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[BlocklistScheduler.scheduler updateSchedule];
|
2008-09-01 15:46:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateBlocklistFields
|
2008-03-29 23:38:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const exists = tr_blocklistExists(fHandle);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-03-30 01:10:18 +00:00
|
|
|
if (exists)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* countString = [NSString formattedUInteger:tr_blocklistGetRuleCount(fHandle)];
|
|
|
|
fBlocklistMessageField.stringValue = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"%@ IP address rules in list", "Prefs -> blocklist -> message"), countString];
|
2008-03-30 01:10:18 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
fBlocklistMessageField.stringValue = NSLocalizedString(@"A blocklist must first be downloaded", "Prefs -> blocklist -> message");
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* updatedDateString;
|
2008-09-01 04:04:00 +00:00
|
|
|
if (exists)
|
2008-09-01 03:26:04 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDate* updatedDate = [fDefaults objectForKey:@"BlocklistNewLastUpdateSuccess"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-09-01 04:04:00 +00:00
|
|
|
if (updatedDate)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
updatedDateString = [NSDateFormatter localizedStringFromDate:updatedDate dateStyle:NSDateFormatterFullStyle
|
|
|
|
timeStyle:NSDateFormatterShortStyle];
|
|
|
|
}
|
2008-09-01 04:04:00 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-09-01 04:04:00 +00:00
|
|
|
updatedDateString = NSLocalizedString(@"N/A", "Prefs -> blocklist -> message");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-09-01 03:26:04 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-09-01 04:04:00 +00:00
|
|
|
updatedDateString = NSLocalizedString(@"Never", "Prefs -> blocklist -> message");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fBlocklistDateField.stringValue = [NSString
|
|
|
|
stringWithFormat:@"%@: %@", NSLocalizedString(@"Last updated", "Prefs -> blocklist -> message"), updatedDateString];
|
2008-03-29 23:38:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateBlocklistURLField
|
2010-11-15 00:25:18 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* blocklistString = fBlocklistURLField.stringValue;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setObject:blocklistString forKey:@"BlocklistURL"];
|
2021-08-07 07:27:56 +00:00
|
|
|
tr_blocklistSetURL(fHandle, blocklistString.UTF8String);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-11-15 00:25:18 +00:00
|
|
|
[self updateBlocklistButton];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateBlocklistButton
|
2010-11-15 00:25:18 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* blocklistString = [fDefaults objectForKey:@"BlocklistURL"];
|
|
|
|
BOOL const enable = (blocklistString && ![blocklistString isEqualToString:@""]) && [fDefaults boolForKey:@"BlocklistNew"];
|
2021-08-07 07:27:56 +00:00
|
|
|
fBlocklistButton.enabled = enable;
|
2010-11-15 00:25:18 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setAutoStartDownloads:(id)sender
|
2010-03-26 02:28:41 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetPaused(fHandle, ![fDefaults boolForKey:@"AutoStartDownload"]);
|
2010-03-26 02:28:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applySpeedSettings:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionLimitSpeed(fHandle, TR_UP, [fDefaults boolForKey:@"CheckUpload"]);
|
|
|
|
tr_sessionSetSpeedLimit_KBps(fHandle, TR_UP, [fDefaults integerForKey:@"UploadLimit"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionLimitSpeed(fHandle, TR_DOWN, [fDefaults boolForKey:@"CheckDownload"]);
|
|
|
|
tr_sessionSetSpeedLimit_KBps(fHandle, TR_DOWN, [fDefaults integerForKey:@"DownloadLimit"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applyAltSpeedSettings
|
2009-03-28 17:18:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetAltSpeed_KBps(fHandle, TR_UP, [fDefaults integerForKey:@"SpeedLimitUploadLimit"]);
|
|
|
|
tr_sessionSetAltSpeed_KBps(fHandle, TR_DOWN, [fDefaults integerForKey:@"SpeedLimitDownloadLimit"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];
|
2009-03-28 17:18:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applyRatioSetting:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetRatioLimited(fHandle, [fDefaults boolForKey:@"RatioCheck"]);
|
|
|
|
tr_sessionSetRatioLimit(fHandle, [fDefaults floatForKey:@"RatioLimit"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-05 02:42:04 +00:00
|
|
|
//reload main table for seeding progress
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-12 03:13:14 +00:00
|
|
|
//reload global settings in inspector
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateGlobalOptions" object:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRatioStop:(id)sender
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setFloat:[sender floatValue] forKey:@"RatioLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self applyRatioSetting:nil];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateRatioStopField
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-02-14 21:15:57 +00:00
|
|
|
if (fHasLoaded)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
fRatioStopField.floatValue = [fDefaults floatForKey:@"RatioLimit"];
|
|
|
|
}
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateRatioStopFieldOld
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
|
|
|
[self updateRatioStopField];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self applyRatioSetting:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)applyIdleStopSetting:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetIdleLimited(fHandle, [fDefaults boolForKey:@"IdleLimitCheck"]);
|
|
|
|
tr_sessionSetIdleLimit(fHandle, [fDefaults integerForKey:@"IdleLimitMinutes"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-05 02:38:11 +00:00
|
|
|
//reload main table for remaining seeding time
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-12 03:13:14 +00:00
|
|
|
//reload global settings in inspector
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateGlobalOptions" object:nil];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setIdleStop:(id)sender
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setInteger:[sender integerValue] forKey:@"IdleLimitMinutes"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self applyIdleStopSetting:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateLimitStopField
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
|
|
|
if (fHasLoaded)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
fIdleStopField.integerValue = [fDefaults integerForKey:@"IdleLimitMinutes"];
|
|
|
|
}
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateLimitFields
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (!fHasLoaded)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fUploadField.intValue = [fDefaults integerForKey:@"UploadLimit"];
|
|
|
|
fDownloadField.intValue = [fDefaults integerForKey:@"DownloadLimit"];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGlobalLimit:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setInteger:[sender intValue] forKey:sender == fUploadField ? @"UploadLimit" : @"DownloadLimit"];
|
|
|
|
[self applySpeedSettings:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSpeedLimit:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setInteger:[sender intValue]
|
|
|
|
forKey:sender == fSpeedLimitUploadField ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
|
2009-03-28 17:18:43 +00:00
|
|
|
[self applyAltSpeedSettings];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setAutoSpeedLimit:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionUseAltSpeedTime(fHandle, [fDefaults boolForKey:@"SpeedLimitAuto"]);
|
2009-03-28 17:18:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setAutoSpeedLimitTime:(id)sender
|
2009-03-28 17:18:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetAltSpeedBegin(fHandle, [PrefsController dateToTimeSum:[fDefaults objectForKey:@"SpeedLimitAutoOnDate"]]);
|
|
|
|
tr_sessionSetAltSpeedEnd(fHandle, [PrefsController dateToTimeSum:[fDefaults objectForKey:@"SpeedLimitAutoOffDate"]]);
|
2009-03-28 17:18:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setAutoSpeedLimitDay:(id)sender
|
2009-04-04 03:39:06 +00:00
|
|
|
{
|
2021-09-24 12:56:57 +00:00
|
|
|
tr_sessionSetAltSpeedDay(fHandle, static_cast<tr_sched_day>([sender selectedItem].tag));
|
2009-04-04 03:39:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (NSInteger)dateToTimeSum:(NSDate*)date
|
2009-03-28 17:18:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSCalendar* calendar = NSCalendar.currentCalendar;
|
|
|
|
NSDateComponents* components = [calendar components:NSCalendarUnitHour | NSCalendarUnitMinute fromDate:date];
|
2021-08-07 07:27:56 +00:00
|
|
|
return components.hour * 60 + components.minute;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (NSDate*)timeSumToDate:(NSInteger)sum
|
2009-04-05 15:55:20 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDateComponents* comps = [[NSDateComponents alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
comps.hour = sum / 60;
|
|
|
|
comps.minute = sum % 60;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return [NSCalendar.currentCalendar dateFromComponents:comps];
|
2009-04-05 15:55:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)control:(NSControl*)control textShouldBeginEditing:(NSText*)fieldEditor
|
2007-12-06 00:27:39 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fInitialString = control.stringValue;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-06 01:07:56 +00:00
|
|
|
return YES;
|
2007-12-06 00:27:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)control:(NSControl*)control didFailToFormatString:(NSString*)string errorDescription:(NSString*)error
|
2007-12-06 00:27:39 +00:00
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
if (fInitialString)
|
2007-12-06 01:07:56 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
control.stringValue = fInitialString;
|
2007-12-06 01:07:56 +00:00
|
|
|
fInitialString = nil;
|
|
|
|
}
|
2007-12-06 00:27:39 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setBadge:(id)sender
|
2008-03-29 23:38:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)openNotificationSystemPrefs:(NSButton*)sender
|
2012-08-19 19:06:52 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:@"/System/Library/PreferencePanes/Notifications.prefPane"]];
|
2012-08-19 19:06:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resetWarnings:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults removeObjectForKey:@"WarningDuplicate"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningRemainingSpace"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningFolderDataSameName"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningResetStats"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningCreatorBlankAddress"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningCreatorPrivateBlankAddress"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningRemoveTrackers"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningInvalidOpen"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningRemoveCompleted"];
|
|
|
|
[fDefaults removeObjectForKey:@"WarningDonate"];
|
2009-10-02 21:51:09 +00:00
|
|
|
//[fDefaults removeObjectForKey: @"WarningLegal"];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setDefaultForMagnets:(id)sender
|
2009-11-29 22:07:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* bundleID = NSBundle.mainBundle.bundleIdentifier;
|
|
|
|
OSStatus const result = LSSetDefaultHandlerForURLScheme((CFStringRef) @"magnet", (__bridge CFStringRef)bundleID);
|
2009-12-05 15:42:14 +00:00
|
|
|
if (result != noErr)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-12-05 15:42:14 +00:00
|
|
|
NSLog(@"Failed setting default magnet link handler");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-11-29 22:07:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setQueue:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-08-02 12:43:26 +00:00
|
|
|
//let's just do both - easier that way
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetQueueEnabled(fHandle, TR_DOWN, [fDefaults boolForKey:@"Queue"]);
|
|
|
|
tr_sessionSetQueueEnabled(fHandle, TR_UP, [fDefaults boolForKey:@"QueueSeed"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-17 01:49:55 +00:00
|
|
|
//handle if any transfers switch from queued to paused
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateQueue" object:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setQueueNumber:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const number = [sender intValue];
|
|
|
|
BOOL const seed = sender == fQueueSeedField;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setInteger:number forKey:seed ? @"QueueSeedNumber" : @"QueueDownloadNumber"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-02 12:43:26 +00:00
|
|
|
tr_sessionSetQueueSize(fHandle, seed ? TR_UP : TR_DOWN, number);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setStalled:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetQueueStalledEnabled(fHandle, [fDefaults boolForKey:@"CheckStalled"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-08 03:24:23 +00:00
|
|
|
//reload main table for stalled status
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setStalledMinutes:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const min = [sender intValue];
|
|
|
|
[fDefaults setInteger:min forKey:@"StalledMinutes"];
|
2011-08-06 03:09:40 +00:00
|
|
|
tr_sessionSetQueueStalledMinutes(fHandle, min);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-17 01:49:55 +00:00
|
|
|
//reload main table for stalled status
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setDownloadLocation:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setBool:fFolderPopUp.indexOfSelectedItem == DOWNLOAD_FOLDER forKey:@"DownloadLocationConstant"];
|
2013-08-10 02:29:12 +00:00
|
|
|
[self updateShowAddMagnetWindowField];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)folderSheetShow:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.prompt = NSLocalizedString(@"Select", "Preferences -> Open panel 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 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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFolderPopUp selectItemAtIndex:DOWNLOAD_FOLDER];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* folder = panel.URLs[0].path;
|
|
|
|
[fDefaults setObject:folder forKey:@"DownloadFolder"];
|
|
|
|
[fDefaults setBool:YES forKey:@"DownloadLocationConstant"];
|
2013-08-10 02:29:12 +00:00
|
|
|
[self updateShowAddMagnetWindowField];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-05-15 16:42:37 +00:00
|
|
|
assert(folder.length > 0);
|
2021-08-07 07:27:56 +00:00
|
|
|
tr_sessionSetDownloadDir(fHandle, folder.fileSystemRepresentation);
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//reset if cancelled
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFolderPopUp selectItemAtIndex:[fDefaults boolForKey:@"DownloadLocationConstant"] ? DOWNLOAD_FOLDER : DOWNLOAD_TORRENT];
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)incompleteFolderSheetShow:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.prompt = NSLocalizedString(@"Select", "Preferences -> Open panel 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 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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* folder = panel.URLs[0].path;
|
|
|
|
[fDefaults setObject:folder forKey:@"IncompleteDownloadFolder"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-05-15 16:42:37 +00:00
|
|
|
assert(folder.length > 0);
|
2021-08-07 07:27:56 +00:00
|
|
|
tr_sessionSetIncompleteDir(fHandle, folder.fileSystemRepresentation);
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
[fIncompleteFolderPopUp selectItemAtIndex:0];
|
2011-12-11 22:31:01 +00:00
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)doneScriptSheetShow:(id)sender
|
2010-11-23 00:32:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.prompt = NSLocalizedString(@"Select", "Preferences -> Open panel prompt");
|
|
|
|
panel.allowsMultipleSelection = NO;
|
|
|
|
panel.canChooseFiles = YES;
|
|
|
|
panel.canChooseDirectories = NO;
|
|
|
|
panel.canCreateDirectories = NO;
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filePath = panel.URLs[0].path;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-05-15 16:42:37 +00:00
|
|
|
assert(filePath.length > 0);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setObject:filePath forKey:@"DoneScriptPath"];
|
2021-10-13 03:46:12 +00:00
|
|
|
tr_sessionSetScript(fHandle, TR_SCRIPT_ON_TORRENT_DONE, filePath.fileSystemRepresentation);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setBool:YES forKey:@"DoneScriptEnabled"];
|
2021-10-13 03:46:12 +00:00
|
|
|
tr_sessionSetScriptEnabled(fHandle, TR_SCRIPT_ON_TORRENT_DONE, YES);
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDoneScriptPopUp selectItemAtIndex:0];
|
2011-12-11 22:31:01 +00:00
|
|
|
}];
|
2010-11-23 00:32:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setUseIncompleteFolder:(id)sender
|
2009-10-21 13:01:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetIncompleteDirEnabled(fHandle, [fDefaults boolForKey:@"UseIncompleteDownloadFolder"]);
|
2009-10-21 13:01:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRenamePartialFiles:(id)sender
|
2010-02-06 18:44:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetIncompleteFileNamingEnabled(fHandle, [fDefaults boolForKey:@"RenamePartialFiles"]);
|
2010-02-06 18:44:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setShowAddMagnetWindow:(id)sender
|
2013-08-10 02:29:12 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
[fDefaults setBool:(fShowMagnetAddWindowCheck.state == NSControlStateValueOn) forKey:@"MagnetOpenAsk"];
|
2013-08-10 02:29:12 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateShowAddMagnetWindowField
|
2013-08-10 02:29:12 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![fDefaults boolForKey:@"DownloadLocationConstant"])
|
2013-08-10 02:29:12 +00:00
|
|
|
{
|
|
|
|
//always show the add window for magnet links when the download location is the same as the torrent file
|
2021-10-31 15:18:27 +00:00
|
|
|
fShowMagnetAddWindowCheck.state = NSControlStateValueOn;
|
2021-08-07 07:27:56 +00:00
|
|
|
fShowMagnetAddWindowCheck.enabled = NO;
|
2013-08-10 02:29:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
fShowMagnetAddWindowCheck.state = [fDefaults boolForKey:@"MagnetOpenAsk"];
|
2021-08-07 07:27:56 +00:00
|
|
|
fShowMagnetAddWindowCheck.enabled = YES;
|
2013-08-10 02:29:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setDoneScriptEnabled:(id)sender
|
2010-11-23 00:32:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fDefaults boolForKey:@"DoneScriptEnabled"] &&
|
|
|
|
![NSFileManager.defaultManager fileExistsAtPath:[fDefaults stringForKey:@"DoneScriptPath"]])
|
2010-11-23 00:32:43 +00:00
|
|
|
{
|
|
|
|
// enabled is set but script file doesn't exist, so prompt for one and disable until they pick one
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setBool:NO forKey:@"DoneScriptEnabled"];
|
|
|
|
[self doneScriptSheetShow:sender];
|
2010-11-23 00:32:43 +00:00
|
|
|
}
|
2021-10-13 03:46:12 +00:00
|
|
|
tr_sessionSetScriptEnabled(fHandle, TR_SCRIPT_ON_TORRENT_DONE, [fDefaults boolForKey:@"DoneScriptEnabled"]);
|
2010-11-23 00:32:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setAutoImport:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path;
|
|
|
|
if ((path = [fDefaults stringForKey:@"AutoImportDirectory"]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
VDKQueue* watcherQueue = ((Controller*)NSApp.delegate).fileWatcherQueue;
|
|
|
|
if ([fDefaults boolForKey:@"AutoImport"])
|
2013-01-19 05:03:00 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
path = path.stringByExpandingTildeInPath;
|
2021-08-15 09:41:48 +00:00
|
|
|
[watcherQueue addPath:path notifyingAbout:VDKQueueNotifyAboutWrite];
|
2013-01-19 05:03:00 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2013-01-19 05:03:00 +00:00
|
|
|
[watcherQueue removeAllPaths];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"AutoImportSettingChange" object:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self importFolderSheetShow:nil];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)importFolderSheetShow:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.prompt = NSLocalizedString(@"Select", "Preferences -> Open panel prompt");
|
|
|
|
panel.allowsMultipleSelection = NO;
|
|
|
|
panel.canChooseFiles = NO;
|
|
|
|
panel.canChooseDirectories = YES;
|
|
|
|
panel.canCreateDirectories = YES;
|
2007-09-16 01:02:06 +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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
VDKQueue* watcherQueue = ((Controller*)NSApp.delegate).fileWatcherQueue;
|
2013-01-19 05:03:00 +00:00
|
|
|
[watcherQueue removeAllPaths];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path = (panel.URLs[0]).path;
|
|
|
|
[fDefaults setObject:path forKey:@"AutoImportDirectory"];
|
|
|
|
[watcherQueue addPath:path.stringByExpandingTildeInPath notifyingAbout:VDKQueueNotifyAboutWrite];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"AutoImportSettingChange" object:self];
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
2013-01-19 05:03:00 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path = [fDefaults stringForKey:@"AutoImportDirectory"];
|
2013-01-19 05:03:00 +00:00
|
|
|
if (!path)
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setBool:NO forKey:@"AutoImport"];
|
2013-01-19 05:03:00 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fImportFolderPopUp selectItemAtIndex:0];
|
2011-12-11 22:31:01 +00:00
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setAutoSize:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"AutoSizeSettingChange" object:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRPCEnabled:(id)sender
|
2008-06-03 19:11:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL enable = [fDefaults boolForKey:@"RPC"];
|
2008-12-06 01:18:25 +00:00
|
|
|
tr_sessionSetRPCEnabled(fHandle, enable);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setRPCWebUIDiscovery:nil];
|
2008-06-03 19:11:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)linkWebUI:(id)sender
|
2008-07-19 13:40:23 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* urlString = [NSString stringWithFormat:WEBUI_URL, [fDefaults integerForKey:@"RPCPort"]];
|
|
|
|
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:urlString]];
|
2008-07-19 13:40:23 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRPCAuthorize:(id)sender
|
2008-06-05 16:50:39 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetRPCPasswordEnabled(fHandle, [fDefaults boolForKey:@"RPCAuthorize"]);
|
2008-06-05 16:50:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRPCUsername:(id)sender
|
2008-06-05 16:50:39 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetRPCUsername(fHandle, [fDefaults stringForKey:@"RPCUsername"].UTF8String);
|
2008-06-05 16:50:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRPCPassword:(id)sender
|
2008-06-05 16:50:39 +00:00
|
|
|
{
|
2009-03-14 15:53:13 +00:00
|
|
|
fRPCPassword = [[sender stringValue] copy];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
char const* password = [sender stringValue].UTF8String;
|
|
|
|
[self setKeychainPassword:password forService:RPC_KEYCHAIN_SERVICE username:RPC_KEYCHAIN_NAME];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-16 18:31:44 +00:00
|
|
|
tr_sessionSetRPCPassword(fHandle, password);
|
2008-06-13 19:56:09 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateRPCPassword
|
2008-06-13 19:56:09 +00:00
|
|
|
{
|
2008-06-15 20:47:24 +00:00
|
|
|
UInt32 passwordLength;
|
2021-08-15 09:41:48 +00:00
|
|
|
char const* password = nil;
|
|
|
|
SecKeychainFindGenericPassword(
|
|
|
|
NULL,
|
|
|
|
strlen(RPC_KEYCHAIN_SERVICE),
|
|
|
|
RPC_KEYCHAIN_SERVICE,
|
|
|
|
strlen(RPC_KEYCHAIN_NAME),
|
|
|
|
RPC_KEYCHAIN_NAME,
|
|
|
|
&passwordLength,
|
|
|
|
(void**)&password,
|
|
|
|
NULL);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-15 20:47:24 +00:00
|
|
|
if (password != NULL)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
char fullPassword[passwordLength + 1];
|
2008-06-15 20:47:24 +00:00
|
|
|
strncpy(fullPassword, password, passwordLength);
|
|
|
|
fullPassword[passwordLength] = '\0';
|
2021-08-15 09:41:48 +00:00
|
|
|
SecKeychainItemFreeContent(NULL, (void*)password);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-15 20:47:24 +00:00
|
|
|
tr_sessionSetRPCPassword(fHandle, fullPassword);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fRPCPassword = [[NSString alloc] initWithUTF8String:fullPassword];
|
2021-08-07 07:27:56 +00:00
|
|
|
fRPCPasswordField.stringValue = fRPCPassword;
|
2008-06-15 20:47:24 +00:00
|
|
|
}
|
2009-03-14 15:53:13 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-03-14 15:53:13 +00:00
|
|
|
fRPCPassword = nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-05 16:50:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRPCPort:(id)sender
|
2008-06-03 19:11:43 +00:00
|
|
|
{
|
|
|
|
int port = [sender intValue];
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setInteger:port forKey:@"RPCPort"];
|
2008-06-03 19:11:43 +00:00
|
|
|
tr_sessionSetRPCPort(fHandle, port);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setRPCWebUIDiscovery:nil];
|
2008-06-03 19:11:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRPCUseWhitelist:(id)sender
|
2008-10-01 23:02:37 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_sessionSetRPCWhitelistEnabled(fHandle, [fDefaults boolForKey:@"RPCUseWhitelist"]);
|
2008-10-01 23:02:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRPCWebUIDiscovery:(id)sender
|
2008-12-06 02:59:04 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fDefaults boolForKey:@"RPC"] && [fDefaults boolForKey:@"RPCWebDiscovery"])
|
|
|
|
{
|
|
|
|
[BonjourController.defaultController startWithPort:[fDefaults integerForKey:@"RPCPort"]];
|
|
|
|
}
|
2008-12-06 02:59:04 +00:00
|
|
|
else
|
2012-09-10 02:01:07 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (BonjourController.defaultControllerExists)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[BonjourController.defaultController stop];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-10 02:01:07 +00:00
|
|
|
}
|
2008-12-06 02:59:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateRPCWhitelist
|
2008-06-04 03:50:10 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* string = [fRPCWhitelistArray componentsJoinedByString:@","];
|
2021-08-07 07:27:56 +00:00
|
|
|
tr_sessionSetRPCWhitelist(fHandle, string.UTF8String);
|
2008-06-04 03:50:10 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)addRemoveRPCIP:(id)sender
|
2008-06-04 04:48:17 +00:00
|
|
|
{
|
|
|
|
//don't allow add/remove when currently adding - it leads to weird results
|
2021-08-07 07:27:56 +00:00
|
|
|
if (fRPCWhitelistTable.editedRow != -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-06-04 04:48:17 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([[sender cell] tagForSegment:[sender selectedSegment]] == RPC_IP_REMOVE_TAG)
|
2008-06-04 04:48:17 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fRPCWhitelistArray removeObjectsAtIndexes:fRPCWhitelistTable.selectedRowIndexes];
|
|
|
|
[fRPCWhitelistTable deselectAll:self];
|
2008-10-01 22:17:25 +00:00
|
|
|
[fRPCWhitelistTable reloadData];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setObject:fRPCWhitelistArray forKey:@"RPCWhitelist"];
|
2008-10-01 22:17:25 +00:00
|
|
|
[self updateRPCWhitelist];
|
2008-06-04 04:48:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fRPCWhitelistArray addObject:@""];
|
2008-10-01 22:17:25 +00:00
|
|
|
[fRPCWhitelistTable reloadData];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const row = fRPCWhitelistArray.count - 1;
|
|
|
|
[fRPCWhitelistTable selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
|
|
|
[fRPCWhitelistTable editColumn:0 row:row withEvent:nil select:YES];
|
2008-06-04 04:48:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView
|
2008-06-04 03:50:10 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return fRPCWhitelistArray.count;
|
2008-06-04 03:50:10 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)tableView:(NSTableView*)tableView objectValueForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
|
2008-06-04 03:50:10 +00:00
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
return fRPCWhitelistArray[row];
|
2008-06-04 03:50:10 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)tableView:(NSTableView*)tableView
|
|
|
|
setObjectValue:(id)object
|
|
|
|
forTableColumn:(NSTableColumn*)tableColumn
|
|
|
|
row:(NSInteger)row
|
2008-06-04 03:50:10 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* components = [object componentsSeparatedByString:@"."];
|
|
|
|
NSMutableArray* newComponents = [NSMutableArray arrayWithCapacity:4];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-01 22:17:25 +00:00
|
|
|
//create better-formatted ip string
|
|
|
|
BOOL valid = false;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (components.count == 4)
|
2008-10-01 22:17:25 +00:00
|
|
|
{
|
|
|
|
valid = true;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSString* component in components)
|
2008-06-04 03:50:10 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([component isEqualToString:@"*"])
|
|
|
|
{
|
|
|
|
[newComponents addObject:component];
|
|
|
|
}
|
2008-10-01 22:17:25 +00:00
|
|
|
else
|
2008-06-04 03:50:10 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
int num = component.intValue;
|
2008-10-01 22:17:25 +00:00
|
|
|
if (num >= 0 && num < 256)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[newComponents addObject:@(num).stringValue];
|
|
|
|
}
|
2008-06-04 03:50:10 +00:00
|
|
|
else
|
2008-09-30 14:08:21 +00:00
|
|
|
{
|
2008-10-01 22:17:25 +00:00
|
|
|
valid = false;
|
|
|
|
break;
|
2008-09-30 14:08:21 +00:00
|
|
|
}
|
2008-06-04 03:50:10 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 22:17:25 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* newIP;
|
2008-10-01 22:17:25 +00:00
|
|
|
if (valid)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
newIP = [newComponents componentsJoinedByString:@"."];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-01 22:17:25 +00:00
|
|
|
//don't allow the same ip address
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fRPCWhitelistArray containsObject:newIP] && ![fRPCWhitelistArray[row] isEqualToString:newIP])
|
|
|
|
{
|
2008-10-01 22:17:25 +00:00
|
|
|
valid = false;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-04 03:50:10 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-01 22:17:25 +00:00
|
|
|
if (valid)
|
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
fRPCWhitelistArray[row] = newIP;
|
2021-08-15 09:41:48 +00:00
|
|
|
[fRPCWhitelistArray sortUsingSelector:@selector(compareNumeric:)];
|
2008-10-01 22:17:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSBeep();
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fRPCWhitelistArray[row] isEqualToString:@""])
|
|
|
|
{
|
|
|
|
[fRPCWhitelistArray removeObjectAtIndex:row];
|
|
|
|
}
|
2008-10-01 22:17:25 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fRPCWhitelistTable deselectAll:self];
|
2008-10-01 22:17:25 +00:00
|
|
|
[fRPCWhitelistTable reloadData];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setObject:fRPCWhitelistArray forKey:@"RPCWhitelist"];
|
2008-10-01 22:17:25 +00:00
|
|
|
[self updateRPCWhitelist];
|
2008-06-04 03:50:10 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)tableViewSelectionDidChange:(NSNotification*)notification
|
2008-06-04 04:48:17 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fRPCAddRemoveControl setEnabled:fRPCWhitelistTable.numberOfSelectedRows > 0 forSegment:RPC_IP_REMOVE_TAG];
|
2008-06-04 04:48:17 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)helpForScript:(id)sender
|
2010-12-09 19:50:16 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSHelpManager.sharedHelpManager openHelpAnchor:@"script"
|
|
|
|
inBook:[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleHelpBookName"]];
|
2010-12-09 19:50:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)helpForPeers:(id)sender
|
2008-04-06 05:07:28 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSHelpManager.sharedHelpManager openHelpAnchor:@"peers"
|
|
|
|
inBook:[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleHelpBookName"]];
|
2008-04-06 05:07:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)helpForNetwork:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSHelpManager.sharedHelpManager openHelpAnchor:@"network"
|
|
|
|
inBook:[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleHelpBookName"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)helpForRemote:(id)sender
|
2008-06-11 03:28:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSHelpManager.sharedHelpManager openHelpAnchor:@"remote"
|
|
|
|
inBook:[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleHelpBookName"]];
|
2008-06-11 03:28:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)rpcUpdatePrefs
|
2008-06-03 17:55:43 +00:00
|
|
|
{
|
|
|
|
//encryption
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_encryption_mode const encryptionMode = tr_sessionGetEncryption(fHandle);
|
|
|
|
[fDefaults setBool:encryptionMode != TR_CLEAR_PREFERRED forKey:@"EncryptionPrefer"];
|
|
|
|
[fDefaults setBool:encryptionMode == TR_ENCRYPTION_REQUIRED forKey:@"EncryptionRequire"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//download directory
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* downloadLocation = @(tr_sessionGetDownloadDir(fHandle)).stringByStandardizingPath;
|
|
|
|
[fDefaults setObject:downloadLocation forKey:@"DownloadFolder"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* incompleteLocation = @(tr_sessionGetIncompleteDir(fHandle)).stringByStandardizingPath;
|
|
|
|
[fDefaults setObject:incompleteLocation forKey:@"IncompleteDownloadFolder"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const useIncomplete = tr_sessionIsIncompleteDirEnabled(fHandle);
|
|
|
|
[fDefaults setBool:useIncomplete forKey:@"UseIncompleteDownloadFolder"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const usePartialFileRanaming = tr_sessionIsIncompleteFileNamingEnabled(fHandle);
|
|
|
|
[fDefaults setBool:usePartialFileRanaming forKey:@"RenamePartialFiles"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-18 03:50:19 +00:00
|
|
|
//utp
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const utp = tr_sessionIsUTPEnabled(fHandle);
|
|
|
|
[fDefaults setBool:utp forKey:@"UTPGlobal"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//peers
|
2021-08-15 09:41:48 +00:00
|
|
|
uint16_t const peersTotal = tr_sessionGetPeerLimit(fHandle);
|
|
|
|
[fDefaults setInteger:peersTotal forKey:@"PeersTotal"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
uint16_t const peersTorrent = tr_sessionGetPeerLimitPerTorrent(fHandle);
|
|
|
|
[fDefaults setInteger:peersTorrent forKey:@"PeersTorrent"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//pex
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const pex = tr_sessionIsPexEnabled(fHandle);
|
|
|
|
[fDefaults setBool:pex forKey:@"PEXGlobal"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-05-21 04:35:40 +00:00
|
|
|
//dht
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const dht = tr_sessionIsDHTEnabled(fHandle);
|
|
|
|
[fDefaults setBool:dht forKey:@"DHTGlobal"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-18 03:26:54 +00:00
|
|
|
//lpd
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const lpd = tr_sessionIsLPDEnabled(fHandle);
|
|
|
|
[fDefaults setBool:lpd forKey:@"LocalPeerDiscoveryGlobal"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-26 02:28:41 +00:00
|
|
|
//auto start
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const autoStart = !tr_sessionGetPaused(fHandle);
|
|
|
|
[fDefaults setBool:autoStart forKey:@"AutoStartDownload"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//port
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_port const port = tr_sessionGetPeerPort(fHandle);
|
|
|
|
[fDefaults setInteger:port forKey:@"BindPort"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const nat = tr_sessionIsPortForwardingEnabled(fHandle);
|
|
|
|
[fDefaults setBool:nat forKey:@"NatTraversal"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
fPeerPort = -1;
|
|
|
|
fNatStatus = -1;
|
|
|
|
[self updatePortStatus];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const randomPort = tr_sessionGetPeerPortRandomOnStart(fHandle);
|
|
|
|
[fDefaults setBool:randomPort forKey:@"RandomPort"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//speed limit - down
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const downLimitEnabled = tr_sessionIsSpeedLimited(fHandle, TR_DOWN);
|
|
|
|
[fDefaults setBool:downLimitEnabled forKey:@"CheckDownload"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const downLimit = tr_sessionGetSpeedLimit_KBps(fHandle, TR_DOWN);
|
|
|
|
[fDefaults setInteger:downLimit forKey:@"DownloadLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//speed limit - up
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const upLimitEnabled = tr_sessionIsSpeedLimited(fHandle, TR_UP);
|
|
|
|
[fDefaults setBool:upLimitEnabled forKey:@"CheckUpload"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const upLimit = tr_sessionGetSpeedLimit_KBps(fHandle, TR_UP);
|
|
|
|
[fDefaults setInteger:upLimit forKey:@"UploadLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//alt speed limit enabled
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const useAltSpeed = tr_sessionUsesAltSpeed(fHandle);
|
|
|
|
[fDefaults setBool:useAltSpeed forKey:@"SpeedLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//alt speed limit - down
|
2021-08-15 09:41:48 +00:00
|
|
|
int const downLimitAlt = tr_sessionGetAltSpeed_KBps(fHandle, TR_DOWN);
|
|
|
|
[fDefaults setInteger:downLimitAlt forKey:@"SpeedLimitDownloadLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//alt speed limit - up
|
2021-08-15 09:41:48 +00:00
|
|
|
int const upLimitAlt = tr_sessionGetAltSpeed_KBps(fHandle, TR_UP);
|
|
|
|
[fDefaults setInteger:upLimitAlt forKey:@"SpeedLimitUploadLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//alt speed limit schedule
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const useAltSpeedSched = tr_sessionUsesAltSpeedTime(fHandle);
|
|
|
|
[fDefaults setBool:useAltSpeedSched forKey:@"SpeedLimitAuto"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDate* limitStartDate = [PrefsController timeSumToDate:tr_sessionGetAltSpeedBegin(fHandle)];
|
|
|
|
[fDefaults setObject:limitStartDate forKey:@"SpeedLimitAutoOnDate"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDate* limitEndDate = [PrefsController timeSumToDate:tr_sessionGetAltSpeedEnd(fHandle)];
|
|
|
|
[fDefaults setObject:limitEndDate forKey:@"SpeedLimitAutoOffDate"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const limitDay = tr_sessionGetAltSpeedDay(fHandle);
|
|
|
|
[fDefaults setInteger:limitDay forKey:@"SpeedLimitAutoDay"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//blocklist
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const blocklist = tr_blocklistIsEnabled(fHandle);
|
|
|
|
[fDefaults setBool:blocklist forKey:@"BlocklistNew"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* blocklistURL = @(tr_blocklistGetURL(fHandle));
|
|
|
|
[fDefaults setObject:blocklistURL forKey:@"BlocklistURL"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//seed ratio
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const ratioLimited = tr_sessionIsRatioLimited(fHandle);
|
|
|
|
[fDefaults setBool:ratioLimited forKey:@"RatioCheck"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
float const ratioLimit = tr_sessionGetRatioLimit(fHandle);
|
|
|
|
[fDefaults setFloat:ratioLimit forKey:@"RatioLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-06 03:09:40 +00:00
|
|
|
//idle seed limit
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const idleLimited = tr_sessionIsIdleLimited(fHandle);
|
|
|
|
[fDefaults setBool:idleLimited forKey:@"IdleLimitCheck"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger const idleLimitMin = tr_sessionGetIdleLimit(fHandle);
|
|
|
|
[fDefaults setInteger:idleLimitMin forKey:@"IdleLimitMinutes"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-02 12:43:26 +00:00
|
|
|
//queue
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const downloadQueue = tr_sessionGetQueueEnabled(fHandle, TR_DOWN);
|
|
|
|
[fDefaults setBool:downloadQueue forKey:@"Queue"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const downloadQueueNum = tr_sessionGetQueueSize(fHandle, TR_DOWN);
|
|
|
|
[fDefaults setInteger:downloadQueueNum forKey:@"QueueDownloadNumber"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const seedQueue = tr_sessionGetQueueEnabled(fHandle, TR_UP);
|
|
|
|
[fDefaults setBool:seedQueue forKey:@"QueueSeed"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const seedQueueNum = tr_sessionGetQueueSize(fHandle, TR_UP);
|
|
|
|
[fDefaults setInteger:seedQueueNum forKey:@"QueueSeedNumber"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const checkStalled = tr_sessionGetQueueStalledEnabled(fHandle);
|
|
|
|
[fDefaults setBool:checkStalled forKey:@"CheckStalled"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
int const stalledMinutes = tr_sessionGetQueueStalledMinutes(fHandle);
|
|
|
|
[fDefaults setInteger:stalledMinutes forKey:@"StalledMinutes"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-11-23 00:32:43 +00:00
|
|
|
//done script
|
2021-10-13 03:46:12 +00:00
|
|
|
BOOL const doneScriptEnabled = tr_sessionIsScriptEnabled(fHandle, TR_SCRIPT_ON_TORRENT_DONE);
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setBool:doneScriptEnabled forKey:@"DoneScriptEnabled"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-13 03:46:12 +00:00
|
|
|
NSString* doneScriptPath = @(tr_sessionGetScript(fHandle, TR_SCRIPT_ON_TORRENT_DONE));
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setObject:doneScriptPath forKey:@"DoneScriptPath"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 18:00:51 +00:00
|
|
|
//update gui if loaded
|
2008-06-03 17:55:43 +00:00
|
|
|
if (fHasLoaded)
|
|
|
|
{
|
|
|
|
//encryption handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-05 15:22:18 +00:00
|
|
|
//download directory handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-18 03:50:19 +00:00
|
|
|
//utp handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fPeersGlobalField.intValue = peersTotal;
|
|
|
|
fPeersTorrentField.intValue = peersTorrent;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//pex handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-05-21 04:35:40 +00:00
|
|
|
//dht handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-05-19 23:08:14 +00:00
|
|
|
//lpd handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fPortField.intValue = port;
|
2008-06-03 17:55:43 +00:00
|
|
|
//port forwarding (nat) handled by bindings
|
2009-04-05 15:36:51 +00:00
|
|
|
//random port handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//limit check handled by bindings
|
2021-08-07 07:27:56 +00:00
|
|
|
fDownloadField.intValue = downLimit;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-03 17:55:43 +00:00
|
|
|
//limit check handled by bindings
|
2021-08-07 07:27:56 +00:00
|
|
|
fUploadField.intValue = upLimit;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fSpeedLimitDownloadField.intValue = downLimitAlt;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fSpeedLimitUploadField.intValue = upLimitAlt;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//speed limit schedule handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 20:13:16 +00:00
|
|
|
//speed limit schedule times and day handled by bindings
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fBlocklistURLField.stringValue = blocklistURL;
|
2010-11-15 00:25:18 +00:00
|
|
|
[self updateBlocklistButton];
|
2009-04-05 15:36:51 +00:00
|
|
|
[self updateBlocklistFields];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
//ratio limit enabled handled by bindings
|
2021-08-07 07:27:56 +00:00
|
|
|
fRatioStopField.floatValue = ratioLimit;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
//idle limit enabled handled by bindings
|
2021-08-07 07:27:56 +00:00
|
|
|
fIdleStopField.integerValue = idleLimitMin;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-06 03:09:40 +00:00
|
|
|
//queues enabled handled by bindings
|
2021-08-07 07:27:56 +00:00
|
|
|
fQueueDownloadField.intValue = downloadQueueNum;
|
|
|
|
fQueueSeedField.intValue = seedQueueNum;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-08 03:24:23 +00:00
|
|
|
//check stalled handled by bindings
|
2021-08-07 07:27:56 +00:00
|
|
|
fStalledField.intValue = stalledMinutes;
|
2008-06-03 17:55:43 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-12 03:13:14 +00:00
|
|
|
//reload global settings in inspector
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateGlobalOptions" object:nil];
|
2008-06-03 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PrefsController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPrefView:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* identifier;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (sender)
|
|
|
|
{
|
2008-11-29 22:50:04 +00:00
|
|
|
identifier = [sender itemIdentifier];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:identifier forKey:@"SelectedPrefView"];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-11-29 22:50:04 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
identifier = [NSUserDefaults.standardUserDefaults stringForKey:@"SelectedPrefView"];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSView* view;
|
|
|
|
if ([identifier isEqualToString:TOOLBAR_TRANSFERS])
|
|
|
|
{
|
2008-11-29 22:50:04 +00:00
|
|
|
view = fTransfersView;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([identifier isEqualToString:TOOLBAR_GROUPS])
|
|
|
|
{
|
2008-11-29 22:50:04 +00:00
|
|
|
view = fGroupsView;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([identifier isEqualToString:TOOLBAR_BANDWIDTH])
|
|
|
|
{
|
2008-11-29 22:50:04 +00:00
|
|
|
view = fBandwidthView;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([identifier isEqualToString:TOOLBAR_PEERS])
|
|
|
|
{
|
2008-11-29 22:50:04 +00:00
|
|
|
view = fPeersView;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([identifier isEqualToString:TOOLBAR_NETWORK])
|
|
|
|
{
|
2008-11-29 22:50:04 +00:00
|
|
|
view = fNetworkView;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([identifier isEqualToString:TOOLBAR_REMOTE])
|
|
|
|
{
|
2008-11-29 22:50:04 +00:00
|
|
|
view = fRemoteView;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-11-29 22:50:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
identifier = TOOLBAR_GENERAL; //general view is the default selected
|
|
|
|
view = fGeneralView;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.window.toolbar.selectedItemIdentifier = identifier;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSWindow* window = self.window;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (window.contentView == view)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect windowRect = window.frame;
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const difference = NSHeight(view.frame) - NSHeight(window.contentView.frame);
|
2007-09-16 01:02:06 +00:00
|
|
|
windowRect.origin.y -= difference;
|
|
|
|
windowRect.size.height += difference;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
view.hidden = YES;
|
|
|
|
window.contentView = view;
|
2021-08-15 09:41:48 +00:00
|
|
|
[window setFrame:windowRect display:YES animate:YES];
|
2021-08-07 07:27:56 +00:00
|
|
|
view.hidden = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set title label
|
|
|
|
if (sender)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
window.title = [sender label];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSToolbar* toolbar = window.toolbar;
|
|
|
|
NSString* itemIdentifier = toolbar.selectedItemIdentifier;
|
|
|
|
for (NSToolbarItem* item in toolbar.items)
|
|
|
|
{
|
|
|
|
if ([item.itemIdentifier isEqualToString:itemIdentifier])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
window.title = item.label;
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static NSString* getOSStatusDescription(OSStatus errorCode)
|
2017-02-05 15:41:47 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [NSError errorWithDomain:NSOSStatusErrorDomain code:errorCode userInfo:NULL].description;
|
2017-02-05 15:41:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setKeychainPassword:(char const*)password forService:(char const*)service username:(char const*)username
|
2008-06-13 18:47:38 +00:00
|
|
|
{
|
2008-06-15 20:47:24 +00:00
|
|
|
SecKeychainItemRef item = NULL;
|
2008-06-16 23:13:56 +00:00
|
|
|
NSUInteger passwordLength = strlen(password);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-15 20:47:24 +00:00
|
|
|
OSStatus result = SecKeychainFindGenericPassword(NULL, strlen(service), service, strlen(username), username, NULL, NULL, &item);
|
|
|
|
if (result == noErr && item)
|
2008-06-13 18:47:38 +00:00
|
|
|
{
|
2008-06-16 18:31:44 +00:00
|
|
|
if (passwordLength > 0) //found, so update
|
2008-06-15 20:47:24 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
result = SecKeychainItemModifyAttributesAndData(item, NULL, passwordLength, (void const*)password);
|
2008-06-15 20:47:24 +00:00
|
|
|
if (result != noErr)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-02-05 15:41:47 +00:00
|
|
|
NSLog(@"Problem updating Keychain item: %@", getOSStatusDescription(result));
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-15 20:47:24 +00:00
|
|
|
}
|
|
|
|
else //remove the item
|
|
|
|
{
|
|
|
|
result = SecKeychainItemDelete(item);
|
|
|
|
if (result != noErr)
|
2017-02-05 15:41:47 +00:00
|
|
|
{
|
|
|
|
NSLog(@"Problem removing Keychain item: %@", getOSStatusDescription(result));
|
|
|
|
}
|
2008-06-15 20:47:24 +00:00
|
|
|
}
|
2008-06-13 18:47:38 +00:00
|
|
|
}
|
2008-06-15 20:47:24 +00:00
|
|
|
else if (result == errSecItemNotFound) //not found, so add
|
2008-06-13 18:47:38 +00:00
|
|
|
{
|
2008-06-16 18:31:44 +00:00
|
|
|
if (passwordLength > 0)
|
2008-06-15 20:47:24 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
result = SecKeychainAddGenericPassword(NULL, strlen(service), service, strlen(username), username, passwordLength, (void const*)password, NULL);
|
2008-06-15 20:47:24 +00:00
|
|
|
if (result != noErr)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-02-05 15:41:47 +00:00
|
|
|
NSLog(@"Problem adding Keychain item: %@", getOSStatusDescription(result));
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-15 20:47:24 +00:00
|
|
|
}
|
2008-06-13 18:47:38 +00:00
|
|
|
}
|
2008-06-15 20:47:24 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-02-05 15:41:47 +00:00
|
|
|
NSLog(@"Problem accessing Keychain: %@", getOSStatusDescription(result));
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-13 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|