Archived
1

-Fixed a search bug: Returned false results when having a & in query

-Added Functionality: Send Lyrics to matching iTunes Tracks
This commit is contained in:
Kim Wittenburg
2012-06-26 11:17:05 +02:00
parent 41b1ef775c
commit 6a132a51d0
8 changed files with 438 additions and 79 deletions

View File

@@ -77,7 +77,7 @@
NSMenuItem *titleItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"iLyrics.text.loadNextResultsFrom", @"") action:@selector(nothingResponsible:soDisable:titleItem:) keyEquivalent:@""];
[menu addItem:titleItem];
for (id<LyricsHoster> hoster in [ilyrics lyricsHosters]) {
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", [hoster name]] action:@selector(loadNextResults:) keyEquivalent:@""];
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:[hoster name] action:@selector(loadNextResults:) keyEquivalent:@""];
[menuItem setTarget:self];
[menu addItem:menuItem];
}
@@ -265,6 +265,23 @@
}
- (IBAction)sendLyricsToiTunes:(id)sender {
NSString *title = NSLocalizedString(@"iTunes.messages.sentToiTunes.title", @"");
NSString *detail = NSLocalizedString(@"iTunes.messages.sentToiTunes.detail", @"");
NSString *sendToCurrent = NSLocalizedString(@"iTunes.messages.sentToiTunes.sendToCurrent", @"");
NSString *sendToMatching = NSLocalizedString(@"iTunes.messages.sentToiTunes.sendToMatching", @"");
NSString *cancel = NSLocalizedString(@"Cancel", @"");
NSBeginAlertSheet(title, sendToCurrent, cancel, sendToMatching, window, self, nil, @selector(sendLyricsToiTunesSheetDidDismiss:returnCode:contextInfo:), nil, detail);
}
- (void)sendLyricsToiTunesSheetDidDismiss: (NSWindow *) sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSAlertDefaultReturn) {
[self sendLyricsToCurrentiTunesTrack:nil];
} else if (returnCode == NSAlertOtherReturn) {
[self sendLyricsToTracksMatchingTrack:nil];
}
}
- (IBAction)sendLyricsToCurrentiTunesTrack:(id)sender {
iTunesTrack *track = [[ilyrics iTunes] currentTrack];
NSString *name = [track name];
if (name == nil) {
@@ -275,18 +292,43 @@
if (oldLyrics != nil && [oldLyrics length] > 0) {
NSBeginAlertSheet(NSLocalizedString(@"iTunes.messages.replaceLyrics.title", @""), NSLocalizedString(@"Yes", @""), NSLocalizedString(@"No", @""), nil, window, self, @selector(replaceLyricsSheetDidEnd:returnCode:contextInfo:), nil, nil, NSLocalizedString(@"iTunes.messages.replaceLyrics.detail", @""));
} else {
[self replaceLyricsSheetDidEnd:nil returnCode:NSAlertDefaultReturn contextInfo:nil];
[self sendLyricsToiTunesTrack:[[ilyrics iTunes] currentTrack]];
}
}
- (IBAction)sendLyricsToTracksMatchingTrack:(id)sender {
iTunesSource *iTunesSrc = [[[ilyrics iTunes] sources] objectAtIndex:0];
iTunesLibraryPlaylist *library = [[iTunesSrc libraryPlaylists] objectAtIndex:0];
NSString *name = [currentLyrics name];
NSString *artist = [currentLyrics artist];
BOOL foundTrack = NO;
for (iTunesFileTrack *track in [library fileTracks]) {
if ([[track name] rangeOfString:name options:NSCaseInsensitiveSearch].location != NSNotFound && [[track artist] rangeOfString:artist options:NSCaseInsensitiveSearch].location != NSNotFound) {
[self sendLyricsToiTunesTrack:track];
foundTrack = YES;
}
}
if (!foundTrack) {
NSString *title = NSLocalizedString(@"iTunes.messages.noMatchingTracks.title", @"");
NSString *detail = [[NSLocalizedString(@"iTunes.messages.noMatchingTracks.detail", @"") stringByReplacingOccurrencesOfString:@"%track%" withString:name] stringByReplacingOccurrencesOfString:@"%artist%" withString:artist];
NSString *ok = NSLocalizedString(@"OK", @"");
NSBeginAlertSheet(title, ok, nil, nil, window, nil, nil, nil, nil, detail);
}
}
- (void)replaceLyricsSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSAlertDefaultReturn) {
iTunesTrack *track = [[ilyrics iTunes] currentTrack];
[track setLyrics:[lyricsArea string]];
[GrowlApplicationBridge notifyWithTitle:NSLocalizedString(@"Growl.messages.lyricsSent.title", @"") description:[NSString stringWithFormat:NSLocalizedString(@"Growl.messages.lyricsSent.detail", @""), [track name]] notificationName:@"Lyrics sent to iTunes" iconData:nil priority:0 isSticky:NO clickContext:nil];
[self sendLyricsToiTunesTrack:track];
}
}
- (void)sendLyricsToiTunesTrack:(iTunesTrack *)track {
[track setLyrics:[lyricsArea string]];
[GrowlApplicationBridge notifyWithTitle:NSLocalizedString(@"Growl.messages.lyricsSent.title", @"") description:[NSString stringWithFormat:NSLocalizedString(@"Growl.messages.lyricsSent.detail", @""), [track name]] notificationName:@"Lyrics sent to iTunes" iconData:nil priority:0 isSticky:NO clickContext:nil];
}
- (IBAction)downloadLyrics:(id)sender {
NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setAllowedFileTypes:[NSArray arrayWithObject:@"txt"]];
@@ -373,6 +415,18 @@
BOOL enabled = lyricsSelected && [[ilyrics iTunes] isRunning];
return enabled;
}
if (action == @selector(sendLyricsToCurrentiTunesTrack:)) {
if (![[ilyrics iTunes] isRunning]) {
return NO;
}
NSString *name = [[[ilyrics iTunes] currentTrack] name];
BOOL enabled = lyricsSelected && name != nil && [name length]>0;
return enabled;
}
if (action == @selector(sendLyricsToMatchingiTunesTrack:)) {
BOOL enabled = lyricsSelected && [[ilyrics iTunes] isRunning];
return enabled;
}
if (action == @selector(getCurrentiTunesSong:)) {
return [[ilyrics iTunes] isRunning];
}