2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2009-01-10 23:37:37 +00:00
|
|
|
* Copyright (c) 2005-2009 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"
|
2008-11-01 15:22:32 +00:00
|
|
|
#import "PortChecker.h"
|
2008-12-06 01:18:25 +00:00
|
|
|
#import "BonjourController.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
#import "UKKQueue.h"
|
2008-10-25 20:54:09 +00:00
|
|
|
#import "utils.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
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-11 21:35:01 +00:00
|
|
|
#define PROXY_HTTP 0
|
|
|
|
#define PROXY_SOCKS4 1
|
|
|
|
#define PROXY_SOCKS5 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 PROXY_KEYCHAIN_SERVICE "Transmission:Proxy"
|
|
|
|
#define PROXY_KEYCHAIN_NAME "Proxy"
|
2008-06-13 18:47:38 +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
|
|
|
|
2008-07-19 14:32:11 +00:00
|
|
|
#define WEBUI_URL @"http://localhost:%d/transmission/web/"
|
2008-07-19 13:40:23 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface PrefsController (Private)
|
|
|
|
|
|
|
|
- (void) setPrefView: (id) sender;
|
|
|
|
|
|
|
|
- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
|
|
|
- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
|
|
|
- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
|
|
|
|
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
|
|
|
|
|
2008-12-22 19:14:43 +00:00
|
|
|
tr_session * fHandle;
|
|
|
|
+ (void) setHandle: (tr_session *) handle
|
2008-08-31 20:48:10 +00:00
|
|
|
{
|
|
|
|
fHandle = handle;
|
|
|
|
}
|
|
|
|
|
2008-12-22 19:14:43 +00:00
|
|
|
+ (tr_session *) handle
|
2008-08-31 20:48:10 +00:00
|
|
|
{
|
|
|
|
return fHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
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
|
|
|
{
|
|
|
|
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"];
|
|
|
|
}
|
|
|
|
|
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"]))
|
|
|
|
[[UKKQueue sharedFileWatcher] addPath: [autoPath stringByExpandingTildeInPath]];
|
|
|
|
|
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-06-11 21:35:01 +00:00
|
|
|
//set proxy type
|
|
|
|
[self updateProxyType];
|
2008-06-13 04:22:07 +00:00
|
|
|
[self updateProxyPassword];
|
2008-06-11 21:35:01 +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)
|
|
|
|
fRPCWhitelistArray = [[NSMutableArray arrayWithObject: @"127.0.0.1"] retain];
|
|
|
|
[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"];
|
|
|
|
}
|
|
|
|
|
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];
|
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
|
|
|
[fPortChecker release];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-01 22:17:25 +00:00
|
|
|
[fRPCWhitelistArray release];
|
2008-06-04 03:50:10 +00:00
|
|
|
|
2009-03-14 15:53:13 +00:00
|
|
|
[fRPCPassword release];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
fHasLoaded = YES;
|
|
|
|
|
|
|
|
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];
|
|
|
|
[toolbar release];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setPrefView: nil];
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
|
|
//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];
|
2007-12-06 00:27:39 +00:00
|
|
|
fPortStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
|
2007-09-16 01:02:06 +00:00
|
|
|
selector: @selector(updatePortStatus) userInfo: nil repeats: YES];
|
|
|
|
|
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
|
|
|
|
2008-06-15 04:56:57 +00:00
|
|
|
//set proxy type
|
2008-06-10 22:54:30 +00:00
|
|
|
[fProxyAddressField setStringValue: [fDefaults stringForKey: @"ProxyAddress"]];
|
2008-06-11 21:35:01 +00:00
|
|
|
int proxyType;
|
2009-04-04 03:39:06 +00:00
|
|
|
switch (tr_sessionGetProxyType(fHandle))
|
2008-06-11 21:35:01 +00:00
|
|
|
{
|
|
|
|
case TR_PROXY_SOCKS4:
|
|
|
|
proxyType = PROXY_SOCKS4;
|
|
|
|
break;
|
|
|
|
case TR_PROXY_SOCKS5:
|
|
|
|
proxyType = PROXY_SOCKS5;
|
|
|
|
break;
|
|
|
|
case TR_PROXY_HTTP:
|
|
|
|
proxyType = PROXY_HTTP;
|
|
|
|
}
|
|
|
|
[fProxyTypePopUp selectItemAtIndex: proxyType];
|
2008-06-15 04:56:57 +00:00
|
|
|
|
|
|
|
//set proxy password - does NOT need to be released
|
2008-06-13 04:05:54 +00:00
|
|
|
[fProxyPasswordField setStringValue: [NSString stringWithUTF8String: tr_sessionGetProxyPassword(fHandle)]];
|
2008-06-10 22:54:30 +00:00
|
|
|
|
2008-07-15 01:25:21 +00:00
|
|
|
//set proxy port
|
|
|
|
[fProxyPortField setIntValue: [fDefaults integerForKey: @"ProxyPort"]];
|
|
|
|
|
2008-03-29 23:38:38 +00:00
|
|
|
//set blocklist
|
|
|
|
[self updateBlocklistFields];
|
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
|
|
|
|
|
|
|
//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")];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Transfers.png"]];
|
|
|
|
[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")];
|
|
|
|
[item setImage: [NSImage imageNamed: @"Groups.png"]];
|
|
|
|
[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")];
|
2007-09-16 01:02:06 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
|
|
|
|
[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")];
|
2008-06-13 15:38:02 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Remote.png"]];
|
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
|
|
|
|
{
|
|
|
|
[item release];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [item autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
|
|
|
|
{
|
|
|
|
return [self toolbarDefaultItemIdentifiers: toolbar];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
|
|
|
|
{
|
|
|
|
return [self toolbarAllowedItemIdentifiers: toolbar];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
|
|
|
|
{
|
2008-11-29 22:50:04 +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-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
|
|
|
|
{
|
2009-04-05 15:36:51 +00:00
|
|
|
const int 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);
|
2008-12-11 04:41:23 +00:00
|
|
|
|
|
|
|
[fPortField setIntValue: port];
|
2008-12-11 22:47:07 +00:00
|
|
|
[self setPort: fPortField];
|
2008-12-11 04:41:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 04:29:27 +00:00
|
|
|
- (void) setRandomPortOnStart: (id) sender
|
|
|
|
{
|
|
|
|
tr_sessionSetPeerPortRandomOnStart(fHandle, [sender state] == NSOnState);
|
|
|
|
}
|
|
|
|
|
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];
|
2007-12-18 20:02:49 +00:00
|
|
|
[fPortChecker release];
|
|
|
|
}
|
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")];
|
2007-10-28 03:29:20 +00:00
|
|
|
[fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.png"]];
|
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")];
|
2007-10-28 03:29:20 +00:00
|
|
|
[fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];
|
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")];
|
2007-10-28 03:29:20 +00:00
|
|
|
[fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.png"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-18 20:02:49 +00:00
|
|
|
[fPortChecker release];
|
|
|
|
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
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
NSArray * directories = [NSArray arrayWithObjects: @"/System/Library/Sounds", @"/Library/Sounds", @"Library/Sounds", nil];
|
2007-09-17 00:01:57 +00:00
|
|
|
|
2008-12-26 07:25:17 +00:00
|
|
|
for (NSString * directory in directories)
|
|
|
|
{
|
|
|
|
BOOL isDirectory;
|
2007-09-17 00:01:57 +00:00
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath: directory isDirectory: &isDirectory] && isDirectory)
|
|
|
|
{
|
2008-12-26 07:25:17 +00:00
|
|
|
NSArray * directoryContents = [[NSFileManager defaultManager] directoryContentsAtPath: directory];
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
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"];
|
|
|
|
}
|
|
|
|
|
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"]);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2009-01-06 02:07:55 +00:00
|
|
|
const BOOL enable = [sender state] == NSOnState;
|
2008-03-29 23:38:38 +00:00
|
|
|
[fDefaults setBool: enable forKey: @"Blocklist"];
|
|
|
|
tr_blocklistSetEnabled(fHandle, enable);
|
2008-09-01 15:46:00 +00:00
|
|
|
|
|
|
|
[[BlocklistScheduler scheduler] updateSchedule];
|
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)
|
|
|
|
{
|
|
|
|
NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init];
|
|
|
|
[numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
|
2008-03-30 03:40:13 +00:00
|
|
|
[numberFormatter setMaximumFractionDigits: 0];
|
2008-03-30 01:10:18 +00:00
|
|
|
NSString * countString = [numberFormatter stringFromNumber: [NSNumber numberWithInt: tr_blocklistGetRuleCount(fHandle)]];
|
|
|
|
[numberFormatter release];
|
|
|
|
|
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
|
|
|
|
|
|
|
[fBlocklistEnableCheck setEnabled: exists];
|
|
|
|
[fBlocklistEnableCheck setState: exists && [fDefaults boolForKey: @"Blocklist"]];
|
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
|
|
|
{
|
2008-09-01 04:04:00 +00:00
|
|
|
NSDate * updatedDate = [fDefaults objectForKey: @"BlocklistLastUpdate"];
|
|
|
|
if (updatedDate)
|
|
|
|
{
|
|
|
|
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
[dateFormatter setDateStyle: NSDateFormatterFullStyle];
|
|
|
|
[dateFormatter setTimeStyle: NSDateFormatterShortStyle];
|
|
|
|
|
|
|
|
updatedDateString = [dateFormatter stringFromDate: updatedDate];
|
|
|
|
[dateFormatter release];
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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"]);
|
|
|
|
tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"UploadLimit"]);
|
|
|
|
|
|
|
|
tr_sessionLimitSpeed(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
|
|
|
|
tr_sessionSetSpeedLimit(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
|
|
|
|
{
|
|
|
|
tr_sessionSetAltSpeed(fHandle, TR_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
|
|
|
|
tr_sessionSetAltSpeed(fHandle, TR_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
|
|
|
|
|
|
|
|
[[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
|
|
|
//[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
|
|
|
|
tr_sessionSetRatioLimited(fHandle, [fDefaults boolForKey: @"RatioCheck"]);
|
|
|
|
tr_sessionSetRatioLimit(fHandle, [fDefaults floatForKey: @"RatioLimit"]);
|
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"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[self applyRatioSetting: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioStop: (id) sender
|
|
|
|
{
|
2007-12-06 00:27:39 +00:00
|
|
|
[fDefaults setFloat: [sender floatValue] forKey: @"RatioLimit"];
|
2009-02-14 21:15:57 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self applyRatioSetting: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|
|
|
|
{
|
|
|
|
NSDateComponents * comps = [[[NSDateComponents alloc] init] autorelease];
|
|
|
|
[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
|
|
|
|
{
|
2007-12-06 01:07:56 +00:00
|
|
|
[fInitialString release];
|
2007-12-06 00:27:39 +00:00
|
|
|
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];
|
2007-12-06 01:07:56 +00:00
|
|
|
[fInitialString release];
|
|
|
|
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
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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"];
|
|
|
|
[fDefaults removeObjectForKey: @"WarningRemoveBuiltInTracker"];
|
|
|
|
[fDefaults removeObjectForKey: @"WarningInvalidOpen"];
|
2009-08-14 23:44:25 +00:00
|
|
|
[fDefaults removeObjectForKey: @"WarningDonate"];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQueue: (id) sender
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setQueueNumber: (id) sender
|
|
|
|
{
|
2007-12-06 00:27:39 +00:00
|
|
|
[fDefaults setInteger: [sender intValue] forKey: sender == fQueueDownloadField ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setQueue: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setStalled: (id) sender
|
|
|
|
{
|
2007-12-31 04:18:40 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setStalledMinutes: (id) sender
|
|
|
|
{
|
2007-12-06 00:27:39 +00:00
|
|
|
[fDefaults setInteger: [sender intValue] forKey: @"StalledMinutes"];
|
2007-09-16 01:02:06 +00:00
|
|
|
[self setStalled: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: nil types: nil
|
|
|
|
modalForWindow: [self window] modalDelegate: self didEndSelector:
|
|
|
|
@selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: nil types: nil
|
|
|
|
modalForWindow: [self window] modalDelegate: self didEndSelector:
|
|
|
|
@selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAutoImport: (id) sender
|
|
|
|
{
|
|
|
|
NSString * path;
|
|
|
|
if ((path = [fDefaults stringForKey: @"AutoImportDirectory"]))
|
|
|
|
{
|
|
|
|
path = [path stringByExpandingTildeInPath];
|
|
|
|
if ([fDefaults boolForKey: @"AutoImport"])
|
|
|
|
[[UKKQueue sharedFileWatcher] addPath: path];
|
|
|
|
else
|
|
|
|
[[UKKQueue sharedFileWatcher] removePathFromQueue: path];
|
|
|
|
|
|
|
|
[[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];
|
|
|
|
|
|
|
|
[panel beginSheetForDirectory: nil file: nil types: nil
|
|
|
|
modalForWindow: [self window] modalDelegate: self didEndSelector:
|
|
|
|
@selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAutoSize: (id) sender
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
|
|
|
|
}
|
|
|
|
|
2008-06-10 18:08:57 +00:00
|
|
|
- (void) setProxyEnabled: (id) sender
|
|
|
|
{
|
|
|
|
tr_sessionSetProxyEnabled(fHandle, [fDefaults boolForKey: @"Proxy"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setProxyAddress: (id) sender
|
|
|
|
{
|
2008-06-10 22:54:30 +00:00
|
|
|
NSString * address = [sender stringValue];
|
2008-11-09 12:12:29 +00:00
|
|
|
tr_sessionSetProxy(fHandle, [address UTF8String]);
|
|
|
|
[fDefaults setObject: address forKey: @"ProxyAddress"];
|
2008-06-10 18:08:57 +00:00
|
|
|
}
|
|
|
|
|
2008-07-15 01:25:21 +00:00
|
|
|
- (void) setProxyPort: (id) sender
|
|
|
|
{
|
|
|
|
int port = [sender intValue];
|
|
|
|
[fDefaults setInteger: port forKey: @"ProxyPort"];
|
|
|
|
tr_sessionSetProxyPort(fHandle, port);
|
|
|
|
}
|
|
|
|
|
2008-06-11 21:35:01 +00:00
|
|
|
- (void) setProxyType: (id) sender
|
|
|
|
{
|
|
|
|
NSString * type;
|
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case PROXY_HTTP:
|
|
|
|
type = @"HTTP";
|
|
|
|
break;
|
|
|
|
case PROXY_SOCKS4:
|
|
|
|
type = @"SOCKS4";
|
|
|
|
break;
|
|
|
|
case PROXY_SOCKS5:
|
|
|
|
type = @"SOCKS5";
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDefaults setObject: type forKey: @"ProxyType"];
|
|
|
|
[self updateProxyType];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateProxyType
|
|
|
|
{
|
|
|
|
NSString * typeString = [fDefaults stringForKey: @"ProxyType"];
|
|
|
|
tr_proxy_type type;
|
|
|
|
if ([typeString isEqualToString: @"SOCKS4"])
|
|
|
|
type = TR_PROXY_SOCKS4;
|
|
|
|
else if ([typeString isEqualToString: @"SOCKS5"])
|
2008-08-07 02:50:30 +00:00
|
|
|
type = TR_PROXY_SOCKS5;
|
2008-06-11 21:35:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//safety
|
|
|
|
if (![typeString isEqualToString: @"HTTP"])
|
|
|
|
{
|
|
|
|
typeString = @"HTTP";
|
|
|
|
[fDefaults setObject: typeString forKey: @"ProxyType"];
|
|
|
|
}
|
|
|
|
type = TR_PROXY_HTTP;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_sessionSetProxyType(fHandle, type);
|
|
|
|
}
|
|
|
|
|
2008-06-12 03:59:55 +00:00
|
|
|
- (void) setProxyAuthorize: (id) sender
|
|
|
|
{
|
2008-06-13 04:05:54 +00:00
|
|
|
BOOL enable = [fDefaults boolForKey: @"ProxyAuthorize"];
|
|
|
|
tr_sessionSetProxyAuthEnabled(fHandle, enable);
|
2008-06-12 03:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setProxyUsername: (id) sender
|
|
|
|
{
|
|
|
|
tr_sessionSetProxyUsername(fHandle, [[fDefaults stringForKey: @"ProxyUsername"] UTF8String]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setProxyPassword: (id) sender
|
|
|
|
{
|
2008-06-16 18:31:44 +00:00
|
|
|
const char * password = [[sender stringValue] UTF8String];
|
2008-06-13 18:47:38 +00:00
|
|
|
[self setKeychainPassword: password forService: PROXY_KEYCHAIN_SERVICE username: PROXY_KEYCHAIN_NAME];
|
2008-06-12 03:59:55 +00:00
|
|
|
|
2008-06-16 18:31:44 +00:00
|
|
|
tr_sessionSetProxyPassword(fHandle, password);
|
2008-06-12 03:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateProxyPassword
|
|
|
|
{
|
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(PROXY_KEYCHAIN_SERVICE), PROXY_KEYCHAIN_SERVICE,
|
|
|
|
strlen(PROXY_KEYCHAIN_NAME), PROXY_KEYCHAIN_NAME, &passwordLength, (void **)&password, NULL);
|
2008-06-13 19:56:09 +00:00
|
|
|
|
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_sessionSetProxyPassword(fHandle, fullPassword);
|
|
|
|
[fProxyPasswordField setStringValue: [NSString stringWithUTF8String: fullPassword]];
|
|
|
|
}
|
2008-06-12 03:59:55 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2009-03-14 15:53:13 +00:00
|
|
|
[fRPCPassword release];
|
|
|
|
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
|
|
|
|
2009-03-14 15:53:13 +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
|
|
|
|
[[BonjourController defaultController] stop];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-10-01 22:17:25 +00:00
|
|
|
int row = [fRPCWhitelistArray count] - 1;
|
|
|
|
[fRPCWhitelistTable selectRow: row byExtendingSelection: NO];
|
|
|
|
[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
|
|
|
}
|
|
|
|
|
2008-04-06 05:07:28 +00:00
|
|
|
- (void) helpForPeers: (id) sender
|
|
|
|
{
|
|
|
|
[[NSHelpManager sharedHelpManager] openHelpAnchor: @"PeersPrefs"
|
|
|
|
inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) helpForNetwork: (id) sender
|
|
|
|
{
|
2008-04-06 05:07:28 +00:00
|
|
|
[[NSHelpManager sharedHelpManager] openHelpAnchor: @"NetworkPrefs"
|
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
|
|
|
|
{
|
|
|
|
[[NSHelpManager sharedHelpManager] openHelpAnchor: @"RemotePrefs"
|
|
|
|
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
|
|
|
|
|
|
|
//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);
|
|
|
|
[fDefaults setInteger: peersTotal forKey: @"PeersTorrent"];
|
|
|
|
|
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"];
|
|
|
|
|
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"];
|
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
const int downLimit = tr_sessionGetSpeedLimit(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"];
|
|
|
|
|
2009-04-05 15:36:51 +00:00
|
|
|
const int upLimit = tr_sessionGetSpeedLimit(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
|
|
|
|
const int downLimitAlt = tr_sessionGetAltSpeed(fHandle, TR_DOWN);
|
|
|
|
[fDefaults setInteger: downLimit forKey: @"SpeedLimitDownloadLimit"];
|
|
|
|
|
|
|
|
//alt speed limit - up
|
|
|
|
const int upLimitAlt = tr_sessionGetAltSpeed(fHandle, TR_UP);
|
|
|
|
[fDefaults setInteger: upLimitAlt forKey: @"SpeedLimitDownloadLimit"];
|
|
|
|
|
|
|
|
//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);
|
|
|
|
[fDefaults setBool: blocklist forKey: @"Blocklist"];
|
|
|
|
|
|
|
|
//seed ratio
|
|
|
|
const BOOL ratioLimited = tr_sessionIsRatioLimited(fHandle);
|
|
|
|
[fDefaults setBool: ratioLimited forKey: @"RatioCheck"];
|
|
|
|
|
|
|
|
const float ratioLimit = tr_sessionGetRatioLimit(fHandle);
|
|
|
|
[fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
[self updateBlocklistFields];
|
|
|
|
|
|
|
|
//ratio limit enabled handled by bindings
|
|
|
|
[fRatioStopField setFloatValue: ratioLimit];
|
2008-06-03 17:55:43 +00:00
|
|
|
}
|
2009-04-05 15:55:20 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" 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];
|
|
|
|
float difference = ([view frame].size.height - [[window contentView] frame].size.height) * [window userSpaceScaleFactor];
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
|
|
|
|
{
|
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
|
2009-04-05 17:48:03 +00:00
|
|
|
|
|
|
|
NSString * folder = [[openPanel filenames] objectAtIndex: 0];
|
|
|
|
[fDefaults setObject: folder forKey: @"DownloadFolder"];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
|
2009-04-05 17:48:03 +00:00
|
|
|
|
|
|
|
tr_sessionSetDownloadDir(fHandle, [folder UTF8String]);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//reset if cancelled
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
|
|
|
|
{
|
|
|
|
if (code == NSOKButton)
|
|
|
|
[fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
|
|
|
|
[fIncompleteFolderPopUp selectItemAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
|
|
|
|
{
|
|
|
|
NSString * path = [fDefaults stringForKey: @"AutoImportDirectory"];
|
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
|
|
|
UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
|
|
|
|
if (path)
|
|
|
|
[sharedQueue removePathFromQueue: [path stringByExpandingTildeInPath]];
|
|
|
|
|
|
|
|
path = [[openPanel filenames] objectAtIndex: 0];
|
|
|
|
[fDefaults setObject: path forKey: @"AutoImportDirectory"];
|
|
|
|
[sharedQueue addPath: [path stringByExpandingTildeInPath]];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
|
|
|
|
}
|
|
|
|
else if (!path)
|
|
|
|
[fDefaults setBool: NO forKey: @"AutoImport"];
|
|
|
|
|
|
|
|
[fImportFolderPopUp selectItemAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
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
|