Changeset 38


Ignore:
Timestamp:
Jan 21, 2006, 3:11:57 AM (15 years ago)
Author:
titer
Message:

Use setBool: and setInt: for setting defaults instead of first changing
to strings
Put default settings in a plist

Location:
trunk/macosx
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r37 r38  
    314314        {
    315315            tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
    316                                  [downloadFolder UTF8String] );
     316                                 [[downloadFolder stringByExpandingTildeInPath] UTF8String] );
    317317            tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
    318318        }
  • trunk/macosx/PrefsController.m

    r34 r38  
    2323#import "PrefsController.h"
    2424
    25 #define DEFAULT_UPLOAD      @"20"
    2625#define MIN_PORT            1
    2726#define MAX_PORT            65535
     
    5150+ (void) initialize
    5251{
    53     NSDictionary   * appDefaults;
    54     NSString       * desktop, * port;
    55 
    56     /* Register defaults settings:
    57         - Simple bar
    58         - Always download to Desktop
    59         - Port TR_DEFAULT_PORT
    60         - Upload limit DEFAULT_UPLOAD
    61         - Limit upload
    62         - Ask before quitting
    63         - Ask before removing */
    64     desktop = [NSHomeDirectory() stringByAppendingString: @"/Desktop"];
    65     port = [NSString stringWithFormat: @"%d", TR_DEFAULT_PORT];
    66 
    67     appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
    68                     @"NO",          @"UseAdvancedBar",
    69                     @"Constant",    @"DownloadChoice",
    70                     desktop,        @"DownloadFolder",
    71                     port,           @"BindPort",
    72                     DEFAULT_UPLOAD, @"UploadLimit",
    73                     @"YES",         @"CheckUpload",
    74                     @"YES",         @"CheckQuit",
    75                     @"YES",         @"CheckRemove",
    76                     NULL];
    77     [[NSUserDefaults standardUserDefaults] registerDefaults: appDefaults];
     52    [[NSUserDefaults standardUserDefaults] registerDefaults:
     53        [NSDictionary dictionaryWithContentsOfFile:
     54            [[NSBundle mainBundle] pathForResource: @"Defaults"
     55                ofType: @"plist"]]];
    7856}
    7957
     
    10179    //set download folder
    10280    NSString * downloadChoice  = [fDefaults stringForKey: @"DownloadChoice"];
    103     fDownloadFolder = [fDefaults stringForKey: @"DownloadFolder"];
     81    fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
    10482    [fDownloadFolder retain];
    10583
     
    127105    if ([fDefaults integerForKey: @"UploadLimit"] < 0)
    128106    {
    129         [fDefaults setObject: DEFAULT_UPLOAD forKey: @"UploadLimit"];
    130         [fDefaults setObject: @"NO" forKey: @"CheckUpload"];
     107        [fDefaults setInteger: 20 forKey: @"UploadLimit"];
     108        [fDefaults setBool: NO forKey: @"CheckUpload"];
    131109    }
    132110   
    133111    //set upload limit
    134     BOOL checkUpload = [[fDefaults stringForKey: @"CheckUpload"] isEqualToString:@"YES"];
     112    BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"];
    135113    int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
    136114   
     
    139117    [fUploadField setEnabled: checkUpload];
    140118   
    141     if (!checkUpload || uploadLimit == 0)
    142         uploadLimit = -1;
    143     tr_setUploadLimit( fHandle, uploadLimit );
     119    tr_setUploadLimit( fHandle, checkUpload ? uploadLimit : -1 );
    144120   
    145121    //set remove and quit prompts
    146     [fQuitCheck setState:([[fDefaults stringForKey: @"CheckQuit"]
    147                 isEqualToString:@"YES"] ? NSOnState : NSOffState)];
    148     [fRemoveCheck setState:([[fDefaults stringForKey: @"CheckRemove"]
    149                 isEqualToString:@"YES"] ? NSOnState : NSOffState)];
     122    [fQuitCheck setState: [fDefaults boolForKey: @"CheckQuit"] ?
     123        NSOnState : NSOffState];
     124    [fRemoveCheck setState: [fDefaults boolForKey: @"CheckRemove"] ?
     125        NSOnState : NSOffState];
    150126}
    151127
     
    214190    {
    215191        tr_setBindPort( fHandle, bindPort );
    216         [fDefaults setObject: [NSString stringWithFormat: @"%d", bindPort]
    217                     forKey: @"BindPort"];
     192        [fDefaults setInteger: bindPort forKey: @"BindPort"];
    218193    }
    219194}
     
    223198    BOOL checkUpload = [fUploadCheck state] == NSOnState;
    224199
    225     [fDefaults setObject: checkUpload ? @"YES" : @"NO"
    226                             forKey: @"CheckUpload"];
    227    
    228     [self setUploadLimit: sender];
     200    [fDefaults setBool: checkUpload forKey: @"CheckUpload"];
     201   
     202    [self setUploadLimit: nil];
    229203    [fUploadField setEnabled: checkUpload];
    230204}
     
    245219    else
    246220    {
    247         [fDefaults setObject: [NSString stringWithFormat: @"%d", uploadLimit]
    248             forKey: @"UploadLimit"];
     221        [fDefaults setInteger: uploadLimit forKey: @"UploadLimit"];
    249222    }
    250223   
     
    256229- (void) setQuitMessage: (id) sender
    257230{
    258     [fDefaults setObject: ([fQuitCheck state] == NSOnState ? @"YES" : @"NO")
    259                 forKey: @"CheckQuit"];
     231    [fDefaults setBool: ( [fQuitCheck state] == NSOnState )
     232        forKey: @"CheckQuit"];
    260233}
    261234
    262235- (void) setRemoveMessage: (id) sender
    263236{
    264     [fDefaults setObject: ([fRemoveCheck state] == NSOnState ? @"YES" : @"NO")
    265                 forKey: @"CheckRemove"];
     237    [fDefaults setBool: ( [fRemoveCheck state] == NSOnState )
     238        forKey: @"CheckRemove"];
    266239}
    267240
  • trunk/macosx/Transmission.xcodeproj/project.pbxproj

    r37 r38  
    2929                4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCB80981D27700BE280E /* ResumeAll.png */; };
    3030                4DE5CCBB0981D27700BE280E /* PauseAll.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCB90981D27700BE280E /* PauseAll.png */; };
     31                4DE5CCCB0981D9BE00BE280E /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4DE5CCCA0981D9BE00BE280E /* Defaults.plist */; };
    3132                4DF0C5AB0899190500DD8943 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DF0C5A90899190500DD8943 /* Controller.m */; };
    3233                4DF0C5AE08991C1600DD8943 /* libtransmission.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DF0C5AD08991C1600DD8943 /* libtransmission.a */; };
     
    103104                4DE5CCB80981D27700BE280E /* ResumeAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeAll.png; path = Images/ResumeAll.png; sourceTree = "<group>"; };
    104105                4DE5CCB90981D27700BE280E /* PauseAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseAll.png; path = Images/PauseAll.png; sourceTree = "<group>"; };
     106                4DE5CCCA0981D9BE00BE280E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Defaults.plist; sourceTree = "<group>"; };
    105107                4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; };
    106108                4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; };
     
    110112                4DF7500908A103AD007B0D70 /* Remove.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Remove.png; path = Images/Remove.png; sourceTree = "<group>"; };
    111113                8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
    112                 8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; };
     114                8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; };
    113115/* End PBXFileReference section */
    114116
     
    217219                                4DE5CCB80981D27700BE280E /* ResumeAll.png */,
    218220                                4DE5CCB90981D27700BE280E /* PauseAll.png */,
     221                                4DE5CCCA0981D9BE00BE280E /* Defaults.plist */,
    219222                                8D1107310486CEB800E47090 /* Info.plist */,
    220223                                089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
     
    310313                                4DE5CCBA0981D27700BE280E /* ResumeAll.png in Resources */,
    311314                                4DE5CCBB0981D27700BE280E /* PauseAll.png in Resources */,
     315                                4DE5CCCB0981D9BE00BE280E /* Defaults.plist in Resources */,
    312316                        );
    313317                        runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset for help on using the changeset viewer.