Changeset 6226


Ignore:
Timestamp:
Jun 19, 2008, 3:47:11 AM (13 years ago)
Author:
livings124
Message:

have the speed limit timer keep track of what the next state should be instead of determining it when the timer fires

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r6223 r6226  
    221221- (void) autoSpeedLimitChange: (NSNotification *) notification;
    222222- (void) autoSpeedLimit: (NSTimer *) timer;
    223 - (void) setAutoSpeedLimitTimer: (BOOL) nextIsOn;
     223- (void) setAutoSpeedLimitTimer: (BOOL) nextIsLimit;
    224224
    225225- (void) setLimitGlobalEnabled: (id) sender;
  • trunk/macosx/Controller.m

    r6225 r6226  
    23842384- (void) autoSpeedLimit: (NSTimer *) timer
    23852385{
    2386     //check if should toggle (for cases where users might have manually
    2387     NSCalendarDate * onDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:
    2388                                 [[fDefaults objectForKey: @"SpeedLimitAutoOnDate"] timeIntervalSinceReferenceDate]],
    2389                     * offDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:
    2390                                 [[fDefaults objectForKey: @"SpeedLimitAutoOffDate"] timeIntervalSinceReferenceDate]],
    2391                     * nowDate = [NSCalendarDate calendarDate];
    2392    
    2393     BOOL currentlyLimiting = [fDefaults boolForKey: @"SpeedLimit"], toggle;
    2394     if (currentlyLimiting)
    2395         toggle = [nowDate hourOfDay] == [offDate hourOfDay] && [nowDate minuteOfHour] == [offDate minuteOfHour];
    2396     else
    2397         toggle = [nowDate hourOfDay] == [onDate hourOfDay] && [nowDate minuteOfHour] == [onDate minuteOfHour];
    2398    
    2399     if (toggle)
     2386    BOOL shouldLimit = [[timer userInfo] boolValue];
     2387   
     2388    if ([fDefaults boolForKey: @"SpeedLimit"] != shouldLimit)
    24002389    {
    24012390        [self toggleSpeedLimit: nil];
     
    24062395            description: NSLocalizedString(@"Bandwidth settings changed", "Growl notification description")
    24072396            notificationName: GROWL_AUTO_SPEED_LIMIT iconData: nil priority: 0 isSticky: NO clickContext: nil];
    2408            
    2409             currentlyLimiting != currentlyLimiting;
    2410     }
    2411    
    2412     [self setAutoSpeedLimitTimer: !currentlyLimiting];
    2413 }
    2414 
    2415 - (void) setAutoSpeedLimitTimer: (BOOL) nextIsOn
    2416 {
    2417     NSDate * timerDate = [fDefaults objectForKey: nextIsOn ? @"SpeedLimitAutoOnDate" : @"SpeedLimitAutoOffDate"],
     2397    }
     2398   
     2399    [self setAutoSpeedLimitTimer: !shouldLimit];
     2400}
     2401
     2402- (void) setAutoSpeedLimitTimer: (BOOL) nextIsLimit
     2403{
     2404    NSDate * timerDate = [fDefaults objectForKey: nextIsLimit ? @"SpeedLimitAutoOnDate" : @"SpeedLimitAutoOffDate"],
    24182405            * nowDate = [NSDate date];
    24192406   
     
    24402427   
    24412428    fSpeedLimitTimer = [[NSTimer alloc] initWithFireDate: dateToUse interval: 0 target: self selector: @selector(autoSpeedLimit:)
    2442                         userInfo: nil repeats: NO];
     2429                        userInfo: [NSNumber numberWithBool: nextIsLimit] repeats: NO];
    24432430   
    24442431    [[NSRunLoop currentRunLoop] addTimer: fSpeedLimitTimer forMode: NSDefaultRunLoopMode];
Note: See TracChangeset for help on using the changeset viewer.