Changeset 740


Ignore:
Timestamp:
Aug 8, 2006, 2:11:51 AM (15 years ago)
Author:
livings124
Message:

Allow scheduling of speed limit.
Preference window saves when closing again.

Location:
trunk/macosx
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r721 r740  
    6161    BOOL                            fSpeedLimitEnabled;
    6262    NSImage                         * fSpeedLimitNormalImage, * fSpeedLimitBlueImage, * fSpeedLimitGraphiteImage;
     63    NSTimer                         * fSpeedLimitTimer;
    6364   
    6465    IBOutlet ImageBackgroundView    * fStatusBar;
     
    147148
    148149- (void) toggleSpeedLimit: (id) sender;
     150- (void) autoSpeedLimit: (NSTimer *) timer;
    149151
    150152- (void) setLimitGlobalEnabled: (id) sender;
  • trunk/macosx/Controller.m

    r735 r740  
    5252#define WINDOW_REGULAR_WIDTH    468.0
    5353
     54#define AUTO_SPEED_LIMIT_SECONDS    10.0
     55
    5456#define WEBSITE_URL @"http://transmission.m0k.org/"
    5557#define FORUM_URL   @"http://transmission.m0k.org/forum/"
     
    345347        [self showInfo: nil];
    346348   
     349    //timer to auto toggle speed limit
     350    fSpeedLimitTimer = [NSTimer scheduledTimerWithTimeInterval: AUTO_SPEED_LIMIT_SECONDS target: self
     351        selector: @selector(autoSpeedLimit:) userInfo: nil repeats: YES];
     352   
    347353    //timer to check for auto import every 15 seconds, must do after everything else is set up
    348354    fAutoImportTimer = [NSTimer scheduledTimerWithTimeInterval: 15.0 target: self
     
    398404    //stop timers
    399405    [fAutoImportTimer invalidate];
     406    [fSpeedLimitTimer invalidate];
    400407    [fTimer invalidate];
    401408   
     
    12021209}
    12031210
     1211- (void) autoSpeedLimit: (NSTimer *) timer
     1212{
     1213    BOOL autoOn, autoOff;
     1214    if (!(autoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"])
     1215            && !(autoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"]))
     1216        return;
     1217 
     1218    //do nothing if time to turn on and off are equal
     1219    int onHour, offHour;
     1220    if ((onHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"])
     1221            == (offHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"]) && autoOn && autoOff)
     1222        return;
     1223   
     1224    NSCalendarDate * currentDate = [NSCalendarDate calendarDate];
     1225    //do nothing if not within first few seconds of hour
     1226    if ([currentDate minuteOfHour] > 0 || [currentDate secondOfMinute] >= AUTO_SPEED_LIMIT_SECONDS)
     1227        return;
     1228   
     1229    if ([currentDate hourOfDay] == (fSpeedLimitEnabled ? offHour : onHour))
     1230        [self toggleSpeedLimit: nil];
     1231}
     1232
    12041233- (void) setLimitGlobalEnabled: (id) sender
    12051234{
  • trunk/macosx/Defaults.plist

    r735 r740  
    7575        <key>SpeedLimit</key>
    7676        <false/>
     77        <key>SpeedLimitAutoOff</key>
     78        <false/>
     79        <key>SpeedLimitAutoOffHour</key>
     80        <integer>0</integer>
     81        <key>SpeedLimitAutoOn</key>
     82        <false/>
     83        <key>SpeedLimitAutoOnHour</key>
     84        <integer>12</integer>
    7785        <key>SpeedLimitDownloadLimit</key>
    7886        <integer>10</integer>
  • trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib

    r737 r740  
    33        {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
    44        {CLASS = MenuButton; LANGUAGE = ObjC; SUPERCLASS = NSButton; },
     5        {CLASS = NSDatePicker; LANGUAGE = ObjC; SUPERCLASS = NSControl; },
    56        {
    67            ACTIONS = {
     
    910                setAutoImport = id;
    1011                setAutoSize = id;
     12                setAutoSpeedLimitCheck = id;
     13                setAutoSpeedLimitHour = id;
    1114                setBadge = id;
    1215                setDownloadLocation = id;
     
    5255                fRemoveDownloadingCheck = NSButton;
    5356                fSeedingSoundPopUp = NSPopUpButton;
     57                fSpeedLimitAutoOffCheck = NSButton;
     58                fSpeedLimitAutoOffField = NSTextField;
     59                fSpeedLimitAutoOnCheck = NSButton;
     60                fSpeedLimitAutoOnField = NSTextField;
    5461                fSpeedLimitDownloadField = NSTextField;
    5562                fSpeedLimitUploadField = NSTextField;
  • trunk/macosx/English.lproj/PrefsWindow.nib/info.nib

    r737 r740  
    88        <dict>
    99                <key>153</key>
    10                 <string>59 422 582 217 0 0 1152 842 </string>
     10                <string>95 422 582 291 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>84 320 582 304 0 0 1152 842 </string>
     14                <string>138 419 582 304 0 0 1152 842 </string>
    1515                <key>66</key>
    1616                <string>179 527 582 104 0 0 1152 842 </string>
     
    2424        <key>IBOpenObjects</key>
    2525        <array>
    26                 <integer>41</integer>
     26                <integer>153</integer>
    2727        </array>
    2828        <key>IBSystem Version</key>
  • trunk/macosx/PrefsController.h

    r737 r740  
    4646
    4747    IBOutlet NSTextField    * fUploadField, * fDownloadField,
    48                             * fSpeedLimitUploadField, * fSpeedLimitDownloadField;
    49     IBOutlet NSButton       * fUploadCheck, * fDownloadCheck;
     48                            * fSpeedLimitUploadField, * fSpeedLimitDownloadField,
     49                            * fSpeedLimitAutoOnField, * fSpeedLimitAutoOffField;
     50    IBOutlet NSButton       * fUploadCheck, * fDownloadCheck,
     51                            * fSpeedLimitAutoOnCheck, * fSpeedLimitAutoOffCheck;
    5052
    5153    IBOutlet NSTextField    * fPortField;
     
    8284- (void) setSpeedLimit: (id) sender;
    8385
     86- (void) setAutoSpeedLimitCheck: (id) sender;
     87- (void) setAutoSpeedLimitHour: (id) sender;
     88
    8489- (void) setLimit:          (id) sender;
    8590- (void) setLimitCheck:     (id) sender;
  • trunk/macosx/PrefsController.m

    r737 r740  
    7878        fHandle = handle;
    7979       
    80         [[self window] update]; //make sure nib is loaded right away
     80        NSWindow * window = [self window];
     81        [window setDelegate: window];
     82        [window update]; //make sure nib is loaded right away
    8183    }
    8284    return self;
     
    169171        tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1);
    170172    }
     173   
     174    //set auto speed limit
     175    BOOL speedLimitAutoOn = [fDefaults boolForKey: @"SpeedLimitAutoOn"];
     176    int speedLimitAutoOnHour = [fDefaults integerForKey: @"SpeedLimitAutoOnHour"];
     177   
     178    [fSpeedLimitAutoOnCheck setState: speedLimitAutoOn];
     179    [fSpeedLimitAutoOnField setIntValue: speedLimitAutoOnHour];
     180    [fSpeedLimitAutoOnField setEnabled: speedLimitAutoOn];
     181   
     182    BOOL speedLimitAutoOff = [fDefaults boolForKey: @"SpeedLimitAutoOff"];
     183    int speedLimitAutoOffHour = [fDefaults integerForKey: @"SpeedLimitAutoOffHour"];
     184   
     185    [fSpeedLimitAutoOffCheck setState: speedLimitAutoOff];
     186    [fSpeedLimitAutoOffField setIntValue: speedLimitAutoOffHour];
     187    [fSpeedLimitAutoOffField setEnabled: speedLimitAutoOff];
    171188   
    172189    //set ratio limit
     
    376393        if (![fDefaults boolForKey: @"SpeedLimit"])
    377394        {
     395            int realLimit = [check state] ? limit : -1;
    378396            if (sender == fUploadField)
    379                 tr_setUploadLimit(fHandle, [fUploadCheck state] ? limit : -1);
     397                tr_setUploadLimit(fHandle, realLimit);
    380398            else
    381                 tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? limit : -1);
     399                tr_setDownloadLimit(fHandle, realLimit);
    382400        }
    383401       
     
    482500}
    483501
     502- (void) setAutoSpeedLimitCheck: (id) sender
     503{
     504    NSString * key;
     505    NSTextField * field;
     506    if (sender == fSpeedLimitAutoOnCheck)
     507    {
     508        key = @"SpeedLimitAutoOn";
     509        field = fSpeedLimitAutoOnField;
     510    }
     511    else
     512    {
     513        key = @"SpeedLimitAutoOff";
     514        field = fSpeedLimitAutoOffField;
     515    }
     516   
     517    BOOL check = [sender state] == NSOnState;
     518    [self setAutoSpeedLimitHour: field];
     519    [field setEnabled: check];
     520   
     521    [fDefaults setBool: check forKey: key];
     522}
     523
     524- (void) setAutoSpeedLimitHour: (id) sender
     525{
     526    NSString * key = (sender == fSpeedLimitAutoOnField) ? @"SpeedLimitAutoOnHour" : @"SpeedLimitAutoOffHour";
     527
     528    int hour = [sender intValue];
     529    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", hour]] || hour < 0 || hour > 23)
     530    {
     531        NSBeep();
     532        hour = [fDefaults integerForKey: key];
     533        [sender setIntValue: hour];
     534    }
     535    else
     536        [fDefaults setInteger: hour forKey: key];
     537}
     538
    484539- (void) setRatio: (id) sender
    485540{
     
    733788}
    734789
    735 - (void) windowWillClose: (NSNotification *) notification
    736 {
    737     [[self window] makeFirstResponder: nil];
    738 }
    739 
    740790@end
    741791
  • trunk/macosx/PrefsWindow.m

    r726 r740  
    2727@implementation PrefsWindow
    2828
    29 -(void) keyDown: (NSEvent *) event
     29- (void) keyDown: (NSEvent *) event
    3030{
     31    [super keyDown: event];
    3132    if ([event keyCode] == 53) //esc key
    3233        [self close];
    3334}
    3435
     36- (void) windowWillClose: (NSNotification *) notification
     37{
     38    [self makeFirstResponder: nil]; //essentially saves changes on window close
     39}
     40
    3541@end
Note: See TracChangeset for help on using the changeset viewer.