Changeset 752


Ignore:
Timestamp:
Aug 11, 2006, 10:58:14 PM (15 years ago)
Author:
livings124
Message:

Scheduler is now more automatic.

Location:
trunk/macosx
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r750 r752  
    149149
    150150- (void) toggleSpeedLimit: (id) sender;
    151 - (void) autoSpeedLimit: (NSTimer *) timer;
     151- (void) autoSpeedLimit: (id) sender;
    152152
    153153- (void) setLimitGlobalEnabled: (id) sender;
  • trunk/macosx/Controller.m

    r750 r752  
    306306                    name: @"RatioGlobalChange" object: nil];
    307307   
     308    [nc addObserver: self selector: @selector(autoSpeedLimit:)
     309                    name: @"AutoSpeedLimitChange" object: nil];
     310   
    308311    [nc addObserver: self selector: @selector(autoImportChange:)
    309312                    name: @"AutoImportSettingChange" object: nil];
     
    352355   
    353356    //timer to auto toggle speed limit
     357    [self autoSpeedLimit: nil];
    354358    fSpeedLimitTimer = [NSTimer scheduledTimerWithTimeInterval: AUTO_SPEED_LIMIT_SECONDS target: self
    355359        selector: @selector(autoSpeedLimit:) userInfo: nil repeats: YES];
     
    12521256}
    12531257
    1254 - (void) autoSpeedLimit: (NSTimer *) timer
    1255 {
    1256     BOOL autoOn, autoOff;
    1257     if (!(autoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"])
    1258             && !(autoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"]))
     1258- (void) autoSpeedLimit: (id) sender
     1259{
     1260    if (![fDefaults boolForKey: @"SpeedLimitAuto"])
    12591261        return;
    12601262 
     
    12621264    int onHour, offHour;
    12631265    if ((onHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"])
    1264             == (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]) && autoOn && autoOff)
     1266            == (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]))
    12651267        return;
    12661268   
    1267     NSCalendarDate * currentDate = [NSCalendarDate calendarDate];
    1268     //toggle if within first few seconds of hour
    1269     if ([currentDate minuteOfHour] == 0 && [currentDate secondOfMinute] < AUTO_SPEED_LIMIT_SECONDS
    1270             && [currentDate hourOfDay] == (fSpeedLimitEnabled ? offHour : onHour))
     1269    BOOL rangeForOn = onHour < offHour;
     1270    int min, max;
     1271    if (rangeForOn)
     1272    {
     1273        min = onHour;
     1274        max = offHour;
     1275    }
     1276    else
     1277    {
     1278        min = offHour;
     1279        max = onHour;
     1280    }
     1281   
     1282    int hour = [[NSCalendarDate calendarDate] hourOfDay];
     1283    BOOL inRange = hour >= min && hour < max;
     1284   
     1285    if ((!fSpeedLimitEnabled && (rangeForOn == inRange)) || (fSpeedLimitEnabled && (rangeForOn != inRange)))
    12711286    {
    12721287        [self toggleSpeedLimit: nil];
  • trunk/macosx/Defaults.plist

    r740 r752  
    7575        <key>SpeedLimit</key>
    7676        <false/>
    77         <key>SpeedLimitAutoOff</key>
     77        <key>SpeedLimitAuto</key>
    7878        <false/>
    7979        <key>SpeedLimitAutoOffHour</key>
    8080        <integer>0</integer>
    81         <key>SpeedLimitAutoOn</key>
    82         <false/>
    8381        <key>SpeedLimitAutoOnHour</key>
    8482        <integer>12</integer>
  • trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib

    r746 r752  
    5656                fRemoveDownloadingCheck = NSButton;
    5757                fSeedingSoundPopUp = NSPopUpButton;
    58                 fSpeedLimitAutoOffCheck = NSButton;
     58                fSpeedLimitAutoCheck = NSButton;
    5959                fSpeedLimitAutoOffField = NSTextField;
    60                 fSpeedLimitAutoOnCheck = NSButton;
    6160                fSpeedLimitAutoOnField = NSTextField;
    6261                fSpeedLimitDownloadField = NSTextField;
  • trunk/macosx/English.lproj/PrefsWindow.nib/info.nib

    r746 r752  
    44<dict>
    55        <key>IBDocumentLocation</key>
    6         <string>49 70 356 240 0 0 1152 842 </string>
     6        <string>49 68 356 240 0 0 1152 842 </string>
    77        <key>IBEditorPositions</key>
    88        <dict>
    99                <key>153</key>
    10                 <string>285 433 582 291 0 0 1152 842 </string>
     10                <string>119 348 584 311 0 0 1152 842 </string>
    1111                <key>28</key>
    1212                <string>58 372 582 290 0 0 1152 842 </string>
    1313                <key>41</key>
    14                 <string>138 419 582 304 0 0 1152 842 </string>
     14                <string>285 427 582 304 0 0 1152 842 </string>
    1515                <key>66</key>
    16                 <string>71 359 585 104 0 0 1152 842 </string>
     16                <string>164 527 582 104 0 0 1152 842 </string>
    1717        </dict>
    1818        <key>IBFramework Version</key>
     
    2424        <key>IBOpenObjects</key>
    2525        <array>
    26                 <integer>66</integer>
     26                <integer>153</integer>
    2727        </array>
    2828        <key>IBSystem Version</key>
  • trunk/macosx/PrefsController.h

    r746 r752  
    4949                            * fSpeedLimitAutoOnField, * fSpeedLimitAutoOffField;
    5050    IBOutlet NSButton       * fUploadCheck, * fDownloadCheck,
    51                             * fSpeedLimitAutoOnCheck, * fSpeedLimitAutoOffCheck;
     51                            * fSpeedLimitAutoCheck;
    5252
    5353    IBOutlet NSTextField    * fPortField;
  • trunk/macosx/PrefsController.m

    r746 r752  
    171171   
    172172    //set auto speed limit
    173     BOOL speedLimitAutoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"];
     173    BOOL speedLimitAuto = [fDefaults boolForKey: @"SpeedLimitAuto"];
     174    [fSpeedLimitAutoCheck setState: speedLimitAuto];
     175   
    174176    int speedLimitAutoOnHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"];
    175    
    176     [fSpeedLimitAutoOnCheck setState: speedLimitAutoOn];
    177177    [fSpeedLimitAutoOnField setIntValue: speedLimitAutoOnHour];
    178     [fSpeedLimitAutoOnField setEnabled: speedLimitAutoOn];
    179    
    180     BOOL speedLimitAutoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"];
     178    [fSpeedLimitAutoOnField setEnabled: speedLimitAuto];
     179   
    181180    int speedLimitAutoOffHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"];
    182    
    183     [fSpeedLimitAutoOffCheck setState: speedLimitAutoOff];
    184181    [fSpeedLimitAutoOffField setIntValue: speedLimitAutoOffHour];
    185     [fSpeedLimitAutoOffField setEnabled: speedLimitAutoOff];
     182    [fSpeedLimitAutoOffField setEnabled: speedLimitAuto];
    186183   
    187184    //set ratio limit
     
    500497- (void) setAutoSpeedLimitCheck: (id) sender
    501498{
    502     NSString * key;
    503     NSTextField * field;
    504     if (sender == fSpeedLimitAutoOnCheck)
    505     {
    506         key = @"SpeedLimitAutoOn";
    507         field = fSpeedLimitAutoOnField;
    508     }
    509     else
    510     {
    511         key = @"SpeedLimitAutoOff";
    512         field = fSpeedLimitAutoOffField;
    513     }
    514    
    515499    BOOL check = [sender state] == NSOnState;
    516     [self setAutoSpeedLimitHour: field];
    517     [field setEnabled: check];
    518    
    519     [fDefaults setBool: check forKey: key];
     500   
     501    [fDefaults setBool: check forKey: @"SpeedLimitAuto"];
     502
     503    [self setAutoSpeedLimitHour: fSpeedLimitAutoOnField];
     504    [fSpeedLimitAutoOnField setEnabled: check];
     505   
     506    [self setAutoSpeedLimitHour: fSpeedLimitAutoOffField];
     507    [fSpeedLimitAutoOffField setEnabled: check];
    520508}
    521509
     
    533521    else
    534522        [fDefaults setInteger: hour forKey: key];
     523   
     524    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
    535525}
    536526
Note: See TracChangeset for help on using the changeset viewer.