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:@""];
203 lastSongIdentifier = @"0-0";
205 upcomingSongsItem = nil;
206 [upcomingSongsMenu release];
207 upcomingSongsMenu = nil;
210 [ratingMenu release];
214 [playlistMenu release];
221 for (i = 0; i < [myMenu count]; i++) {
222 NSString *item = [myMenu objectAtIndex:i];
223 if ([item isEqualToString:@"Play/Pause"]) {
224 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
225 playPauseItem = [menu addItemWithTitle:@"Play"
226 action:@selector(playPause:)
230 [self setKeyEquivalentForCode:[tempCombo keyCode]
231 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
234 } else if ([item isEqualToString:@"Next Track"]) {
235 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
236 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
237 action:@selector(nextSong:)
241 [self setKeyEquivalentForCode:[tempCombo keyCode]
242 andModifiers:[tempCombo modifiers] onItem:nextTrack];
245 } else if ([item isEqualToString:@"Previous Track"]) {
246 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
247 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
248 action:@selector(prevSong:)
252 [self setKeyEquivalentForCode:[tempCombo keyCode]
253 andModifiers:[tempCombo modifiers] onItem:prevTrack];
256 } else if ([item isEqualToString:@"Fast Forward"]) {
257 [menu addItemWithTitle:@"Fast Forward"
258 action:@selector(fastForward:)
260 } else if ([item isEqualToString:@"Rewind"]) {
261 [menu addItemWithTitle:@"Rewind"
262 action:@selector(rewind:)
264 } else if ([item isEqualToString:@"Show Player"]) {
265 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
266 action:@selector(showPlayer:)
268 } else if ([item isEqualToString:@"Upcoming Songs"]) {
269 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
272 } else if ([item isEqualToString:@"Playlists"]) {
273 playlistItem = [menu addItemWithTitle:@"Playlists"
276 } else if ([item isEqualToString:@"EQ Presets"]) {
277 eqItem = [menu addItemWithTitle:@"EQ Presets"
280 } else if ([item isEqualToString:@"PreferencesÉ"]) {
281 [menu addItemWithTitle:@"PreferencesÉ"
282 action:@selector(showPreferences:)
284 } else if ([item isEqualToString:@"Quit"]) {
285 [menu addItemWithTitle:@"Quit"
286 action:@selector(quitMenuTunes:)
288 } else if ([item isEqualToString:@"Current Track Info"]) {
289 trackInfoIndex = [menu numberOfItems];
290 [menu addItemWithTitle:@"No Song"
293 } else if ([item isEqualToString:@"Song Rating"]) {
294 unichar fullstar = 0x2605;
295 unichar emptystar = 0x2606;
296 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
297 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
300 ratingItem = [menu addItemWithTitle:@"Song Rating"
304 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
306 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
309 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
312 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
315 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
318 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
321 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
324 [ratingItem setSubmenu:ratingMenu];
325 } else if ([item isEqualToString:@"<separator>"]) {
326 [menu addItem:[NSMenuItem separatorItem]];
331 [self rebuildPlaylistMenu];
335 [self rebuildEQPresetsMenu];
338 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
340 if (upcomingSongsItem) {
341 [self rebuildUpcomingSongsMenu];
345 if (isPlayingRadio || !playlist) {
346 [ratingItem setEnabled:NO];
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];
356 //Set the new unique song identifier
357 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
359 //If we're in a playlist or radio mode
360 if ( (trackInfoIndex > -1) && (playlist || isPlayingRadio) ) {
363 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) && (i > -1) ) {
364 [menu removeItemAtIndex:i];
365 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
368 title = [currentRemote currentSongTitle];
370 if (!isPlayingRadio) {
371 if ([defaults boolForKey:@"showTime"]) {
372 NSString *length = [currentRemote currentSongLength];
373 char character = [length characterAtIndex:0];
374 if ( (character > '0') && (character < '9') ) {
375 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
379 if ([defaults boolForKey:@"showArtist"]) {
380 NSString *artist = [currentRemote currentSongArtist];
382 if ([artist length] > 0) {
383 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
386 didHaveArtistName = (([artist length] > 0) ? YES : NO);
389 if ([defaults boolForKey:@"showAlbum"]) {
390 NSString *album = [currentRemote currentSongAlbum];
392 if ([album length] > 0) {
393 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
394 didHaveAlbumName = (([album length]) ? YES : NO);
399 if ([title length] > 0) {
400 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
404 [statusItem setMenu:menu];
410 //Rebuild the upcoming songs submenu. Can be improved a lot.
411 - (void)rebuildUpcomingSongsMenu
413 int curIndex = [currentRemote currentPlaylistIndex];
414 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
415 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
417 if (!isPlayingRadio) {
419 int curTrack = [currentRemote currentSongIndex];
422 [upcomingSongsMenu release];
423 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
424 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
425 [upcomingSongsItem setEnabled:YES];
427 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
429 NSString *curSong = [currentRemote songTitleAtIndex:i];
430 NSMenuItem *songItem;
431 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
432 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
433 [upcomingSongsMenu addItem:songItem];
441 [upcomingSongsItem setSubmenu:nil];
442 [upcomingSongsItem setEnabled:NO];
446 - (void)rebuildPlaylistMenu
448 NSArray *playlists = [currentRemote playlists];
449 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
451 [playlistMenu release];
452 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
454 for (i = 0; i < [playlists count]; i++) {
455 NSString *playlistName = [playlists objectAtIndex:i];
456 NSMenuItem *tempItem;
457 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
458 [tempItem setTag:i + 1];
459 [playlistMenu addItem:tempItem];
462 [playlistItem setSubmenu:playlistMenu];
463 [playlistItem setEnabled:YES];
465 if (!isPlayingRadio && currentPlaylist) {
466 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
470 //Build a menu with the list of all available EQ presets
471 - (void)rebuildEQPresetsMenu
473 NSArray *eqPresets = [currentRemote eqPresets];
474 NSMenuItem *enabledItem;
478 eqMenu = [[NSMenu alloc] initWithTitle:@""];
480 enabledItem = [eqMenu addItemWithTitle:@"Enabled"
481 action:@selector(selectEQPreset:)
483 [enabledItem setTag:-1];
485 if ([currentRemote equalizerEnabled]) {
486 [enabledItem setState:NSOnState];
489 [eqMenu addItem:[NSMenuItem separatorItem]];
491 for (i = 0; i < [eqPresets count]; i++) {
492 NSString *name = [eqPresets objectAtIndex:i];
493 NSMenuItem *tempItem;
495 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
497 [eqMenu addItem:tempItem];
501 [eqItem setSubmenu:eqMenu];
502 [eqItem setEnabled:YES];
504 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
507 - (void)updateRatingMenu
509 int currentSongRating = ([currentRemote currentSongRating] * 5);
510 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
511 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
514 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
515 lastSongRating = currentSongRating;
516 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
522 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
523 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
524 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
528 [self updateRatingMenu];
530 //Update Play/Pause menu item
532 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
533 [playPauseItem setTitle:@"Pause"];
535 [playPauseItem setTitle:@"Play"];
546 - (void)selectSong:(id)sender
548 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
551 - (void)selectPlaylist:(id)sender
553 int playlist = [sender tag];
554 [currentRemote switchToPlaylistAtIndex:playlist];
557 - (void)selectEQPreset:(id)sender
559 int curSet = [currentRemote currentEQPresetIndex];
560 int item = [sender tag];
563 [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
565 [currentRemote setEqualizerEnabled:YES];
566 [currentRemote switchToEQAtIndex:item];
567 [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
568 [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
572 - (void)selectSongRating:(id)sender
574 int newRating = [sender tag];
575 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
576 [sender setState:NSOnState];
577 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
578 lastSongRating = newRating / 20;
581 - (void)playPause:(id)sender
583 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
585 if (state == ITMTRemotePlayerPlaying) {
586 [currentRemote pause];
587 [playPauseItem setTitle:@"Play"];
588 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
589 [currentRemote pause];
590 [currentRemote play];
592 [currentRemote play];
593 [playPauseItem setTitle:@"Pause"];
597 - (void)nextSong:(id)sender
599 [currentRemote goToNextSong];
602 - (void)prevSong:(id)sender
604 [currentRemote goToPreviousSong];
607 - (void)fastForward:(id)sender
609 [currentRemote forward];
610 [playPauseItem setTitle:@"Play"];
613 - (void)rewind:(id)sender
615 [currentRemote rewind];
616 [playPauseItem setTitle:@"Play"];
621 - (void)quitMenuTunes:(id)sender
623 [NSApp terminate:self];
626 - (void)showPlayer:(id)sender
628 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
629 [currentRemote showPrimaryInterface];
631 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
632 NSLog(@"Error Launching Player");
637 - (void)showPreferences:(id)sender
639 [[PreferencesController sharedPrefs] setController:self];
640 [[PreferencesController sharedPrefs] showPrefsWindow:self];
643 - (void)closePreferences
645 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
650 - (ITMTRemote *)currentRemote
652 return currentRemote;
663 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
664 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
665 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
666 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
667 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
672 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
674 if ([defaults objectForKey:@"PlayPause"] != nil) {
675 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
676 combo:[defaults keyComboForKey:@"PlayPause"]
677 target:self action:@selector(playPause:)];
680 if ([defaults objectForKey:@"NextTrack"] != nil) {
681 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
682 combo:[defaults keyComboForKey:@"NextTrack"]
683 target:self action:@selector(nextSong:)];
686 if ([defaults objectForKey:@"PrevTrack"] != nil) {
687 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
688 combo:[defaults keyComboForKey:@"PrevTrack"]
689 target:self action:@selector(prevSong:)];
692 if ([defaults objectForKey:@"TrackInfo"] != nil) {
693 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
694 combo:[defaults keyComboForKey:@"TrackInfo"]
695 target:self action:@selector(showCurrentTrackInfo)];
698 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
699 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
700 combo:[defaults keyComboForKey:@"UpcomingSongs"]
701 target:self action:@selector(showUpcomingSongs)];
707 // Show Current Track Info And Show Upcoming Songs Floaters
711 - (void)showCurrentTrackInfo
713 NSString *trackName = [currentRemote currentSongTitle];
714 if (!statusWindow && [trackName length]) {
715 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
716 NSString *stringToShow = @"";
718 if ([defaults boolForKey:@"showName"]) {
719 if ([defaults boolForKey:@"showArtist"]) {
720 NSString *trackArtist = [currentRemote currentSongArtist];
721 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
723 stringToShow = [stringToShow stringByAppendingString:trackName];
724 stringToShow = [stringToShow stringByAppendingString:@"\n"];
727 if ([defaults boolForKey:@"showAlbum"]) {
728 NSString *trackAlbum = [currentRemote currentSongAlbum];
729 if ([trackAlbum length]) {
730 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
731 stringToShow = [stringToShow stringByAppendingString:@"\n"];
735 if ([defaults boolForKey:@"showTime"]) {
736 NSString *trackTime = [currentRemote currentSongLength];
737 if ([trackTime length]) {
738 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
743 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
744 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
746 stringToShow = [stringToShow stringByAppendingString:
747 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
749 stringToShow = [stringToShow stringByAppendingString:
750 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
755 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
758 /*[statusWindow setText:stringToShow];
759 [NSTimer scheduledTimerWithTimeInterval:3.0
761 selector:@selector(fadeAndCloseStatusWindow)
767 - (void)showUpcomingSongs
769 int curPlaylist = [currentRemote currentPlaylistIndex];
771 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
774 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
775 int curTrack = [currentRemote currentSongIndex];
777 NSString *songs = @"";
779 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
781 NSString *curSong = [currentRemote songTitleAtIndex:i];
782 songs = [songs stringByAppendingString:curSong];
783 songs = [songs stringByAppendingString:@"\n"];
788 //SHOW STATUS WINDOW HERE WITH STRING songs
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]];