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 unichar fullstar = 0x2605;
136 unichar emptystar = 0x2606;
137 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
138 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
139 //Build the song rating menu
140 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
141 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:0];
142 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:20];
143 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:40];
144 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:60];
145 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:80];
146 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:100];
148 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
151 isAppRunning = ITMTRemotePlayerRunning;
155 isAppRunning = ITMTRemotePlayerRunning;
158 - (void)applicationTerminated:(NSNotification *)note
160 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
161 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
162 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
163 [notRunningMenu addItem:[NSMenuItem separatorItem]];
164 [notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""];
165 [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""];
167 [refreshTimer invalidate];
168 [refreshTimer release];
171 isAppRunning = ITMTRemotePlayerNotRunning;
173 [ratingMenu release];
175 [statusItem setMenu:[notRunningMenu autorelease]];
179 /*************************************************************************/
181 #pragma mark INSTANCE METHODS
182 /*************************************************************************/
184 - (void)startTimerInNewThread
186 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
187 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
188 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
190 selector:@selector(timerUpdate)
192 repeats:YES] retain];
197 //Recreate the status item menu
200 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
201 NSArray *myMenu = [defaults arrayForKey:@"menu"];
202 int playlist = [currentRemote currentPlaylistIndex];
205 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
210 lastPlaylistIndex = -1;
213 menu = [[NSMenu alloc] initWithTitle:@""];
217 upcomingSongsItem = nil;
218 [upcomingSongsMenu release];
219 upcomingSongsMenu = nil;
222 [ratingItem setSubmenu:nil];
226 [playlistMenu release];
233 //Build the custom menu
234 for (i = 0; i < [myMenu count]; i++) {
235 NSString *item = [myMenu objectAtIndex:i];
236 if ([item isEqualToString:@"Play/Pause"]) {
237 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
238 playPauseItem = [menu addItemWithTitle:@"Play"
239 action:@selector(playPause:)
243 [self setKeyEquivalentForCode:[tempCombo keyCode]
244 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
247 } else if ([item isEqualToString:@"Next Track"]) {
248 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
249 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
250 action:@selector(nextSong:)
254 [self setKeyEquivalentForCode:[tempCombo keyCode]
255 andModifiers:[tempCombo modifiers] onItem:nextTrack];
258 } else if ([item isEqualToString:@"Previous Track"]) {
259 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
260 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
261 action:@selector(prevSong:)
265 [self setKeyEquivalentForCode:[tempCombo keyCode]
266 andModifiers:[tempCombo modifiers] onItem:prevTrack];
269 } else if ([item isEqualToString:@"Fast Forward"]) {
270 [menu addItemWithTitle:@"Fast Forward"
271 action:@selector(fastForward:)
273 } else if ([item isEqualToString:@"Rewind"]) {
274 [menu addItemWithTitle:@"Rewind"
275 action:@selector(rewind:)
277 } else if ([item isEqualToString:@"Show Player"]) {
278 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
279 action:@selector(showPlayer:)
281 } else if ([item isEqualToString:@"Upcoming Songs"]) {
282 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
285 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
286 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
287 [upcomingSongsItem setEnabled:NO];
288 } else if ([item isEqualToString:@"Playlists"]) {
289 playlistItem = [menu addItemWithTitle:@"Playlists"
292 } else if ([item isEqualToString:@"EQ Presets"]) {
293 eqItem = [menu addItemWithTitle:@"EQ Presets"
296 } else if ([item isEqualToString:@"PreferencesÉ"]) {
297 [menu addItemWithTitle:@"PreferencesÉ"
298 action:@selector(showPreferences:)
300 } else if ([item isEqualToString:@"Quit"]) {
301 [menu addItemWithTitle:@"Quit"
302 action:@selector(quitMenuTunes:)
304 } else if ([item isEqualToString:@"Current Track Info"]) {
305 trackInfoIndex = [menu numberOfItems];
306 [menu addItemWithTitle:@"No Song"
309 } else if ([item isEqualToString:@"Song Rating"]) {
310 ratingItem = [menu addItemWithTitle:@"Song Rating"
313 [ratingItem setSubmenu:ratingMenu];
314 } else if ([item isEqualToString:@"<separator>"]) {
315 [menu addItem:[NSMenuItem separatorItem]];
320 [self rebuildPlaylistMenu];
324 [self rebuildEQPresetsMenu];
327 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
329 if (upcomingSongsItem) {
330 [self rebuildUpcomingSongsMenu];
334 if (isPlayingRadio || !playlist) {
335 [ratingItem setEnabled:NO];
337 int currentSongRating = ([currentRemote currentSongRating] * 5);
338 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
339 lastSongRating = currentSongRating;
340 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
341 [ratingItem setEnabled:YES];
345 //Set the new unique song identifier
346 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
348 //If we're in a playlist or radio mode
349 if ( (trackInfoIndex > -1) && (playlist || isPlayingRadio) ) {
352 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) && (i > -1) ) {
353 [menu removeItemAtIndex:i];
354 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
357 title = [currentRemote currentSongTitle];
359 if (!isPlayingRadio) {
360 if ([defaults boolForKey:@"showTime"]) {
361 NSString *length = [currentRemote currentSongLength];
362 char character = [length characterAtIndex:0];
363 if ( (character > '0') && (character < '9') ) {
364 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
368 if ([defaults boolForKey:@"showTrackRating"]) {
369 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [[ratingMenu itemAtIndex:[currentRemote currentSongRating] * 5] title]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
372 if ([defaults boolForKey:@"showArtist"]) {
373 NSString *artist = [currentRemote currentSongArtist];
374 if ([artist length] > 0) {
375 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
379 if ([defaults boolForKey:@"showAlbum"]) {
380 NSString *album = [currentRemote currentSongAlbum];
381 if ([album length] > 0) {
382 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
387 if ([title length] > 0) {
388 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
392 [statusItem setMenu:menu];
398 //Rebuild the upcoming songs submenu. Can be improved a lot.
399 - (void)rebuildUpcomingSongsMenu
401 int curIndex = [currentRemote currentPlaylistIndex];
402 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
403 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
405 if (!isPlayingRadio) {
407 int curTrack = [currentRemote currentSongIndex];
410 [upcomingSongsMenu release];
411 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
412 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
413 [upcomingSongsItem setEnabled:YES];
415 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
417 NSString *curSong = [currentRemote songTitleAtIndex:i];
418 NSMenuItem *songItem;
419 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
420 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
421 [upcomingSongsMenu addItem:songItem];
429 [upcomingSongsItem setSubmenu:nil];
430 [upcomingSongsItem setEnabled:NO];
434 - (void)rebuildPlaylistMenu
436 NSArray *playlists = [currentRemote playlists];
437 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
439 [playlistMenu release];
440 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
442 for (i = 0; i < [playlists count]; i++) {
443 NSString *playlistName = [playlists objectAtIndex:i];
444 NSMenuItem *tempItem;
445 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
446 [tempItem setTag:i + 1];
447 [playlistMenu addItem:tempItem];
450 [playlistItem setSubmenu:playlistMenu];
451 [playlistItem setEnabled:YES];
453 if (!isPlayingRadio && currentPlaylist) {
454 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
458 //Build a menu with the list of all available EQ presets
459 - (void)rebuildEQPresetsMenu
461 NSArray *eqPresets = [currentRemote eqPresets];
462 NSMenuItem *enabledItem;
466 eqMenu = [[NSMenu alloc] initWithTitle:@""];
468 enabledItem = [eqMenu addItemWithTitle:@"Enabled"
469 action:@selector(selectEQPreset:)
471 [enabledItem setTag:-1];
473 if ([currentRemote equalizerEnabled]) {
474 [enabledItem setState:NSOnState];
477 [eqMenu addItem:[NSMenuItem separatorItem]];
479 for (i = 0; i < [eqPresets count]; i++) {
480 NSString *name = [eqPresets objectAtIndex:i];
481 NSMenuItem *tempItem;
483 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
485 [eqMenu addItem:tempItem];
489 [eqItem setSubmenu:eqMenu];
490 [eqItem setEnabled:YES];
492 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
495 - (void)updateRatingMenu
497 int currentSongRating = ([currentRemote currentSongRating] * 5);
498 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
499 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
502 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
503 lastSongRating = currentSongRating;
504 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
510 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
511 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
512 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
516 [self updateRatingMenu];
518 //Update Play/Pause menu item
520 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
521 [playPauseItem setTitle:@"Pause"];
523 [playPauseItem setTitle:@"Play"];
534 - (void)selectSong:(id)sender
536 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
539 - (void)selectPlaylist:(id)sender
541 int playlist = [sender tag];
542 [currentRemote switchToPlaylistAtIndex:playlist];
545 - (void)selectEQPreset:(id)sender
547 int curSet = [currentRemote currentEQPresetIndex];
548 int item = [sender tag];
551 [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
553 [currentRemote setEqualizerEnabled:YES];
554 [currentRemote switchToEQAtIndex:item];
555 [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
556 [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
560 - (void)selectSongRating:(id)sender
562 int newRating = [sender tag];
563 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
564 [sender setState:NSOnState];
565 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
566 lastSongRating = newRating / 20;
569 - (void)playPause:(id)sender
571 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
573 if (state == ITMTRemotePlayerPlaying) {
574 [currentRemote pause];
575 [playPauseItem setTitle:@"Play"];
576 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
577 [currentRemote pause];
578 [currentRemote play];
580 [currentRemote play];
581 [playPauseItem setTitle:@"Pause"];
585 - (void)nextSong:(id)sender
587 [currentRemote goToNextSong];
590 - (void)prevSong:(id)sender
592 [currentRemote goToPreviousSong];
595 - (void)fastForward:(id)sender
597 [currentRemote forward];
598 [playPauseItem setTitle:@"Play"];
601 - (void)rewind:(id)sender
603 [currentRemote rewind];
604 [playPauseItem setTitle:@"Play"];
609 - (void)quitMenuTunes:(id)sender
611 [NSApp terminate:self];
614 - (void)showPlayer:(id)sender
616 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
617 [currentRemote showPrimaryInterface];
619 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
620 NSLog(@"Error Launching Player");
625 - (void)showPreferences:(id)sender
627 [[PreferencesController sharedPrefs] setController:self];
628 [[PreferencesController sharedPrefs] showPrefsWindow:self];
631 - (void)closePreferences
633 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
638 - (ITMTRemote *)currentRemote
640 return currentRemote;
651 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
652 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
653 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
654 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
655 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
660 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
662 if ([defaults objectForKey:@"PlayPause"] != nil) {
663 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
664 combo:[defaults keyComboForKey:@"PlayPause"]
665 target:self action:@selector(playPause:)];
668 if ([defaults objectForKey:@"NextTrack"] != nil) {
669 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
670 combo:[defaults keyComboForKey:@"NextTrack"]
671 target:self action:@selector(nextSong:)];
674 if ([defaults objectForKey:@"PrevTrack"] != nil) {
675 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
676 combo:[defaults keyComboForKey:@"PrevTrack"]
677 target:self action:@selector(prevSong:)];
680 if ([defaults objectForKey:@"TrackInfo"] != nil) {
681 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
682 combo:[defaults keyComboForKey:@"TrackInfo"]
683 target:self action:@selector(showCurrentTrackInfo)];
686 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
687 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
688 combo:[defaults keyComboForKey:@"UpcomingSongs"]
689 target:self action:@selector(showUpcomingSongs)];
695 // Show Current Track Info And Show Upcoming Songs Floaters
699 - (void)showCurrentTrackInfo
701 NSString *trackName = [currentRemote currentSongTitle];
702 if (!statusWindow && [trackName length]) {
703 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
704 NSString *stringToShow = @"";
706 if ([defaults boolForKey:@"showName"]) {
707 if ([defaults boolForKey:@"showArtist"]) {
708 NSString *trackArtist = [currentRemote currentSongArtist];
709 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
711 stringToShow = [stringToShow stringByAppendingString:trackName];
712 stringToShow = [stringToShow stringByAppendingString:@"\n"];
715 if ([defaults boolForKey:@"showAlbum"]) {
716 NSString *trackAlbum = [currentRemote currentSongAlbum];
717 if ([trackAlbum length]) {
718 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
719 stringToShow = [stringToShow stringByAppendingString:@"\n"];
723 if ([defaults boolForKey:@"showTime"]) {
724 NSString *trackTime = [currentRemote currentSongLength];
725 if ([trackTime length]) {
726 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
731 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
732 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
734 stringToShow = [stringToShow stringByAppendingString:
735 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
737 stringToShow = [stringToShow stringByAppendingString:
738 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
743 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
746 /*[statusWindow setText:stringToShow];
747 [NSTimer scheduledTimerWithTimeInterval:3.0
749 selector:@selector(fadeAndCloseStatusWindow)
755 - (void)showUpcomingSongs
757 int curPlaylist = [currentRemote currentPlaylistIndex];
759 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
762 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
763 int curTrack = [currentRemote currentSongIndex];
765 NSString *songs = @"";
767 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
769 NSString *curSong = [currentRemote songTitleAtIndex:i];
770 songs = [songs stringByAppendingString:curSong];
771 songs = [songs stringByAppendingString:@"\n"];
776 //SHOW STATUS WINDOW HERE WITH STRING songs
779 /*[statusWindow setText:songs];
780 [NSTimer scheduledTimerWithTimeInterval:3.0
782 selector:@selector(fadeAndCloseStatusWindow)
789 - (void)fadeAndCloseStatusWindow
791 [statusWindow orderOut:self];
794 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
795 onItem:(NSMenuItem *)item
797 unichar charcode = 'a';
799 long cocoaModifiers = 0;
800 static long carbonToCocoa[6][2] =
802 { cmdKey, NSCommandKeyMask },
803 { optionKey, NSAlternateKeyMask },
804 { controlKey, NSControlKeyMask },
805 { shiftKey, NSShiftKeyMask },
808 for (i = 0; i < 6; i++) {
809 if (modifiers & carbonToCocoa[i][0]) {
810 cocoaModifiers += carbonToCocoa[i][1];
813 [item setKeyEquivalentModifierMask:cocoaModifiers];
815 //Missing key combos for some keys. Must find them later.
829 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
830 NSLog(@"%@", menuRef);
831 SetMenuItemCommandKey(menuRef, 0, NO, 49);
832 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
833 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
839 charcode = NSDeleteFunctionKey;
855 charcode = NSF5FunctionKey;
859 charcode = NSF6FunctionKey;
863 charcode = NSF7FunctionKey;
867 charcode = NSF3FunctionKey;
871 charcode = NSF8FunctionKey;
875 charcode = NSF9FunctionKey;
879 charcode = NSF11FunctionKey;
883 charcode = NSF3FunctionKey;
887 charcode = NSF14FunctionKey;
891 charcode = NSF10FunctionKey;
895 charcode = NSF12FunctionKey;
899 charcode = NSF13FunctionKey;
903 charcode = NSInsertFunctionKey;
907 charcode = NSHomeFunctionKey;
911 charcode = NSPageUpFunctionKey;
915 charcode = NSDeleteFunctionKey;
919 charcode = NSF4FunctionKey;
923 charcode = NSEndFunctionKey;
927 charcode = NSF2FunctionKey;
931 charcode = NSPageDownFunctionKey;
935 charcode = NSF1FunctionKey;
939 charcode = NSLeftArrowFunctionKey;
943 charcode = NSRightArrowFunctionKey;
947 charcode = NSDownArrowFunctionKey;
951 charcode = NSUpArrowFunctionKey;
955 if (charcode == 'a') {
961 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
962 keyTrans = KeyTranslate(kchr, code, &state);
964 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
965 } else if (charcode != 'b') {
966 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];