Ignore:
Timestamp:
Sep 25, 2006, 6:37:45 PM (15 years ago)
Author:
joshe
Message:

Merge nat-traversal branch to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PrefsController.m

    r850 r920  
    3434#define DOWNLOAD_ASK        3
    3535
    36 #define START_YES_CHECK_TAG     0
    37 #define START_WAIT_CHECK_TAG    1
    38 #define START_NO_CHECK_TAG      2
    39 
    4036#define UPDATE_DAILY    0
    4137#define UPDATE_WEEKLY   1
     
    8076- (void) dealloc
    8177{
     78    [fNatStatusTimer invalidate];
     79
    8280    [fDownloadFolder release];
    8381    [fImportFolder release];
     
    126124    [fPortField setIntValue: bindPort];
    127125    tr_setBindPort(fHandle, bindPort);
     126   
     127    //set NAT
     128    BOOL natShouldEnable = [fDefaults boolForKey: @"NatTraversal"];
     129    if (natShouldEnable)
     130        tr_natTraversalEnable(fHandle);
     131    [fNatCheck setState: natShouldEnable];
     132   
     133    fNatStatus = -1;
     134    [self updateNatStatus];
     135    fNatStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
     136                        selector: @selector(updateNatStatus) userInfo: nil repeats: YES];
    128137   
    129138    //checks for old version upload speed of -1
     
    250259        [fDefaults setObject: [fSeedingSoundPopUp titleOfSelectedItem] forKey: @"SeedingSound"];
    251260   
    252     //set start setting
    253     NSString * startSetting = [fDefaults stringForKey: @"StartSetting"];
    254     int tag;
    255     if ([startSetting isEqualToString: @"Start"])
    256         tag = START_YES_CHECK_TAG;
    257     else if ([startSetting isEqualToString: @"Wait"])
    258         tag = START_WAIT_CHECK_TAG;
    259     else
    260         tag = START_NO_CHECK_TAG;
    261    
    262     [fStartMatrix selectCellWithTag: tag];
    263     [fStartNumberField setEnabled: tag == START_WAIT_CHECK_TAG];
    264     [fStartNumberField setIntValue: [fDefaults integerForKey: @"WaitToStartNumber"]];
     261    //set start settings
     262    BOOL useQueue = [fDefaults boolForKey: @"Queue"];
     263    [fQueueCheck setState: useQueue];
     264    [fQueueNumberField setEnabled: useQueue];
     265    [fQueueNumberField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]];
     266   
     267    [fStartAtOpenCheck setState: [fDefaults boolForKey: @"StartAtOpen"]];
    265268   
    266269    //set private torrents
     
    355358        tr_setBindPort(fHandle, bindPort);
    356359        [fDefaults setInteger: bindPort forKey: @"BindPort"];
     360       
     361        [self updateNatStatus];
     362    }
     363}
     364
     365- (void) setNat: (id) sender
     366{
     367    BOOL enable = [sender state] == NSOnState;
     368    enable ? tr_natTraversalEnable(fHandle) : tr_natTraversalDisable(fHandle);
     369    [fDefaults setBool: enable forKey: @"NatTraversal"];
     370   
     371    [self updateNatStatus];
     372}
     373
     374- (void) updateNatStatus
     375{
     376    int status = tr_natTraversalStatus(fHandle);
     377    if (fNatStatus == status)
     378        return;
     379    fNatStatus = status;
     380   
     381    if (status == 2)
     382    {
     383        [fNatStatusField setStringValue: @"Ports successfully mapped"];
     384        [fNatStatusImage setImage: [NSImage imageNamed: @"Check.png"]];
     385    }
     386    else if (status == 3 || status == 4)
     387    {
     388        [fNatStatusField setStringValue: @"Error mapping ports"];
     389        [fNatStatusImage setImage: [NSImage imageNamed: @"Error.tiff"]];
     390    }
     391    else
     392    {
     393        [fNatStatusField setStringValue: @""];
     394        [fNatStatusImage setImage: nil];
    357395    }
    358396}
     
    662700}
    663701
    664 - (void) setStartSetting: (id) sender
    665 {
    666     NSString * startSetting;
    667 
    668     int tag = [[fStartMatrix selectedCell] tag];
    669     if (tag == START_YES_CHECK_TAG)
    670         startSetting = @"Start";
    671     else if (tag == START_WAIT_CHECK_TAG)
    672         startSetting = @"Wait";
    673     else
    674         startSetting = @"Manual";
    675    
    676     [fDefaults setObject: startSetting forKey: @"StartSetting"];
    677    
    678     [self setStartNumber: fStartNumberField];
    679     [fStartNumberField setEnabled: tag == START_WAIT_CHECK_TAG];
    680 }
    681 
    682 - (void) setStartNumber: (id) sender
    683 {
    684     int waitNumber = [sender intValue];
    685     if (![[sender stringValue] isEqualToString: [NSString stringWithInt: waitNumber]] || waitNumber < 1)
     702- (void) setStartAtOpen: (id) sender
     703{
     704    [fDefaults setBool: [sender state] == NSOnState forKey: @"StartAtOpen"];
     705}
     706
     707- (void) setUseQueue: (id) sender
     708{
     709    BOOL useQueue = [sender state] == NSOnState;
     710   
     711    [fDefaults setBool: useQueue forKey: @"Queue"];
     712    [self setQueueNumber: fQueueNumberField];
     713    [fQueueNumberField setEnabled: useQueue];
     714}
     715
     716- (void) setQueueNumber: (id) sender
     717{
     718    int queueNumber = [sender intValue];
     719    if (![[sender stringValue] isEqualToString: [NSString stringWithInt: queueNumber]] || queueNumber < 1)
    686720    {
    687721        NSBeep();
    688         waitNumber = [fDefaults floatForKey: @"WaitToStartNumber"];
    689         [sender setIntValue: waitNumber];
    690     }
    691     else
    692         [fDefaults setInteger: waitNumber forKey: @"WaitToStartNumber"];
     722        queueNumber = [fDefaults integerForKey: @"QueueDownloadNumber"];
     723        [sender setIntValue: queueNumber];
     724    }
     725    else
     726        [fDefaults setInteger: queueNumber forKey: @"QueueDownloadNumber"];
    693727   
    694728    [[NSNotificationCenter defaultCenter] postNotificationName: @"GlobalStartSettingChange" object: self];
Note: See TracChangeset for help on using the changeset viewer.