1/*
2   Project: MPDCon
3
4   Copyright (C) 2012
5
6   Author: Sebastian Reitenbach
7
8   Created: 2012-09-02
9
10   Lyrics Inspector
11
12   This application is free software; you can redistribute it and/or
13   modify it under the terms of the GNU General Public
14   License as published by the Free Software Foundation; either
15   version 2 of the License, or (at your option) any later version.
16
17   This application is distributed in the hope that it will be useful,
18   but WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20   Library General Public License for more details.
21
22   You should have received a copy of the GNU General Public
23   License along with this library; if not, write to the Free
24   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
25*/
26
27#include <AppKit/AppKit.h>
28#include "LyricsInspector.h"
29#include "PlaylistItem.h"
30
31@implementation LyricsInspector
32
33/* --------------------------
34   - Initialization Methods -
35   --------------------------*/
36+ (id) sharedLyricsInspector
37{
38  static LyricsInspector *_sharedLyricsInspector = nil;
39
40  if (! _sharedLyricsInspector) {
41      _sharedLyricsInspector = [[LyricsInspector allocWithZone: [self zone]] init];
42  }
43
44  return _sharedLyricsInspector;
45}
46
47- (id) init
48{
49  if ((self = [self initWithWindowNibName: @"LyricsInspector"]) != nil)
50    {
51      [self setWindowFrameAutosaveName: @"LyricsInspector"];
52      mpdController = [MPDController sharedMPDController];
53    }
54  return self;
55}
56
57- (void) dealloc
58{
59  [lyricsURL release];
60
61  [super dealloc];
62}
63
64/* GUI methods */
65- (void) awakeFromNib
66{
67  NSNotificationCenter *defCenter;
68  defCenter = [NSNotificationCenter defaultCenter];
69  [defCenter addObserver: self
70                selector: @selector(songChanged:)
71                    name: SongChangedNotification
72                  object: nil];
73
74  [self updateLyrics];
75}
76
77
78
79/* the method behind the button */
80- (void) openURL: (id)sender
81{
82  [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: lyricsURL]];
83}
84
85/* the delegate methods */
86- (void) songChanged:(NSNotification *)aNotif
87{
88  [self updateLyrics];
89}
90
91- (void) updateLyrics
92{
93  PlaylistItem *currentSong;
94  NSDictionary *lyrics;
95
96  currentSong = [mpdController getCurrentSong];
97  [artist setStringValue:[currentSong getArtist]];
98  [title setStringValue:[currentSong getTitle]];
99
100  lyrics = [currentSong getLyrics];
101  [lyricsText setStringValue: [lyrics objectForKey:@"lyricsText"]];
102  lyricsURL = [[lyrics objectForKey:@"lyricsURL"] copy];
103
104  return;
105}
106@end
107