2005-06-02 18:16:43 +00:00
|
|
|
#import "AppController.h"
|
2007-02-18 17:35:28 +00:00
|
|
|
#import "KFTypeSelectTableView.h""
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
@implementation AppController
|
|
|
|
|
2006-09-30 13:25:45 +00:00
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
[self initDefaults];
|
2007-02-18 17:35:28 +00:00
|
|
|
|
|
|
|
/* Use KFTypeSelectTableView as our NSTableView base class to allow type-select searching of all
|
|
|
|
* table and outline views.
|
|
|
|
*/
|
|
|
|
[[KFTypeSelectTableView class] poseAsClass:[NSTableView class]];
|
2006-09-30 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
- (IBAction)openFiles:(id)sender
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
NSOpenPanel *p;
|
|
|
|
|
|
|
|
p = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[p setCanChooseDirectories:YES];
|
|
|
|
[p setAllowsMultipleSelection:YES];
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[p beginSheetForDirectory:nil file:nil types:[playlistController acceptableFileTypes] modalForWindow:mainWindow modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
|
2006-09-17 18:11:29 +00:00
|
|
|
// [p beginForDirectory:nil file:nil types:[playlistController acceptableFileTypes] modelessDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
/* if ([p runModalForTypes:[playlistController acceptableFileTypes]] == NSOKButton)
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2006-09-02 16:09:20 +00:00
|
|
|
[playlistController addPaths:[p filenames] sort:YES];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2006-09-02 16:09:20 +00:00
|
|
|
*/
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
|
|
|
|
{
|
|
|
|
if (returnCode == NSOKButton)
|
|
|
|
{
|
2006-09-02 16:09:20 +00:00
|
|
|
[playlistController addPaths:[panel filenames] sort:YES];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
// [panel release];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)delEntries:(id)sender
|
|
|
|
{
|
|
|
|
[playlistController remove:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PlaylistEntry *)currentEntry
|
|
|
|
{
|
|
|
|
return [playlistController currentEntry];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
|
|
|
|
{
|
2006-04-13 03:20:31 +00:00
|
|
|
// DBLog(@"W00t");
|
2005-06-02 18:16:43 +00:00
|
|
|
return [key isEqualToString:@"currentEntry"];
|
|
|
|
}
|
|
|
|
|
2007-02-17 19:33:31 +00:00
|
|
|
- (void)initShowColumn:(NSMenuItem *)showColumn withIdentifier:(NSString *)identifier
|
|
|
|
{
|
|
|
|
id tc = [playlistView tableColumnWithIdentifier:identifier];
|
|
|
|
|
|
|
|
NSArray *visibleColumnIdentifiers = [[NSUserDefaults standardUserDefaults] objectForKey:[playlistView columnVisibilitySaveName]];
|
|
|
|
if (visibleColumnIdentifiers) {
|
|
|
|
NSEnumerator *enumerator = [visibleColumnIdentifiers objectEnumerator];
|
|
|
|
id column;
|
|
|
|
while (column = [enumerator nextObject]) {
|
|
|
|
if ([visibleColumnIdentifiers containsObject:identifier]) {
|
|
|
|
[showColumn setState:NSOnState];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[showColumn setState:NSOffState];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[showColumn setRepresentedObject: tc];
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2006-09-30 13:25:45 +00:00
|
|
|
// [self initDefaults];
|
2006-09-02 16:09:20 +00:00
|
|
|
|
2006-04-13 03:20:31 +00:00
|
|
|
// DBLog(@"AWAKe");
|
2005-07-11 20:27:47 +00:00
|
|
|
[playButton setToolTip:NSLocalizedString(@"PlayButtonTooltip", @"")];
|
|
|
|
[prevButton setToolTip:NSLocalizedString(@"PrevButtonTooltip", @"")];
|
|
|
|
[nextButton setToolTip:NSLocalizedString(@"NextButtonTooltip", @"")];
|
|
|
|
[infoButton setToolTip:NSLocalizedString(@"InfoButtonTooltip", @"")];
|
|
|
|
[shuffleButton setToolTip:NSLocalizedString(@"ShuffleButtonTooltip", @"")];
|
|
|
|
[repeatButton setToolTip:NSLocalizedString(@"RepeatButtonTooltip", @"")];
|
2006-04-13 03:20:31 +00:00
|
|
|
|
2007-02-17 19:33:31 +00:00
|
|
|
[self initShowColumn: showIndexColumn withIdentifier: @"index"];
|
|
|
|
[self initShowColumn: showTitleColumn withIdentifier: @"title"];
|
|
|
|
[self initShowColumn: showArtistColumn withIdentifier: @"artist"];
|
|
|
|
[self initShowColumn: showAlbumColumn withIdentifier: @"album"];
|
|
|
|
[self initShowColumn: showGenreColumn withIdentifier: @"genre"];
|
|
|
|
[self initShowColumn: showLengthColumn withIdentifier: @"length"];
|
|
|
|
[self initShowColumn: showTrackColumn withIdentifier: @"track"];
|
|
|
|
[self initShowColumn: showYearColumn withIdentifier: @"year"];
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[self registerHotKeys];
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
NSString *filename = @"~/Library/Application Support/Cog/Default.playlist";
|
|
|
|
[playlistController loadPlaylist:[filename stringByExpandingTildeInPath]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
|
|
|
{
|
2006-04-13 03:20:31 +00:00
|
|
|
// DBLog(@"QUITTING");
|
2005-06-02 18:16:43 +00:00
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSString *folder = @"~/Library/Application Support/Cog/";
|
|
|
|
|
|
|
|
folder = [folder stringByExpandingTildeInPath];
|
|
|
|
|
|
|
|
if ([fileManager fileExistsAtPath: folder] == NO)
|
|
|
|
{
|
|
|
|
[fileManager createDirectoryAtPath: folder attributes: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *fileName = @"Default.playlist";
|
2006-04-13 03:20:31 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
[playlistController savePlaylist:[folder stringByAppendingPathComponent: fileName]];
|
2006-04-13 03:20:31 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)savePlaylist:(id)sender
|
|
|
|
{
|
|
|
|
if ([playlistController playlistFilename] == nil)
|
|
|
|
[self savePlaylistAs:sender];
|
|
|
|
|
|
|
|
[playlistController savePlaylist:[playlistController playlistFilename]];
|
|
|
|
}
|
|
|
|
- (IBAction)savePlaylistAs:(id)sender
|
|
|
|
{
|
|
|
|
NSSavePanel *p;
|
|
|
|
|
|
|
|
p = [NSSavePanel savePanel];
|
|
|
|
|
|
|
|
[p setAllowedFileTypes:[playlistController acceptablePlaylistTypes]];
|
|
|
|
|
|
|
|
if ([p runModalForDirectory:nil file:[[playlistController playlistFilename] lastPathComponent]] == NSOKButton)
|
|
|
|
{
|
|
|
|
[playlistController setPlaylistFilename:[p filename]];
|
2006-04-13 03:20:31 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
[playlistController savePlaylist:[p filename]];
|
|
|
|
}
|
|
|
|
}
|
2006-05-13 04:51:11 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (IBAction)loadPlaylist:(id)sender
|
|
|
|
{
|
|
|
|
NSOpenPanel *p;
|
2006-05-13 04:51:11 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
p = [NSOpenPanel openPanel];
|
2006-05-13 04:51:11 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
[p setCanChooseDirectories:NO];
|
|
|
|
[p setAllowsMultipleSelection:NO];
|
2006-05-13 04:51:11 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
if ([p runModalForTypes:[playlistController acceptablePlaylistTypes]] == NSOKButton)
|
|
|
|
{
|
|
|
|
[playlistController setPlaylistFilename:[p filename]];
|
2006-05-13 04:51:11 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
[playlistController loadPlaylist:[p filename]];
|
|
|
|
}
|
2006-05-13 04:51:11 +00:00
|
|
|
|
2005-07-23 19:10:06 +00:00
|
|
|
[mainWindow makeKeyAndOrderFront:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
|
|
|
|
{
|
|
|
|
// if (flag == NO)
|
|
|
|
[mainWindow makeKeyAndOrderFront:self];
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
|
|
|
{
|
2005-06-30 16:13:22 +00:00
|
|
|
DBLog(@"Adding path: %@", filename);
|
2006-05-12 14:34:59 +00:00
|
|
|
[playlistController addPaths:[NSArray arrayWithObject:filename] sort:NO];
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
|
|
|
|
{
|
2005-06-30 16:13:22 +00:00
|
|
|
DBLog(@"Adding paths: %@", filenames);
|
2006-04-13 03:20:31 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
[playlistController addPaths:filenames sort:YES];
|
|
|
|
[theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
|
|
|
|
}
|
|
|
|
|
2006-04-04 01:08:21 +00:00
|
|
|
- (IBAction)toggleInfoDrawer:(id)sender
|
|
|
|
{
|
|
|
|
[mainWindow makeKeyAndOrderFront:self];
|
2006-04-13 03:20:31 +00:00
|
|
|
|
2006-04-04 01:08:21 +00:00
|
|
|
[infoDrawer toggle:self];
|
|
|
|
}
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
- (IBAction)toggleFileDrawer:(id)sender
|
|
|
|
{
|
|
|
|
[mainWindow makeKeyAndOrderFront:self];
|
2007-02-18 21:35:53 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[fileDrawer toggle:self];
|
|
|
|
}
|
|
|
|
|
2006-04-04 01:08:21 +00:00
|
|
|
- (void)drawerDidOpen:(NSNotification *)notification
|
|
|
|
{
|
2007-02-18 18:59:23 +00:00
|
|
|
if ([notification object] == infoDrawer) {
|
2006-09-02 16:09:20 +00:00
|
|
|
[infoButton setState:NSOnState];
|
2007-02-18 18:59:23 +00:00
|
|
|
}
|
|
|
|
else if ([notification object] == fileDrawer) {
|
2006-09-02 16:09:20 +00:00
|
|
|
[fileButton setState:NSOnState];
|
2007-02-18 18:59:23 +00:00
|
|
|
|
|
|
|
[mainWindow makeFirstResponder: fileOutlineView];
|
|
|
|
}
|
2006-04-04 01:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawerDidClose:(NSNotification *)notification
|
|
|
|
{
|
2007-02-18 18:59:23 +00:00
|
|
|
if ([notification object] == infoDrawer) {
|
2006-09-02 16:09:20 +00:00
|
|
|
[infoButton setState:NSOffState];
|
2007-02-18 18:59:23 +00:00
|
|
|
}
|
|
|
|
else if ([notification object] == fileDrawer) {
|
2007-02-18 21:35:53 +00:00
|
|
|
NSLog(@"CLOSED");
|
2006-09-02 16:09:20 +00:00
|
|
|
[fileButton setState:NSOffState];
|
2007-02-18 18:59:23 +00:00
|
|
|
|
|
|
|
[mainWindow makeFirstResponder: playlistView];
|
|
|
|
}
|
2006-04-04 01:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)donate:(id)sender
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://sourceforge.net/project/project_donations.php?group_id=140003"]];
|
|
|
|
}
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
- (void)initDefaults
|
|
|
|
{
|
|
|
|
NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary];
|
2006-09-10 21:27:20 +00:00
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:35] forKey:@"hotKeyPlayKeyCode"];
|
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPlayModifiers"];
|
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:'P'] forKey:@"hotKeyPlayCharacter"];
|
2006-09-02 16:09:20 +00:00
|
|
|
|
2006-09-10 21:27:20 +00:00
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:45] forKey:@"hotKeyNextKeyCode"];
|
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyNextModifiers"];
|
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:'N'] forKey:@"hotKeyNextCharacter"];
|
2006-09-02 16:09:20 +00:00
|
|
|
|
2006-09-10 21:27:20 +00:00
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:15] forKey:@"hotKeyPreviousKeyCode"];
|
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPreviousModifiers"];
|
|
|
|
[userDefaultsValuesDict setObject:[NSNumber numberWithInt:'R'] forKey:@"hotKeyPreviousCharacter"];
|
|
|
|
|
2006-09-17 18:11:29 +00:00
|
|
|
[userDefaultsValuesDict setObject:[@"~/Music" stringByExpandingTildeInPath] forKey:@"fileDrawerRootPath"];
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
//Register and sync defaults
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
2006-09-10 21:27:20 +00:00
|
|
|
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyPlayKeyCode" options:0 context:nil];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyPreviousKeyCode" options:0 context:nil];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyNextKeyCode" options:0 context:nil];
|
2006-09-17 18:11:29 +00:00
|
|
|
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.fileDrawerRootPath" options:0 context:nil];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 21:27:20 +00:00
|
|
|
- (void) observeValueForKeyPath:(NSString *)keyPath
|
|
|
|
ofObject:(id)object
|
|
|
|
change:(NSDictionary *)change
|
|
|
|
context:(void *)context
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
2006-09-10 21:27:20 +00:00
|
|
|
if ([keyPath isEqualToString:@"values.hotKeyPlayKeyCode"]) {
|
|
|
|
[self registerHotKeys];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
2006-09-10 21:27:20 +00:00
|
|
|
else if ([keyPath isEqualToString:@"values.hotKeyPreviousKeyCode"]) {
|
|
|
|
[self registerHotKeys];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
2006-09-10 21:27:20 +00:00
|
|
|
else if ([keyPath isEqualToString:@"values.hotKeyNextKeyCode"]) {
|
|
|
|
[self registerHotKeys];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
2006-09-17 18:11:29 +00:00
|
|
|
else if ([keyPath isEqualToString:@"values.fileDrawerRootPath"]) {
|
|
|
|
[fileTreeController setRootPath:[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"fileDrawerRootPath"]];
|
|
|
|
}
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 21:27:20 +00:00
|
|
|
- (void)registerHotKeys
|
2006-09-02 16:09:20 +00:00
|
|
|
{
|
2006-09-10 21:27:20 +00:00
|
|
|
NSLog(@"REGISTERING HOTKEYS");
|
|
|
|
|
|
|
|
[playHotKey release];
|
|
|
|
playHotKey = [[NDHotKeyEvent alloc]
|
|
|
|
initWithKeyCode: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayKeyCode"] intValue]
|
|
|
|
character: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayCharacter"] intValue]
|
|
|
|
modifierFlags: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayModifiers"] intValue]
|
|
|
|
];
|
|
|
|
|
|
|
|
[prevHotKey release];
|
|
|
|
prevHotKey = [[NDHotKeyEvent alloc]
|
2007-02-17 19:33:31 +00:00
|
|
|
initWithKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousKeyCode"]
|
2006-09-10 21:27:20 +00:00
|
|
|
character: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousCharacter"]
|
|
|
|
modifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousModifiers"]
|
|
|
|
];
|
|
|
|
|
|
|
|
[nextHotKey release];
|
|
|
|
nextHotKey = [[NDHotKeyEvent alloc]
|
|
|
|
initWithKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextKeyCode"]
|
|
|
|
character: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextCharacter"]
|
|
|
|
modifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextModifiers"]
|
|
|
|
];
|
|
|
|
|
|
|
|
[playHotKey setTarget:self selector:@selector(clickPlay)];
|
|
|
|
[prevHotKey setTarget:self selector:@selector(clickPrev)];
|
|
|
|
[nextHotKey setTarget:self selector:@selector(clickNext)];
|
|
|
|
|
|
|
|
[playHotKey setEnabled:YES];
|
|
|
|
[prevHotKey setEnabled:YES];
|
|
|
|
[nextHotKey setEnabled:YES];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)clickPlay
|
|
|
|
{
|
|
|
|
[playButton performClick:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)clickPrev
|
|
|
|
{
|
|
|
|
NSLog(@"PREV");
|
|
|
|
[prevButton performClick:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)clickNext
|
|
|
|
{
|
|
|
|
NSLog(@"NEXT");
|
|
|
|
[nextButton performClick:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|