1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +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"] ) if( [downloadChoice isEqualToString: @"Constant"] )
{ {
tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
[downloadFolder UTF8String] ); [[downloadFolder stringByExpandingTildeInPath] UTF8String] );
tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
} }
else if( [downloadChoice isEqualToString: @"Torrent"] ) 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" #import "PrefsController.h"
#define DEFAULT_UPLOAD @"20"
#define MIN_PORT 1 #define MIN_PORT 1
#define MAX_PORT 65535 #define MAX_PORT 65535
@ -50,31 +49,10 @@
+ (void) initialize + (void) initialize
{ {
NSDictionary * appDefaults; [[NSUserDefaults standardUserDefaults] registerDefaults:
NSString * desktop, * port; [NSDictionary dictionaryWithContentsOfFile:
[[NSBundle mainBundle] pathForResource: @"Defaults"
/* Register defaults settings: ofType: @"plist"]]];
- 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];
} }
- (void)dealloc - (void)dealloc
@ -100,7 +78,7 @@
//set download folder //set download folder
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
fDownloadFolder = [fDefaults stringForKey: @"DownloadFolder"]; fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
[fDownloadFolder retain]; [fDownloadFolder retain];
if( [downloadChoice isEqualToString: @"Constant"] ) if( [downloadChoice isEqualToString: @"Constant"] )
@ -126,27 +104,25 @@
//checks for old version upload speed of -1 //checks for old version upload speed of -1
if ([fDefaults integerForKey: @"UploadLimit"] < 0) if ([fDefaults integerForKey: @"UploadLimit"] < 0)
{ {
[fDefaults setObject: DEFAULT_UPLOAD forKey: @"UploadLimit"]; [fDefaults setInteger: 20 forKey: @"UploadLimit"];
[fDefaults setObject: @"NO" forKey: @"CheckUpload"]; [fDefaults setBool: NO forKey: @"CheckUpload"];
} }
//set upload limit //set upload limit
BOOL checkUpload = [[fDefaults stringForKey: @"CheckUpload"] isEqualToString:@"YES"]; BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"];
int uploadLimit = [fDefaults integerForKey: @"UploadLimit"]; int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
[fUploadCheck setState: checkUpload ? NSOnState : NSOffState]; [fUploadCheck setState: checkUpload ? NSOnState : NSOffState];
[fUploadField setIntValue: uploadLimit]; [fUploadField setIntValue: uploadLimit];
[fUploadField setEnabled: checkUpload]; [fUploadField setEnabled: checkUpload];
if (!checkUpload || uploadLimit == 0) tr_setUploadLimit( fHandle, checkUpload ? uploadLimit : -1 );
uploadLimit = -1;
tr_setUploadLimit( fHandle, uploadLimit );
//set remove and quit prompts //set remove and quit prompts
[fQuitCheck setState:([[fDefaults stringForKey: @"CheckQuit"] [fQuitCheck setState: [fDefaults boolForKey: @"CheckQuit"] ?
isEqualToString:@"YES"] ? NSOnState : NSOffState)]; NSOnState : NSOffState];
[fRemoveCheck setState:([[fDefaults stringForKey: @"CheckRemove"] [fRemoveCheck setState: [fDefaults boolForKey: @"CheckRemove"] ?
isEqualToString:@"YES"] ? NSOnState : NSOffState)]; NSOnState : NSOffState];
} }
- (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier: - (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier:
@ -213,8 +189,7 @@
else else
{ {
tr_setBindPort( fHandle, bindPort ); tr_setBindPort( fHandle, bindPort );
[fDefaults setObject: [NSString stringWithFormat: @"%d", bindPort] [fDefaults setInteger: bindPort forKey: @"BindPort"];
forKey: @"BindPort"];
} }
} }
@ -222,10 +197,9 @@
{ {
BOOL checkUpload = [fUploadCheck state] == NSOnState; BOOL checkUpload = [fUploadCheck state] == NSOnState;
[fDefaults setObject: checkUpload ? @"YES" : @"NO" [fDefaults setBool: checkUpload forKey: @"CheckUpload"];
forKey: @"CheckUpload"];
[self setUploadLimit: sender]; [self setUploadLimit: nil];
[fUploadField setEnabled: checkUpload]; [fUploadField setEnabled: checkUpload];
} }
@ -244,8 +218,7 @@
} }
else else
{ {
[fDefaults setObject: [NSString stringWithFormat: @"%d", uploadLimit] [fDefaults setInteger: uploadLimit forKey: @"UploadLimit"];
forKey: @"UploadLimit"];
} }
if ([fUploadCheck state] == NSOffState || uploadLimit == 0) if ([fUploadCheck state] == NSOffState || uploadLimit == 0)
@ -255,13 +228,13 @@
- (void) setQuitMessage: (id) sender - (void) setQuitMessage: (id) sender
{ {
[fDefaults setObject: ([fQuitCheck state] == NSOnState ? @"YES" : @"NO") [fDefaults setBool: ( [fQuitCheck state] == NSOnState )
forKey: @"CheckQuit"]; forKey: @"CheckQuit"];
} }
- (void) setRemoveMessage: (id) sender - (void) setRemoveMessage: (id) sender
{ {
[fDefaults setObject: ([fRemoveCheck state] == NSOnState ? @"YES" : @"NO") [fDefaults setBool: ( [fRemoveCheck state] == NSOnState )
forKey: @"CheckRemove"]; forKey: @"CheckRemove"];
} }

View file

@ -28,6 +28,7 @@
4DE5CCA90980739100BE280E /* Badge.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCA80980739100BE280E /* Badge.png */; }; 4DE5CCA90980739100BE280E /* Badge.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCA80980739100BE280E /* Badge.png */; };
4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCB80981D27700BE280E /* ResumeAll.png */; }; 4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCB80981D27700BE280E /* ResumeAll.png */; };
4DE5CCBB0981D27700BE280E /* PauseAll.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCB90981D27700BE280E /* PauseAll.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 */; }; 4DF0C5AB0899190500DD8943 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF0C5A90899190500DD8943 /* Controller.m */; };
4DF0C5AE08991C1600DD8943 /* libtransmission.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DF0C5AD08991C1600DD8943 /* libtransmission.a */; }; 4DF0C5AE08991C1600DD8943 /* libtransmission.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DF0C5AD08991C1600DD8943 /* libtransmission.a */; };
4DF7500C08A103AD007B0D70 /* Open.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DF7500708A103AD007B0D70 /* Open.png */; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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; }; 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>"; }; 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>"; }; 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>"; }; 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 */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -216,6 +218,7 @@
4DE5CCA80980739100BE280E /* Badge.png */, 4DE5CCA80980739100BE280E /* Badge.png */,
4DE5CCB80981D27700BE280E /* ResumeAll.png */, 4DE5CCB80981D27700BE280E /* ResumeAll.png */,
4DE5CCB90981D27700BE280E /* PauseAll.png */, 4DE5CCB90981D27700BE280E /* PauseAll.png */,
4DE5CCCA0981D9BE00BE280E /* Defaults.plist */,
8D1107310486CEB800E47090 /* Info.plist */, 8D1107310486CEB800E47090 /* Info.plist */,
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
29B97318FDCFA39411CA2CEA /* MainMenu.nib */, 29B97318FDCFA39411CA2CEA /* MainMenu.nib */,
@ -309,6 +312,7 @@
4DE5CCA90980739100BE280E /* Badge.png in Resources */, 4DE5CCA90980739100BE280E /* Badge.png in Resources */,
4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */, 4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */,
4DE5CCBB0981D27700BE280E /* PauseAll.png in Resources */, 4DE5CCBB0981D27700BE280E /* PauseAll.png in Resources */,
4DE5CCCB0981D9BE00BE280E /* Defaults.plist in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };