Release No. 1.1
Added Auto-Lyrics Improved the preferences window
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
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;
|
||||
}
|
||||
|
||||
28
iLyrics/AutoLyrics.h
Normal file
28
iLyrics/AutoLyrics.h
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// AutoLyrics.h
|
||||
// iLyrics
|
||||
//
|
||||
// Created by Kim Wittenburg on 16.06.12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Growl/Growl.h>
|
||||
#import "iTunes.h"
|
||||
#import "Magistrix.h"
|
||||
|
||||
@interface AutoLyrics : NSObject
|
||||
|
||||
@property NSUInteger interval;
|
||||
@property BOOL enabled;
|
||||
@property BOOL replaceOldLyrics;
|
||||
|
||||
+(AutoLyrics *)autoLyrics;
|
||||
|
||||
-(void) shouldSetLyrics: (NSTimer *)timer;
|
||||
-(void) setLyrics;
|
||||
|
||||
-(void) saveToDefaults: (NSUserDefaults *)defaults;
|
||||
-(void) loadFromDefaults: (NSUserDefaults *)defaults;
|
||||
|
||||
@end
|
||||
94
iLyrics/AutoLyrics.m
Normal file
94
iLyrics/AutoLyrics.m
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// AutoLyrics.m
|
||||
// iLyrics
|
||||
//
|
||||
// Created by Kim Wittenburg on 16.06.12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AutoLyrics.h"
|
||||
|
||||
@implementation AutoLyrics {
|
||||
NSTimer *timer;
|
||||
NSUInteger interval;
|
||||
BOOL enabled;
|
||||
}
|
||||
|
||||
@synthesize replaceOldLyrics;
|
||||
|
||||
AutoLyrics *instace;
|
||||
|
||||
+(AutoLyrics *)autoLyrics {
|
||||
if (instace == nil) {
|
||||
instace = [[AutoLyrics alloc] init];
|
||||
[instace loadFromDefaults:[NSUserDefaults standardUserDefaults]];
|
||||
}
|
||||
return instace;
|
||||
}
|
||||
|
||||
-(id)init {
|
||||
enabled = NO;
|
||||
replaceOldLyrics = NO;
|
||||
[self setInterval:5];
|
||||
return [super init];
|
||||
}
|
||||
|
||||
-(BOOL)enabled {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
-(void)setEnabled:(BOOL)flag {
|
||||
enabled = flag;
|
||||
}
|
||||
|
||||
//In seconds
|
||||
-(void)setInterval:(NSUInteger)i {
|
||||
interval = i;
|
||||
if (timer) {
|
||||
[timer invalidate];
|
||||
}
|
||||
timer = [[NSTimer alloc] initWithFireDate:[[NSDate alloc]init] interval:interval target:self selector:@selector(shouldSetLyrics:) userInfo:nil repeats:YES];
|
||||
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
-(NSUInteger)interval {
|
||||
return interval;
|
||||
}
|
||||
|
||||
-(void)shouldSetLyrics: (NSTimer *) sender {
|
||||
if (enabled) {
|
||||
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
|
||||
iTunesTrack *current = [iTunes currentTrack];
|
||||
if ([current name] != nil) {
|
||||
if (replaceOldLyrics || [[current lyrics] length] == 0) {
|
||||
[self setLyrics];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setLyrics {
|
||||
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
|
||||
iTunesTrack *track = [iTunes currentTrack];
|
||||
Magistrix *magistrix = [[Magistrix alloc] init];
|
||||
[magistrix startNewSearchForQuery:[NSString stringWithFormat:@"%@ - %@", [track name], [track artist]]];
|
||||
NSArray *results = [magistrix nextResults];
|
||||
if (results != nil && [results count] > 0) {
|
||||
Lyrics *lyrics = [magistrix lyricsBySearchResult:[results objectAtIndex:0]];
|
||||
[track setLyrics:[lyrics lyrics]];
|
||||
[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];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-(void)saveToDefaults:(NSUserDefaults *)defaults {
|
||||
[defaults setBool:enabled forKey:@"Auto Lyrics Enabled"];
|
||||
[defaults setBool:replaceOldLyrics forKey:@"Auto Lyrics replaces old lyrics"];
|
||||
}
|
||||
|
||||
-(void)loadFromDefaults:(NSUserDefaults *)defaults {
|
||||
enabled = [defaults boolForKey:@"Auto Lyrics Enabled"];
|
||||
replaceOldLyrics = [defaults boolForKey:@"Auto Lyrics replaces old lyrics"];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
-(void) resetLoadedResults;
|
||||
|
||||
//Return nil for a "network error"
|
||||
-(Lyrics*) lyricsBySearchResult: (SearchResult *) result;
|
||||
|
||||
@end
|
||||
|
||||
@@ -183,8 +183,9 @@
|
||||
|
||||
- (void)replaceLyricsSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
|
||||
if (returnCode == NSAlertDefaultReturn) {
|
||||
[[iTunes currentTrack] setLyrics:[lyricsArea string]];
|
||||
[GrowlApplicationBridge notifyWithTitle:NSLocalizedString(@"Growl.messages.lyricsSent.title", @"") description:NSLocalizedString(@"Growl.messages.lyricsSent.detail", @"") notificationName:@"Lyrics sent to iTunes" iconData:nil priority:0 isSticky:NO clickContext:nil];
|
||||
iTunesTrack *track = [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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,28 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "LyricsHoster.h"
|
||||
#import "PreferencesWindow.h"
|
||||
#import "AutoLyrics.h"
|
||||
|
||||
@interface PreferencesController : NSObject <NSTableViewDataSource>
|
||||
@interface PreferencesController : NSObject <NSWindowDelegate, NSTableViewDataSource>
|
||||
|
||||
@property (unsafe_unretained) IBOutlet PreferencesWindow *preferencesWindow;
|
||||
@property (weak) IBOutlet NSToolbarItem *generalButton;
|
||||
@property (weak) IBOutlet NSTableView *hosterTable;
|
||||
@property NSArray *hosters;
|
||||
@property (weak) IBOutlet NSView *generalView;
|
||||
@property (weak) IBOutlet NSView *autoLyricsView;
|
||||
@property (weak) IBOutlet NSButton *toggleAutoLyricsButton;
|
||||
@property (weak) IBOutlet NSButton *replaceOldCheckBox;
|
||||
|
||||
-(void) addHoster: (id<LyricsHoster>) hoster;
|
||||
-(void) removeHoster: (id<LyricsHoster>) hoster;
|
||||
|
||||
- (IBAction)showGeneralPreferences:(id)sender;
|
||||
- (IBAction)showAutoLyricsPreferences:(id)sender;
|
||||
|
||||
- (IBAction)toggleAutoLyrics:(id)sender;
|
||||
- (IBAction)changeAutoLyricsInterval:(id)sender;
|
||||
- (IBAction)toggleReplaceOldLyrics:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
@@ -5,19 +5,47 @@
|
||||
// Created by Kim Wittenburg on 14.06.12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
//TODO: Implement Auto-Lyricds Interval
|
||||
//TODO: Set the title of the window when the toolbar button selection changed
|
||||
|
||||
#import "PreferencesController.h"
|
||||
|
||||
@implementation PreferencesController {
|
||||
NSMutableArray *hosters;
|
||||
AutoLyrics *autoLyrics;
|
||||
}
|
||||
@synthesize generalView;
|
||||
@synthesize autoLyricsView;
|
||||
@synthesize toggleAutoLyricsButton;
|
||||
@synthesize replaceOldCheckBox;
|
||||
@synthesize preferencesWindow;
|
||||
@synthesize generalButton;
|
||||
@synthesize hosterTable;
|
||||
|
||||
-(id)init {
|
||||
autoLyrics = [AutoLyrics autoLyrics];
|
||||
hosters = [[NSMutableArray alloc] init];
|
||||
return [super init];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Window Delegate Methods
|
||||
|
||||
-(void)awakeFromNib {
|
||||
if ([autoLyrics enabled]) {
|
||||
[self enableAutoLyrics:toggleAutoLyricsButton];
|
||||
} else {
|
||||
[self disableAutoLyrics:toggleAutoLyricsButton];
|
||||
}
|
||||
if ([autoLyrics replaceOldLyrics]) {
|
||||
[replaceOldCheckBox setState:NSOnState];
|
||||
} else {
|
||||
[replaceOldCheckBox setState:NSOffState];
|
||||
}
|
||||
[[preferencesWindow toolbar] setSelectedItemIdentifier:@"general"];
|
||||
[self showGeneralPreferences:nil];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Properties
|
||||
|
||||
@@ -42,6 +70,45 @@
|
||||
[hosterTable reloadData];
|
||||
}
|
||||
|
||||
- (IBAction)showGeneralPreferences:(id)sender {
|
||||
[self changeContentViewTo:generalView];
|
||||
}
|
||||
|
||||
-(IBAction)showAutoLyricsPreferences:(id)sender {
|
||||
[self changeContentViewTo:autoLyricsView];
|
||||
}
|
||||
|
||||
- (IBAction)toggleAutoLyrics:(id)sender {
|
||||
if ([autoLyrics enabled]) {
|
||||
[self disableAutoLyrics:sender];
|
||||
} else {
|
||||
[self enableAutoLyrics:sender];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)enableAutoLyrics: (id) sender{
|
||||
[autoLyrics setEnabled:YES];
|
||||
[sender setTitle:NSLocalizedString(@"iLyrics.text.disableAutoLyrics", @"")];
|
||||
}
|
||||
|
||||
-(void)disableAutoLyrics: (id) sender {
|
||||
[autoLyrics setEnabled:NO];
|
||||
[sender setTitle:NSLocalizedString(@"iLyrics.text.enableAutoLyrics", @"")];
|
||||
}
|
||||
|
||||
- (IBAction)changeAutoLyricsInterval:(id)sender {
|
||||
NSLog(@"%i", [sender intValue]);
|
||||
}
|
||||
|
||||
- (IBAction)toggleReplaceOldLyrics:(id)sender {
|
||||
[autoLyrics setReplaceOldLyrics:[sender state] == NSOnState];
|
||||
}
|
||||
|
||||
- (void)changeContentViewTo: (NSView *)view {
|
||||
[preferencesWindow setContentView:view];
|
||||
//[preferencesWindow setFrame:[view frame] display:YES animate:YES];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Table Data Source
|
||||
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
|
||||
@@ -57,7 +124,6 @@
|
||||
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
|
||||
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
|
||||
return [dateFormatter stringFromDate:version];
|
||||
// return desc == nil ? NSLocalizedString(@"iLyrics.text.illegalDateFormat", @"") : desc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
iLyrics/PreferencesWindow.h
Normal file
13
iLyrics/PreferencesWindow.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// PreferencesWindow.h
|
||||
// iLyrics
|
||||
//
|
||||
// Created by Kim Wittenburg on 16.06.12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface PreferencesWindow : NSWindow
|
||||
|
||||
@end
|
||||
20
iLyrics/PreferencesWindow.m
Normal file
20
iLyrics/PreferencesWindow.m
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// PreferencesWindow.m
|
||||
// iLyrics
|
||||
//
|
||||
// Created by Kim Wittenburg on 16.06.12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PreferencesWindow.h"
|
||||
|
||||
@implementation PreferencesWindow
|
||||
|
||||
-(BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem {
|
||||
if ([anItem action]==@selector(toggleToolbarShown:)) {
|
||||
return NO;
|
||||
}
|
||||
return [super validateUserInterfaceItem:anItem];
|
||||
}
|
||||
|
||||
@end
|
||||
5115
iLyrics/de.lproj/MainMenu.xib
Normal file
5115
iLyrics/de.lproj/MainMenu.xib
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -17,11 +17,11 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<string>1.1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<string>5</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.music</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
Reference in New Issue
Block a user