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/iLyrics.m
Kim Wittenburg 221b43e29f Archive Project
2017-07-25 16:38:32 +02:00

79 lines
2.1 KiB
Objective-C
Executable File

//
// 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<LyricsHoster> hoster = [self hosterWithName:name];
if (hoster) {
[reorderedHosters addObject:hoster];
}
}
if ([reorderedHosters count] == [lyricsHosters count]) {
lyricsHosters = reorderedHosters;
}
}
-(id<LyricsHoster>)preferredHoster {
return [lyricsHosters objectAtIndex:0];
}
-(id<LyricsHoster>)hosterWithName:(NSString *)name {
for (id<LyricsHoster> hoster in lyricsHosters) {
if ([name isEqualToString:[hoster name]]) {
return hoster;
}
}
return nil;
}
-(void)saveToDefaults:(NSUserDefaults *)defaults {
NSMutableArray *hosterNames = [[NSMutableArray alloc] init];
for (id<LyricsHoster> hoster in lyricsHosters) {
[hosterNames addObject:[hoster name]];
}
[defaults setObject:hosterNames forKey:@"Lyrics Hosters"];
}
@end