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;
15 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
16 onItem:(NSMenuItem *)item;
20 @implementation MainController
22 /*************************************************************************/
24 #pragma mark INITIALIZATION/DEALLOCATION METHODS
25 /*************************************************************************/
29 if ( ( self = [super init] ) ) {
30 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
31 statusWindow = [StatusWindow sharedWindow];
39 [refreshTimer invalidate];
40 [refreshTimer release];
49 - (void)applicationDidFinishLaunching:(NSNotification *)note
51 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
52 currentRemote = [self loadRemote];
53 [currentRemote begin];
55 //Setup for notification of the remote player launching or quitting
56 [[[NSWorkspace sharedWorkspace] notificationCenter]
58 selector:@selector(applicationTerminated:)
59 name:NSWorkspaceDidTerminateApplicationNotification
62 [[[NSWorkspace sharedWorkspace] notificationCenter]
64 selector:@selector(applicationLaunched:)
65 name:NSWorkspaceDidLaunchApplicationNotification
68 if ( ! [defaults objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered.
69 [[PreferencesController sharedPrefs] registerDefaults];
72 statusItem = [[ITStatusItem alloc]
73 initWithStatusBar:[NSStatusBar systemStatusBar]
74 withLength:NSSquareStatusItemLength];
76 menu = [[NSMenu alloc] initWithTitle:@""];
77 if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) {
78 [self applicationLaunched:nil];
80 [self applicationTerminated:nil];
83 [statusItem setImage:[NSImage imageNamed:@"menu"]];
84 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
85 // Below line of code is for creating builds for Beta Testers
86 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
89 - (void)applicationWillTerminate:(NSNotification *)note
92 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
95 - (ITMTRemote *)loadRemote
97 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
100 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
101 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
102 NSString *bundlePath;
104 while ( (bundlePath = [enumerator nextObject]) ) {
105 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
108 Class remoteClass = [remoteBundle principalClass];
110 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
111 [remoteClass isKindOfClass:[NSObject class]]) {
113 id remote = [remoteClass remote];
114 [remoteArray addObject:remote];
119 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
120 // if ( [remoteArray count] > 1 ) {
121 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
123 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
126 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
127 return [remoteArray objectAtIndex:0];
133 - (void)applicationLaunched:(NSNotification *)note
135 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
136 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
139 [statusItem setMenu:menu];
141 isAppRunning = ITMTRemotePlayerRunning;
145 isAppRunning = ITMTRemotePlayerRunning;
148 - (void)applicationTerminated:(NSNotification *)note
150 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
151 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
152 [[notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""] setTarget:self];
153 [notRunningMenu addItem:[NSMenuItem separatorItem]];
154 [[notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
155 [[notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
156 [statusItem setMenu:[notRunningMenu autorelease]];
158 [refreshTimer invalidate];
159 [refreshTimer release];
167 /*************************************************************************/
169 #pragma mark INSTANCE METHODS
170 /*************************************************************************/
172 - (void)startTimerInNewThread
174 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
175 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
176 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
178 selector:@selector(timerUpdate)
180 repeats:YES] retain];
185 //Recreate the status item menu
188 NSArray *myMenu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
192 lastPlaylistIndex = -1;
193 didHaveAlbumName = ([[currentRemote currentSongAlbum] length] > 0);
194 didHaveArtistName = ([[currentRemote currentSongArtist] length] > 0);
197 menu = [[NSMenu alloc] initWithTitle:@""];
199 /*while ([menu numberOfItems] > 0) {
200 [menu removeItemAtIndex:0];
204 lastSongIdentifier = @"0-0";
206 upcomingSongsItem = nil;
207 [upcomingSongsMenu release];
208 upcomingSongsMenu = nil;
211 [ratingMenu release];
215 [playlistMenu release];
222 for (i = 0; i < [myMenu count]; i++) {
223 NSString *item = [myMenu objectAtIndex:i];
224 if ([item isEqualToString:@"Play/Pause"]) {
225 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
226 playPauseItem = [menu addItemWithTitle:@"Play"
227 action:@selector(playPause:)
231 [self setKeyEquivalentForCode:[tempCombo keyCode]
232 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
235 } else if ([item isEqualToString:@"Next Track"]) {
236 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
237 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
238 action:@selector(nextSong:)
242 [self setKeyEquivalentForCode:[tempCombo keyCode]
243 andModifiers:[tempCombo modifiers] onItem:nextTrack];
246 } else if ([item isEqualToString:@"Previous Track"]) {
247 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
248 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
249 action:@selector(prevSong:)
253 [self setKeyEquivalentForCode:[tempCombo keyCode]
254 andModifiers:[tempCombo modifiers] onItem:prevTrack];
257 } else if ([item isEqualToString:@"Fast Forward"]) {
258 [menu addItemWithTitle:@"Fast Forward"
259 action:@selector(fastForward:)
261 } else if ([item isEqualToString:@"Rewind"]) {
262 [menu addItemWithTitle:@"Rewind"
263 action:@selector(rewind:)
265 } else if ([item isEqualToString:@"Upcoming Songs"]) {
266 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
269 } else if ([item isEqualToString:@"Playlists"]) {
270 playlistItem = [menu addItemWithTitle:@"Playlists"
273 } else if ([item isEqualToString:@"EQ Presets"]) {
274 eqItem = [menu addItemWithTitle:@"EQ Presets"
277 } else if ([item isEqualToString:@"PreferencesÉ"]) {
278 [menu addItemWithTitle:@"PreferencesÉ"
279 action:@selector(showPreferences:)
281 } else if ([item isEqualToString:@"Quit"]) {
282 [menu addItemWithTitle:@"Quit"
283 action:@selector(quitMenuTunes:)
285 } else if ([item isEqualToString:@"Current Track Info"]) {
286 trackInfoIndex = [menu numberOfItems];
287 [menu addItemWithTitle:@"No Song"
290 } else if ([item isEqualToString:@"Song Rating"]) {
291 unichar fullstar = 0x2605;
292 unichar emptystar = 0x2606;
293 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
294 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
297 ratingItem = [menu addItemWithTitle:@"Song Rating"
301 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
303 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
306 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
309 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
312 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
315 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
318 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
320 } else if ([item isEqualToString:@"<separator>"]) {
321 [menu addItem:[NSMenuItem separatorItem]];
325 [statusItem setMenu:menu];
333 //Rebuild the upcoming songs submenu. Can be improved a lot.
334 - (void)rebuildUpcomingSongsMenu
336 int curIndex = [currentRemote currentPlaylistIndex];
337 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
338 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
340 if (!isPlayingRadio) {
342 int curTrack = [currentRemote currentSongIndex];
345 [upcomingSongsMenu release];
346 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
347 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
348 [upcomingSongsItem setEnabled:YES];
350 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
352 NSString *curSong = [currentRemote songTitleAtIndex:i];
353 NSMenuItem *songItem;
354 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
355 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
356 [upcomingSongsMenu addItem:songItem];
364 [upcomingSongsItem setSubmenu:nil];
365 [upcomingSongsItem setEnabled:NO];
369 - (void)rebuildPlaylistMenu
371 NSArray *playlists = [currentRemote playlists];
372 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
374 [playlistMenu release];
375 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
377 for (i = 0; i < [playlists count]; i++) {
378 NSString *playlistName = [playlists objectAtIndex:i];
379 NSMenuItem *tempItem;
380 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
381 [tempItem setTag:i + 1];
382 [playlistMenu addItem:tempItem];
385 [playlistItem setSubmenu:playlistMenu];
386 [playlistItem setEnabled:YES];
388 if (!isPlayingRadio && currentPlaylist) {
389 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
393 //Build a menu with the list of all available EQ presets
394 - (void)rebuildEQPresetsMenu
396 NSArray *eqPresets = [currentRemote eqPresets];
397 NSMenuItem *enabledItem;
401 eqMenu = [[NSMenu alloc] initWithTitle:@""];
403 enabledItem = [eqMenu addItemWithTitle:@"Enabled"
404 action:@selector(selectEQPreset:)
406 [enabledItem setTag:-1];
408 if ([currentRemote equalizerEnabled]) {
409 [enabledItem setState:NSOnState];
412 [eqMenu addItem:[NSMenuItem separatorItem]];
414 for (i = 0; i < [eqPresets count]; i++) {
415 NSString *name = [eqPresets objectAtIndex:i];
416 NSMenuItem *tempItem;
418 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
420 [eqMenu addItem:tempItem];
424 [eqItem setSubmenu:eqMenu];
425 [eqItem setEnabled:YES];
427 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
430 - (void)updateRatingMenu
432 int currentSongRating = ([currentRemote currentSongRating] * 5);
433 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
434 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
437 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
438 lastSongRating = currentSongRating;
439 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
445 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
446 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
447 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
451 [self updateRatingMenu];
453 //Update Play/Pause menu item
455 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
456 [playPauseItem setTitle:@"Pause"];
458 [playPauseItem setTitle:@"Play"];
465 NSUserDefaults *defaults;
466 int playlist = [currentRemote currentPlaylistIndex];
469 if ( (isAppRunning == ITMTRemotePlayerNotRunning) ) {
473 defaults = [NSUserDefaults standardUserDefaults];
474 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
476 if (upcomingSongsItem) {
477 [self rebuildUpcomingSongsMenu];
481 [self rebuildPlaylistMenu];
485 [self rebuildEQPresetsMenu];
489 if (isPlayingRadio || !playlist) {
490 [ratingItem setEnabled:NO];
491 if ([ratingItem submenu]) {
492 [ratingItem setSubmenu:nil];
495 int currentSongRating = ([currentRemote currentSongRating] * 5);
496 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
497 lastSongRating = currentSongRating;
498 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
499 [ratingItem setEnabled:YES];
500 [ratingItem setSubmenu:ratingMenu];
504 //Set the new unique song identifier
505 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
507 //If we're in a playlist or radio mode
508 if ( (trackInfoIndex > -1) && (playlist || isPlayingRadio) ) {
509 NSString *title, *album, *artist;
511 if ( (temp = [menu indexOfItemWithTitle:@"No Song"]) && (temp > -1) ) {
512 [menu removeItemAtIndex:temp];
513 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:temp];
516 title = [currentRemote currentSongTitle];
518 if (!isPlayingRadio) {
519 ([defaults boolForKey:@"showAlbum"]) ? (album = [currentRemote currentSongAlbum]) :
521 ([defaults boolForKey:@"showArtist"]) ? (artist = [currentRemote currentSongArtist]) :
523 if ([defaults boolForKey:@"showTime"]) {
524 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
527 if ([artist length] > 0) {
528 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
531 if ([album length] > 0) {
532 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
535 if ([defaults boolForKey:@"showArtist"]) {
536 didHaveArtistName = (([artist length] > 0) ? YES : NO);
539 if ([defaults boolForKey:@"showAlbum"]) {
540 didHaveAlbumName = (([album length] > 0) ? YES : NO);
544 if ([title length] > 0) {
545 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
558 - (void)selectSong:(id)sender
560 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
563 - (void)selectPlaylist:(id)sender
565 int playlist = [sender tag];
566 [currentRemote switchToPlaylistAtIndex:playlist];
569 - (void)selectEQPreset:(id)sender
571 int curSet = [currentRemote currentEQPresetIndex];
572 int item = [sender tag];
575 [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
577 [currentRemote setEqualizerEnabled:YES];
578 [currentRemote switchToEQAtIndex:item];
579 [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
580 [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
584 - (void)selectSongRating:(id)sender
586 int newRating = [sender tag];
587 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
588 [sender setState:NSOnState];
589 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
590 lastSongRating = newRating / 20;
593 - (void)playPause:(id)sender
595 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
597 if (state == ITMTRemotePlayerPlaying) {
598 [currentRemote pause];
599 [playPauseItem setTitle:@"Play"];
600 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
601 [currentRemote pause];
602 [currentRemote play];
604 [currentRemote play];
605 [playPauseItem setTitle:@"Pause"];
609 - (void)nextSong:(id)sender
611 [currentRemote goToNextSong];
614 - (void)prevSong:(id)sender
616 [currentRemote goToPreviousSong];
619 - (void)fastForward:(id)sender
621 [currentRemote forward];
622 [playPauseItem setTitle:@"Play"];
625 - (void)rewind:(id)sender
627 [currentRemote rewind];
628 [playPauseItem setTitle:@"Play"];
633 - (void)quitMenuTunes:(id)sender
635 [NSApp terminate:self];
638 - (void)showPlayer:(id)sender
640 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
641 [currentRemote showPrimaryInterface];
643 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
644 NSLog(@"Error Launching Player");
649 - (void)showPreferences:(id)sender
651 [[PreferencesController sharedPrefs] setController:self];
652 [[PreferencesController sharedPrefs] showPrefsWindow:self];
655 - (void)closePreferences
657 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
671 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
672 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
673 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
674 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
675 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
680 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
682 if ([defaults objectForKey:@"PlayPause"] != nil) {
683 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
684 combo:[defaults keyComboForKey:@"PlayPause"]
685 target:self action:@selector(playPause:)];
688 if ([defaults objectForKey:@"NextTrack"] != nil) {
689 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
690 combo:[defaults keyComboForKey:@"NextTrack"]
691 target:self action:@selector(nextSong:)];
694 if ([defaults objectForKey:@"PrevTrack"] != nil) {
695 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
696 combo:[defaults keyComboForKey:@"PrevTrack"]
697 target:self action:@selector(prevSong:)];
700 if ([defaults objectForKey:@"TrackInfo"] != nil) {
701 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
702 combo:[defaults keyComboForKey:@"TrackInfo"]
703 target:self action:@selector(showCurrentTrackInfo)];
706 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
707 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
708 combo:[defaults keyComboForKey:@"UpcomingSongs"]
709 target:self action:@selector(showUpcomingSongs)];
715 // Show Current Track Info And Show Upcoming Songs Floaters
719 - (void)showCurrentTrackInfo
721 NSString *trackName = [currentRemote currentSongTitle];
722 if (!statusWindow && [trackName length]) {
723 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
724 NSString *stringToShow = @"";
726 if ([defaults boolForKey:@"showName"]) {
727 if ([defaults boolForKey:@"showArtist"]) {
728 NSString *trackArtist = [currentRemote currentSongArtist];
729 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
731 stringToShow = [stringToShow stringByAppendingString:trackName];
732 stringToShow = [stringToShow stringByAppendingString:@"\n"];
735 if ([defaults boolForKey:@"showAlbum"]) {
736 NSString *trackAlbum = [currentRemote currentSongAlbum];
737 if ([trackAlbum length]) {
738 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
739 stringToShow = [stringToShow stringByAppendingString:@"\n"];
743 if ([defaults boolForKey:@"showTime"]) {
744 NSString *trackTime = [currentRemote currentSongLength];
745 if ([trackTime length]) {
746 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
751 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
752 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
754 stringToShow = [stringToShow stringByAppendingString:
755 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
757 stringToShow = [stringToShow stringByAppendingString:
758 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
762 [statusWindow setText:stringToShow];
763 [NSTimer scheduledTimerWithTimeInterval:3.0
765 selector:@selector(fadeAndCloseStatusWindow)
771 - (void)showUpcomingSongs
773 int curPlaylist = [currentRemote currentPlaylistIndex];
775 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
778 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
779 int curTrack = [currentRemote currentSongIndex];
781 NSString *songs = @"";
783 statusWindow = [ITTransientStatusWindow sharedWindow];
784 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
786 NSString *curSong = [currentRemote songTitleAtIndex:i];
787 songs = [songs stringByAppendingString:curSong];
788 songs = [songs stringByAppendingString:@"\n"];
791 [statusWindow setText:songs];
792 [NSTimer scheduledTimerWithTimeInterval:3.0
794 selector:@selector(fadeAndCloseStatusWindow)
801 - (void)fadeAndCloseStatusWindow
803 [statusWindow orderOut:self];
806 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
807 onItem:(NSMenuItem *)item
809 unichar charcode = 'a';
811 long cocoaModifiers = 0;
812 static long carbonToCocoa[6][2] =
814 { cmdKey, NSCommandKeyMask },
815 { optionKey, NSAlternateKeyMask },
816 { controlKey, NSControlKeyMask },
817 { shiftKey, NSShiftKeyMask },
820 for (i = 0; i < 6; i++) {
821 if (modifiers & carbonToCocoa[i][0]) {
822 cocoaModifiers += carbonToCocoa[i][1];
825 [item setKeyEquivalentModifierMask:cocoaModifiers];
827 //Missing key combos for some keys. Must find them later.
841 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
842 NSLog(@"%@", menuRef);
843 SetMenuItemCommandKey(menuRef, 0, NO, 49);
844 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
845 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
851 charcode = NSDeleteFunctionKey;
867 charcode = NSF5FunctionKey;
871 charcode = NSF6FunctionKey;
875 charcode = NSF7FunctionKey;
879 charcode = NSF3FunctionKey;
883 charcode = NSF8FunctionKey;
887 charcode = NSF9FunctionKey;
891 charcode = NSF11FunctionKey;
895 charcode = NSF3FunctionKey;
899 charcode = NSF14FunctionKey;
903 charcode = NSF10FunctionKey;
907 charcode = NSF12FunctionKey;
911 charcode = NSF13FunctionKey;
915 charcode = NSInsertFunctionKey;
919 charcode = NSHomeFunctionKey;
923 charcode = NSPageUpFunctionKey;
927 charcode = NSDeleteFunctionKey;
931 charcode = NSF4FunctionKey;
935 charcode = NSEndFunctionKey;
939 charcode = NSF2FunctionKey;
943 charcode = NSPageDownFunctionKey;
947 charcode = NSF1FunctionKey;
951 charcode = NSLeftArrowFunctionKey;
955 charcode = NSRightArrowFunctionKey;
959 charcode = NSDownArrowFunctionKey;
963 charcode = NSUpArrowFunctionKey;
967 if (charcode == 'a') {
973 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
974 keyTrans = KeyTranslate(kchr, code, &state);
976 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
977 } else if (charcode != 'b') {
978 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];