// // iLyrics.m // iLyrics // // Created by Kim Wittenburg on 19.06.12. // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "iLyrics.h" @implementation iLyrics iLyrics *ilyrics; @synthesize lyricsHosters; @synthesize magistrix; @synthesize songtexte; @synthesize mp3Lyrics; @synthesize iTunes; @synthesize spotify; +(iLyrics *)sharediLyrics { if (ilyrics == nil) { ilyrics = [[iLyrics alloc] init]; } return ilyrics; } -(id)init { self = [super init]; if (self) { iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"]; spotify = [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"]; magistrix = [[Magistrix alloc] init]; songtexte = [[Songtexte alloc] init]; //mp3Lyrics = [[MP3Lyrics alloc] init]; lyricsHosters = [NSMutableArray arrayWithObjects:/*magistrix, */songtexte, /*mp3Lyrics,*/ nil]; [self loadFromDefaults:[NSUserDefaults standardUserDefaults]]; } return self; } -(void)loadFromDefaults:(NSUserDefaults *)defaults { NSArray *hosterNames = [defaults objectForKey:@"Lyrics Hosters"]; NSMutableArray *reorderedHosters = [[NSMutableArray alloc] init]; for (NSString *name in hosterNames) { id hoster = [self hosterWithName:name]; if (hoster) { [reorderedHosters addObject:hoster]; } } if ([reorderedHosters count] == [lyricsHosters count]) { lyricsHosters = reorderedHosters; } } -(id)preferredHoster { return [lyricsHosters objectAtIndex:0]; } -(id)hosterWithName:(NSString *)name { for (id hoster in lyricsHosters) { if ([name isEqualToString:[hoster name]]) { return hoster; } } return nil; } -(void)saveToDefaults:(NSUserDefaults *)defaults { NSMutableArray *hosterNames = [[NSMutableArray alloc] init]; for (id hoster in lyricsHosters) { [hosterNames addObject:[hoster name]]; } [defaults setObject:hosterNames forKey:@"Lyrics Hosters"]; } @end