// // TopController.m // Top // // Created by Simon Brenner on 2008-01-01. // Copyright 2008 __MyCompanyName__. All rights reserved. // #import "TopController.h" #import "PreferencesController.h" #import "ProcessLister.h" #import "PsRunner.h" @implementation TopController -(void)awakeFromNib { printf("+awakeFromNib\n"); statusItem=[[[NSStatusBar systemStatusBar]statusItemWithLength:NSVariableStatusItemLength] retain]; pollrate=[[[NSUserDefaults standardUserDefaults] stringForKey:CDCPollRate] doubleValue]; mainTimer=[[NSTimer scheduledTimerWithTimeInterval:(pollrate) target:self selector:@selector(timer:) userInfo:nil repeats:YES] retain]; [statusItem setHighlightMode:YES]; [statusItem setTitle:@"*"]; [statusItem setToolTip:NSLocalizedString(@"StartingTop",@"StartingTop")]; [statusItem setMenu:theMenu]; [statusItem setEnabled:YES]; [mainTimer fire]; [self listProcesses: self]; printf("-awakeFromNib\n"); } +(void)initialize { NSMutableDictionary *defaultValues=[NSMutableDictionary dictionary]; [defaultValues setObject:@"1" forKey:CDCPollRate]; [defaultValues setObject:@"0" forKey:CDCStartAtLogin]; [[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues]; } -(id)init { if(self=[super init]) { // For listening to changes in preferences.... NSNotificationCenter *nc; nc=[NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(handlePrefsChange:) name:CDCPrefsChanged object:nil]; } return self; } -(void)handlePrefsChange:(NSNotification *)aNotification { [mainTimer invalidate]; [mainTimer release]; pollrate=[[[NSUserDefaults standardUserDefaults] stringForKey:CDCPollRate] doubleValue]; mainTimer=[[NSTimer scheduledTimerWithTimeInterval:(pollrate) target:self selector:@selector(timer:) userInfo:nil repeats:YES] retain]; [mainTimer fire]; } -(void)timer:(NSTimer*)timer { //printf("timer called!"); } -(IBAction)openPreferences:(id)sender { printf("+openPreferences\n"); if(!preferencesController) preferencesController=[[PreferencesController alloc] init]; [NSApp activateIgnoringOtherApps:YES]; [[preferencesController window] makeKeyAndOrderFront:nil]; printf("-openPreferences\n"); } -(IBAction)openAbout:(id)sender { [NSApp orderFrontStandardAboutPanel:nil]; } -(IBAction)listProcesses:(id)sender { printf("+listProcesses\n"); /*NSMutableArray *array = [ProcessLister allProcesses]; for (int i=0; i < [array count]; i++) { NSString *str = [array objectAtIndex: i]; //printf("Proc name: \"%s\"\n", [str cString]); } [array release];*/ PsRunner *psr = [PsRunner new]; NSArray *arr = [psr run]; printf("-listProcesses\n"); } @end