]> granicus.if.org Git - transmission/commitdiff
have the speed limit timer keep track of what the next state should be instead of...
authorMitchell Livingston <livings124@transmissionbt.com>
Thu, 19 Jun 2008 03:47:11 +0000 (03:47 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Thu, 19 Jun 2008 03:47:11 +0000 (03:47 +0000)
macosx/Controller.h
macosx/Controller.m

index 2a674c4a4ca65dde1e8b72d116581d87291159ea..570b68232e70f19b648579341059697f43b36f0e 100644 (file)
@@ -220,7 +220,7 @@ typedef enum
 - (void) toggleSpeedLimit: (id) sender;
 - (void) autoSpeedLimitChange: (NSNotification *) notification;
 - (void) autoSpeedLimit: (NSTimer *) timer;
-- (void) setAutoSpeedLimitTimer: (BOOL) nextIsOn;
+- (void) setAutoSpeedLimitTimer: (BOOL) nextIsLimit;
 
 - (void) setLimitGlobalEnabled: (id) sender;
 - (void) setQuickLimitGlobal: (id) sender;
index 0ebbf30a171b027debc06fc922a82955bc296cdd..f8c89c10d9c0e003d876fed614e1e4b784a158f6 100644 (file)
@@ -2383,20 +2383,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
 //only called from fSpeedLimitTimer
 - (void) autoSpeedLimit: (NSTimer *) timer
 {
-    //check if should toggle (for cases where users might have manually
-    NSCalendarDate * onDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:
-                                [[fDefaults objectForKey: @"SpeedLimitAutoOnDate"] timeIntervalSinceReferenceDate]],
-                    * offDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:
-                                [[fDefaults objectForKey: @"SpeedLimitAutoOffDate"] timeIntervalSinceReferenceDate]],
-                    * nowDate = [NSCalendarDate calendarDate];
-    
-    BOOL currentlyLimiting = [fDefaults boolForKey: @"SpeedLimit"], toggle;
-    if (currentlyLimiting)
-        toggle = [nowDate hourOfDay] == [offDate hourOfDay] && [nowDate minuteOfHour] == [offDate minuteOfHour];
-    else
-        toggle = [nowDate hourOfDay] == [onDate hourOfDay] && [nowDate minuteOfHour] == [onDate minuteOfHour];
+    BOOL shouldLimit = [[timer userInfo] boolValue];
     
-    if (toggle)
+    if ([fDefaults boolForKey: @"SpeedLimit"] != shouldLimit)
     {
         [self toggleSpeedLimit: nil];
         
@@ -2405,16 +2394,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
                 : NSLocalizedString(@"Speed Limit Auto Disabled", "Growl notification title")
             description: NSLocalizedString(@"Bandwidth settings changed", "Growl notification description")
             notificationName: GROWL_AUTO_SPEED_LIMIT iconData: nil priority: 0 isSticky: NO clickContext: nil];
-            
-            currentlyLimiting != currentlyLimiting;
     }
     
-    [self setAutoSpeedLimitTimer: !currentlyLimiting];
+    [self setAutoSpeedLimitTimer: !shouldLimit];
 }
 
-- (void) setAutoSpeedLimitTimer: (BOOL) nextIsOn
+- (void) setAutoSpeedLimitTimer: (BOOL) nextIsLimit
 {
-    NSDate * timerDate = [fDefaults objectForKey: nextIsOn ? @"SpeedLimitAutoOnDate" : @"SpeedLimitAutoOffDate"],
+    NSDate * timerDate = [fDefaults objectForKey: nextIsLimit ? @"SpeedLimitAutoOnDate" : @"SpeedLimitAutoOffDate"],
             * nowDate = [NSDate date];
     
     //create date with combination of the current date and the date to go off
@@ -2439,7 +2426,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
         dateToUse = [dateToUse addTimeInterval: 60 * 60 * 24]; //60 sec * 60 min * 24 hr
     
     fSpeedLimitTimer = [[NSTimer alloc] initWithFireDate: dateToUse interval: 0 target: self selector: @selector(autoSpeedLimit:)
-                        userInfo: nil repeats: NO];
+                        userInfo: [NSNumber numberWithBool: nextIsLimit] repeats: NO];
     
     [[NSRunLoop currentRunLoop] addTimer: fSpeedLimitTimer forMode: NSDefaultRunLoopMode];
     [[NSRunLoop currentRunLoop] addTimer: fSpeedLimitTimer forMode: NSModalPanelRunLoopMode];