1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-03 21:12:05 +00:00

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

This commit is contained in:
Mitchell Livingston 2008-06-19 03:47:11 +00:00
parent f4fb4d7b27
commit 1c2b05f75f
2 changed files with 7 additions and 20 deletions

View 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;

View 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 shouldLimit = [[timer userInfo] boolValue];
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];
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];