From d5fb5edc15231cd5d0cd3f19d5e6f66dc5b99455 Mon Sep 17 00:00:00 2001 From: Eric Petit Date: Sat, 21 Jan 2006 03:11:57 +0000 Subject: [PATCH] Use setBool: and setInt: for setting defaults instead of first changing to strings Put default settings in a plist --- macosx/Controller.m | 2 +- macosx/Defaults.plist | 40 +++++++++++ macosx/PrefsController.m | 69 ++++++------------- macosx/Transmission.xcodeproj/project.pbxproj | 6 +- 4 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 macosx/Defaults.plist diff --git a/macosx/Controller.m b/macosx/Controller.m index cc9604a73..b87a80928 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -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"] ) diff --git a/macosx/Defaults.plist b/macosx/Defaults.plist new file mode 100644 index 000000000..845c8f6a3 --- /dev/null +++ b/macosx/Defaults.plist @@ -0,0 +1,40 @@ + + + + + BadgeCompleted + + BadgeDownloadRate + + BadgeUploadRate + + BindPort + 9090 + CheckQuit + + CheckRemove + + CheckUpload + + DownloadChoice + Constant + DownloadFolder + ~/Desktop + InfoVisible + + Move + + MoveChoice + Constant + MoveFolder + ~/Desktop + ShowInspector + + UploadLimit + 20 + UseAdvancedBar + + VersionStartupCheck + + + diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 2f0679ad6..56817fd23 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -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 diff --git a/macosx/Transmission.xcodeproj/project.pbxproj b/macosx/Transmission.xcodeproj/project.pbxproj index bafad7eca..812f1a9eb 100644 --- a/macosx/Transmission.xcodeproj/project.pbxproj +++ b/macosx/Transmission.xcodeproj/project.pbxproj @@ -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 = ""; }; 4DE5CCB80981D27700BE280E /* ResumeAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeAll.png; path = Images/ResumeAll.png; sourceTree = ""; }; 4DE5CCB90981D27700BE280E /* PauseAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseAll.png; path = Images/PauseAll.png; sourceTree = ""; }; + 4DE5CCCA0981D9BE00BE280E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Defaults.plist; sourceTree = ""; }; 4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = ""; }; 4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = ""; }; 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 = ""; }; 4DF7500908A103AD007B0D70 /* Remove.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Remove.png; path = Images/Remove.png; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; - 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; };