1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

Use setBool: and setInt: for setting defaults instead of first changing

to strings
 Put default settings in a plist
This commit is contained in:
Eric Petit 2006-01-21 03:11:57 +00:00
parent 97ae614cf8
commit d5fb5edc15
4 changed files with 67 additions and 50 deletions

View file

@ -313,7 +313,7 @@ static void sleepCallBack( void * controller, io_service_t y,
if( [downloadChoice isEqualToString: @"Constant"] )
{
tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
[downloadFolder UTF8String] );
[[downloadFolder stringByExpandingTildeInPath] UTF8String] );
tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
}
else if( [downloadChoice isEqualToString: @"Torrent"] )

40
macosx/Defaults.plist Normal file
View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BadgeCompleted</key>
<true/>
<key>BadgeDownloadRate</key>
<false/>
<key>BadgeUploadRate</key>
<false/>
<key>BindPort</key>
<integer>9090</integer>
<key>CheckQuit</key>
<true/>
<key>CheckRemove</key>
<true/>
<key>CheckUpload</key>
<true/>
<key>DownloadChoice</key>
<string>Constant</string>
<key>DownloadFolder</key>
<string>~/Desktop</string>
<key>InfoVisible</key>
<false/>
<key>Move</key>
<false/>
<key>MoveChoice</key>
<string>Constant</string>
<key>MoveFolder</key>
<string>~/Desktop</string>
<key>ShowInspector</key>
<false/>
<key>UploadLimit</key>
<integer>20</integer>
<key>UseAdvancedBar</key>
<false/>
<key>VersionStartupCheck</key>
<true/>
</dict>
</plist>

View file

@ -22,7 +22,6 @@
#import "PrefsController.h"
#define DEFAULT_UPLOAD @"20"
#define MIN_PORT 1
#define MAX_PORT 65535
@ -50,31 +49,10 @@
+ (void) initialize
{
NSDictionary * appDefaults;
NSString * desktop, * port;
/* Register defaults settings:
- Simple bar
- Always download to Desktop
- Port TR_DEFAULT_PORT
- Upload limit DEFAULT_UPLOAD
- Limit upload
- Ask before quitting
- Ask before removing */
desktop = [NSHomeDirectory() stringByAppendingString: @"/Desktop"];
port = [NSString stringWithFormat: @"%d", TR_DEFAULT_PORT];
appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
@"NO", @"UseAdvancedBar",
@"Constant", @"DownloadChoice",
desktop, @"DownloadFolder",
port, @"BindPort",
DEFAULT_UPLOAD, @"UploadLimit",
@"YES", @"CheckUpload",
@"YES", @"CheckQuit",
@"YES", @"CheckRemove",
NULL];
[[NSUserDefaults standardUserDefaults] registerDefaults: appDefaults];
[[NSUserDefaults standardUserDefaults] registerDefaults:
[NSDictionary dictionaryWithContentsOfFile:
[[NSBundle mainBundle] pathForResource: @"Defaults"
ofType: @"plist"]]];
}
- (void)dealloc
@ -100,7 +78,7 @@
//set download folder
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
fDownloadFolder = [fDefaults stringForKey: @"DownloadFolder"];
fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
[fDownloadFolder retain];
if( [downloadChoice isEqualToString: @"Constant"] )
@ -126,27 +104,25 @@
//checks for old version upload speed of -1
if ([fDefaults integerForKey: @"UploadLimit"] < 0)
{
[fDefaults setObject: DEFAULT_UPLOAD forKey: @"UploadLimit"];
[fDefaults setObject: @"NO" forKey: @"CheckUpload"];
[fDefaults setInteger: 20 forKey: @"UploadLimit"];
[fDefaults setBool: NO forKey: @"CheckUpload"];
}
//set upload limit
BOOL checkUpload = [[fDefaults stringForKey: @"CheckUpload"] isEqualToString:@"YES"];
BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"];
int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
[fUploadCheck setState: checkUpload ? NSOnState : NSOffState];
[fUploadField setIntValue: uploadLimit];
[fUploadField setEnabled: checkUpload];
if (!checkUpload || uploadLimit == 0)
uploadLimit = -1;
tr_setUploadLimit( fHandle, uploadLimit );
tr_setUploadLimit( fHandle, checkUpload ? uploadLimit : -1 );
//set remove and quit prompts
[fQuitCheck setState:([[fDefaults stringForKey: @"CheckQuit"]
isEqualToString:@"YES"] ? NSOnState : NSOffState)];
[fRemoveCheck setState:([[fDefaults stringForKey: @"CheckRemove"]
isEqualToString:@"YES"] ? NSOnState : NSOffState)];
[fQuitCheck setState: [fDefaults boolForKey: @"CheckQuit"] ?
NSOnState : NSOffState];
[fRemoveCheck setState: [fDefaults boolForKey: @"CheckRemove"] ?
NSOnState : NSOffState];
}
- (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier:
@ -213,8 +189,7 @@
else
{
tr_setBindPort( fHandle, bindPort );
[fDefaults setObject: [NSString stringWithFormat: @"%d", bindPort]
forKey: @"BindPort"];
[fDefaults setInteger: bindPort forKey: @"BindPort"];
}
}
@ -222,10 +197,9 @@
{
BOOL checkUpload = [fUploadCheck state] == NSOnState;
[fDefaults setObject: checkUpload ? @"YES" : @"NO"
forKey: @"CheckUpload"];
[fDefaults setBool: checkUpload forKey: @"CheckUpload"];
[self setUploadLimit: sender];
[self setUploadLimit: nil];
[fUploadField setEnabled: checkUpload];
}
@ -244,8 +218,7 @@
}
else
{
[fDefaults setObject: [NSString stringWithFormat: @"%d", uploadLimit]
forKey: @"UploadLimit"];
[fDefaults setInteger: uploadLimit forKey: @"UploadLimit"];
}
if ([fUploadCheck state] == NSOffState || uploadLimit == 0)
@ -255,14 +228,14 @@
- (void) setQuitMessage: (id) sender
{
[fDefaults setObject: ([fQuitCheck state] == NSOnState ? @"YES" : @"NO")
forKey: @"CheckQuit"];
[fDefaults setBool: ( [fQuitCheck state] == NSOnState )
forKey: @"CheckQuit"];
}
- (void) setRemoveMessage: (id) sender
{
[fDefaults setObject: ([fRemoveCheck state] == NSOnState ? @"YES" : @"NO")
forKey: @"CheckRemove"];
[fDefaults setBool: ( [fRemoveCheck state] == NSOnState )
forKey: @"CheckRemove"];
}
- (void) setDownloadLocation: (id) sender

