2006-07-16 19:39:23 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2006 Transmission authors and contributors
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#import "StringAdditions.h"
|
2006-09-05 04:28:07 +00:00
|
|
|
#import "UKKQueue.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
#define DOWNLOAD_FOLDER 0
|
|
|
|
#define DOWNLOAD_TORRENT 2
|
2006-07-29 16:58:44 +00:00
|
|
|
#define DOWNLOAD_ASK 3
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
#define UPDATE_DAILY 0
|
|
|
|
#define UPDATE_WEEKLY 1
|
|
|
|
#define UPDATE_NEVER 2
|
|
|
|
|
2006-10-24 20:51:47 +00:00
|
|
|
#define TOOLBAR_GENERAL @"TOOLBAR_GENERAL"
|
|
|
|
#define TOOLBAR_TRANSFERS @"TOOLBAR_TRANSFERS"
|
|
|
|
#define TOOLBAR_BANDWIDTH @"TOOLBAR_BANDWIDTH"
|
|
|
|
#define TOOLBAR_NETWORK @"TOOLBAR_NETWORK"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
@interface PrefsController (Private)
|
|
|
|
|
2006-10-24 21:25:03 +00:00
|
|
|
- (void) setPrefView: (id) sender;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
2006-11-03 16:01:45 +00:00
|
|
|
- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PrefsController
|
|
|
|
|
2006-07-30 22:11:08 +00:00
|
|
|
- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle
|
|
|
|
{
|
2006-07-30 22:20:20 +00:00
|
|
|
if ((self = [self initWithWindowNibName: name]))
|
2006-07-30 22:11:08 +00:00
|
|
|
{
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
fHandle = handle;
|
2006-08-02 21:24:53 +00:00
|
|
|
|
2006-10-21 20:41:10 +00:00
|
|
|
//checks for old version upload speed of -1
|
|
|
|
if ([fDefaults integerForKey: @"UploadLimit"] < 0)
|
|
|
|
{
|
|
|
|
[fDefaults setInteger: 20 forKey: @"UploadLimit"];
|
|
|
|
[fDefaults setBool: NO forKey: @"CheckUpload"];
|
|
|
|
}
|
|
|
|
|
2006-10-25 02:57:00 +00:00
|
|
|
//set auto import
|
|
|
|
if ([fDefaults boolForKey: @"AutoImport"])
|
2006-10-27 19:14:04 +00:00
|
|
|
[[UKKQueue sharedFileWatcher] addPath:
|
|
|
|
[[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
|
2006-10-25 02:57:00 +00:00
|
|
|
|
|
|
|
//set bind port
|
|
|
|
int bindPort = [fDefaults integerForKey: @"BindPort"];
|
|
|
|
tr_setBindPort(fHandle, bindPort);
|
|
|
|
|
|
|
|
//set NAT
|
2007-01-19 04:42:31 +00:00
|
|
|
tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]);
|
2006-10-25 02:57:00 +00:00
|
|
|
|
|
|
|
//actually set bandwidth limits
|
2006-10-27 19:14:04 +00:00
|
|
|
[self applySpeedSettings: nil];
|
2006-10-29 17:05:27 +00:00
|
|
|
|
|
|
|
//set play sound
|
|
|
|
NSMutableArray * sounds = [NSMutableArray array];
|
2007-02-09 15:02:25 +00:00
|
|
|
NSEnumerator * soundEnumerator;
|
2006-10-29 17:05:27 +00:00
|
|
|
|
|
|
|
//get list of all sounds and sort alphabetically
|
2007-02-09 15:02:25 +00:00
|
|
|
if (soundEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: @"System/Library/Sounds"])
|
|
|
|
{
|
|
|
|
NSString * sound;
|
|
|
|
while ((sound = [soundEnumerator nextObject]))
|
|
|
|
{
|
|
|
|
sound = [sound stringByDeletingPathExtension];
|
|
|
|
if ([NSSound soundNamed: sound])
|
|
|
|
[sounds addObject: sound];
|
|
|
|
}
|
|
|
|
}
|
2006-10-29 17:05:27 +00:00
|
|
|
|
|
|
|
fSounds = [[sounds sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)] retain];
|
2006-07-30 22:11:08 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-10-25 02:57:00 +00:00
|
|
|
if (fNatStatusTimer)
|
|
|
|
[fNatStatusTimer invalidate];
|
2006-10-29 17:05:27 +00:00
|
|
|
[fSounds release];
|
2006-10-27 19:14:04 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-07-30 22:11:08 +00:00
|
|
|
- (void) awakeFromNib
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-03-11 22:12:01 +00:00
|
|
|
fHasLoaded = YES;
|
2006-12-31 23:24:23 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
|
|
|
|
[fToolbar setDelegate: self];
|
|
|
|
[fToolbar setAllowsUserCustomization: NO];
|
|
|
|
[[self window] setToolbar: fToolbar];
|
|
|
|
[fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
|
|
|
|
[fToolbar setSizeMode: NSToolbarSizeModeRegular];
|
|
|
|
|
|
|
|
[fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
|
2006-10-24 21:25:03 +00:00
|
|
|
[self setPrefView: nil];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
//set download folder
|
|
|
|
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
|
|
|
|
if ([downloadChoice isEqualToString: @"Constant"])
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
|
|
|
|
else if ([downloadChoice isEqualToString: @"Torrent"])
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
|
|
|
|
else
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
|
|
|
|
|
2006-12-31 23:24:23 +00:00
|
|
|
//set stop ratio
|
|
|
|
[self updateRatioStopField];
|
|
|
|
|
|
|
|
//set limits
|
|
|
|
[self updateLimitFields];
|
|
|
|
|
2006-12-31 21:38:35 +00:00
|
|
|
//set speed limit
|
|
|
|
[fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]];
|
|
|
|
[fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]];
|
|
|
|
|
|
|
|
//set port
|
|
|
|
[fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]];
|
2006-09-28 21:14:49 +00:00
|
|
|
[self updatePortStatus];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
fNatStatus = -1;
|
|
|
|
[self updateNatStatus];
|
|
|
|
fNatStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
|
|
|
|
selector: @selector(updateNatStatus) userInfo: nil repeats: YES];
|
2006-12-31 23:24:23 +00:00
|
|
|
|
|
|
|
//set queue values
|
2007-01-09 03:25:13 +00:00
|
|
|
[fQueueDownloadField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]];
|
|
|
|
[fQueueSeedField setIntValue: [fDefaults integerForKey: @"QueueSeedNumber"]];
|
2006-12-31 23:24:23 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
//set update check
|
|
|
|
NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"];
|
|
|
|
if ([updateCheck isEqualToString: @"Weekly"])
|
|
|
|
[fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
|
|
|
|
else if ([updateCheck isEqualToString: @"Never"])
|
|
|
|
[fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
|
|
|
|
else
|
|
|
|
[fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
|
|
|
|
}
|
|
|
|
|
2006-10-25 02:57:00 +00:00
|
|
|
- (void) setUpdater: (SUUpdater *) updater
|
|
|
|
{
|
|
|
|
fUpdater = updater;
|
|
|
|
}
|
|
|
|
|
2006-10-27 19:14:04 +00:00
|
|
|
- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident
|
|
|
|
willBeInsertedIntoToolbar: (BOOL) flag
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
|
|
|
NSToolbarItem * item;
|
|
|
|
item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
|
|
|
|
|
|
|
|
if ([ident isEqualToString: TOOLBAR_GENERAL])
|
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"General", "Preferences -> General toolbar item title")];
|
2006-07-16 19:39:23 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Preferences.png"]];
|
|
|
|
[item setTarget: self];
|
2006-10-24 21:25:03 +00:00
|
|
|
[item setAction: @selector(setPrefView:)];
|
2006-11-06 02:05:32 +00:00
|
|
|
[item setAutovalidates: NO];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
|
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Transfers", "Preferences -> Transfers toolbar item title")];
|
2006-07-16 19:39:23 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Transfers.png"]];
|
|
|
|
[item setTarget: self];
|
2006-10-24 21:25:03 +00:00
|
|
|
[item setAction: @selector(setPrefView:)];
|
2006-11-06 02:05:32 +00:00
|
|
|
[item setAutovalidates: NO];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
|
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> Bandwidth toolbar item title")];
|
2006-07-16 19:39:23 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
|
|
|
|
[item setTarget: self];
|
2006-10-24 21:25:03 +00:00
|
|
|
[item setAction: @selector(setPrefView:)];
|
2006-11-06 02:05:32 +00:00
|
|
|
[item setAutovalidates: NO];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: TOOLBAR_NETWORK])
|
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
[item setLabel: NSLocalizedString(@"Network", "Preferences -> Network toolbar item title")];
|
2006-07-16 19:39:23 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"Network.png"]];
|
|
|
|
[item setTarget: self];
|
2006-10-24 21:25:03 +00:00
|
|
|
[item setAction: @selector(setPrefView:)];
|
2006-11-06 02:05:32 +00:00
|
|
|
[item setAutovalidates: NO];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[item release];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
|
|
|
|
{
|
|
|
|
return [self toolbarDefaultItemIdentifiers: toolbar];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
|
|
|
|
{
|
|
|
|
return [self toolbarAllowedItemIdentifiers: toolbar];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
|
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS,
|
|
|
|
TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPort: (id) sender
|
|
|
|
{
|
2006-12-31 21:38:35 +00:00
|
|
|
int port = [sender intValue];
|
|
|
|
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", port]])
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
[sender setIntValue: [fDefaults integerForKey: @"BindPort"]];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDefaults setInteger: port forKey: @"BindPort"];
|
|
|
|
|
2006-10-27 19:14:04 +00:00
|
|
|
tr_setBindPort(fHandle, [fDefaults integerForKey: @"BindPort"]);
|
|
|
|
[self updateNatStatus];
|
|
|
|
[self updatePortStatus];
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 21:14:49 +00:00
|
|
|
- (void) updatePortStatus
|
|
|
|
{
|
2006-11-03 02:49:16 +00:00
|
|
|
PortChecker * portChecker = [[PortChecker alloc] initWithDelegate: self];
|
2006-09-28 21:14:49 +00:00
|
|
|
|
2006-11-03 02:49:16 +00:00
|
|
|
[fPortStatusField setStringValue: [NSLocalizedString(@"Checking port status",
|
|
|
|
"Preferences -> Network -> port status") stringByAppendingEllipsis]];
|
|
|
|
[fPortStatusImage setImage: nil];
|
|
|
|
[fPortStatusProgress startAnimation: self];
|
2007-02-07 05:32:16 +00:00
|
|
|
|
|
|
|
tr_handle_status_t * stat = tr_handleStatus(fHandle);
|
|
|
|
[portChecker probePort: stat->publicPort];
|
2006-09-28 21:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) portCheckerDidFinishProbing: (PortChecker *) portChecker
|
|
|
|
{
|
|
|
|
[fPortStatusProgress stopAnimation: self];
|
|
|
|
switch ([portChecker status])
|
|
|
|
{
|
|
|
|
case PORT_STATUS_OPEN:
|
2006-10-24 20:34:13 +00:00
|
|
|
[fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Network -> port status")];
|
2006-09-28 21:14:49 +00:00
|
|
|
[fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
|
|
|
|
break;
|
|
|
|
case PORT_STATUS_STEALTH:
|
2006-10-24 20:34:13 +00:00
|
|
|
[fPortStatusField setStringValue: NSLocalizedString(@"Port is stealth", "Preferences -> Network -> port status")];
|
2006-09-28 21:14:49 +00:00
|
|
|
[fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
|
|
|
|
break;
|
|
|
|
case PORT_STATUS_CLOSED:
|
2006-10-24 20:34:13 +00:00
|
|
|
[fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status")];
|
2006-09-28 21:14:49 +00:00
|
|
|
[fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
|
|
|
|
break;
|
|
|
|
case PORT_STATUS_ERROR:
|
2006-10-24 20:51:47 +00:00
|
|
|
[fPortStatusField setStringValue: NSLocalizedString(@"Unable to check port status",
|
|
|
|
"Preferences -> Network -> port status")];
|
2006-09-28 21:14:49 +00:00
|
|
|
[fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.tiff"]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[portChecker release];
|
|
|
|
}
|
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
- (void) setNat: (id) sender
|
|
|
|
{
|
2007-01-19 04:42:31 +00:00
|
|
|
tr_natTraversalEnable(fHandle, [fDefaults boolForKey: @"NatTraversal"]);
|
2006-09-25 18:37:45 +00:00
|
|
|
[self updateNatStatus];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateNatStatus
|
|
|
|
{
|
2007-02-07 05:32:16 +00:00
|
|
|
tr_handle_status_t * stat = tr_handleStatus(fHandle);
|
|
|
|
if (fNatStatus == stat->natTraversalStatus)
|
2006-09-25 18:37:45 +00:00
|
|
|
return;
|
2007-02-07 05:32:16 +00:00
|
|
|
fNatStatus = stat->natTraversalStatus;
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2007-02-07 05:32:16 +00:00
|
|
|
if (fNatStatus == TR_NAT_TRAVERSAL_MAPPED)
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
[fNatStatusField setStringValue: NSLocalizedString(@"Port successfully mapped",
|
|
|
|
"Preferences -> Network -> port map status")];
|
2006-10-04 20:10:45 +00:00
|
|
|
[fNatStatusImage setImage: [NSImage imageNamed: @"GreenDot.tiff"]];
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
2007-02-07 05:32:16 +00:00
|
|
|
else if (fNatStatus == TR_NAT_TRAVERSAL_NOTFOUND || fNatStatus == TR_NAT_TRAVERSAL_ERROR)
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
[fNatStatusField setStringValue: NSLocalizedString(@"Error mapping port",
|
|
|
|
"Preferences -> Network -> port map status")];
|
2006-10-04 01:46:20 +00:00
|
|
|
[fNatStatusImage setImage: [NSImage imageNamed: @"RedDot.tiff"]];
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fNatStatusField setStringValue: @""];
|
|
|
|
[fNatStatusImage setImage: nil];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2006-10-11 18:55:20 +00:00
|
|
|
|
|
|
|
[self updatePortStatus];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2006-10-27 19:14:04 +00:00
|
|
|
- (void) applySpeedSettings: (id) sender
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2006-10-27 19:14:04 +00:00
|
|
|
if ([fDefaults boolForKey: @"SpeedLimit"])
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2006-12-27 00:22:38 +00:00
|
|
|
tr_setGlobalUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
|
|
|
|
tr_setGlobalDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-27 00:22:38 +00:00
|
|
|
tr_setGlobalUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
|
2006-10-25 02:57:00 +00:00
|
|
|
? [fDefaults integerForKey: @"UploadLimit"] : -1);
|
2006-12-27 00:22:38 +00:00
|
|
|
tr_setGlobalDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
|
2006-10-27 19:14:04 +00:00
|
|
|
? [fDefaults integerForKey: @"DownloadLimit"] : -1);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 23:24:23 +00:00
|
|
|
- (void) updateRatioStopField
|
|
|
|
{
|
2007-03-11 22:12:01 +00:00
|
|
|
if (!fHasLoaded)
|
2006-12-31 23:24:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
[fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioStop: (id) sender
|
|
|
|
{
|
|
|
|
float ratio = [sender floatValue];
|
|
|
|
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratio]] || ratio < 0)
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
[sender setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDefaults setFloat: ratio forKey: @"RatioLimit"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateLimitFields
|
|
|
|
{
|
2007-03-11 22:12:01 +00:00
|
|
|
if (!fHasLoaded)
|
2006-12-31 23:24:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
[fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
|
|
|
|
[fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setGlobalLimit: (id) sender
|
|
|
|
{
|
|
|
|
BOOL upload = sender == fUploadField;
|
|
|
|
|
|
|
|
int limit = [sender intValue];
|
|
|
|
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
[sender setIntValue: [fDefaults integerForKey: upload ? @"UploadLimit" : @"DownloadLimit"]];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDefaults setInteger: limit forKey: upload ? @"UploadLimit" : @"DownloadLimit"];
|
|
|
|
|
|
|
|
[self applySpeedSettings: self];
|
|
|
|
}
|
|
|
|
|
2006-12-31 21:38:35 +00:00
|
|
|
- (void) setSpeedLimit: (id) sender
|
|
|
|
{
|
|
|
|
BOOL upload = sender == fSpeedLimitUploadField;
|
|
|
|
|
|
|
|
int limit = [sender intValue];
|
|
|
|
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]])
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
[sender setIntValue: [fDefaults integerForKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"]];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDefaults setInteger: limit forKey: upload ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
|
|
|
|
|
|
|
|
[self applySpeedSettings: self];
|
|
|
|
}
|
|
|
|
|
2006-11-01 16:37:14 +00:00
|
|
|
- (void) setAutoSpeedLimit: (id) sender
|
2006-08-08 02:11:51 +00:00
|
|
|
{
|
2006-08-11 22:58:14 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
|
2006-08-08 02:11:51 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) setBadge: (id) sender
|
|
|
|
{
|
2006-07-30 21:49:58 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-07 02:28:31 +00:00
|
|
|
- (void) setSound: (id) sender
|
|
|
|
{
|
|
|
|
//play sound when selecting
|
|
|
|
NSSound * sound;
|
2007-02-09 15:02:25 +00:00
|
|
|
if ((sound = [NSSound soundNamed: [sender titleOfSelectedItem]]))
|
2006-08-07 02:28:31 +00:00
|
|
|
[sound play];
|
2006-08-07 00:46:47 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) setUpdate: (id) sender
|
|
|
|
{
|
|
|
|
int index = [fUpdatePopUp indexOfSelectedItem];
|
2007-02-09 15:02:25 +00:00
|
|
|
NSString * update;
|
2006-07-16 19:39:23 +00:00
|
|
|
NSTimeInterval seconds;
|
|
|
|
if (index == UPDATE_DAILY)
|
|
|
|
{
|
2007-02-09 15:02:25 +00:00
|
|
|
update = @"Daily";
|
2006-07-16 19:39:23 +00:00
|
|
|
seconds = 86400;
|
|
|
|
}
|
|
|
|
else if (index == UPDATE_WEEKLY)
|
|
|
|
{
|
2007-02-09 15:02:25 +00:00
|
|
|
update = @"Weekly";
|
2006-07-16 19:39:23 +00:00
|
|
|
seconds = 604800;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-09 15:02:25 +00:00
|
|
|
update = @"Never";
|
2006-07-16 19:39:23 +00:00
|
|
|
seconds = 0;
|
|
|
|
}
|
2007-02-09 15:02:25 +00:00
|
|
|
|
|
|
|
[fDefaults setObject: update forKey: @"UpdateCheck"];
|
2006-07-16 19:39:23 +00:00
|
|
|
[fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
|
2006-10-25 02:57:00 +00:00
|
|
|
|
|
|
|
if (fUpdater)
|
|
|
|
[fUpdater scheduleCheckWithInterval: seconds];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-01-09 03:25:13 +00:00
|
|
|
- (void) setQueue: (id) sender
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
|
|
|
}
|
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
- (void) setQueueNumber: (id) sender
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-01-09 03:25:13 +00:00
|
|
|
BOOL download = sender == fQueueDownloadField;
|
|
|
|
|
2006-12-31 23:24:23 +00:00
|
|
|
int limit = [sender intValue];
|
|
|
|
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
|
|
|
|
{
|
|
|
|
NSBeep();
|
2007-01-09 03:25:13 +00:00
|
|
|
[sender setIntValue: [fDefaults integerForKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"]];
|
2006-12-31 23:24:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-09 03:25:13 +00:00
|
|
|
[fDefaults setInteger: limit forKey: download ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
|
2006-12-31 23:24:23 +00:00
|
|
|
|
2007-01-09 03:25:13 +00:00
|
|
|
[self setQueue: nil];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDownloadLocation: (id) sender
|
|
|
|
{
|
|
|
|
switch ([fFolderPopUp indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case DOWNLOAD_FOLDER:
|
|
|
|
[fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
|
|
|
|
break;
|
|
|
|
case DOWNLOAD_TORRENT:
|
|
|
|
[fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"];
|
|
|
|
break;
|
|
|
|
case DOWNLOAD_ASK:
|
|
|
|
[fDefaults setObject: @"Ask" forKey: @"DownloadChoice"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) folderSheetShow: (id) sender
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setPrompt: @"Select"];
|
|
|
|
[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];
|
|
|
|
}
|
|
|
|
|
2006-11-03 16:01:45 +00:00
|
|
|
- (void) incompleteFolderSheetShow: (id) sender
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setPrompt: @"Select"];
|
|
|
|
[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];
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) setAutoImport: (id) sender
|
|
|
|
{
|
2006-11-10 04:55:52 +00:00
|
|
|
NSString * path = [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath];
|
2006-10-27 19:14:04 +00:00
|
|
|
if ([fDefaults boolForKey: @"AutoImport"])
|
2006-11-10 04:55:52 +00:00
|
|
|
[[UKKQueue sharedFileWatcher] addPath: path];
|
2006-09-05 04:28:07 +00:00
|
|
|
else
|
2006-11-10 04:55:52 +00:00
|
|
|
[[UKKQueue sharedFileWatcher] removePathFromQueue: path];
|
2006-09-05 04:28:07 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) importFolderSheetShow: (id) sender
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setPrompt: @"Select"];
|
|
|
|
[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];
|
|
|
|
}
|
|
|
|
|
2006-07-22 16:38:05 +00:00
|
|
|
- (void) setAutoSize: (id) sender
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
|
|
|
|
}
|
|
|
|
|
2006-08-08 23:03:45 +00:00
|
|
|
- (void) helpForNetwork: (id) sender
|
|
|
|
{
|
|
|
|
[[NSHelpManager sharedHelpManager] openHelpAnchor: @"PortForwarding"
|
|
|
|
inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PrefsController (Private)
|
|
|
|
|
2006-10-24 21:25:03 +00:00
|
|
|
- (void) setPrefView: (id) sender
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2006-10-24 21:25:03 +00:00
|
|
|
NSView * view = fGeneralView;
|
|
|
|
if (sender)
|
|
|
|
{
|
|
|
|
NSString * identifier = [sender itemIdentifier];
|
|
|
|
if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
|
|
|
|
view = fTransfersView;
|
|
|
|
else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
|
|
|
|
view = fBandwidthView;
|
|
|
|
else if ([identifier isEqualToString: TOOLBAR_NETWORK])
|
|
|
|
view = fNetworkView;
|
|
|
|
else;
|
|
|
|
}
|
2006-09-28 21:37:19 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
NSWindow * window = [self window];
|
2006-08-15 00:02:23 +00:00
|
|
|
if ([window contentView] == view)
|
|
|
|
return;
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
NSRect windowRect = [window frame];
|
|
|
|
int difference = [view frame].size.height - [[window contentView] frame].size.height;
|
|
|
|
windowRect.origin.y -= difference;
|
|
|
|
windowRect.size.height += difference;
|
|
|
|
|
|
|
|
[view setHidden: YES];
|
2006-08-15 00:02:23 +00:00
|
|
|
[window setContentView: view];
|
2006-07-16 19:39:23 +00:00
|
|
|
[window setFrame: windowRect display: YES animate: YES];
|
|
|
|
[view setHidden: NO];
|
2006-10-24 21:04:40 +00:00
|
|
|
|
2006-10-24 21:25:03 +00:00
|
|
|
//set title label
|
|
|
|
if (sender)
|
|
|
|
[window setTitle: [sender label]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSToolbarItem * item;
|
|
|
|
NSEnumerator * enumerator = [[fToolbar items] objectEnumerator];
|
|
|
|
while ((item = [enumerator nextObject]))
|
|
|
|
if ([[item itemIdentifier] isEqualToString: [fToolbar selectedItemIdentifier]])
|
|
|
|
{
|
|
|
|
[window setTitle: [item label]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//for network view make sure progress indicator hides itself
|
|
|
|
if (view == fNetworkView && [fPortStatusImage image])
|
|
|
|
[fPortStatusProgress setDisplayedWhenStopped: NO];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
|
|
|
|
{
|
2006-07-22 20:39:33 +00:00
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
|
2006-10-27 19:14:04 +00:00
|
|
|
[fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
|
2006-07-22 20:39:33 +00:00
|
|
|
[fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//reset if cancelled
|
|
|
|
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
|
|
|
|
if ([downloadChoice isEqualToString: @"Constant"])
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
|
|
|
|
else if ([downloadChoice isEqualToString: @"Torrent"])
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
|
|
|
|
else
|
|
|
|
[fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2006-11-03 16:01:45 +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];
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
|
|
|
|
{
|
2006-09-05 04:28:07 +00:00
|
|
|
if (code == NSOKButton)
|
|
|
|
{
|
|
|
|
UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
|
2006-10-27 19:14:04 +00:00
|
|
|
[sharedQueue removePathFromQueue: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
|
2006-09-05 04:28:07 +00:00
|
|
|
|
2006-10-27 19:14:04 +00:00
|
|
|
[fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"AutoImportDirectory"];
|
2006-09-05 04:28:07 +00:00
|
|
|
|
2006-10-27 19:14:04 +00:00
|
|
|
[sharedQueue addPath: [[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath]];
|
2006-09-05 04:28:07 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
|
|
|
|
}
|
|
|
|
[fImportFolderPopUp selectItemAtIndex: 0];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|