cog/AppController.m

199 lines
5.2 KiB
Matlab
Raw Normal View History

2005-06-02 18:16:43 +00:00
#import "AppController.h"
@implementation AppController
- (IBAction)addFiles:(id)sender
{
NSOpenPanel *p;
p = [NSOpenPanel openPanel];
[p setCanChooseDirectories:YES];
[p setAllowsMultipleSelection:YES];
// [p beginSheetForDirectory:nil file:nil types:[`listController acceptableFileTypes] modalForWindow:mainWindow modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
// [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
if ([p runModalForTypes:[playlistController acceptableFileTypes]] == NSOKButton)
{
[playlistController addPaths:[p filenames] sort:NO];
[self updateTotalTime];
2005-06-02 18:16:43 +00:00
}
2005-06-02 18:16:43 +00:00
}
- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton)
{
[playlistController addPaths:[panel filenames] sort:NO];
}
[panel release];
}
- (IBAction)delEntries:(id)sender
{
[playlistController remove:self];
[self updateTotalTime];
2005-06-02 18:16:43 +00:00
}
- (PlaylistEntry *)currentEntry
{
return [playlistController currentEntry];
}
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
{
// DBLog(@"W00t");
2005-06-02 18:16:43 +00:00
return [key isEqualToString:@"currentEntry"];
}
- (void)awakeFromNib
{
// DBLog(@"AWAKe");
2005-07-11 20:27:47 +00:00
[playButton setToolTip:NSLocalizedString(@"PlayButtonTooltip", @"")];
[stopButton setToolTip:NSLocalizedString(@"StopButtonTooltip", @"")];
[prevButton setToolTip:NSLocalizedString(@"PrevButtonTooltip", @"")];
[nextButton setToolTip:NSLocalizedString(@"NextButtonTooltip", @"")];
[addButton setToolTip:NSLocalizedString(@"AddButtonTooltip", @"")];
[remButton setToolTip:NSLocalizedString(@"RemoveButtonTooltip", @"")];
[infoButton setToolTip:NSLocalizedString(@"InfoButtonTooltip", @"")];
[shuffleButton setToolTip:NSLocalizedString(@"ShuffleButtonTooltip", @"")];
[repeatButton setToolTip:NSLocalizedString(@"RepeatButtonTooltip", @"")];
2005-06-02 18:16:43 +00:00
NSString *filename = @"~/Library/Application Support/Cog/Default.playlist";
[playlistController loadPlaylist:[filename stringByExpandingTildeInPath]];
[self updateTotalTime];
2005-06-02 18:16:43 +00:00
}
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
// 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";
2005-06-02 18:16:43 +00:00
[playlistController savePlaylist:[folder stringByAppendingPathComponent: fileName]];
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]];
2005-06-02 18:16:43 +00:00
[playlistController savePlaylist:[p filename]];
}
}
- (IBAction)loadPlaylist:(id)sender
{
NSOpenPanel *p;
p = [NSOpenPanel openPanel];
[p setCanChooseDirectories:NO];
[p setAllowsMultipleSelection:NO];
if ([p runModalForTypes:[playlistController acceptablePlaylistTypes]] == NSOKButton)
{
[playlistController setPlaylistFilename:[p filename]];
[playlistController loadPlaylist:[p filename]];
[self updateTotalTime];
2005-06-02 18:16:43 +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
{
DBLog(@"Adding path: %@", filename);
2005-06-02 18:16:43 +00:00
if ([playlistController addPaths:[NSArray arrayWithObject:filename] sort:NO] != 1)
return NO;
return YES;
}
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
{
DBLog(@"Adding paths: %@", filenames);
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-04 01:08:21 +00:00
[infoDrawer toggle:self];
}
- (void)drawerDidOpen:(NSNotification *)notification
{
[infoButton setState:NSOnState];
}
- (void)drawerDidClose:(NSNotification *)notification
{
[infoButton setState:NSOffState];
}
- (IBAction)donate:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://sourceforge.net/project/project_donations.php?group_id=140003"]];
}
- (void)updateTotalTime
{
double tt=0;
NSArray* entries = [playlistController arrangedObjects];
NSEnumerator *enumerator = [entries objectEnumerator];
PlaylistEntry* pe;
while (pe = [enumerator nextObject]) {
tt += [pe length];
}
int sec = (int)(tt/1000.0);
NSString* ttstring = [NSString stringWithFormat:@"Cog - %i:%02i",sec/60, sec%60];
[mainWindow setTitle:ttstring];
}
2005-06-02 18:16:43 +00:00
@end