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