1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00
transmission/macosx/PrefsController.m

691 lines
21 KiB
Mathematica
Raw Normal View History

2006-01-12 17:43:21 +00:00
/******************************************************************************
* $Id$
*
2006-03-23 12:39:39 +00:00
* Copyright (c) 2005-2006 Transmission authors and contributors
2006-01-12 17:43:21 +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"
2006-03-23 12:39:39 +00:00
#import "StringAdditions.h"
2006-01-12 17:43:21 +00:00
#define MIN_PORT 1
#define MAX_PORT 65535
2006-01-12 18:57:23 +00:00
#define DOWNLOAD_FOLDER 0
2006-01-12 18:58:57 +00:00
#define DOWNLOAD_TORRENT 2
#define DOWNLOAD_ASK 3
#define START_YES_CHECK_TAG 0
#define START_WAIT_CHECK_TAG 1
#define START_NO_CHECK_TAG 2
2006-01-12 18:57:23 +00:00
#define UPDATE_DAILY 0
#define UPDATE_WEEKLY 1
#define UPDATE_NEVER 2
2006-01-29 22:01:08 +00:00
2006-01-12 18:57:23 +00:00
#define TOOLBAR_GENERAL @"General"
#define TOOLBAR_TRANSFERS @"Transfers"
#define TOOLBAR_BANDWIDTH @"Bandwidth"
2006-01-12 18:57:23 +00:00
#define TOOLBAR_NETWORK @"Network"
2006-01-12 17:43:21 +00:00
@interface PrefsController (Private)
2006-01-12 18:57:23 +00:00
- (void) showGeneralPref: (id) sender;
- (void) showTransfersPref: (id) sender;
- (void) showBandwidthPref: (id) sender;
2006-01-12 18:57:23 +00:00
- (void) showNetworkPref: (id) sender;
- (void) setPrefView: (NSView *) view;
- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
2006-01-12 17:43:21 +00:00
- (void) updatePopUp;
@end
@implementation PrefsController
2006-01-12 18:57:23 +00:00
+ (void) initialize
2006-01-12 17:43:21 +00:00
{
[[NSUserDefaults standardUserDefaults] registerDefaults:
[NSDictionary dictionaryWithContentsOfFile:
[[NSBundle mainBundle] pathForResource: @"Defaults" ofType: @"plist"]]];
2006-01-12 18:57:23 +00:00
}
2006-01-12 17:43:21 +00:00
- (void) dealloc
2006-01-12 18:57:23 +00:00
{
[fDownloadFolder release];
[super dealloc];
2006-01-12 17:43:21 +00:00
}
- (void) setPrefs: (tr_handle_t *) handle
2006-01-12 17:43:21 +00:00
{
2006-01-12 18:57:23 +00:00
fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
[fToolbar setDelegate: self];
[fToolbar setAllowsUserCustomization: NO];
[[self window] setToolbar: fToolbar];
2006-01-12 18:57:23 +00:00
[fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
[fToolbar setSizeMode: NSToolbarSizeModeRegular];
[fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
[self showGeneralPref: nil];
2006-01-12 18:57:23 +00:00
fDefaults = [NSUserDefaults standardUserDefaults];
fHandle = handle;
2006-01-12 18:57:23 +00:00
//set download folder
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
2006-01-12 18:57:23 +00:00
[fDownloadFolder retain];
if ([downloadChoice isEqualToString: @"Constant"])
2006-01-12 18:58:57 +00:00
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
else if ([downloadChoice isEqualToString: @"Torrent"])
2006-01-12 18:58:57 +00:00
[fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
2006-01-12 18:57:23 +00:00
else
2006-01-12 18:58:57 +00:00
[fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
2006-01-12 18:57:23 +00:00
[self updatePopUp];
2006-01-12 17:43:21 +00:00
2006-01-12 18:57:23 +00:00
//set bind port
int bindPort = [fDefaults integerForKey: @"BindPort"];
[fPortField setIntValue: bindPort];
tr_setBindPort(fHandle, bindPort);
2006-01-12 18:57:23 +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-01-12 18:57:23 +00:00
}
//set upload limit
BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"];
2006-01-12 18:57:23 +00:00
int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
[fUploadCheck setState: checkUpload];
2006-01-12 18:57:23 +00:00
[fUploadField setIntValue: uploadLimit];
[fUploadField setEnabled: checkUpload];
//set download limit
BOOL checkDownload = [fDefaults boolForKey: @"CheckDownload"];
int downloadLimit = [fDefaults integerForKey: @"DownloadLimit"];
[fDownloadCheck setState: checkDownload];
[fDownloadField setIntValue: downloadLimit];
[fDownloadField setEnabled: checkDownload];
//set speed limit
int speedLimitUploadLimit = [fDefaults integerForKey: @"SpeedLimitUploadLimit"];
[fSpeedLimitUploadField setIntValue: speedLimitUploadLimit];
int speedLimitDownloadLimit = [fDefaults integerForKey: @"SpeedLimitDownloadLimit"];
[fSpeedLimitDownloadField setIntValue: speedLimitDownloadLimit];
//actually set bandwidth limits
2006-07-01 00:44:22 +00:00
if ([fDefaults boolForKey: @"SpeedLimit"])
{
tr_setUploadLimit(fHandle, speedLimitUploadLimit);
tr_setDownloadLimit(fHandle, speedLimitDownloadLimit);
}
else
{
tr_setUploadLimit(fHandle, checkUpload ? uploadLimit : -1);
tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1);
}
2006-01-12 18:57:23 +00:00
//set ratio limit
BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"];
[fRatioCheck setState: ratioCheck];
[fRatioField setEnabled: ratioCheck];
[fRatioField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
2006-01-12 18:57:23 +00:00
//set remove and quit prompts
BOOL isQuitCheck = [fDefaults boolForKey: @"CheckQuit"],
isRemoveCheck = [fDefaults boolForKey: @"CheckRemove"];
[fQuitCheck setState: isQuitCheck];
[fRemoveCheck setState: isRemoveCheck];
[fQuitDownloadingCheck setState: [fDefaults boolForKey: @"CheckQuitDownloading"]];
[fQuitDownloadingCheck setEnabled: isQuitCheck];
[fRemoveDownloadingCheck setState: [fDefaults boolForKey: @"CheckRemoveDownloading"]];
[fRemoveDownloadingCheck setEnabled: isRemoveCheck];
2006-01-29 19:47:54 +00:00
//set dock badging
[fBadgeDownloadRateCheck setState: [fDefaults boolForKey: @"BadgeDownloadRate"]];
[fBadgeUploadRateCheck setState: [fDefaults boolForKey: @"BadgeUploadRate"]];
//set start setting
NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
int tag;
if ([startSetting isEqualToString: @"Start"])
tag = START_YES_CHECK_TAG;
else if ([startSetting isEqualToString: @"Wait"])
tag = START_WAIT_CHECK_TAG;
else
tag = START_NO_CHECK_TAG;
[fStartMatrix selectCellWithTag: tag];
[fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG];
[fWaitToStartField setIntValue: [fDefaults integerForKey: @"WaitToStartNumber"]];
//set private torrents
BOOL copyTorrents = [fDefaults boolForKey: @"SavePrivateTorrent"];
[fCopyTorrentCheck setState: copyTorrents];
[fDeleteOriginalTorrentCheck setEnabled: copyTorrents];
[fDeleteOriginalTorrentCheck setState: [fDefaults boolForKey: @"DeleteOriginalTorrent"]];
2006-01-29 22:01:08 +00:00
//set update check
NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"];
if ([updateCheck isEqualToString: @"Weekly"])
2006-01-29 22:01:08 +00:00
[fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
else if ([updateCheck isEqualToString: @"Never"])
2006-01-29 22:01:08 +00:00
[fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
else
[fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
2006-01-12 17:43:21 +00:00
}
2006-01-12 18:57:23 +00:00
- (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier:
(NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag
2006-01-12 17:43:21 +00:00
{
2006-01-12 18:57:23 +00:00
NSToolbarItem * item;
item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
2006-01-12 17:43:21 +00:00
2006-01-12 18:57:23 +00:00
if ([ident isEqualToString: TOOLBAR_GENERAL])
2006-01-12 17:43:21 +00:00
{
2006-01-12 18:57:23 +00:00
[item setLabel: TOOLBAR_GENERAL];
[item setImage: [NSImage imageNamed: @"Preferences.png"]];
[item setTarget: self];
[item setAction: @selector( showGeneralPref: )];
}
else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
{
[item setLabel: TOOLBAR_TRANSFERS];
[item setImage: [NSImage imageNamed: @"Transfers.png"]];
[item setTarget: self];
[item setAction: @selector( showTransfersPref: )];
}
else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
{
[item setLabel: TOOLBAR_BANDWIDTH];
[item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
[item setTarget: self];
[item setAction: @selector( showBandwidthPref: )];
}
2006-01-12 18:57:23 +00:00
else if ([ident isEqualToString: TOOLBAR_NETWORK])
{
[item setLabel: TOOLBAR_NETWORK];
[item setImage: [NSImage imageNamed: @"Network.png"]];
[item setTarget: self];
[item setAction: @selector( showNetworkPref: )];
2006-01-12 17:43:21 +00:00
}
else
{
2006-01-12 18:57:23 +00:00
[item release];
return nil;
2006-01-12 17:43:21 +00:00
}
2006-01-12 18:57:23 +00:00
return item;
2006-01-12 17:43:21 +00:00
}
- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
2006-01-12 17:43:21 +00:00
{
return [self toolbarDefaultItemIdentifiers: toolbar];
2006-01-12 17:43:21 +00:00
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
2006-01-12 17:43:21 +00:00
{
return [self toolbarAllowedItemIdentifiers: toolbar];
2006-01-12 18:57:23 +00:00
}
2006-01-12 17:43:21 +00:00
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
2006-01-12 18:57:23 +00:00
{
return [NSArray arrayWithObjects:
TOOLBAR_GENERAL, TOOLBAR_TRANSFERS,
TOOLBAR_BANDWIDTH, TOOLBAR_NETWORK, nil];
2006-01-12 18:57:23 +00:00
}
2006-01-12 17:43:21 +00:00
2006-01-12 18:57:23 +00:00
- (void) setPort: (id) sender
{
int bindPort = [sender intValue];
if (![[NSString stringWithInt: bindPort] isEqualToString: [sender stringValue]]
|| bindPort < MIN_PORT || bindPort > MAX_PORT)
{
NSBeep();
bindPort = [fDefaults integerForKey: @"BindPort"];
[sender setIntValue: bindPort];
}
else
{
tr_setBindPort( fHandle, bindPort );
[fDefaults setInteger: bindPort forKey: @"BindPort"];
}
2006-01-12 18:57:23 +00:00
}
- (void) setLimit: (id) sender
{
NSString * key;
NSButton * check;
NSString * type;
if (sender == fUploadField)
{
key = @"UploadLimit";
check = fUploadCheck;
type = @"Upload";
}
else
{
key = @"DownloadLimit";
check = fDownloadCheck;
type = @"Download";
}
int limit = [sender intValue];
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
{
NSBeep();
limit = [fDefaults integerForKey: key];
[sender setIntValue: limit];
}
else
{
2006-07-01 00:44:22 +00:00
if (![fDefaults boolForKey: @"SpeedLimit"])
{
if (sender == fUploadField)
tr_setUploadLimit(fHandle, [fUploadCheck state] ? limit : -1);
else
tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? limit : -1);
}
[fDefaults setInteger: limit forKey: key];
}
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithBool: [check state]], @"Enable",
[NSNumber numberWithInt: limit], @"Limit",
type, @"Type", nil];
[[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange" object: dict];
}
- (void) setLimitCheck: (id) sender
2006-01-12 18:57:23 +00:00
{
NSString * key;
NSTextField * field;
if (sender == fUploadCheck)
{
key = @"CheckUpload";
field = fUploadField;
}
else
{
key = @"CheckDownload";
field = fDownloadField;
}
BOOL check = [sender state] == NSOnState;
[self setLimit: field];
[field setEnabled: check];
[fDefaults setBool: check forKey: key];
2006-01-12 18:57:23 +00:00
}
2006-01-12 17:43:21 +00:00
- (void) setLimitEnabled: (BOOL) enable type: (NSString *) type
2006-01-12 18:57:23 +00:00
{
NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck;
[check setState: enable ? NSOnState : NSOffState];
[self setLimitCheck: check];
}
- (void) setQuickLimit: (int) limit type: (NSString *) type
{
NSButton * check;
if ([type isEqualToString: @"Upload"])
2006-01-12 17:43:21 +00:00
{
[fUploadField setIntValue: limit];
check = fUploadCheck;
2006-01-12 17:43:21 +00:00
}
2006-01-12 18:57:23 +00:00
else
{
[fDownloadField setIntValue: limit];
check = fDownloadCheck;
2006-01-12 18:57:23 +00:00
}
[check setState: NSOnState];
[self setLimitCheck: check];
2006-01-12 18:57:23 +00:00
}
2006-01-12 17:43:21 +00:00
- (void) enableSpeedLimit: (BOOL) enable
{
2006-07-01 00:44:22 +00:00
if ([fDefaults boolForKey: @"SpeedLimit"] != enable)
{
2006-07-01 00:44:22 +00:00
[fDefaults setBool: enable forKey: @"SpeedLimit"];
2006-07-01 00:44:22 +00:00
if (enable)
{
tr_setUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
tr_setDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
}
else
{
tr_setUploadLimit(fHandle, [fUploadCheck state] ? [fDefaults integerForKey: @"UploadLimit"] : -1);
tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
}
}
}
- (void) setSpeedLimit: (id) sender
{
2006-07-01 00:44:22 +00:00
NSString * key = sender == fSpeedLimitUploadField ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit";
int limit = [sender intValue];
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0)
{
NSBeep();
limit = [fDefaults integerForKey: key];
[sender setIntValue: limit];
}
else
{
2006-07-01 00:44:22 +00:00
if ([fDefaults boolForKey: @"SpeedLimit"])
{
if (sender == fSpeedLimitUploadField)
tr_setUploadLimit(fHandle, limit);
else
tr_setDownloadLimit(fHandle, limit);
}
[fDefaults setInteger: limit forKey: key];
}
}
- (void) setRatio: (id) sender
{
float ratioLimit = [sender floatValue];
if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]]
|| ratioLimit < 0)
{
NSBeep();
ratioLimit = [fDefaults floatForKey: @"RatioLimit"];
[sender setFloatValue: ratioLimit];
}
else
[fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithBool: [fRatioCheck state]], @"Enable",
[NSNumber numberWithFloat: ratioLimit], @"Ratio", nil];
[[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: dict];
}
- (void) setRatioCheck: (id) sender
{
BOOL check = [sender state] == NSOnState;
[self setRatio: fRatioField];
[fRatioField setEnabled: check];
[fDefaults setBool: check forKey: @"RatioCheck"];
}
- (void) setRatioEnabled: (BOOL) enable
2006-01-12 18:57:23 +00:00
{
int state = enable ? NSOnState : NSOffState;
[fRatioCheck setState: state];
[self setRatioCheck: fRatioCheck];
2006-01-12 17:43:21 +00:00
}
- (void) setQuickRatio: (float) ratioLimit
2006-01-12 18:57:23 +00:00
{
[fRatioField setFloatValue: ratioLimit];
[fRatioCheck setState: NSOnState];
[self setRatioCheck: fRatioCheck];
}
- (void) setShowMessage: (id) sender
{
BOOL state = [sender state];
if (sender == fQuitCheck)
{
[fDefaults setBool: state forKey: @"CheckQuit"];
[fQuitDownloadingCheck setEnabled: state];
}
else if (sender == fRemoveCheck)
{
[fDefaults setBool: state forKey: @"CheckRemove"];
[fRemoveDownloadingCheck setEnabled: state];
}
if (sender == fQuitDownloadingCheck)
[fDefaults setBool: state forKey: @"CheckQuitDownloading"];
else if (sender == fRemoveDownloadingCheck)
[fDefaults setBool: state forKey: @"CheckRemoveDownloading"];
else;
2006-01-12 18:57:23 +00:00
}
2006-01-12 17:43:21 +00:00
2006-01-29 19:47:54 +00:00
- (void) setBadge: (id) sender
{
if (sender == fBadgeDownloadRateCheck)
[fDefaults setBool: [sender state] forKey: @"BadgeDownloadRate"];
2006-01-29 19:47:54 +00:00
else if (sender == fBadgeUploadRateCheck)
[fDefaults setBool: [sender state] forKey: @"BadgeUploadRate"];
2006-01-29 19:47:54 +00:00
else;
}
2006-01-29 22:01:08 +00:00
- (void) setUpdate: (id) sender
{
int index = [fUpdatePopUp indexOfSelectedItem];
NSTimeInterval seconds;
if (index == UPDATE_DAILY)
2006-01-29 22:01:08 +00:00
{
[fDefaults setObject: @"Daily" forKey: @"UpdateCheck"];
seconds = 86400;
}
else if (index == UPDATE_WEEKLY)
{
[fDefaults setObject: @"Weekly" forKey: @"UpdateCheck"];
seconds = 604800;
2006-01-29 22:01:08 +00:00
}
else
{
[fDefaults setObject: @"Never" forKey: @"UpdateCheck"];
seconds = 0;
}
[fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
[fUpdater scheduleCheckWithInterval: seconds];
2006-01-29 22:01:08 +00:00
}
- (void) setStartSetting: (id) sender
{
NSString * startSetting;
int tag = [[fStartMatrix selectedCell] tag];
if (tag == START_YES_CHECK_TAG)
startSetting = @"Start";
else if (tag == START_WAIT_CHECK_TAG)
startSetting = @"Wait";
else
startSetting = @"Manual";
[fDefaults setObject: startSetting forKey: @"StartSetting"];
[self setWaitToStart: fWaitToStartField];
[fWaitToStartField setEnabled: tag == START_WAIT_CHECK_TAG];
}
- (void) setWaitToStart: (id) sender
{
int waitNumber = [sender intValue];
if (![[sender stringValue] isEqualToString: [NSString stringWithInt: waitNumber]] || waitNumber < 1)
{
NSBeep();
waitNumber = [fDefaults floatForKey: @"WaitToStartNumber"];
[sender setIntValue: waitNumber];
}
else
[fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"];
2006-06-23 22:32:01 +00:00
[[NSNotificationCenter defaultCenter] postNotificationName: @"GlobalStartSettingChange" object: self];
}
- (void) setMoveTorrent: (id) sender
{
int state = [sender state];
if (sender == fCopyTorrentCheck)
{
[fDefaults setBool: state forKey: @"SavePrivateTorrent"];
[fDeleteOriginalTorrentCheck setEnabled: state];
if (state == NSOffState)
{
[fDeleteOriginalTorrentCheck setState: NSOffState];
[fDefaults setBool: NO forKey: @"DeleteOriginalTorrent"];
}
}
else
[fDefaults setBool: state forKey: @"DeleteOriginalTorrent"];
}
2006-01-12 18:57:23 +00:00
- (void) setDownloadLocation: (id) sender
{
//Download folder
switch ([fFolderPopUp indexOfSelectedItem])
2006-01-12 18:57:23 +00:00
{
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;
}
}
2006-01-12 17:43:21 +00:00
- (void) checkUpdate
{
[fUpdater checkForUpdates: nil];
}
2006-01-12 17:43:21 +00:00
- (void) folderSheetShow: (id) sender
{
2006-01-12 18:57:23 +00:00
NSOpenPanel * panel = [NSOpenPanel openPanel];
2006-01-12 17:43:21 +00:00
[panel setPrompt: @"Select"];
[panel setAllowsMultipleSelection: NO];
[panel setCanChooseFiles: NO];
[panel setCanChooseDirectories: YES];
[panel setCanCreateDirectories: YES];
2006-01-12 17:43:21 +00:00
[panel beginSheetForDirectory: nil file: nil types: nil
modalForWindow: [self window] modalDelegate: self didEndSelector:
2006-01-12 17:43:21 +00:00
@selector( folderSheetClosed:returnCode:contextInfo: )
contextInfo: nil];
2006-01-12 17:43:21 +00:00
}
- (void) windowWillClose: (NSNotification *) notification
{
[[self window] makeFirstResponder: nil];
}
@end
2006-01-12 17:43:21 +00:00
2006-01-12 18:57:23 +00:00
@implementation PrefsController (Private)
2006-01-12 17:43:21 +00:00
2006-01-12 18:57:23 +00:00
- (void) showGeneralPref: (id) sender
{
[self setPrefView: fGeneralView];
2006-01-12 17:43:21 +00:00
}
- (void) showTransfersPref: (id) sender
{
[self setPrefView: fTransfersView];
}
- (void) showBandwidthPref: (id) sender
{
[self setPrefView: fBandwidthView];
}
2006-01-12 18:57:23 +00:00
- (void) showNetworkPref: (id) sender
2006-01-12 17:43:21 +00:00
{
2006-01-12 18:57:23 +00:00
[self setPrefView: fNetworkView];
2006-01-12 17:43:21 +00:00
}
2006-01-12 18:57:23 +00:00
- (void) setPrefView: (NSView *) view
2006-01-12 17:43:21 +00:00
{
NSWindow * window = [self window];
NSRect windowRect = [window frame];
int difference = [view frame].size.height - [[window contentView] frame].size.height;
2006-01-12 18:57:23 +00:00
windowRect.origin.y -= difference;
windowRect.size.height += difference;
[window setTitle: [fToolbar selectedItemIdentifier]];
2006-01-12 18:57:23 +00:00
[window setContentView: view];
[view setHidden: YES];
[window setFrame: windowRect display: YES animate: YES];
[view setHidden: NO];
2006-01-12 18:57:23 +00:00
}
2006-01-12 17:43:21 +00:00
- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
2006-01-12 18:57:23 +00:00
{
2006-01-12 18:58:57 +00:00
if (code == NSOKButton)
{
[fDownloadFolder release];
fDownloadFolder = [[openPanel filenames] objectAtIndex: 0];
[fDownloadFolder retain];
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
[fDefaults setObject: fDownloadFolder forKey: @"DownloadFolder"];
[fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
[self updatePopUp];
}
else
{
//reset if cancelled
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
if ([downloadChoice isEqualToString: @"Constant"])
2006-01-12 18:58:57 +00:00
[fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
else if ([downloadChoice isEqualToString: @"Torrent"])
2006-01-12 18:58:57 +00:00
[fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
else
[fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
}
2006-01-12 17:43:21 +00:00
}
- (void) updatePopUp
{
2006-06-14 17:58:40 +00:00
//get and resize the icon
NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFile: fDownloadFolder];
[icon setScalesWhenResized: YES];
[icon setSize: NSMakeSize(16.0, 16.0)];
//update menu item
NSMenuItem * menuItem = (NSMenuItem *) [fFolderPopUp itemAtIndex: 0];
2006-01-12 17:43:21 +00:00
[menuItem setTitle: [fDownloadFolder lastPathComponent]];
2006-06-14 17:58:40 +00:00
[menuItem setImage: icon];
2006-01-12 17:43:21 +00:00
}
@end