View file

@ -28,6 +28,7 @@
4DE5CCA90980739100BE280E /* Badge.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCA80980739100BE280E /* Badge.png */; };
4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCB80981D27700BE280E /* ResumeAll.png */; };
4DE5CCBB0981D27700BE280E /* PauseAll.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCB90981D27700BE280E /* PauseAll.png */; };
4DE5CCCB0981D9BE00BE280E /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCCA0981D9BE00BE280E /* Defaults.plist */; };
4DF0C5AB0899190500DD8943 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF0C5A90899190500DD8943 /* Controller.m */; };
4DF0C5AE08991C1600DD8943 /* libtransmission.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DF0C5AD08991C1600DD8943 /* libtransmission.a */; };
4DF7500C08A103AD007B0D70 /* Open.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DF7500708A103AD007B0D70 /* Open.png */; };
@ -102,6 +103,7 @@
4DE5CCA80980739100BE280E /* Badge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Badge.png; path = Images/Badge.png; sourceTree = "<group>"; };
4DE5CCB80981D27700BE280E /* ResumeAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeAll.png; path = Images/ResumeAll.png; sourceTree = "<group>"; };
4DE5CCB90981D27700BE280E /* PauseAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseAll.png; path = Images/PauseAll.png; sourceTree = "<group>"; };
4DE5CCCA0981D9BE00BE280E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Defaults.plist; sourceTree = "<group>"; };
4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; };
4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; };
4DF0C5AD08991C1600DD8943 /* libtransmission.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtransmission.a; path = ../libtransmission/libtransmission.a; sourceTree = SOURCE_ROOT; };
@ -109,7 +111,7 @@
4DF7500808A103AD007B0D70 /* Info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Info.png; path = Images/Info.png; sourceTree = "<group>"; };
4DF7500908A103AD007B0D70 /* Remove.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Remove.png; path = Images/Remove.png; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; };
8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -216,6 +218,7 @@
4DE5CCA80980739100BE280E /* Badge.png */,
4DE5CCB80981D27700BE280E /* ResumeAll.png */,
4DE5CCB90981D27700BE280E /* PauseAll.png */,
4DE5CCCA0981D9BE00BE280E /* Defaults.plist */,
8D1107310486CEB800E47090 /* Info.plist */,
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
29B97318FDCFA39411CA2CEA /* MainMenu.nib */,
@ -309,6 +312,7 @@
4DE5CCA90980739100BE280E /* Badge.png in Resources */,
4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */,
4DE5CCBB0981D27700BE280E /* PauseAll.png in Resources */,
4DE5CCCB0981D9BE00BE280E /* Defaults.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};