Changeset 333 for trunk


Ignore:
Timestamp:
08/09/07 09:03:58 (17 years ago)
Author:
Nicholas Riley
Message:

AntiRSI.[hm]: Replaced unnecessary use of KVO on reset_session_timer_time with setReset_session_timer_time; now reset_session_timer_time is a NSCalendarDate that doesn't need converting every time it's used. Invalidate badge_session_minutes so the badge changes when the work color is adjusted in preferences.

Location:
trunk/Cocoa/AntiRSI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/AntiRSI/AntiRSI.h

    r332 r333  
    8787    bool reset_session_timer_daily;
    8888    bool reset_session_timer_after;
    89     NSDate *reset_session_timer_time;
     89    NSCalendarDate *reset_session_timer_time;
    9090    int reset_session_timer_after_hours;
    9191       
  • trunk/Cocoa/AntiRSI/AntiRSI.m

    r332 r333  
    2626extern CFTimeInterval CGSSecondsSinceLastInputEvent(unsigned long eventType);
    2727
     28static int badge_session_minutes = -1;
     29
    2830@implementation AntiRSI
     31
     32- (void)computeResetSessionDate;
     33{
     34    NSCalendarDate *now = [NSCalendarDate calendarDate];
     35    NSCalendarDate *reset =
     36        [NSCalendarDate dateWithYear:[now yearOfCommonEra]
     37                               month:[now monthOfYear]
     38                                 day:[now dayOfMonth]
     39                                hour:[reset_session_timer_time hourOfDay]
     40                              minute:[reset_session_timer_time minuteOfHour]
     41                              second:0
     42                            timeZone:[NSTimeZone systemTimeZone]];
     43    if ([now compare:reset] != NSOrderedAscending)
     44        reset = [reset dateByAddingYears:0 months:0 days:1 hours:0 minutes:0 seconds:0];
     45    reset_session_date = [reset timeIntervalSinceReferenceDate];
     46}
    2947
    3048// bindings methods
     
    5371{       work_break_period = 60 * round(f); }
    5472
     73- (void)setReset_session_timer_time:(NSDate *)d;
     74{
     75    if (reset_session_timer_time != nil)
     76        [reset_session_timer_time autorelease];
     77    reset_session_timer_time = [[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:[d timeIntervalSinceReferenceDate]];
     78    [reset_session_timer_time setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
     79    [self computeResetSessionDate];
     80}
     81
    5582- (void)installTimer:(double)interval
    5683{
     
    103130        elapsed=[c retain];
    104131    [dock_badge setBadgeColor:elapsed];
     132    badge_session_minutes = -1;
    105133        [self drawDockImage];
    106134}
     
    225253        [self bind:@"background" toObject:dc withKeyPath:@"values.background" options:unarchive];
    226254   
    227     // watch for timer changes
    228     [dc addObserver:self forKeyPath:@"values.reset_session_timer_time" options:0 context:NULL];
    229    
    230255        // alert every binding
    231256        [dc revert:self];
     
    236261        // about dialog
    237262        [version setStringValue:[NSString stringWithFormat:@"Version %@", sVersion]];
    238 }
    239 
    240 - (void)computeResetSessionDate;
    241 {
    242     NSTimeZone *systemZone = [NSTimeZone systemTimeZone];
    243     NSCalendarDate *today = [NSCalendarDate calendarDate];
    244     NSCalendarDate *reset = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:[reset_session_timer_time timeIntervalSinceReferenceDate]];
    245     [reset setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    246     reset = [NSCalendarDate dateWithYear:[today yearOfCommonEra]
    247                                    month:[today monthOfYear]
    248                                      day:[today dayOfMonth]
    249                                     hour:[reset hourOfDay]
    250                                   minute:[reset minuteOfHour]
    251                                   second:0
    252                                 timeZone:systemZone];
    253     if ([today compare:reset] != NSOrderedAscending)
    254         reset = [reset dateByAddingYears:0 months:0 days:1 hours:0 minutes:0 seconds:0];
    255     reset_session_date = [reset timeIntervalSinceReferenceDate];
    256 }
    257 
    258 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
    259 {
    260     if ([keyPath isEqualToString:@"values.reset_session_timer_time"])
    261         [self computeResetSessionDate];
    262263}
    263264
     
    534535    if (draw_dock_badge) {
    535536        static NSImage *badge = nil;
    536         static int badge_session_minutes = -1;
    537537        int session_minutes = (int)session_t / 60;
    538538        if (badge_session_minutes != session_minutes) {
Note: See TracChangeset for help on using the changeset viewer.