Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ilyrics/iLyrics/AppDelegate.m
Kim Wittenburg cf3b960d85 Release No. 1.1
Added Auto-Lyrics
Improved the preferences window
2012-06-17 01:06:46 +02:00

103 lines
3.0 KiB
Objective-C

//
// 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];
[[AutoLyrics autoLyrics] saveToDefaults: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