Changeset 332 for trunk/Cocoa


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

version.plist: Not needed.

Info.plist: Updated for 1.4njr2.

AUTHORS: Updated Onne Gorter's email address and added mine.

AntiRSI.[hm]: Added dock badge session timer display and auto-reset options. Updated URLs to point to my Web site; should probably just switch to Sparkle.

CTBadge: Added customized version.

English.lproj/InfoPlist.strings: Updated for 1.4njr2; credit myself and Chad; remove Onne Gorter's URL.

English.lproj/MainMenu.nib: Preference changes; add cmd-R for manual reset.

Location:
trunk/Cocoa/AntiRSI
Files:
10 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/AntiRSI

    • Property svn:ignore set to
      build
  • trunk/Cocoa/AntiRSI/AUTHORS

    r327 r332  
    1 Onne Gorter <o.gorter@student.utwente.nl>
     1Onne Gorter <o.gorter@gmail.com>
     2Nicholas Riley <antirsi@sabi.net>
  • trunk/Cocoa/AntiRSI/AntiRSI.h

    r331 r332  
    2121#import <Cocoa/Cocoa.h>
    2222#import "AntiRSIView.h"
     23#import "CTBadge.h"
    2324
    24 #define sLatestVersionURL @"http://tech.inhelsinki.nl/antirsi/antirsi_version.txt"
    25 #define sURL @"http://tech.inhelsinki.nl/antirsi/"
    26 #define sVersion @"1.4"
     25#define sLatestVersionURL @"http://web.sabi.net/nriley/software/AntiRSI-version.txt"
     26#define sURL @"http://web.sabi.net/nriley/software/#antirsi"
     27#define sVersion @"1.4njr2"
    2728
    2829typedef enum _AntiRSIState {
     
    4344    IBOutlet NSTextField *status;
    4445        IBOutlet NSTextField *version; // XXX unused?
     46    IBOutlet NSDatePicker *reset_session_time;
    4547   
    4648    // dock menu
     
    5153        NSImage* dock_image;
    5254        NSImage* original_dock_image;
     55    CTBadge* dock_badge;
    5356       
    5457        // window to display the views in
     
    6770    double session_t;
    6871        double date;
     72    double reset_session_date;
    6973               
    7074        // various timing lengths
     
    7983        bool lock_focus;
    8084        bool draw_dock_image;
     85        bool draw_dock_badge;
    8186        bool draw_dock_image_q;
     87    bool reset_session_timer_daily;
     88    bool reset_session_timer_after;
     89    NSDate *reset_session_timer_time;
     90    int reset_session_timer_after_hours;
    8291       
    8392        // various colors
  • trunk/Cocoa/AntiRSI/AntiRSI.m

    r331 r332  
    102102        [elapsed autorelease];
    103103        elapsed=[c retain];
     104    [dock_badge setBadgeColor:elapsed];
    104105        [self drawDockImage];
    105106}
     
    152153        original_dock_image = [NSImage imageNamed:@"AntiRSI"];
    153154        draw_dock_image_q = YES;
     155    dock_badge = [[CTBadge systemBadge] retain];
     156    [dock_badge setBadgeColor:elapsed];
    154157       
    155158        // setup main window that will show either micropause or workbreak
     
    165168        [main_window center];
    166169        [main_window setContentView:view];
     170    NSTimeZone *utcZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
     171    [reset_session_time setTimeZone:utcZone];
    167172    [progress setEnabled:NO];
    168173    NSFont *myriad = [NSFont fontWithName: @"Myriad" size: 40];
     
    181186       
    182187        // 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];
    195208
    196209        // bind to defauls controller
    197         id dc = [NSUserDefaultsController sharedUserDefaultsController];
    198210        [self bind:@"micro_pause_period" toObject:dc withKeyPath:@"values.micro_pause_period" options:nil];
    199211        [self bind:@"micro_pause_duration" toObject:dc withKeyPath:@"values.micro_pause_duration" options:nil];
     
    202214        [self bind:@"sample_interval" toObject:dc withKeyPath:@"values.sample_interval" options:nil];
    203215        [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];
    204217        [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];
    205222        NSDictionary* unarchive = [NSDictionary dictionaryWithObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"];
    206223        [self bind:@"elapsed" toObject:dc withKeyPath:@"values.elapsed" options:unarchive];
    207224        [self bind:@"taking" toObject:dc withKeyPath:@"values.taking" options:unarchive];
    208225        [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   
    210230        // alert every binding
    211         [[NSUserDefaultsController sharedUserDefaultsController] revert:self];
     231        [dc revert:self];
    212232
    213233        // start the timer
     
    218238}
    219239
     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
    220264// tick every second and update status
    221265- (void)tick:(NSTimer *)timer
    222266{
    223267        // calculate time since last tick
    224         double new_date = [NSDate timeIntervalSinceReferenceDate];
    225         double tick_time = new_date - date;
     268        NSTimeInterval new_date = [NSDate timeIntervalSinceReferenceDate];
     269        NSTimeInterval tick_time = new_date - date;
    226270        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   
    228278        // check if we are still on track of normal time, otherwise we might have slept or something
    229279        if (tick_time > work_break_duration) {
     
    268318    }
    269319    // 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    }
    270325   
    271326        // calculate slack, this gives a sort of 3 history filtered idea.
     
    476531        [p stroke];
    477532       
     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   
    478546        [dock_image unlockFocus];
    479547
  • trunk/Cocoa/AntiRSI/AntiRSI.xcodeproj/project.pbxproj

    r330 r332  
    88
    99/* Begin PBXBuildFile section */
     10                464D9ADE0C6A622B005A0582 /* CTBadge.h in Headers */ = {isa = PBXBuildFile; fileRef = 464D9ADA0C6A622B005A0582 /* CTBadge.h */; };
     11                464D9ADF0C6A622B005A0582 /* CTBadge.m in Sources */ = {isa = PBXBuildFile; fileRef = 464D9ADB0C6A622B005A0582 /* CTBadge.m */; };
     12                464D9AE00C6A622B005A0582 /* CTGradient.h in Headers */ = {isa = PBXBuildFile; fileRef = 464D9ADC0C6A622B005A0582 /* CTGradient.h */; };
     13                464D9AE10C6A622B005A0582 /* CTGradient.m in Sources */ = {isa = PBXBuildFile; fileRef = 464D9ADD0C6A622B005A0582 /* CTGradient.m */; };
     14                464D9B790C6A760B005A0582 /* CTBadge_1.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 464D9B750C6A760B005A0582 /* CTBadge_1.pdf */; };
     15                464D9B7A0C6A760B005A0582 /* CTBadge_3.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 464D9B760C6A760B005A0582 /* CTBadge_3.pdf */; };
     16                464D9B7B0C6A760B005A0582 /* CTBadge_4.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 464D9B770C6A760B005A0582 /* CTBadge_4.pdf */; };
     17                464D9B7C0C6A760B005A0582 /* CTBadge_5.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 464D9B780C6A760B005A0582 /* CTBadge_5.pdf */; };
    1018                4DB6164E061B59EA002EF355 /* AntiRSI.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DB6164C061B59EA002EF355 /* AntiRSI.h */; };
    1119                4DB6164F061B59EA002EF355 /* AntiRSI.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DB6164D061B59EA002EF355 /* AntiRSI.m */; };
     
    3139                29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
    3240                32CA4F630368D1EE00C91783 /* AntiRSI_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AntiRSI_Prefix.pch; sourceTree = "<group>"; };
     41                464D9ADA0C6A622B005A0582 /* CTBadge.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = CTBadge.h; path = CTBadge/CTBadge.h; sourceTree = "<group>"; };
     42                464D9ADB0C6A622B005A0582 /* CTBadge.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; name = CTBadge.m; path = CTBadge/CTBadge.m; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
     43                464D9ADC0C6A622B005A0582 /* CTGradient.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = CTGradient.h; path = CTBadge/CTGradient.h; sourceTree = "<group>"; };
     44                464D9ADD0C6A622B005A0582 /* CTGradient.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = CTGradient.m; path = CTBadge/CTGradient.m; sourceTree = "<group>"; };
     45                464D9B750C6A760B005A0582 /* CTBadge_1.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = CTBadge_1.pdf; sourceTree = "<group>"; };
     46                464D9B760C6A760B005A0582 /* CTBadge_3.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = CTBadge_3.pdf; sourceTree = "<group>"; };
     47                464D9B770C6A760B005A0582 /* CTBadge_4.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = CTBadge_4.pdf; sourceTree = "<group>"; };
     48                464D9B780C6A760B005A0582 /* CTBadge_5.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = CTBadge_5.pdf; sourceTree = "<group>"; };
    3349                4DB6164C061B59EA002EF355 /* AntiRSI.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AntiRSI.h; sourceTree = "<group>"; };
    3450                4DB6164D061B59EA002EF355 /* AntiRSI.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = AntiRSI.m; sourceTree = "<group>"; wrapsLines = 1; };
     
    99115                        children = (
    100116                                080E96DDFE201D6D7F000001 /* Classes */,
     117                                464D9AE40C6A622F005A0582 /* CTBadge */,
    101118                                29B97315FDCFA39411CA2CEA /* Other Sources */,
    102119                                29B97317FDCFA39411CA2CEA /* Resources */,
     
    134151                        );
    135152                        name = Frameworks;
     153                        sourceTree = "<group>";
     154                };
     155                464D9AE40C6A622F005A0582 /* CTBadge */ = {
     156                        isa = PBXGroup;
     157                        children = (
     158                                464D9B740C6A760B005A0582 /* badges */,
     159                                464D9ADA0C6A622B005A0582 /* CTBadge.h */,
     160                                464D9ADB0C6A622B005A0582 /* CTBadge.m */,
     161                                464D9ADC0C6A622B005A0582 /* CTGradient.h */,
     162                                464D9ADD0C6A622B005A0582 /* CTGradient.m */,
     163                        );
     164                        name = CTBadge;
     165                        sourceTree = "<group>";
     166                };
     167                464D9B740C6A760B005A0582 /* badges */ = {
     168                        isa = PBXGroup;
     169                        children = (
     170                                464D9B750C6A760B005A0582 /* CTBadge_1.pdf */,
     171                                464D9B760C6A760B005A0582 /* CTBadge_3.pdf */,
     172                                464D9B770C6A760B005A0582 /* CTBadge_4.pdf */,
     173                                464D9B780C6A760B005A0582 /* CTBadge_5.pdf */,
     174                        );
     175                        name = badges;
     176                        path = CTBadge/badges;
    136177                        sourceTree = "<group>";
    137178                };
     
    147188                                4DF73F68061E136200B0D9C9 /* AntiRSIView.h in Headers */,
    148189                                E1F60362098592D800806C3B /* AntiRSILevelIndicator.h in Headers */,
     190                                464D9ADE0C6A622B005A0582 /* CTBadge.h in Headers */,
     191                                464D9AE00C6A622B005A0582 /* CTGradient.h in Headers */,
    149192                        );
    150193                        runOnlyForDeploymentPostprocessing = 0;
     
    202245                                8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
    203246                                4DF73F86061E155C00B0D9C9 /* AntiRSI.icns in Resources */,
     247                                464D9B790C6A760B005A0582 /* CTBadge_1.pdf in Resources */,
     248                                464D9B7A0C6A760B005A0582 /* CTBadge_3.pdf in Resources */,
     249                                464D9B7B0C6A760B005A0582 /* CTBadge_4.pdf in Resources */,
     250                                464D9B7C0C6A760B005A0582 /* CTBadge_5.pdf in Resources */,
    204251                        );
    205252                        runOnlyForDeploymentPostprocessing = 0;
     
    216263                                4DF73F67061E136200B0D9C9 /* AntiRSIView.m in Sources */,
    217264                                E1F60361098592D800806C3B /* AntiRSILevelIndicator.m in Sources */,
     265                                464D9ADF0C6A622B005A0582 /* CTBadge.m in Sources */,
     266                                464D9AE10C6A622B005A0582 /* CTGradient.m in Sources */,
    218267                        );
    219268                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Cocoa/AntiRSI/English.lproj

    • Property svn:ignore set to
      *~*
  • trunk/Cocoa/AntiRSI/English.lproj/MainMenu.nib/classes.nib

    r330 r332  
    1616                postpone = NSButton;
    1717                progress = NSLevelIndicator;
     18                "reset_session_time" = NSDatePicker;
    1819                "session_time" = NSTextField;
    1920                "session_time_item" = NSMenuItem;
     
    3233        {CLASS = AntiRSIView; LANGUAGE = ObjC; SUPERCLASS = NSView; },
    3334        {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
     35        {CLASS = NSDatePicker; LANGUAGE = ObjC; SUPERCLASS = NSControl; },
    3436        {CLASS = NSLevelIndicator; LANGUAGE = ObjC; SUPERCLASS = NSControl; }
    3537    );
  • trunk/Cocoa/AntiRSI/English.lproj/MainMenu.nib/info.nib

    r331 r332  
    88        <dict>
    99                <key>259</key>
    10                 <string>688 524 300 322 0 0 1680 1028 </string>
     10                <string>668 524 300 322 0 0 1680 1028 </string>
    1111                <key>29</key>
    1212                <string>276 845 249 44 0 0 1680 1028 </string>
     
    2020        <key>IBOpenObjects</key>
    2121        <array>
    22                 <integer>21</integer>
    2322                <integer>259</integer>
    2423        </array>
  • trunk/Cocoa/AntiRSI/Info.plist

    r330 r332  
    1818        <string>ONNE</string>
    1919        <key>CFBundleVersion</key>
    20         <string>1.4njr1</string>
     20        <string>1.4njr2</string>
    2121        <key>NSMainNibFile</key>
    2222        <string>MainMenu</string>
Note: See TracChangeset for help on using the changeset viewer.