Ignore:
Timestamp:
Mar 28, 2009, 5:18:43 PM (13 years ago)
Author:
livings124
Message:

the Mac build works with the new speed limit libT code - still a bit quirky

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PrefsController.m

    r8058 r8098  
    9191        fDefaults = [NSUserDefaults standardUserDefaults];
    9292       
    93         //checks for old version speeds of -1
    94         if ([fDefaults integerForKey: @"UploadLimit"] < 0)
    95         {
    96             [fDefaults removeObjectForKey: @"UploadLimit"];
    97             [fDefaults setBool: NO forKey: @"CheckUpload"];
    98         }
    99         if ([fDefaults integerForKey: @"DownloadLimit"] < 0)
    100         {
    101             [fDefaults removeObjectForKey: @"DownloadLimit"];
    102             [fDefaults setBool: NO forKey: @"CheckDownload"];
    103         }
    104        
    10593        //check for old version download location (before 1.1)
    10694        NSString * choice;
     
    127115        //set encryption
    128116        [self setEncryptionMode: nil];
    129        
    130         //actually set bandwidth limits
    131         [self applySpeedSettings: nil];
    132117       
    133118        //set proxy type
     
    548533- (void) applySpeedSettings: (id) sender
    549534{
    550     if ([fDefaults boolForKey: @"SpeedLimit"])
    551     {
    552         tr_sessionSetSpeedLimitEnabled(fHandle, TR_UP, 1);
    553         tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
    554        
    555         tr_sessionSetSpeedLimitEnabled(fHandle, TR_DOWN, 1);
    556         tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
    557     }
    558     else
    559     {
    560         tr_sessionSetSpeedLimitEnabled(fHandle, TR_UP, [fDefaults boolForKey: @"CheckUpload"]);
    561         tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"UploadLimit"]);
    562        
    563         tr_sessionSetSpeedLimitEnabled(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
    564         tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"DownloadLimit"]);
    565     }
    566    
     535    tr_sessionLimitSpeed(fHandle, TR_UP, [fDefaults boolForKey: @"CheckUpload"]);
     536    tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"UploadLimit"]);
     537   
     538    tr_sessionLimitSpeed(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
     539    tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"DownloadLimit"]);
     540   
     541    [[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
     542}
     543
     544- (void) applyAltSpeedSettings
     545{
     546    tr_sessionSetAltSpeed(fHandle, TR_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
     547    tr_sessionSetAltSpeed(fHandle, TR_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
     548       
    567549    [[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
    568550}
     
    609591    [fDefaults setInteger: [sender intValue] forKey: sender == fSpeedLimitUploadField
    610592                                                        ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
    611     [self applySpeedSettings: self];
     593    [self applyAltSpeedSettings];
    612594}
    613595
    614596- (void) setAutoSpeedLimit: (id) sender
    615597{
    616     [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
     598    tr_sessionUseAltSpeedTime(fHandle, [fDefaults boolForKey: @"SpeedLimitAuto"]);
     599}
     600
     601- (void) setAutoSpeedLimitTime: (id) sender
     602{
     603    tr_sessionSetAltSpeedBegin(fHandle, [PrefsController dateToTimeSum: [fDefaults objectForKey: @"SpeedLimitAutoOnDate"]]);
     604    tr_sessionSetAltSpeedEnd(fHandle, [PrefsController dateToTimeSum: [fDefaults objectForKey: @"SpeedLimitAutoOffDate"]]);
     605}
     606
     607+ (NSInteger) dateToTimeSum: (NSDate *) date
     608{
     609    NSCalendar * calendar = [NSCalendar currentCalendar];
     610    NSDateComponents * components = [calendar components: NSHourCalendarUnit | NSMinuteCalendarUnit fromDate: date];
     611    return [components hour] * 60 + [components minute];
    617612}
    618613
     
    10491044}
    10501045
     1046#warning probably needs to be updated
    10511047- (void) rpcUpdatePrefs
    10521048{
     
    10801076   
    10811077    //speed limit - down
    1082     BOOL downLimitEnabled = tr_sessionIsSpeedLimitEnabled(fHandle, TR_DOWN);
     1078    BOOL downLimitEnabled = tr_sessionIsSpeedLimited(fHandle, TR_DOWN);
    10831079    [fDefaults setBool: downLimitEnabled forKey: @"CheckDownload"];
    10841080   
     
    10871083   
    10881084    //speed limit - up
    1089     BOOL upLimitEnabled = tr_sessionIsSpeedLimitEnabled(fHandle, TR_UP);
     1085    BOOL upLimitEnabled = tr_sessionIsSpeedLimited(fHandle, TR_UP);
    10901086    [fDefaults setBool: upLimitEnabled forKey: @"CheckUpload"];
    10911087   
Note: See TracChangeset for help on using the changeset viewer.