Changeset 332 for trunk/Cocoa/AntiRSI/AntiRSI.m
- Timestamp:
- 08/09/07 05:48:07 (17 years ago)
- Location:
- trunk/Cocoa/AntiRSI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/AntiRSI
-
Property svn:ignore
set to
build
-
Property svn:ignore
set to
-
trunk/Cocoa/AntiRSI/AntiRSI.m
r331 r332 102 102 [elapsed autorelease]; 103 103 elapsed=[c retain]; 104 [dock_badge setBadgeColor:elapsed]; 104 105 [self drawDockImage]; 105 106 } … … 152 153 original_dock_image = [NSImage imageNamed:@"AntiRSI"]; 153 154 draw_dock_image_q = YES; 155 dock_badge = [[CTBadge systemBadge] retain]; 156 [dock_badge setBadgeColor:elapsed]; 154 157 155 158 // setup main window that will show either micropause or workbreak … … 165 168 [main_window center]; 166 169 [main_window setContentView:view]; 170 NSTimeZone *utcZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; 171 [reset_session_time setTimeZone:utcZone]; 167 172 [progress setEnabled:NO]; 168 173 NSFont *myriad = [NSFont fontWithName: @"Myriad" size: 40]; … … 181 186 182 187 // create initial values 183 NSMutableDictionary* initial = [NSMutableDictionary dictionaryWithCapacity:10]; 184 [initial setObject:[NSNumber numberWithFloat:4] forKey:@"micro_pause_period"]; 185 [initial setObject:[NSNumber numberWithFloat:13] forKey:@"micro_pause_duration"]; 186 [initial setObject:[NSNumber numberWithFloat:50] forKey:@"work_break_period"]; 187 [initial setObject:[NSNumber numberWithFloat:8] forKey:@"work_break_duration"]; 188 [initial setObject:@"Smooth" forKey:@"sample_interval"]; 189 [initial setObject:[NSNumber numberWithBool:YES] forKey:@"draw_dock_image"]; 190 [initial setObject:[NSNumber numberWithBool:NO] forKey:@"lock_focus"]; 191 [initial setObject:[NSArchiver archivedDataWithRootObject:elapsed] forKey:@"elapsed"]; 192 [initial setObject:[NSArchiver archivedDataWithRootObject:taking] forKey:@"taking"]; 193 [initial setObject:[NSArchiver archivedDataWithRootObject:background] forKey:@"background"]; 194 [[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:initial]; 188 NSUserDefaultsController *dc = [NSUserDefaultsController sharedUserDefaultsController]; 189 NSMutableDictionary* initial = [NSMutableDictionary dictionaryWithObjectsAndKeys: 190 [NSNumber numberWithFloat:4], @"micro_pause_period", 191 [NSNumber numberWithFloat:13], @"micro_pause_duration", 192 [NSNumber numberWithFloat:50], @"work_break_period", 193 [NSNumber numberWithFloat:8], @"work_break_duration", 194 @"Smooth", @"sample_interval", 195 [NSNumber numberWithBool:YES], @"draw_dock_image", 196 [NSNumber numberWithBool:YES], @"draw_dock_badge", 197 [NSNumber numberWithBool:NO], @"lock_focus", 198 [NSNumber numberWithBool:NO], @"reset_session_timer_daily", 199 [NSNumber numberWithBool:NO], @"reset_session_timer_after", 200 [NSCalendarDate dateWithYear:2000 month:1 day:1 hour:6 minute:0 second:0 timeZone:utcZone], @"reset_session_timer_time", 201 [NSNumber numberWithInt:8], @"reset_session_timer_after_hours", 202 [NSArchiver archivedDataWithRootObject:elapsed], @"elapsed", 203 [NSArchiver archivedDataWithRootObject:taking], @"taking", 204 [NSArchiver archivedDataWithRootObject:background], @"background", 205 nil]; 206 [[NSUserDefaults standardUserDefaults] registerDefaults:initial]; 207 [dc setInitialValues:initial]; 195 208 196 209 // bind to defauls controller 197 id dc = [NSUserDefaultsController sharedUserDefaultsController];198 210 [self bind:@"micro_pause_period" toObject:dc withKeyPath:@"values.micro_pause_period" options:nil]; 199 211 [self bind:@"micro_pause_duration" toObject:dc withKeyPath:@"values.micro_pause_duration" options:nil]; … … 202 214 [self bind:@"sample_interval" toObject:dc withKeyPath:@"values.sample_interval" options:nil]; 203 215 [self bind:@"draw_dock_image" toObject:dc withKeyPath:@"values.draw_dock_image" options:nil]; 216 [self bind:@"draw_dock_badge" toObject:dc withKeyPath:@"values.draw_dock_badge" options:nil]; 204 217 [self bind:@"lock_focus" toObject:dc withKeyPath:@"values.lock_focus" options:nil]; 218 [self bind:@"reset_session_timer_daily" toObject:dc withKeyPath:@"values.reset_session_timer_daily" options:nil]; 219 [self bind:@"reset_session_timer_after" toObject:dc withKeyPath:@"values.reset_session_timer_after" options:nil]; 220 [self bind:@"reset_session_timer_time" toObject:dc withKeyPath:@"values.reset_session_timer_time" options:nil]; 221 [self bind:@"reset_session_timer_after_hours" toObject:dc withKeyPath:@"values.reset_session_timer_after_hours" options:nil]; 205 222 NSDictionary* unarchive = [NSDictionary dictionaryWithObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"]; 206 223 [self bind:@"elapsed" toObject:dc withKeyPath:@"values.elapsed" options:unarchive]; 207 224 [self bind:@"taking" toObject:dc withKeyPath:@"values.taking" options:unarchive]; 208 225 [self bind:@"background" toObject:dc withKeyPath:@"values.background" options:unarchive]; 209 226 227 // watch for timer changes 228 [dc addObserver:self forKeyPath:@"values.reset_session_timer_time" options:0 context:NULL]; 229 210 230 // alert every binding 211 [ [NSUserDefaultsController sharedUserDefaultsController]revert:self];231 [dc revert:self]; 212 232 213 233 // start the timer … … 218 238 } 219 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]; 262 } 263 220 264 // tick every second and update status 221 265 - (void)tick:(NSTimer *)timer 222 266 { 223 267 // calculate time since last tick 224 doublenew_date = [NSDate timeIntervalSinceReferenceDate];225 doubletick_time = new_date - date;268 NSTimeInterval new_date = [NSDate timeIntervalSinceReferenceDate]; 269 NSTimeInterval tick_time = new_date - date; 226 270 date = new_date; 227 271 272 if (reset_session_timer_daily && date >= reset_session_date) { 273 [self resetSession:nil]; 274 [self computeResetSessionDate]; 275 return; 276 } 277 228 278 // check if we are still on track of normal time, otherwise we might have slept or something 229 279 if (tick_time > work_break_duration) { … … 268 318 } 269 319 // NSLog(@"CGEventSource %.2f, CGS %.2f", idle_time, cgs_idle_time); 320 321 if (reset_session_timer_after && idle_time > reset_session_timer_after_hours * 3600) { 322 [self resetSession:nil]; 323 return; 324 } 270 325 271 326 // calculate slack, this gives a sort of 3 history filtered idea. … … 476 531 [p stroke]; 477 532 533 // draw session time 534 if (draw_dock_badge) { 535 static NSImage *badge = nil; 536 static int badge_session_minutes = -1; 537 int session_minutes = (int)session_t / 60; 538 if (badge_session_minutes != session_minutes) { 539 if (badge != nil) [badge release]; 540 badge = [[dock_badge badgeOverlayImageForString: [NSString stringWithFormat:@"%d:%02d", session_minutes / 60, session_minutes % 60] insetX: 3 y: 3] retain]; 541 badge_session_minutes = session_minutes; 542 } 543 [badge compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver]; 544 } 545 478 546 [dock_image unlockFocus]; 479 547
Note:
See TracChangeset
for help on using the changeset viewer.