Scheduler is now more automatic.

This commit is contained in:
Mitchell Livingston 2006-08-11 22:58:14 +00:00
parent af77d3d170
commit cc66511f98
8 changed files with 47 additions and 45 deletions

View File

@ -148,7 +148,7 @@
- (void) setFilter: (id) sender;
- (void) toggleSpeedLimit: (id) sender;
- (void) autoSpeedLimit: (NSTimer *) timer;
- (void) autoSpeedLimit: (id) sender;
- (void) setLimitGlobalEnabled: (id) sender;
- (void) setQuickLimitGlobal: (id) sender;

View File

@ -305,6 +305,9 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
[nc addObserver: self selector: @selector(ratioGlobalChange:)
name: @"RatioGlobalChange" object: nil];
[nc addObserver: self selector: @selector(autoSpeedLimit:)
name: @"AutoSpeedLimitChange" object: nil];
[nc addObserver: self selector: @selector(autoImportChange:)
name: @"AutoImportSettingChange" object: nil];
@ -351,6 +354,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
[self showInfo: nil];
//timer to auto toggle speed limit
[self autoSpeedLimit: nil];
fSpeedLimitTimer = [NSTimer scheduledTimerWithTimeInterval: AUTO_SPEED_LIMIT_SECONDS target: self
selector: @selector(autoSpeedLimit:) userInfo: nil repeats: YES];
@ -1251,23 +1255,34 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
[fPrefsController enableSpeedLimit: fSpeedLimitEnabled];
}
- (void) autoSpeedLimit: (NSTimer *) timer
- (void) autoSpeedLimit: (id) sender
{
BOOL autoOn, autoOff;
if (!(autoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"])
&& !(autoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"]))
if (![fDefaults boolForKey: @"SpeedLimitAuto"])
return;
//do nothing if time to turn on and off are equal
int onHour, offHour;
if ((onHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"])
== (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]) && autoOn && autoOff)
== (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]))
return;
NSCalendarDate * currentDate = [NSCalendarDate calendarDate];
//toggle if within first few seconds of hour
if ([currentDate minuteOfHour] == 0 && [currentDate secondOfMinute] < AUTO_SPEED_LIMIT_SECONDS
&& [currentDate hourOfDay] == (fSpeedLimitEnabled ? offHour : onHour))
BOOL rangeForOn = onHour < offHour;
int min, max;
if (rangeForOn)
{
min = onHour;
max = offHour;
}
else
{
min = offHour;
max = onHour;
}
int hour = [[NSCalendarDate calendarDate] hourOfDay];
BOOL inRange = hour >= min && hour < max;
if ((!fSpeedLimitEnabled && (rangeForOn == inRange)) || (fSpeedLimitEnabled && (rangeForOn != inRange)))
{
[self toggleSpeedLimit: nil];

View File

@ -74,12 +74,10 @@
<string>Order</string>
<key>SpeedLimit</key>
<false/>
<key>SpeedLimitAutoOff</key>
<key>SpeedLimitAuto</key>
<false/>
<key>SpeedLimitAutoOffHour</key>
<integer>0</integer>
<key>SpeedLimitAutoOn</key>
<false/>
<key>SpeedLimitAutoOnHour</key>
<integer>12</integer>
<key>SpeedLimitDownloadLimit</key>

View File

@ -55,9 +55,8 @@
fRemoveCheck = NSButton;
fRemoveDownloadingCheck = NSButton;
fSeedingSoundPopUp = NSPopUpButton;
fSpeedLimitAutoOffCheck = NSButton;
fSpeedLimitAutoCheck = NSButton;
fSpeedLimitAutoOffField = NSTextField;
fSpeedLimitAutoOnCheck = NSButton;
fSpeedLimitAutoOnField = NSTextField;
fSpeedLimitDownloadField = NSTextField;
fSpeedLimitUploadField = NSTextField;

View File

@ -3,17 +3,17 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>49 70 356 240 0 0 1152 842 </string>
<string>49 68 356 240 0 0 1152 842 </string>
<key>IBEditorPositions</key>
<dict>
<key>153</key>
<string>285 433 582 291 0 0 1152 842 </string>
<string>119 348 584 311 0 0 1152 842 </string>
<key>28</key>
<string>58 372 582 290 0 0 1152 842 </string>
<key>41</key>
<string>138 419 582 304 0 0 1152 842 </string>
<string>285 427 582 304 0 0 1152 842 </string>
<key>66</key>
<string>71 359 585 104 0 0 1152 842 </string>
<string>164 527 582 104 0 0 1152 842 </string>
</dict>
<key>IBFramework Version</key>
<string>446.1</string>
@ -23,7 +23,7 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>66</integer>
<integer>153</integer>
</array>
<key>IBSystem Version</key>
<string>8J135</string>

View File

@ -48,7 +48,7 @@
* fSpeedLimitUploadField, * fSpeedLimitDownloadField,
* fSpeedLimitAutoOnField, * fSpeedLimitAutoOffField;
IBOutlet NSButton * fUploadCheck, * fDownloadCheck,
* fSpeedLimitAutoOnCheck, * fSpeedLimitAutoOffCheck;
* fSpeedLimitAutoCheck;
IBOutlet NSTextField * fPortField;

View File

@ -170,19 +170,16 @@
}
//set auto speed limit
BOOL speedLimitAutoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"];
BOOL speedLimitAuto = [fDefaults boolForKey: @"SpeedLimitAuto"];
[fSpeedLimitAutoCheck setState: speedLimitAuto];
int speedLimitAutoOnHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"];
[fSpeedLimitAutoOnCheck setState: speedLimitAutoOn];
[fSpeedLimitAutoOnField setIntValue: speedLimitAutoOnHour];
[fSpeedLimitAutoOnField setEnabled: speedLimitAutoOn];
[fSpeedLimitAutoOnField setEnabled: speedLimitAuto];
BOOL speedLimitAutoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"];
int speedLimitAutoOffHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"];
[fSpeedLimitAutoOffCheck setState: speedLimitAutoOff];
[fSpeedLimitAutoOffField setIntValue: speedLimitAutoOffHour];
[fSpeedLimitAutoOffField setEnabled: speedLimitAutoOff];
[fSpeedLimitAutoOffField setEnabled: speedLimitAuto];
//set ratio limit
BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"];
@ -499,24 +496,15 @@
- (void) setAutoSpeedLimitCheck: (id) sender
{
NSString * key;
NSTextField * field;
if (sender == fSpeedLimitAutoOnCheck)
{
key = @"SpeedLimitAutoOn";
field = fSpeedLimitAutoOnField;
}
else
{
key = @"SpeedLimitAutoOff";
field = fSpeedLimitAutoOffField;
}
BOOL check = [sender state] == NSOnState;
[self setAutoSpeedLimitHour: field];
[field setEnabled: check];
[fDefaults setBool: check forKey: key];
[fDefaults setBool: check forKey: @"SpeedLimitAuto"];
[self setAutoSpeedLimitHour: fSpeedLimitAutoOnField];
[fSpeedLimitAutoOnField setEnabled: check];
[self setAutoSpeedLimitHour: fSpeedLimitAutoOffField];
[fSpeedLimitAutoOffField setEnabled: check];
}
- (void) setAutoSpeedLimitHour: (id) sender
@ -532,6 +520,8 @@
}
else
[fDefaults setInteger: hour forKey: key];
[[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
}
- (void) setRatio: (id) sender