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:@""] setTarget:self];
150 [notRunningMenu addItem:[NSMenuItem separatorItem]];
151 [[notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
152 [[notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
153 [statusItem setMenu:[notRunningMenu autorelease]];
155 [refreshTimer invalidate];
156 [refreshTimer release];
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];
191 lastPlaylistIndex = -1;
192 didHaveAlbumName = ([[currentRemote currentSongAlbum] length] > 0);
193 didHaveArtistName = ([[currentRemote currentSongArtist] length] > 0);
196 menu = [[NSMenu alloc] initWithTitle:@""];
199 lastSongIdentifier = @"0-0";
201 upcomingSongsItem = nil;
202 [upcomingSongsMenu release];
203 upcomingSongsMenu = nil;
206 [ratingMenu release];
210 [playlistMenu release];
217 for (i = 0; i < [myMenu count]; i++) {
218 NSString *item = [myMenu objectAtIndex:i];
219 if ([item isEqualToString:@"Play/Pause"]) {
220 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
221 playPauseItem = [menu addItemWithTitle:@"Play"
222 action:@selector(playPause:)
226 [self setKeyEquivalentForCode:[tempCombo keyCode]
227 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
230 } else if ([item isEqualToString:@"Next Track"]) {
231 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
232 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
233 action:@selector(nextSong:)
237 [self setKeyEquivalentForCode:[tempCombo keyCode]
238 andModifiers:[tempCombo modifiers] onItem:nextTrack];
241 } else if ([item isEqualToString:@"Previous Track"]) {
242 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
243 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
244 action:@selector(prevSong:)
248 [self setKeyEquivalentForCode:[tempCombo keyCode]
249 andModifiers:[tempCombo modifiers] onItem:prevTrack];
252 } else if ([item isEqualToString:@"Fast Forward"]) {
253 [menu addItemWithTitle:@"Fast Forward"
254 action:@selector(fastForward:)
256 } else if ([item isEqualToString:@"Rewind"]) {
257 [menu addItemWithTitle:@"Rewind"
258 action:@selector(rewind:)
260 } else if ([item isEqualToString:@"Upcoming Songs"]) {
261 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
264 } else if ([item isEqualToString:@"Playlists"]) {
265 playlistItem = [menu addItemWithTitle:@"Playlists"
268 } else if ([item isEqualToString:@"EQ Presets"]) {
269 eqItem = [menu addItemWithTitle:@"EQ Presets"
272 } else if ([item isEqualToString:@"PreferencesÉ"]) {
273 [menu addItemWithTitle:@"PreferencesÉ"
274 action:@selector(showPreferences:)
276 } else if ([item isEqualToString:@"Quit"]) {
277 [menu addItemWithTitle:@"Quit"
278 action:@selector(quitMenuTunes:)
280 } else if ([item isEqualToString:@"Current Track Info"]) {
281 trackInfoIndex = [menu numberOfItems];
282 [menu addItemWithTitle:@"No Song"
285 } else if ([item isEqualToString:@"Song Rating"]) {
286 unichar fullstar = 0x2605;
287 unichar emptystar = 0x2606;
288 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
289 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
292 ratingItem = [menu addItemWithTitle:@"Song Rating"
296 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
298 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
301 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
304 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
307 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
310 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
313 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
315 } else if ([item isEqualToString:@"<separator>"]) {
316 [menu addItem:[NSMenuItem separatorItem]];
320 if ( (isAppRunning == ITMTRemotePlayerRunning) ) {
321 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
323 if (upcomingSongsItem) {
324 [self rebuildUpcomingSongsMenu];
328 [self rebuildPlaylistMenu];
332 [self rebuildEQPresetsMenu];
336 if (isPlayingRadio || !playlist) {
337 [ratingItem setEnabled:NO];
338 if ([ratingItem submenu]) {
339 [ratingItem setSubmenu:nil];
342 int currentSongRating = ([currentRemote currentSongRating] * 5);
343 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
344 lastSongRating = currentSongRating;
345 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
346 [ratingItem setEnabled:YES];
347 [ratingItem setSubmenu:ratingMenu];
351 //Set the new unique song identifier
352 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
354 //If we're in a playlist or radio mode
355 if ( (trackInfoIndex > -1) && (playlist || isPlayingRadio) ) {
356 NSString *title, *album, *artist;
358 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) && (i > -1) ) {
359 [menu removeItemAtIndex:i];
360 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
363 title = [currentRemote currentSongTitle];
365 if (!isPlayingRadio) {
366 ([defaults boolForKey:@"showAlbum"]) ? (album = [currentRemote currentSongAlbum]) :
368 ([defaults boolForKey:@"showArtist"]) ? (artist = [currentRemote currentSongArtist]) :
370 if ([defaults boolForKey:@"showTime"]) {
371 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
374 if ([artist length] > 0) {
375 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
378 if ([album length] > 0) {
379 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
382 if ([defaults boolForKey:@"showArtist"]) {
383 didHaveArtistName = (([artist length] > 0) ? YES : NO);
386 if ([defaults boolForKey:@"showAlbum"]) {
387 didHaveAlbumName = (([album length] > 0) ? YES : NO);
391 if ([title length] > 0) {
392 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
397 [statusItem setMenu:menu];
403 //Rebuild the upcoming songs submenu. Can be improved a lot.
404 - (void)rebuildUpcomingSongsMenu
406 int curIndex = [currentRemote currentPlaylistIndex];
407 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
408 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
410 if (!isPlayingRadio) {
412 int curTrack = [currentRemote currentSongIndex];
415 [upcomingSongsMenu release];
416 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
417 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
418 [upcomingSongsItem setEnabled:YES];
420 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
422 NSString *curSong = [currentRemote songTitleAtIndex:i];
423 NSMenuItem *songItem;
424 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
425 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
426 [upcomingSongsMenu addItem:songItem];
434 [upcomingSongsItem setSubmenu:nil];
435 [upcomingSongsItem setEnabled:NO];
439 - (void)rebuildPlaylistMenu
441 NSArray *playlists = [currentRemote playlists];
442 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
444 [playlistMenu release];
445 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
447 for (i = 0; i < [playlists count]; i++) {
448 NSString *playlistName = [playlists objectAtIndex:i];
449 NSMenuItem *tempItem;
450 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
451 [tempItem setTag:i + 1];
452 [playlistMenu addItem:tempItem];
455 [playlistItem setSubmenu:playlistMenu];
456 [playlistItem setEnabled:YES];
458 if (!isPlayingRadio && currentPlaylist) {
459 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
463 //Build a menu with the list of all available EQ presets
464 - (void)rebuildEQPresetsMenu
466 NSArray *eqPresets = [currentRemote eqPresets];
467 NSMenuItem *enabledItem;
471 eqMenu = [[NSMenu alloc] initWithTitle:@""];
473 enabledItem = [eqMenu addItemWithTitle:@"Enabled"
474 action:@selector(selectEQPreset:)
476 [enabledItem setTag:-1];
478 if ([currentRemote equalizerEnabled]) {
479 [enabledItem setState:NSOnState];
482 [eqMenu addItem:[NSMenuItem separatorItem]];
484 for (i = 0; i < [eqPresets count]; i++) {
485 NSString *name = [eqPresets objectAtIndex:i];
486 NSMenuItem *tempItem;
488 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
490 [eqMenu addItem:tempItem];
494 [eqItem setSubmenu:eqMenu];
495 [eqItem setEnabled:YES];
497 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
500 - (void)updateRatingMenu
502 int currentSongRating = ([currentRemote currentSongRating] * 5);
503 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
504 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
507 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
508 lastSongRating = currentSongRating;
509 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
515 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
516 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
517 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
521 [self updateRatingMenu];
523 //Update Play/Pause menu item
525 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
526 [playPauseItem setTitle:@"Pause"];
528 [playPauseItem setTitle:@"Play"];
539 - (void)selectSong:(id)sender
541 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
544 - (void)selectPlaylist:(id)sender
546 int playlist = [sender tag];
547 [currentRemote switchToPlaylistAtIndex:playlist];
550 - (void)selectEQPreset:(id)sender
552 int curSet = [currentRemote currentEQPresetIndex];
553 int item = [sender tag];
556 [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
558 [currentRemote setEqualizerEnabled:YES];
559 [currentRemote switchToEQAtIndex:item];
560 [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
561 [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
565 - (void)selectSongRating:(id)sender
567 int newRating = [sender tag];
568 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
569 [sender setState:NSOnState];
570 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
571 lastSongRating = newRating / 20;
574 - (void)playPause:(id)sender
576 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
578 if (state == ITMTRemotePlayerPlaying) {
579 [currentRemote pause];
580 [playPauseItem setTitle:@"Play"];
581 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
582 [currentRemote pause];
583 [currentRemote play];
585 [currentRemote play];
586 [playPauseItem setTitle:@"Pause"];
590 - (void)nextSong:(id)sender
592 [currentRemote goToNextSong];
595 - (void)prevSong:(id)sender
597 [currentRemote goToPreviousSong];
600 - (void)fastForward:(id)sender
602 [currentRemote forward];
603 [playPauseItem setTitle:@"Play"];
606 - (void)rewind:(id)sender
608 [currentRemote rewind];
609 [playPauseItem setTitle:@"Play"];
614 - (void)quitMenuTunes:(id)sender
616 [NSApp terminate:self];
619 - (void)showPlayer:(id)sender
621 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
622 [currentRemote showPrimaryInterface];
624 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
625 NSLog(@"Error Launching Player");
630 - (void)showPreferences:(id)sender
632 [[PreferencesController sharedPrefs] setController:self];
633 [[PreferencesController sharedPrefs] showPrefsWindow:self];
636 - (void)closePreferences
638 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
652 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
653 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
654 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
655 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
656 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
661 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
663 if ([defaults objectForKey:@"PlayPause"] != nil) {
664 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
665 combo:[defaults keyComboForKey:@"PlayPause"]
666 target:self action:@selector(playPause:)];
669 if ([defaults objectForKey:@"NextTrack"] != nil) {
670 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
671 combo:[defaults keyComboForKey:@"NextTrack"]
672 target:self action:@selector(nextSong:)];
675 if ([defaults objectForKey:@"PrevTrack"] != nil) {
676 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
677 combo:[defaults keyComboForKey:@"PrevTrack"]
678 target:self action:@selector(prevSong:)];
681 if ([defaults objectForKey:@"TrackInfo"] != nil) {
682 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
683 combo:[defaults keyComboForKey:@"TrackInfo"]
684 target:self action:@selector(showCurrentTrackInfo)];
687 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
688 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
689 combo:[defaults keyComboForKey:@"UpcomingSongs"]
690 target:self action:@selector(showUpcomingSongs)];
696 // Show Current Track Info And Show Upcoming Songs Floaters
700 - (void)showCurrentTrackInfo
702 NSString *trackName = [currentRemote currentSongTitle];
703 if (!statusWindow && [trackName length]) {
704 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
705 NSString *stringToShow = @"";
707 if ([defaults boolForKey:@"showName"]) {
708 if ([defaults boolForKey:@"showArtist"]) {
709 NSString *trackArtist = [currentRemote currentSongArtist];
710 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
712 stringToShow = [stringToShow stringByAppendingString:trackName];
713 stringToShow = [stringToShow stringByAppendingString:@"\n"];
716 if ([defaults boolForKey:@"showAlbum"]) {
717 NSString *trackAlbum = [currentRemote currentSongAlbum];
718 if ([trackAlbum length]) {
719 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
720 stringToShow = [stringToShow stringByAppendingString:@"\n"];
724 if ([defaults boolForKey:@"showTime"]) {
725 NSString *trackTime = [currentRemote currentSongLength];
726 if ([trackTime length]) {
727 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
732 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
733 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
735 stringToShow = [stringToShow stringByAppendingString:
736 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
738 stringToShow = [stringToShow stringByAppendingString:
739 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
743 [statusWindow setText:stringToShow];
744 [NSTimer scheduledTimerWithTimeInterval:3.0
746 selector:@selector(fadeAndCloseStatusWindow)
752 - (void)showUpcomingSongs
754 int curPlaylist = [currentRemote currentPlaylistIndex];
756 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
759 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
760 int curTrack = [currentRemote currentSongIndex];
762 NSString *songs = @"";
764 statusWindow = [ITTransientStatusWindow sharedWindow];
765 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
767 NSString *curSong = [currentRemote songTitleAtIndex:i];
768 songs = [songs stringByAppendingString:curSong];
769 songs = [songs stringByAppendingString:@"\n"];
772 [statusWindow setText:songs];
773 [NSTimer scheduledTimerWithTimeInterval:3.0
775 selector:@selector(fadeAndCloseStatusWindow)
782 - (void)fadeAndCloseStatusWindow
784 [statusWindow orderOut:self];
787 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
788 onItem:(NSMenuItem *)item
790 unichar charcode = 'a';
792 long cocoaModifiers = 0;
793 static long carbonToCocoa[6][2] =
795 { cmdKey, NSCommandKeyMask },
796 { optionKey, NSAlternateKeyMask },
797 { controlKey, NSControlKeyMask },
798 { shiftKey, NSShiftKeyMask },
801 for (i = 0; i < 6; i++) {
802 if (modifiers & carbonToCocoa[i][0]) {
803 cocoaModifiers += carbonToCocoa[i][1];
806 [item setKeyEquivalentModifierMask:cocoaModifiers];
808 //Missing key combos for some keys. Must find them later.
822 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
823 NSLog(@"%@", menuRef);
824 SetMenuItemCommandKey(menuRef, 0, NO, 49);
825 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
826 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
832 charcode = NSDeleteFunctionKey;
848 charcode = NSF5FunctionKey;
852 charcode = NSF6FunctionKey;
856 charcode = NSF7FunctionKey;
860 charcode = NSF3FunctionKey;
864 charcode = NSF8FunctionKey;
868 charcode = NSF9FunctionKey;
872 charcode = NSF11FunctionKey;
876 charcode = NSF3FunctionKey;
880 charcode = NSF14FunctionKey;
884 charcode = NSF10FunctionKey;
888 charcode = NSF12FunctionKey;
892 charcode = NSF13FunctionKey;
896 charcode = NSInsertFunctionKey;
900 charcode = NSHomeFunctionKey;
904 charcode = NSPageUpFunctionKey;
908 charcode = NSDeleteFunctionKey;
912 charcode = NSF4FunctionKey;
916 charcode = NSEndFunctionKey;
920 charcode = NSF2FunctionKey;
924 charcode = NSPageDownFunctionKey;
928 charcode = NSF1FunctionKey;
932 charcode = NSLeftArrowFunctionKey;
936 charcode = NSRightArrowFunctionKey;
940 charcode = NSDownArrowFunctionKey;
944 charcode = NSUpArrowFunctionKey;
948 if (charcode == 'a') {
954 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
955 keyTrans = KeyTranslate(kchr, code, &state);
957 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
958 } else if (charcode != 'b') {
959 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];