Total playlist time displayed in title (simon savary)

CQTexperiment
vspader 2006-04-13 03:20:31 +00:00
parent 9377d8647e
commit 3597e03585
10 changed files with 46 additions and 16 deletions

View File

@ -32,11 +32,13 @@
- (IBAction)donate:(id)sender; - (IBAction)donate:(id)sender;
- (void)updateTotalTime;
- (IBAction)toggleInfoDrawer:(id)sender; - (IBAction)toggleInfoDrawer:(id)sender;
- (void)drawerDidOpen:(NSNotification *)notification; - (void)drawerDidOpen:(NSNotification *)notification;
- (void)drawerDidClose:(NSNotification *)notification; - (void)drawerDidClose:(NSNotification *)notification;
//Fun stuff //Fun stuff
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag; - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag;
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename; - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames; - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames;

View File

@ -12,13 +12,14 @@
[p setAllowsMultipleSelection:YES]; [p setAllowsMultipleSelection:YES];
// [p beginSheetForDirectory:nil file:nil types:[`listController acceptableFileTypes] modalForWindow:mainWindow modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL]; // [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]; // [p beginForDirectory:nil file:nil types:[playlistController acceptableFileTypes] modelessDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
if ([p runModalForTypes:[playlistController acceptableFileTypes]] == NSOKButton) if ([p runModalForTypes:[playlistController acceptableFileTypes]] == NSOKButton)
{ {
[playlistController addPaths:[p filenames] sort:NO]; [playlistController addPaths:[p filenames] sort:NO];
[self updateTotalTime];
} }
} }
- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo - (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
@ -34,6 +35,7 @@
- (IBAction)delEntries:(id)sender - (IBAction)delEntries:(id)sender
{ {
[playlistController remove:self]; [playlistController remove:self];
[self updateTotalTime];
} }
- (PlaylistEntry *)currentEntry - (PlaylistEntry *)currentEntry
@ -43,13 +45,13 @@
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key - (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
{ {
// DBLog(@"W00t"); // DBLog(@"W00t");
return [key isEqualToString:@"currentEntry"]; return [key isEqualToString:@"currentEntry"];
} }
- (void)awakeFromNib - (void)awakeFromNib
{ {
// DBLog(@"AWAKe"); // DBLog(@"AWAKe");
[playButton setToolTip:NSLocalizedString(@"PlayButtonTooltip", @"")]; [playButton setToolTip:NSLocalizedString(@"PlayButtonTooltip", @"")];
[stopButton setToolTip:NSLocalizedString(@"StopButtonTooltip", @"")]; [stopButton setToolTip:NSLocalizedString(@"StopButtonTooltip", @"")];
@ -60,14 +62,16 @@
[infoButton setToolTip:NSLocalizedString(@"InfoButtonTooltip", @"")]; [infoButton setToolTip:NSLocalizedString(@"InfoButtonTooltip", @"")];
[shuffleButton setToolTip:NSLocalizedString(@"ShuffleButtonTooltip", @"")]; [shuffleButton setToolTip:NSLocalizedString(@"ShuffleButtonTooltip", @"")];
[repeatButton setToolTip:NSLocalizedString(@"RepeatButtonTooltip", @"")]; [repeatButton setToolTip:NSLocalizedString(@"RepeatButtonTooltip", @"")];
NSString *filename = @"~/Library/Application Support/Cog/Default.playlist"; NSString *filename = @"~/Library/Application Support/Cog/Default.playlist";
[playlistController loadPlaylist:[filename stringByExpandingTildeInPath]]; [playlistController loadPlaylist:[filename stringByExpandingTildeInPath]];
[self updateTotalTime];
} }
- (void)applicationWillTerminate:(NSNotification *)aNotification - (void)applicationWillTerminate:(NSNotification *)aNotification
{ {
// DBLog(@"QUITTING"); // DBLog(@"QUITTING");
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *folder = @"~/Library/Application Support/Cog/"; NSString *folder = @"~/Library/Application Support/Cog/";
@ -79,9 +83,9 @@
} }
NSString *fileName = @"Default.playlist"; NSString *fileName = @"Default.playlist";
[playlistController savePlaylist:[folder stringByAppendingPathComponent: fileName]]; [playlistController savePlaylist:[folder stringByAppendingPathComponent: fileName]];
} }
- (IBAction)savePlaylist:(id)sender - (IBAction)savePlaylist:(id)sender
@ -102,7 +106,7 @@
if ([p runModalForDirectory:nil file:[[playlistController playlistFilename] lastPathComponent]] == NSOKButton) if ([p runModalForDirectory:nil file:[[playlistController playlistFilename] lastPathComponent]] == NSOKButton)
{ {
[playlistController setPlaylistFilename:[p filename]]; [playlistController setPlaylistFilename:[p filename]];
[playlistController savePlaylist:[p filename]]; [playlistController savePlaylist:[p filename]];
} }
} }
@ -120,6 +124,8 @@
[playlistController setPlaylistFilename:[p filename]]; [playlistController setPlaylistFilename:[p filename]];
[playlistController loadPlaylist:[p filename]]; [playlistController loadPlaylist:[p filename]];
[self updateTotalTime];
} }
[mainWindow makeKeyAndOrderFront:self]; [mainWindow makeKeyAndOrderFront:self];
@ -145,7 +151,7 @@
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
{ {
DBLog(@"Adding paths: %@", filenames); DBLog(@"Adding paths: %@", filenames);
[playlistController addPaths:filenames sort:YES]; [playlistController addPaths:filenames sort:YES];
[theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; [theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
} }
@ -153,7 +159,7 @@
- (IBAction)toggleInfoDrawer:(id)sender - (IBAction)toggleInfoDrawer:(id)sender
{ {
[mainWindow makeKeyAndOrderFront:self]; [mainWindow makeKeyAndOrderFront:self];
[infoDrawer toggle:self]; [infoDrawer toggle:self];
} }
@ -172,4 +178,21 @@
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://sourceforge.net/project/project_donations.php?group_id=140003"]]; [[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];
}
@end @end

View File

@ -94,6 +94,7 @@
CLASS = PlaylistView; CLASS = PlaylistView;
LANGUAGE = ObjC; LANGUAGE = ObjC;
OUTLETS = { OUTLETS = {
appController = AppController;
playbackController = PlaybackController; playbackController = PlaybackController;
playlistController = PlaylistController; playlistController = PlaylistController;
}; };

View File

@ -3,7 +3,7 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>IBDocumentLocation</key> <key>IBDocumentLocation</key>
<string>91 411 617 240 0 0 1024 746 </string> <string>69 473 617 240 0 0 1024 746 </string>
<key>IBEditorPositions</key> <key>IBEditorPositions</key>
<dict> <dict>
<key>29</key> <key>29</key>
@ -28,12 +28,12 @@
<integer>3</integer> <integer>3</integer>
<key>IBOpenObjects</key> <key>IBOpenObjects</key>
<array> <array>
<integer>463</integer>
<integer>29</integer> <integer>29</integer>
<integer>21</integer> <integer>21</integer>
<integer>513</integer> <integer>513</integer>
<integer>463</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>
<string>8H14</string> <string>8I127</string>
</dict> </dict>
</plist> </plist>

Binary file not shown.

View File

@ -94,6 +94,7 @@
CLASS = PlaylistView; CLASS = PlaylistView;
LANGUAGE = ObjC; LANGUAGE = ObjC;
OUTLETS = { OUTLETS = {
appController = AppController;
playbackController = PlaybackController; playbackController = PlaybackController;
playlistController = PlaylistController; playlistController = PlaylistController;
}; };

View File

@ -25,6 +25,6 @@
<integer>513</integer> <integer>513</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>
<string>8H14</string> <string>8I127</string>
</dict> </dict>
</plist> </plist>

Binary file not shown.

View File

@ -8,11 +8,13 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "AppController.h"
#import "PlaybackController.h" #import "PlaybackController.h"
#import "PlaylistController.h" #import "PlaylistController.h"
@interface PlaylistView : NSTableView { @interface PlaylistView : NSTableView {
IBOutlet AppController *appController; //needed to update the total time in the main window title
IBOutlet PlaybackController *playbackController; IBOutlet PlaybackController *playbackController;
IBOutlet PlaylistController *playlistController; IBOutlet PlaylistController *playlistController;

View File

@ -54,6 +54,7 @@
if (c == NSDeleteCharacter) if (c == NSDeleteCharacter)
{ {
[playlistController remove:self]; [playlistController remove:self];
[appController updateTotalTime];
} }
else if (c == ' ') else if (c == ' ')
{ {