// // AppDelegate.m // iLyrics // // Created by Kim Wittenburg on 10.06.12. // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "AppDelegate.h" #import "Magistrix.h" @implementation AppDelegate { iTunesApplication *iTunes; NSArray *keyTokens; NSMutableArray *searchFormat; Magistrix *magistrix; } @synthesize window; @synthesize mainController; @synthesize preferencesWindow; @synthesize preferencesController; @synthesize quitWhenAllWindowClosedCheckBox; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { magistrix = [[Magistrix alloc] init]; [preferencesController addHoster:magistrix]; keyTokens = [NSArray arrayWithObjects:@"%name%", @"%artist%", @"%album%", nil]; [window setExcludedFromWindowsMenu:YES]; iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [quitWhenAllWindowClosedCheckBox setState:[defaults boolForKey:@"Quit when all windows are closed"]?NSOnState:NSOffState]; [mainController loadFromDefaults:defaults]; } -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setBool:[quitWhenAllWindowClosedCheckBox state] == NSOnState forKey:@"Quit when all windows are closed"]; [mainController saveToDefalts:defaults]; [defaults synchronize]; return NSTerminateNow; } -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return [quitWhenAllWindowClosedCheckBox state] == NSOnState; } -(BOOL)validateMenuItem:(NSMenuItem *)menuItem { SEL action = [menuItem action]; if (action == @selector(runitunes:)) { return ![iTunes isRunning]; } if (action == @selector(quitiTunes:) || action == @selector(playPauseiTunes:) || action == @selector(previousTrack:) || action == @selector(nextTrack:)) { return [iTunes isRunning]; } return [self respondsToSelector:action]; } /* - (IBAction)showPreferences:(id)sender { [searchFormatField setObjectValue:searchFormat]; [preferencesWindow makeKeyAndOrderFront:sender]; } - (IBAction)searchFormatChanged:(id)sender { NSArray *tokens = [searchFormatField objectValue]; [searchFormat removeAllObjects]; [searchFormat addObjectsFromArray:tokens]; } */ -(NSString *)searchFormat { NSMutableString *string = [[NSMutableString alloc] init]; for (NSString *token in searchFormat) { [string appendString:token]; } return string; } - (IBAction)runiTunes:(id)sender { [iTunes run]; [window update]; } - (IBAction)quitiTunes:(id)sender { [iTunes quit]; [window update]; } - (IBAction)playPauseiTunes:(id)sender { [iTunes playpause]; [window update]; } - (IBAction)previousTrack:(id)sender { [iTunes previousTrack]; } - (IBAction)nextTrack:(id)sender { [iTunes nextTrack]; } @end