Ignore:
Timestamp:
Oct 25, 2006, 2:57:00 AM (16 years ago)
Author:
livings124
Message:

load prefs when first used as opposed to at launch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PrefsController.m

    r1029 r1030  
    7171        }
    7272       
    73         [[self window] update]; //make sure nib is loaded right away
     73        //set download folder and import folder
     74        fDownloadFolder = [[[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath] retain];
     75        fImportFolder = [[[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath] retain];
     76       
     77        //set auto import
     78        if ([fDefaults boolForKey: @"AutoImport"])
     79            [[UKKQueue sharedFileWatcher] addPath: fImportFolder];
     80       
     81        //set bind port
     82        int bindPort = [fDefaults integerForKey: @"BindPort"];
     83        tr_setBindPort(fHandle, bindPort);
     84       
     85        //set NAT
     86        if ([fDefaults boolForKey: @"NatTraversal"])
     87            tr_natTraversalEnable(fHandle);
     88       
     89        //actually set bandwidth limits
     90        if ([fDefaults boolForKey: @"SpeedLimit"])
     91        {
     92            tr_setUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
     93            tr_setDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
     94        }
     95        else
     96        {
     97            tr_setUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
     98                                            ? [fDefaults integerForKey: @"UploadLimit"] : -1);
     99            tr_setDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
     100                                            ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
     101        }
    74102    }
    75103    return self;
     
    78106- (void) dealloc
    79107{
    80     [fNatStatusTimer invalidate];
     108    if (fNatStatusTimer)
     109        [fNatStatusTimer invalidate];
    81110
    82111    [fDownloadFolder release];
     
    99128    //set download folder
    100129    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
    101     fDownloadFolder = [[[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath] retain];
    102130    if ([downloadChoice isEqualToString: @"Constant"])
    103131        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
     
    109137   
    110138    //set auto import
    111     fImportFolder = [[[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath] retain];
    112139    [self updateImportPopUp];
    113140 
     
    116143    [fImportFolderPopUp setEnabled: autoImport];
    117144   
    118     if (autoImport)
    119         [[UKKQueue sharedFileWatcher] addPath: fImportFolder];
    120    
    121145    //set auto size
    122146    [fAutoSizeCheck setState: [fDefaults boolForKey: @"AutoSize"]];
     
    125149    int bindPort = [fDefaults integerForKey: @"BindPort"];
    126150    [fPortField setIntValue: bindPort];
    127     tr_setBindPort(fHandle, bindPort);
    128    
    129151    [self updatePortStatus];
    130152   
    131153    //set NAT
    132     BOOL natShouldEnable = [fDefaults boolForKey: @"NatTraversal"];
    133     if (natShouldEnable)
    134         tr_natTraversalEnable(fHandle);
    135     [fNatCheck setState: natShouldEnable];
     154    [fNatCheck setState: [fDefaults boolForKey: @"NatTraversal"]];
    136155   
    137156    fNatStatus = -1;
     
    142161    //set upload limit
    143162    BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"];
    144     int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
    145    
    146163    [fUploadCheck setState: checkUpload];
    147     [fUploadField setIntValue: uploadLimit];
     164    [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
    148165    [fUploadField setEnabled: checkUpload];
    149166
    150167        //set download limit
    151168    BOOL checkDownload = [fDefaults boolForKey: @"CheckDownload"];
    152     int downloadLimit = [fDefaults integerForKey: @"DownloadLimit"];
    153    
    154169    [fDownloadCheck setState: checkDownload];
    155     [fDownloadField setIntValue: downloadLimit];
     170    [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
    156171    [fDownloadField setEnabled: checkDownload];
    157172   
    158173    //set speed limit
    159     int speedLimitUploadLimit = [fDefaults integerForKey: @"SpeedLimitUploadLimit"];
    160     [fSpeedLimitUploadField setIntValue: speedLimitUploadLimit];
    161    
    162     int speedLimitDownloadLimit = [fDefaults integerForKey: @"SpeedLimitDownloadLimit"];
    163     [fSpeedLimitDownloadField setIntValue: speedLimitDownloadLimit];
    164    
    165     //actually set bandwidth limits
    166     if ([fDefaults boolForKey: @"SpeedLimit"])
    167     {
    168         tr_setUploadLimit(fHandle, speedLimitUploadLimit);
    169         tr_setDownloadLimit(fHandle, speedLimitDownloadLimit);
    170     }
    171     else
    172     {
    173         tr_setUploadLimit(fHandle, checkUpload ? uploadLimit : -1);
    174         tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1);
    175     }
     174    [fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]];
     175    [fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]];
    176176   
    177177    //set auto speed limit
     
    279279    else
    280280        [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
     281}
     282
     283- (void) setUpdater: (SUUpdater *) updater
     284{
     285    fUpdater = updater;
    281286}
    282287
     
    482487    }
    483488   
    484     NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
    485                                     [NSNumber numberWithBool: [check state]], @"Enable",
    486                                     [NSNumber numberWithInt: limit], @"Limit",
    487                                     type, @"Type", nil];
    488     [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange" object: dict];
     489    [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange"
     490                                            object: [[NSNumber alloc] initWithBool: sender == fUploadField]];
    489491}
    490492
     
    511513}
    512514
    513 - (void) setLimitEnabled: (BOOL) enable type: (NSString *) type
    514 {
    515     NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck;
    516     [check setState: enable ? NSOnState : NSOffState];
    517     [self setLimitCheck: check];
     515- (void) setQuickLimitEnabled: (BOOL) enable type: (NSString *) type
     516{
     517    //if interface is loaded, perform change as if user performed it
     518    #warning better way?
     519    if (fToolbar)
     520    {
     521        NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck;
     522        [check setState: enable ? NSOnState : NSOffState];
     523        [self setLimitCheck: check];
     524    }
     525    else
     526    {
     527        BOOL upload = [type isEqualToString: @"Upload"];
     528        [fDefaults setBool: enable forKey: upload ? @"CheckUpload" : @"CheckDownload"];
     529       
     530        [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange"
     531                                                object: [[NSNumber alloc] initWithBool: upload]];
     532    }
    518533}
    519534
    520535- (void) setQuickLimit: (int) limit type: (NSString *) type
    521536{
    522     NSButton * check;
    523     if ([type isEqualToString: @"Upload"])
    524     {
    525         [fUploadField setIntValue: limit];
    526         check = fUploadCheck;
    527     }
    528     else
    529     {
    530         [fDownloadField setIntValue: limit];
    531         check = fDownloadCheck;
    532     }
    533     [check setState: NSOnState];
    534     [self setLimitCheck: check];
     537    //if interface is loaded, perform change as if user performed it
     538    #warning better way?
     539    if (fToolbar)
     540    {
     541        NSButton * check;
     542        if ([type isEqualToString: @"Upload"])
     543        {
     544            [fUploadField setIntValue: limit];
     545            check = fUploadCheck;
     546        }
     547        else
     548        {
     549            [fDownloadField setIntValue: limit];
     550            check = fDownloadCheck;
     551        }
     552        [check setState: NSOnState];
     553        [self setLimitCheck: check];
     554    }
     555    else
     556    {
     557        BOOL upload = [type isEqualToString: @"Upload"];
     558        [fDefaults setBool: YES forKey: upload ? @"CheckUpload" : @"CheckDownload"];
     559        [fDefaults setInteger: limit forKey: upload ? @"UploadLimit" : @"DownloadLimit"];
     560       
     561        [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange"
     562                                                object: [[NSNumber alloc] initWithBool: upload]];
     563    }
    535564}
    536565
     
    548577        else
    549578        {
    550             tr_setUploadLimit(fHandle, [fUploadCheck state] ? [fDefaults integerForKey: @"UploadLimit"] : -1);
    551             tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
     579            tr_setUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
     580                                        ? [fDefaults integerForKey: @"UploadLimit"] : -1);
     581            tr_setDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
     582                                            ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
    552583        }
    553584    }
     
    628659        [fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
    629660   
    630     NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
    631                                 [NSNumber numberWithBool: [fRatioCheck state]], @"Enable",
    632                                 [NSNumber numberWithFloat: ratioLimit], @"Ratio", nil];
    633     [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: dict];
     661    [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: nil];
    634662}
    635663
     
    643671}
    644672
    645 - (void) setRatioEnabled: (BOOL) enable
    646 {
    647     int state = enable ? NSOnState : NSOffState;
    648    
    649     [fRatioCheck setState: state];
    650     [self setRatioCheck: fRatioCheck];
     673- (void) setQuickRatioEnabled: (BOOL) enable
     674{
     675    //if interface is loaded, perform change as if user performed it
     676    #warning better way?
     677    if (fToolbar)
     678    {
     679        int state = enable ? NSOnState : NSOffState;
     680       
     681        [fRatioCheck setState: state];
     682        [self setRatioCheck: fRatioCheck];
     683    }
     684    else
     685    {
     686        [fDefaults setBool: enable forKey: @"RatioCheck"];
     687       
     688        [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: nil];
     689    }
    651690}
    652691
    653692- (void) setQuickRatio: (float) ratioLimit
    654693{
    655     [fRatioField setFloatValue: ratioLimit];
    656    
    657     [fRatioCheck setState: NSOnState];
    658     [self setRatioCheck: fRatioCheck];
     694    //if interface is loaded, perform change as if user performed it
     695    #warning better way?
     696    if (fToolbar)
     697    {
     698        [fRatioField setFloatValue: ratioLimit];
     699       
     700        [fRatioCheck setState: NSOnState];
     701        [self setRatioCheck: fRatioCheck];
     702    }
     703    else
     704    {
     705        [fDefaults setBool: YES forKey: @"RatioCheck"];
     706        [fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
     707       
     708        [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: nil];
     709    }
    659710}
    660711
     
    744795
    745796    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
    746     [fUpdater scheduleCheckWithInterval: seconds];
     797   
     798    if (fUpdater)
     799        [fUpdater scheduleCheckWithInterval: seconds];
    747800}
    748801
     
    811864}
    812865
    813 - (void) checkUpdate
    814 {
    815     [fUpdater checkForUpdates: nil];
    816 }
    817 
    818866- (void) folderSheetShow: (id) sender
    819867{
Note: See TracChangeset for help on using the changeset viewer.