1 #import "MainController.h"
2 #import "PreferencesController.h"
3 #import "HotKeyCenter.h"
4 #import "StatusWindow.h"
6 @interface MainController(Private)
7 - (ITMTRemote *)loadRemote;
8 - (void)rebuildUpcomingSongsMenu;
9 - (void)rebuildPlaylistMenu;
10 - (void)rebuildEQPresetsMenu;
11 - (void)updateRatingMenu;
14 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
15 onItem:(NSMenuItem *)item;
19 @implementation MainController
21 /*************************************************************************/
23 #pragma mark INITIALIZATION/DEALLOCATION METHODS
24 /*************************************************************************/
28 if ( ( self = [super init] ) ) {
29 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
30 statusWindow = [StatusWindow sharedWindow];
38 [refreshTimer invalidate];
39 [refreshTimer release];
48 - (void)applicationDidFinishLaunching:(NSNotification *)note
50 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
51 currentRemote = [self loadRemote];
52 [currentRemote begin];
54 //Setup for notification of the remote player launching or quitting
55 [[[NSWorkspace sharedWorkspace] notificationCenter]
57 selector:@selector(applicationTerminated:)
58 name:NSWorkspaceDidTerminateApplicationNotification
61 [[[NSWorkspace sharedWorkspace] notificationCenter]
63 selector:@selector(applicationLaunched:)
64 name:NSWorkspaceDidLaunchApplicationNotification
67 if ( ! [defaults objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered.
68 [[PreferencesController sharedPrefs] registerDefaults];
71 statusItem = [[ITStatusItem alloc]
72 initWithStatusBar:[NSStatusBar systemStatusBar]
73 withLength:NSSquareStatusItemLength];
75 menu = [[NSMenu alloc] initWithTitle:@""];
76 if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) {
77 [self applicationLaunched:nil];
79 [self applicationTerminated:nil];
82 [statusItem setImage:[NSImage imageNamed:@"menu"]];
83 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
84 // Below line of code is for creating builds for Beta Testers
85 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
88 - (void)applicationWillTerminate:(NSNotification *)note
91 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
94 - (ITMTRemote *)loadRemote
96 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
99 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
100 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
101 NSString *bundlePath;
103 while ( (bundlePath = [enumerator nextObject]) ) {
104 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
107 Class remoteClass = [remoteBundle principalClass];
109 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
110 [remoteClass isKindOfClass:[NSObject class]]) {
112 id remote = [remoteClass remote];
113 [remoteArray addObject:remote];
118 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
119 // if ( [remoteArray count] > 1 ) {
120 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
122 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
125 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
126 return [remoteArray objectAtIndex:0];
132 - (void)applicationLaunched:(NSNotification *)note
134 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
135 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
138 isAppRunning = ITMTRemotePlayerRunning;
142 isAppRunning = ITMTRemotePlayerRunning;
145 - (void)applicationTerminated:(NSNotification *)note
147 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
148 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
149 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
150 [notRunningMenu addItem:[NSMenuItem separatorItem]];
151 [notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""];
152 [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""];
154 [refreshTimer invalidate];
155 [refreshTimer release];
158 isAppRunning = ITMTRemotePlayerNotRunning;
160 [statusItem setMenu:[notRunningMenu autorelease]];
164 /*************************************************************************/
166 #pragma mark INSTANCE METHODS
167 /*************************************************************************/
169 - (void)startTimerInNewThread
171 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
172 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
173 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
175 selector:@selector(timerUpdate)
177 repeats:YES] retain];
182 //Recreate the status item menu
185 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
186 NSArray *myMenu = [defaults arrayForKey:@"menu"];
187 int playlist = [currentRemote currentPlaylistIndex];
190 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
195 lastPlaylistIndex = -1;
196 didHaveAlbumName = ([[currentRemote currentSongAlbum] length] > 0);
197 didHaveArtistName = ([[currentRemote currentSongArtist] length] > 0);
200 menu = [[NSMenu alloc] initWithTitle:@""];
204 upcomingSongsItem = nil;
205 [upcomingSongsMenu release];
206 upcomingSongsMenu = nil;
209 [ratingMenu release];
213 [playlistMenu release];
220 for (i = 0; i < [myMenu count]; i++) {
221 NSString *item = [myMenu objectAtIndex:i];
222 if ([item isEqualToString:@"Play/Pause"]) {
223 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
224 playPauseItem = [menu addItemWithTitle:@"Play"
225 action:@selector(playPause:)
229 [self setKeyEquivalentForCode:[tempCombo keyCode]
230 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
233 } else if ([item isEqualToString:@"Next Track"]) {
234 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
235 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
236 action:@selector(nextSong:)
240 [self setKeyEquivalentForCode:[tempCombo keyCode]
241 andModifiers:[tempCombo modifiers] onItem:nextTrack];
244 } else if ([item isEqualToString:@"Previous Track"]) {
245 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
246 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
247 action:@selector(prevSong:)
251 [self setKeyEquivalentForCode:[tempCombo keyCode]
252 andModifiers:[tempCombo modifiers] onItem:prevTrack];
255 } else if ([item isEqualToString:@"Fast Forward"]) {
256 [menu addItemWithTitle:@"Fast Forward"
257 action:@selector(fastForward:)
259 } else if ([item isEqualToString:@"Rewind"]) {
260 [menu addItemWithTitle:@"Rewind"
261 action:@selector(rewind:)
263 } else if ([item isEqualToString:@"Show Player"]) {
264 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
265 action:@selector(showPlayer:)
267 } else if ([item isEqualToString:@"Upcoming Songs"]) {
268 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
271 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
272 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
273 [upcomingSongsItem setEnabled:NO];
274 } else if ([item isEqualToString:@"Playlists"]) {
275 playlistItem = [menu addItemWithTitle:@"Playlists"
278 } else if ([item isEqualToString:@"EQ Presets"]) {
279 eqItem = [menu addItemWithTitle:@"EQ Presets"
282 } else if ([item isEqualToString:@"PreferencesÉ"]) {
283 [menu addItemWithTitle:@"PreferencesÉ"
284 action:@selector(showPreferences:)
286 } else if ([item isEqualToString:@"Quit"]) {
287 [menu addItemWithTitle:@"Quit"
288 action:@selector(quitMenuTunes:)
290 } else if ([item isEqualToString:@"Current Track Info"]) {
291 trackInfoIndex = [menu numberOfItems];
292 [menu addItemWithTitle:@"No Song"
295 } else if ([item isEqualToString:@"Song Rating"]) {
296 unichar fullstar = 0x2605;
297 unichar emptystar = 0x2606;
298 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
299 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
302 ratingItem = [menu addItemWithTitle:@"Song Rating"
306 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
308 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
311 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
314 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
317 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
320 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
323 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
326 [ratingItem setSubmenu:ratingMenu];
327 } else if ([item isEqualToString:@"<separator>"]) {
328 [menu addItem:[NSMenuItem separatorItem]];
333 [self rebuildPlaylistMenu];
337 [self rebuildEQPresetsMenu];
340 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
342 if (upcomingSongsItem) {
343 [self rebuildUpcomingSongsMenu];
347 if (isPlayingRadio || !playlist) {
348 [ratingItem setEnabled:NO];
350 int currentSongRating = ([currentRemote currentSongRating] * 5);
351 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
352 lastSongRating = currentSongRating;
353 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
354 [ratingItem setEnabled:YES];
358 //Set the new unique song identifier
359 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
361 //If we're in a playlist or radio mode
362 if ( (trackInfoIndex > -1) && (playlist || isPlayingRadio) ) {
365 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) && (i > -1) ) {
366 [menu removeItemAtIndex:i];
367 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
370 title = [currentRemote currentSongTitle];
372 if (!isPlayingRadio) {
373 if ([defaults boolForKey:@"showTime"]) {
374 NSString *length = [currentRemote currentSongLength];
375 char character = [length characterAtIndex:0];
376 if ( (character > '0') && (character < '9') ) {
377 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
381 if ([defaults boolForKey:@"showArtist"]) {
382 NSString *artist = [currentRemote currentSongArtist];
384 if ([artist length] > 0) {
385 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
388 didHaveArtistName = (([artist length] > 0) ? YES : NO);
391 if ([defaults boolForKey:@"showAlbum"]) {
392 NSString *album = [currentRemote currentSongAlbum];
394 if ([album length] > 0) {
395 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
396 didHaveAlbumName = (([album length]) ? YES : NO);
401 if ([title length] > 0) {
402 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
406 [statusItem setMenu:menu];
412 //Rebuild the upcoming songs submenu. Can be improved a lot.
413 - (void)rebuildUpcomingSongsMenu
415 int curIndex = [currentRemote currentPlaylistIndex];
416 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
417 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
419 if (!isPlayingRadio) {
421 int curTrack = [currentRemote currentSongIndex];
424 [upcomingSongsMenu release];
425 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
426 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
427 [upcomingSongsItem setEnabled:YES];
429 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
431 NSString *curSong = [currentRemote songTitleAtIndex:i];
432 NSMenuItem *songItem;
433 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
434 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
435 [upcomingSongsMenu addItem:songItem];
443 [upcomingSongsItem setSubmenu:nil];
444 [upcomingSongsItem setEnabled:NO];
448 - (void)rebuildPlaylistMenu
450 NSArray *playlists = [currentRemote playlists];
451 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
453 [playlistMenu release];
454 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
456 for (i = 0; i < [playlists count]; i++) {
457 NSString *playlistName = [playlists objectAtIndex:i];
458 NSMenuItem *tempItem;
459 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
460 [tempItem setTag:i + 1];
461 [playlistMenu addItem:tempItem];
464 [playlistItem setSubmenu:playlistMenu];
465 [playlistItem setEnabled:YES];
467 if (!isPlayingRadio && currentPlaylist) {
468 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
472 //Build a menu with the list of all available EQ presets
473 - (void)rebuildEQPresetsMenu
475 NSArray *eqPresets = [currentRemote eqPresets];
476 NSMenuItem *enabledItem;
480 eqMenu = [[NSMenu alloc] initWithTitle:@""];
482 enabledItem = [eqMenu addItemWithTitle:@"Enabled"
483 action:@selector(selectEQPreset:)
485 [enabledItem setTag:-1];
487 if ([currentRemote equalizerEnabled]) {
488 [enabledItem setState:NSOnState];
491 [eqMenu addItem:[NSMenuItem separatorItem]];
493 for (i = 0; i < [eqPresets count]; i++) {
494 NSString *name = [eqPresets objectAtIndex:i];
495 NSMenuItem *tempItem;
497 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
499 [eqMenu addItem:tempItem];
503 [eqItem setSubmenu:eqMenu];
504 [eqItem setEnabled:YES];
506 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
509 - (void)updateRatingMenu
511 int currentSongRating = ([currentRemote currentSongRating] * 5);
512 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
513 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
516 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
517 lastSongRating = currentSongRating;
518 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
524 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
525 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
526 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
530 [self updateRatingMenu];
532 //Update Play/Pause menu item
534 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
535 [playPauseItem setTitle:@"Pause"];
537 [playPauseItem setTitle:@"Play"];
548 - (void)selectSong:(id)sender
550 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
553 - (void)selectPlaylist:(id)sender
555 int playlist = [sender tag];
556 [currentRemote switchToPlaylistAtIndex:playlist];
559 - (void)selectEQPreset:(id)sender
561 int curSet = [currentRemote currentEQPresetIndex];
562 int item = [sender tag];
565 [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
567 [currentRemote setEqualizerEnabled:YES];
568 [currentRemote switchToEQAtIndex:item];
569 [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
570 [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
574 - (void)selectSongRating:(id)sender
576 int newRating = [sender tag];
577 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
578 [sender setState:NSOnState];
579 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
580 lastSongRating = newRating / 20;
583 - (void)playPause:(id)sender
585 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
587 if (state == ITMTRemotePlayerPlaying) {
588 [currentRemote pause];
589 [playPauseItem setTitle:@"Play"];
590 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
591 [currentRemote pause];
592 [currentRemote play];
594 [currentRemote play];
595 [playPauseItem setTitle:@"Pause"];
599 - (void)nextSong:(id)sender
601 [currentRemote goToNextSong];
604 - (void)prevSong:(id)sender
606 [currentRemote goToPreviousSong];
609 - (void)fastForward:(id)sender
611 [currentRemote forward];
612 [playPauseItem setTitle:@"Play"];
615 - (void)rewind:(id)sender
617 [currentRemote rewind];
618 [playPauseItem setTitle:@"Play"];
623 - (void)quitMenuTunes:(id)sender
625 [NSApp terminate:self];
628 - (void)showPlayer:(id)sender
630 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
631 [currentRemote showPrimaryInterface];
633 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
634 NSLog(@"Error Launching Player");
639 - (void)showPreferences:(id)sender
641 [[PreferencesController sharedPrefs] setController:self];
642 [[PreferencesController sharedPrefs] showPrefsWindow:self];
645 - (void)closePreferences
647 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
652 - (ITMTRemote *)currentRemote
654 return currentRemote;
665 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
666 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
667 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
668 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
669 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
674 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
676 if ([defaults objectForKey:@"PlayPause"] != nil) {
677 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
678 combo:[defaults keyComboForKey:@"PlayPause"]
679 target:self action:@selector(playPause:)];
682 if ([defaults objectForKey:@"NextTrack"] != nil) {
683 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
684 combo:[defaults keyComboForKey:@"NextTrack"]
685 target:self action:@selector(nextSong:)];
688 if ([defaults objectForKey:@"PrevTrack"] != nil) {
689 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
690 combo:[defaults keyComboForKey:@"PrevTrack"]
691 target:self action:@selector(prevSong:)];
694 if ([defaults objectForKey:@"TrackInfo"] != nil) {
695 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
696 combo:[defaults keyComboForKey:@"TrackInfo"]
697 target:self action:@selector(showCurrentTrackInfo)];
700 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
701 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
702 combo:[defaults keyComboForKey:@"UpcomingSongs"]
703 target:self action:@selector(showUpcomingSongs)];
709 // Show Current Track Info And Show Upcoming Songs Floaters
713 - (void)showCurrentTrackInfo
715 NSString *trackName = [currentRemote currentSongTitle];
716 if (!statusWindow && [trackName length]) {
717 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
718 NSString *stringToShow = @"";
720 if ([defaults boolForKey:@"showName"]) {
721 if ([defaults boolForKey:@"showArtist"]) {
722 NSString *trackArtist = [currentRemote currentSongArtist];
723 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
725 stringToShow = [stringToShow stringByAppendingString:trackName];
726 stringToShow = [stringToShow stringByAppendingString:@"\n"];
729 if ([defaults boolForKey:@"showAlbum"]) {
730 NSString *trackAlbum = [currentRemote currentSongAlbum];
731 if ([trackAlbum length]) {
732 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
733 stringToShow = [stringToShow stringByAppendingString:@"\n"];
737 if ([defaults boolForKey:@"showTime"]) {
738 NSString *trackTime = [currentRemote currentSongLength];
739 if ([trackTime length]) {
740 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
745 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
746 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
748 stringToShow = [stringToShow stringByAppendingString:
749 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
751 stringToShow = [stringToShow stringByAppendingString:
752 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
757 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
760 /*[statusWindow setText:stringToShow];
761 [NSTimer scheduledTimerWithTimeInterval:3.0
763 selector:@selector(fadeAndCloseStatusWindow)
769 - (void)showUpcomingSongs
771 int curPlaylist = [currentRemote currentPlaylistIndex];
773 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
776 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
777 int curTrack = [currentRemote currentSongIndex];
779 NSString *songs = @"";
781 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
783 NSString *curSong = [currentRemote songTitleAtIndex:i];
784 songs = [songs stringByAppendingString:curSong];
785 songs = [songs stringByAppendingString:@"\n"];
790 //SHOW STATUS WINDOW HERE WITH STRING songs
793 /*[statusWindow setText:songs];
794 [NSTimer scheduledTimerWithTimeInterval:3.0
796 selector:@selector(fadeAndCloseStatusWindow)
803 - (void)fadeAndCloseStatusWindow
805 [statusWindow orderOut:self];
808 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
809 onItem:(NSMenuItem *)item
811 unichar charcode = 'a';
813 long cocoaModifiers = 0;
814 static long carbonToCocoa[6][2] =
816 { cmdKey, NSCommandKeyMask },
817 { optionKey, NSAlternateKeyMask },
818 { controlKey, NSControlKeyMask },
819 { shiftKey, NSShiftKeyMask },
822 for (i = 0; i < 6; i++) {
823 if (modifiers & carbonToCocoa[i][0]) {
824 cocoaModifiers += carbonToCocoa[i][1];
827 [item setKeyEquivalentModifierMask:cocoaModifiers];
829 //Missing key combos for some keys. Must find them later.
843 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
844 NSLog(@"%@", menuRef);
845 SetMenuItemCommandKey(menuRef, 0, NO, 49);
846 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
847 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
853 charcode = NSDeleteFunctionKey;
869 charcode = NSF5FunctionKey;
873 charcode = NSF6FunctionKey;
877 charcode = NSF7FunctionKey;
881 charcode = NSF3FunctionKey;
885 charcode = NSF8FunctionKey;
889 charcode = NSF9FunctionKey;
893 charcode = NSF11FunctionKey;
897 charcode = NSF3FunctionKey;
901 charcode = NSF14FunctionKey;
905 charcode = NSF10FunctionKey;
909 charcode = NSF12FunctionKey;
913 charcode = NSF13FunctionKey;
917 charcode = NSInsertFunctionKey;
921 charcode = NSHomeFunctionKey;
925 charcode = NSPageUpFunctionKey;
929 charcode = NSDeleteFunctionKey;
933 charcode = NSF4FunctionKey;
937 charcode = NSEndFunctionKey;
941 charcode = NSF2FunctionKey;
945 charcode = NSPageDownFunctionKey;
949 charcode = NSF1FunctionKey;
953 charcode = NSLeftArrowFunctionKey;
957 charcode = NSRightArrowFunctionKey;
961 charcode = NSDownArrowFunctionKey;
965 charcode = NSUpArrowFunctionKey;
969 if (charcode == 'a') {
975 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
976 keyTrans = KeyTranslate(kchr, code, &state);
978 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
979 } else if (charcode != 'b') {
980 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];