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 [statusItem setMenu:menu];
140 isAppRunning = ITMTRemotePlayerRunning;
144 isAppRunning = ITMTRemotePlayerRunning;
147 - (void)applicationTerminated:(NSNotification *)note
149 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
150 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
151 [[notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""] setTarget:self];
152 [notRunningMenu addItem:[NSMenuItem separatorItem]];
153 [[notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
154 [[notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
155 [statusItem setMenu:[notRunningMenu autorelease]];
157 [refreshTimer invalidate];
158 [refreshTimer release];
166 /*************************************************************************/
168 #pragma mark INSTANCE METHODS
169 /*************************************************************************/
171 - (void)startTimerInNewThread
173 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
174 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
175 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
177 selector:@selector(timerUpdate)
179 repeats:YES] retain];
184 //Recreate the status item menu
187 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
188 NSArray *myMenu = [defaults arrayForKey:@"menu"];
189 int playlist = [currentRemote currentPlaylistIndex];
193 lastPlaylistIndex = -1;
194 didHaveAlbumName = ([[currentRemote currentSongAlbum] length] > 0);
195 didHaveArtistName = ([[currentRemote currentSongArtist] length] > 0);
198 menu = [[NSMenu alloc] initWithTitle:@""];
200 /*while ([menu numberOfItems] > 0) {
201 [menu removeItemAtIndex:0];
205 lastSongIdentifier = @"0-0";
207 upcomingSongsItem = nil;
208 [upcomingSongsMenu release];
209 upcomingSongsMenu = nil;
212 [ratingMenu release];
216 [playlistMenu release];
223 for (i = 0; i < [myMenu count]; i++) {
224 NSString *item = [myMenu objectAtIndex:i];
225 if ([item isEqualToString:@"Play/Pause"]) {
226 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
227 playPauseItem = [menu addItemWithTitle:@"Play"
228 action:@selector(playPause:)
232 [self setKeyEquivalentForCode:[tempCombo keyCode]
233 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
236 } else if ([item isEqualToString:@"Next Track"]) {
237 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
238 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
239 action:@selector(nextSong:)
243 [self setKeyEquivalentForCode:[tempCombo keyCode]
244 andModifiers:[tempCombo modifiers] onItem:nextTrack];
247 } else if ([item isEqualToString:@"Previous Track"]) {
248 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
249 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
250 action:@selector(prevSong:)
254 [self setKeyEquivalentForCode:[tempCombo keyCode]
255 andModifiers:[tempCombo modifiers] onItem:prevTrack];
258 } else if ([item isEqualToString:@"Fast Forward"]) {
259 [menu addItemWithTitle:@"Fast Forward"
260 action:@selector(fastForward:)
262 } else if ([item isEqualToString:@"Rewind"]) {
263 [menu addItemWithTitle:@"Rewind"
264 action:@selector(rewind:)
266 } else if ([item isEqualToString:@"Upcoming Songs"]) {
267 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
270 } else if ([item isEqualToString:@"Playlists"]) {
271 playlistItem = [menu addItemWithTitle:@"Playlists"
274 } else if ([item isEqualToString:@"EQ Presets"]) {
275 eqItem = [menu addItemWithTitle:@"EQ Presets"
278 } else if ([item isEqualToString:@"PreferencesÉ"]) {
279 [menu addItemWithTitle:@"PreferencesÉ"
280 action:@selector(showPreferences:)
282 } else if ([item isEqualToString:@"Quit"]) {
283 [menu addItemWithTitle:@"Quit"
284 action:@selector(quitMenuTunes:)
286 } else if ([item isEqualToString:@"Current Track Info"]) {
287 trackInfoIndex = [menu numberOfItems];
288 [menu addItemWithTitle:@"No Song"
291 } else if ([item isEqualToString:@"Song Rating"]) {
292 unichar fullstar = 0x2605;
293 unichar emptystar = 0x2606;
294 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
295 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
298 ratingItem = [menu addItemWithTitle:@"Song Rating"
302 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
304 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
307 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
310 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
313 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
316 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
319 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
321 } else if ([item isEqualToString:@"<separator>"]) {
322 [menu addItem:[NSMenuItem separatorItem]];
326 if ( (isAppRunning == ITMTRemotePlayerRunning) ) {
327 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
329 if (upcomingSongsItem) {
330 [self rebuildUpcomingSongsMenu];
334 [self rebuildPlaylistMenu];
338 [self rebuildEQPresetsMenu];
342 if (isPlayingRadio || !playlist) {
343 [ratingItem setEnabled:NO];
344 if ([ratingItem submenu]) {
345 [ratingItem setSubmenu:nil];
348 int currentSongRating = ([currentRemote currentSongRating] * 5);
349 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
350 lastSongRating = currentSongRating;
351 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
352 [ratingItem setEnabled:YES];
353 [ratingItem setSubmenu:ratingMenu];
357 //Set the new unique song identifier
358 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
360 //If we're in a playlist or radio mode
361 if ( (trackInfoIndex > -1) && (playlist || isPlayingRadio) ) {
362 NSString *title, *album, *artist;
364 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) && (i > -1) ) {
365 [menu removeItemAtIndex:i];
366 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
369 title = [currentRemote currentSongTitle];
371 if (!isPlayingRadio) {
372 ([defaults boolForKey:@"showAlbum"]) ? (album = [currentRemote currentSongAlbum]) :
374 ([defaults boolForKey:@"showArtist"]) ? (artist = [currentRemote currentSongArtist]) :
376 if ([defaults boolForKey:@"showTime"]) {
377 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
380 if ([artist length] > 0) {
381 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
384 if ([album length] > 0) {
385 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
388 if ([defaults boolForKey:@"showArtist"]) {
389 didHaveArtistName = (([artist length] > 0) ? YES : NO);
392 if ([defaults boolForKey:@"showAlbum"]) {
393 didHaveAlbumName = (([album length] > 0) ? YES : NO);
397 if ([title length] > 0) {
398 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
403 [statusItem setMenu:menu];
409 //Rebuild the upcoming songs submenu. Can be improved a lot.
410 - (void)rebuildUpcomingSongsMenu
412 int curIndex = [currentRemote currentPlaylistIndex];
413 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
414 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
416 if (!isPlayingRadio) {
418 int curTrack = [currentRemote currentSongIndex];
421 [upcomingSongsMenu release];
422 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
423 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
424 [upcomingSongsItem setEnabled:YES];
426 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
428 NSString *curSong = [currentRemote songTitleAtIndex:i];
429 NSMenuItem *songItem;
430 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
431 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
432 [upcomingSongsMenu addItem:songItem];
440 [upcomingSongsItem setSubmenu:nil];
441 [upcomingSongsItem setEnabled:NO];
445 - (void)rebuildPlaylistMenu
447 NSArray *playlists = [currentRemote playlists];
448 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
450 [playlistMenu release];
451 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
453 for (i = 0; i < [playlists count]; i++) {
454 NSString *playlistName = [playlists objectAtIndex:i];
455 NSMenuItem *tempItem;
456 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
457 [tempItem setTag:i + 1];
458 [playlistMenu addItem:tempItem];
461 [playlistItem setSubmenu:playlistMenu];
462 [playlistItem setEnabled:YES];
464 if (!isPlayingRadio && currentPlaylist) {
465 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
469 //Build a menu with the list of all available EQ presets
470 - (void)rebuildEQPresetsMenu
472 NSArray *eqPresets = [currentRemote eqPresets];
473 NSMenuItem *enabledItem;
477 eqMenu = [[NSMenu alloc] initWithTitle:@""];
479 enabledItem = [eqMenu addItemWithTitle:@"Enabled"
480 action:@selector(selectEQPreset:)
482 [enabledItem setTag:-1];
484 if ([currentRemote equalizerEnabled]) {
485 [enabledItem setState:NSOnState];
488 [eqMenu addItem:[NSMenuItem separatorItem]];
490 for (i = 0; i < [eqPresets count]; i++) {
491 NSString *name = [eqPresets objectAtIndex:i];
492 NSMenuItem *tempItem;
494 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
496 [eqMenu addItem:tempItem];
500 [eqItem setSubmenu:eqMenu];
501 [eqItem setEnabled:YES];
503 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
506 - (void)updateRatingMenu
508 int currentSongRating = ([currentRemote currentSongRating] * 5);
509 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
510 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
513 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
514 lastSongRating = currentSongRating;
515 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
521 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
522 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
523 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
527 [self updateRatingMenu];
529 //Update Play/Pause menu item
531 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
532 [playPauseItem setTitle:@"Pause"];
534 [playPauseItem setTitle:@"Play"];
545 - (void)selectSong:(id)sender
547 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
550 - (void)selectPlaylist:(id)sender
552 int playlist = [sender tag];
553 [currentRemote switchToPlaylistAtIndex:playlist];
556 - (void)selectEQPreset:(id)sender
558 int curSet = [currentRemote currentEQPresetIndex];
559 int item = [sender tag];
562 [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
564 [currentRemote setEqualizerEnabled:YES];
565 [currentRemote switchToEQAtIndex:item];
566 [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
567 [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
571 - (void)selectSongRating:(id)sender
573 int newRating = [sender tag];
574 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
575 [sender setState:NSOnState];
576 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
577 lastSongRating = newRating / 20;
580 - (void)playPause:(id)sender
582 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
584 if (state == ITMTRemotePlayerPlaying) {
585 [currentRemote pause];
586 [playPauseItem setTitle:@"Play"];
587 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
588 [currentRemote pause];
589 [currentRemote play];
591 [currentRemote play];
592 [playPauseItem setTitle:@"Pause"];
596 - (void)nextSong:(id)sender
598 [currentRemote goToNextSong];
601 - (void)prevSong:(id)sender
603 [currentRemote goToPreviousSong];
606 - (void)fastForward:(id)sender
608 [currentRemote forward];
609 [playPauseItem setTitle:@"Play"];
612 - (void)rewind:(id)sender
614 [currentRemote rewind];
615 [playPauseItem setTitle:@"Play"];
620 - (void)quitMenuTunes:(id)sender
622 [NSApp terminate:self];
625 - (void)showPlayer:(id)sender
627 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
628 [currentRemote showPrimaryInterface];
630 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
631 NSLog(@"Error Launching Player");
636 - (void)showPreferences:(id)sender
638 [[PreferencesController sharedPrefs] setController:self];
639 [[PreferencesController sharedPrefs] showPrefsWindow:self];
642 - (void)closePreferences
644 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
658 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
659 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
660 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
661 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
662 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
667 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
669 if ([defaults objectForKey:@"PlayPause"] != nil) {
670 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
671 combo:[defaults keyComboForKey:@"PlayPause"]
672 target:self action:@selector(playPause:)];
675 if ([defaults objectForKey:@"NextTrack"] != nil) {
676 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
677 combo:[defaults keyComboForKey:@"NextTrack"]
678 target:self action:@selector(nextSong:)];
681 if ([defaults objectForKey:@"PrevTrack"] != nil) {
682 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
683 combo:[defaults keyComboForKey:@"PrevTrack"]
684 target:self action:@selector(prevSong:)];
687 if ([defaults objectForKey:@"TrackInfo"] != nil) {
688 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
689 combo:[defaults keyComboForKey:@"TrackInfo"]
690 target:self action:@selector(showCurrentTrackInfo)];
693 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
694 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
695 combo:[defaults keyComboForKey:@"UpcomingSongs"]
696 target:self action:@selector(showUpcomingSongs)];
702 // Show Current Track Info And Show Upcoming Songs Floaters
706 - (void)showCurrentTrackInfo
708 NSString *trackName = [currentRemote currentSongTitle];
709 if (!statusWindow && [trackName length]) {
710 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
711 NSString *stringToShow = @"";
713 if ([defaults boolForKey:@"showName"]) {
714 if ([defaults boolForKey:@"showArtist"]) {
715 NSString *trackArtist = [currentRemote currentSongArtist];
716 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
718 stringToShow = [stringToShow stringByAppendingString:trackName];
719 stringToShow = [stringToShow stringByAppendingString:@"\n"];
722 if ([defaults boolForKey:@"showAlbum"]) {
723 NSString *trackAlbum = [currentRemote currentSongAlbum];
724 if ([trackAlbum length]) {
725 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
726 stringToShow = [stringToShow stringByAppendingString:@"\n"];
730 if ([defaults boolForKey:@"showTime"]) {
731 NSString *trackTime = [currentRemote currentSongLength];
732 if ([trackTime length]) {
733 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
738 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
739 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
741 stringToShow = [stringToShow stringByAppendingString:
742 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
744 stringToShow = [stringToShow stringByAppendingString:
745 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
749 [statusWindow setText:stringToShow];
750 [NSTimer scheduledTimerWithTimeInterval:3.0
752 selector:@selector(fadeAndCloseStatusWindow)
758 - (void)showUpcomingSongs
760 int curPlaylist = [currentRemote currentPlaylistIndex];
762 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
765 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
766 int curTrack = [currentRemote currentSongIndex];
768 NSString *songs = @"";
770 statusWindow = [ITTransientStatusWindow sharedWindow];
771 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
773 NSString *curSong = [currentRemote songTitleAtIndex:i];
774 songs = [songs stringByAppendingString:curSong];
775 songs = [songs stringByAppendingString:@"\n"];
778 [statusWindow setText:songs];
779 [NSTimer scheduledTimerWithTimeInterval:3.0
781 selector:@selector(fadeAndCloseStatusWindow)
788 - (void)fadeAndCloseStatusWindow
790 [statusWindow orderOut:self];
793 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
794 onItem:(NSMenuItem *)item
796 unichar charcode = 'a';
798 long cocoaModifiers = 0;
799 static long carbonToCocoa[6][2] =
801 { cmdKey, NSCommandKeyMask },
802 { optionKey, NSAlternateKeyMask },
803 { controlKey, NSControlKeyMask },
804 { shiftKey, NSShiftKeyMask },
807 for (i = 0; i < 6; i++) {
808 if (modifiers & carbonToCocoa[i][0]) {
809 cocoaModifiers += carbonToCocoa[i][1];
812 [item setKeyEquivalentModifierMask:cocoaModifiers];
814 //Missing key combos for some keys. Must find them later.
828 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
829 NSLog(@"%@", menuRef);
830 SetMenuItemCommandKey(menuRef, 0, NO, 49);
831 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
832 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
838 charcode = NSDeleteFunctionKey;
854 charcode = NSF5FunctionKey;
858 charcode = NSF6FunctionKey;
862 charcode = NSF7FunctionKey;
866 charcode = NSF3FunctionKey;
870 charcode = NSF8FunctionKey;
874 charcode = NSF9FunctionKey;
878 charcode = NSF11FunctionKey;
882 charcode = NSF3FunctionKey;
886 charcode = NSF14FunctionKey;
890 charcode = NSF10FunctionKey;
894 charcode = NSF12FunctionKey;
898 charcode = NSF13FunctionKey;
902 charcode = NSInsertFunctionKey;
906 charcode = NSHomeFunctionKey;
910 charcode = NSPageUpFunctionKey;
914 charcode = NSDeleteFunctionKey;
918 charcode = NSF4FunctionKey;
922 charcode = NSEndFunctionKey;
926 charcode = NSF2FunctionKey;
930 charcode = NSPageDownFunctionKey;
934 charcode = NSF1FunctionKey;
938 charcode = NSLeftArrowFunctionKey;
942 charcode = NSRightArrowFunctionKey;
946 charcode = NSDownArrowFunctionKey;
950 charcode = NSUpArrowFunctionKey;
954 if (charcode == 'a') {
960 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
961 keyTrans = KeyTranslate(kchr, code, &state);
963 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
964 } else if (charcode != 'b') {
965 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];