1 #import "MainController.h"
2 #import "PreferencesController.h"
3 #import "HotKeyCenter.h"
4 #import "StatusWindow.h"
6 @interface MainController(Private)
7 - (ITMTRemote *)loadRemote;
8 - (void)rebuildUpcomingSongsMenu;
9 - (void)rebuildPlaylistMenu;
10 - (void)rebuildEQPresetsMenu;
11 - (void)updateRatingMenu;
14 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
15 onItem:(NSMenuItem *)item;
19 @implementation MainController
21 /*************************************************************************/
23 #pragma mark INITIALIZATION/DEALLOCATION METHODS
24 /*************************************************************************/
28 if ( ( self = [super init] ) ) {
29 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
30 statusWindow = [StatusWindow sharedWindow];
38 [refreshTimer invalidate];
39 [refreshTimer release];
48 - (void)applicationDidFinishLaunching:(NSNotification *)note
50 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
51 currentRemote = [self loadRemote];
52 [currentRemote begin];
54 //Setup for notification of the remote player launching or quitting
55 [[[NSWorkspace sharedWorkspace] notificationCenter]
57 selector:@selector(applicationTerminated:)
58 name:NSWorkspaceDidTerminateApplicationNotification
61 [[[NSWorkspace sharedWorkspace] notificationCenter]
63 selector:@selector(applicationLaunched:)
64 name:NSWorkspaceDidLaunchApplicationNotification
67 if ( ! [defaults objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered.
68 [[PreferencesController sharedPrefs] registerDefaults];
71 statusItem = [[ITStatusItem alloc]
72 initWithStatusBar:[NSStatusBar systemStatusBar]
73 withLength:NSSquareStatusItemLength];
75 menu = [[NSMenu alloc] initWithTitle:@""];
76 if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) {
77 [self applicationLaunched:nil];
79 [self applicationTerminated:nil];
82 [statusItem setImage:[NSImage imageNamed:@"menu"]];
83 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
84 // Below line of code is for creating builds for Beta Testers
85 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
88 - (void)applicationWillTerminate:(NSNotification *)note
91 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
94 - (ITMTRemote *)loadRemote
96 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
99 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
100 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
101 NSString *bundlePath;
103 while ( (bundlePath = [enumerator nextObject]) ) {
104 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
107 Class remoteClass = [remoteBundle principalClass];
109 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
110 [remoteClass isKindOfClass:[NSObject class]]) {
112 id remote = [remoteClass remote];
113 [remoteArray addObject:remote];
118 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
119 // if ( [remoteArray count] > 1 ) {
120 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
122 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
125 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
126 return [remoteArray objectAtIndex:0];
132 - (void)applicationLaunched:(NSNotification *)note
134 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
135 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
138 isAppRunning = ITMTRemotePlayerRunning;
142 isAppRunning = ITMTRemotePlayerRunning;
145 - (void)applicationTerminated:(NSNotification *)note
147 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
148 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
149 [[notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""] setTarget:self];
150 [notRunningMenu addItem:[NSMenuItem separatorItem]];
151 [[notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
152 [[notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
153 [statusItem setMenu:[notRunningMenu autorelease]];
155 [refreshTimer invalidate];
156 [refreshTimer release];
164 /*************************************************************************/
166 #pragma mark INSTANCE METHODS
167 /*************************************************************************/
169 - (void)startTimerInNewThread
171 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
172 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
173 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
175 selector:@selector(timerUpdate)
177 repeats:YES] retain];
182 //Recreate the status item menu
185 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
186 NSArray *myMenu = [defaults arrayForKey:@"menu"];
187 int playlist = [currentRemote currentPlaylistIndex];
191 lastPlaylistIndex = -1;
192 didHaveAlbumName = ([[currentRemote currentSongAlbum] length] > 0);
193 didHaveArtistName = ([[currentRemote currentSongArtist] length] > 0);
196 menu = [[NSMenu alloc] initWithTitle:@""];
199 lastSongIdentifier = @"0-0";
201 upcomingSongsItem = nil;
202 [upcomingSongsMenu release];
203 upcomingSongsMenu = nil;
206 [ratingMenu release];
210 [playlistMenu release];
217 for (i = 0; i < [myMenu count]; i++) {
218 NSString *item = [myMenu objectAtIndex:i];
219 if ([item isEqualToString:@"Play/Pause"]) {
220 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
221 playPauseItem = [menu addItemWithTitle:@"Play"
222 action:@selector(playPause:)
226 [self setKeyEquivalentForCode:[tempCombo keyCode]
227 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
230 } else if ([item isEqualToString:@"Next Track"]) {
231 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
232 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
233 action:@selector(nextSong:)
237 [self setKeyEquivalentForCode:[tempCombo keyCode]
238 andModifiers:[tempCombo modifiers] onItem:nextTrack];
241 } else if ([item isEqualToString:@"Previous Track"]) {
242 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
243 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
244 action:@selector(prevSong:)
248 [self setKeyEquivalentForCode:[tempCombo keyCode]
249 andModifiers:[tempCombo modifiers] onItem:prevTrack];
252 } else if ([item isEqualToString:@"Fast Forward"]) {
253 [menu addItemWithTitle:@"Fast Forward"
254 action:@selector(fastForward:)
256 } else if ([item isEqualToString:@"Rewind"]) {
257 [menu addItemWithTitle:@"Rewind"
258 action:@selector(rewind:)
260 } else if ([item isEqualToString:@"Show Player"]) {
261 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
262 action:@selector(showPlayer:)
264 } else if ([item isEqualToString:@"Upcoming Songs"]) {
265 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
268 } else if ([item isEqualToString:@"Playlists"]) {
269 playlistItem = [menu addItemWithTitle:@"Playlists"
272 } else if ([item isEqualToString:@"EQ Presets"]) {
273 eqItem = [menu addItemWithTitle:@"EQ Presets"
276 } else if ([item isEqualToString:@"PreferencesÉ"]) {
277 [menu addItemWithTitle:@"PreferencesÉ"
278 action:@selector(showPreferences:)
280 } else if ([item isEqualToString:@"Quit"]) {
281 [menu addItemWithTitle:@"Quit"
282 action:@selector(quitMenuTunes:)
284 } else if ([item isEqualToString:@"Current Track Info"]) {
285 trackInfoIndex = [menu numberOfItems];
286 [menu addItemWithTitle:@"No Song"
289 } else if ([item isEqualToString:@"Song Rating"]) {
290 unichar fullstar = 0x2605;
291 unichar emptystar = 0x2606;
292 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
293 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
296 ratingItem = [menu addItemWithTitle:@"Song Rating"
300 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
302 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
305 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
308 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
311 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
314 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
317 item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
319 } else if ([item isEqualToString:@"<separator>"]) {
320 [menu addItem:[NSMenuItem separatorItem]];
324 if ( (isAppRunning == ITMTRemotePlayerRunning) ) {
325 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
327 if (upcomingSongsItem) {
328 [self rebuildUpcomingSongsMenu];
332 [self rebuildPlaylistMenu];
336 [self rebuildEQPresetsMenu];
340 if (isPlayingRadio || !playlist) {
341 [ratingItem setEnabled:NO];
342 if ([ratingItem submenu]) {
343 [ratingItem setSubmenu:nil];
346 int currentSongRating = ([currentRemote currentSongRating] * 5);
347 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
348 lastSongRating = currentSongRating;
349 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
350 [ratingItem setEnabled:YES];
351 [ratingItem setSubmenu:ratingMenu];
355 //Set the new unique song identifier
356 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
358 //If we're in a playlist or radio mode
359 if ( (trackInfoIndex > -1) && (playlist || isPlayingRadio) ) {
360 NSString *title, *album, *artist;
362 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) && (i > -1) ) {
363 [menu removeItemAtIndex:i];
364 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
367 title = [currentRemote currentSongTitle];
369 if (!isPlayingRadio) {
370 ([defaults boolForKey:@"showAlbum"]) ? (album = [currentRemote currentSongAlbum]) :
372 ([defaults boolForKey:@"showArtist"]) ? (artist = [currentRemote currentSongArtist]) :
374 if ([defaults boolForKey:@"showTime"]) {
375 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
378 if ([artist length] > 0) {
379 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
382 if ([album length] > 0) {
383 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
386 if ([defaults boolForKey:@"showArtist"]) {
387 didHaveArtistName = (([artist length] > 0) ? YES : NO);
390 if ([defaults boolForKey:@"showAlbum"]) {
391 didHaveAlbumName = (([album length] > 0) ? YES : NO);
395 if ([title length] > 0) {
396 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
401 [statusItem setMenu:menu];
407 //Rebuild the upcoming songs submenu. Can be improved a lot.
408 - (void)rebuildUpcomingSongsMenu
410 int curIndex = [currentRemote currentPlaylistIndex];
411 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
412 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
414 if (!isPlayingRadio) {
416 int curTrack = [currentRemote currentSongIndex];
419 [upcomingSongsMenu release];
420 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
421 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
422 [upcomingSongsItem setEnabled:YES];
424 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
426 NSString *curSong = [currentRemote songTitleAtIndex:i];
427 NSMenuItem *songItem;
428 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
429 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
430 [upcomingSongsMenu addItem:songItem];
438 [upcomingSongsItem setSubmenu:nil];
439 [upcomingSongsItem setEnabled:NO];
443 - (void)rebuildPlaylistMenu
445 NSArray *playlists = [currentRemote playlists];
446 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
448 [playlistMenu release];
449 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
451 for (i = 0; i < [playlists count]; i++) {
452 NSString *playlistName = [playlists objectAtIndex:i];
453 NSMenuItem *tempItem;
454 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
455 [tempItem setTag:i + 1];
456 [playlistMenu addItem:tempItem];
459 [playlistItem setSubmenu:playlistMenu];
460 [playlistItem setEnabled:YES];
462 if (!isPlayingRadio && currentPlaylist) {
463 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
467 //Build a menu with the list of all available EQ presets
468 - (void)rebuildEQPresetsMenu
470 NSArray *eqPresets = [currentRemote eqPresets];
471 NSMenuItem *enabledItem;
475 eqMenu = [[NSMenu alloc] initWithTitle:@""];
477 enabledItem = [eqMenu addItemWithTitle:@"Enabled"
478 action:@selector(selectEQPreset:)
480 [enabledItem setTag:-1];
482 if ([currentRemote equalizerEnabled]) {
483 [enabledItem setState:NSOnState];
486 [eqMenu addItem:[NSMenuItem separatorItem]];
488 for (i = 0; i < [eqPresets count]; i++) {
489 NSString *name = [eqPresets objectAtIndex:i];
490 NSMenuItem *tempItem;
492 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
494 [eqMenu addItem:tempItem];
498 [eqItem setSubmenu:eqMenu];
499 [eqItem setEnabled:YES];
501 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
504 - (void)updateRatingMenu
506 int currentSongRating = ([currentRemote currentSongRating] * 5);
507 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
508 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
511 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
512 lastSongRating = currentSongRating;
513 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
519 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
520 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
521 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
525 [self updateRatingMenu];
527 //Update Play/Pause menu item
529 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
530 [playPauseItem setTitle:@"Pause"];
532 [playPauseItem setTitle:@"Play"];
543 - (void)selectSong:(id)sender
545 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
548 - (void)selectPlaylist:(id)sender
550 int playlist = [sender tag];
551 [currentRemote switchToPlaylistAtIndex:playlist];
554 - (void)selectEQPreset:(id)sender
556 int curSet = [currentRemote currentEQPresetIndex];
557 int item = [sender tag];
560 [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
562 [currentRemote setEqualizerEnabled:YES];
563 [currentRemote switchToEQAtIndex:item];
564 [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
565 [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
569 - (void)selectSongRating:(id)sender
571 int newRating = [sender tag];
572 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
573 [sender setState:NSOnState];
574 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
575 lastSongRating = newRating / 20;
578 - (void)playPause:(id)sender
580 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
582 if (state == ITMTRemotePlayerPlaying) {
583 [currentRemote pause];
584 [playPauseItem setTitle:@"Play"];
585 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
586 [currentRemote pause];
587 [currentRemote play];
589 [currentRemote play];
590 [playPauseItem setTitle:@"Pause"];
594 - (void)nextSong:(id)sender
596 [currentRemote goToNextSong];
599 - (void)prevSong:(id)sender
601 [currentRemote goToPreviousSong];
604 - (void)fastForward:(id)sender
606 [currentRemote forward];
607 [playPauseItem setTitle:@"Play"];
610 - (void)rewind:(id)sender
612 [currentRemote rewind];
613 [playPauseItem setTitle:@"Play"];
618 - (void)quitMenuTunes:(id)sender
620 [NSApp terminate:self];
623 - (void)showPlayer:(id)sender
625 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
626 [currentRemote showPrimaryInterface];
628 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
629 NSLog(@"Error Launching Player");
634 - (void)showPreferences:(id)sender
636 [[PreferencesController sharedPrefs] setController:self];
637 [[PreferencesController sharedPrefs] showPrefsWindow:self];
640 - (void)closePreferences
642 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
656 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
657 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
658 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
659 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
660 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
665 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
667 if ([defaults objectForKey:@"PlayPause"] != nil) {
668 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
669 combo:[defaults keyComboForKey:@"PlayPause"]
670 target:self action:@selector(playPause:)];
673 if ([defaults objectForKey:@"NextTrack"] != nil) {
674 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
675 combo:[defaults keyComboForKey:@"NextTrack"]
676 target:self action:@selector(nextSong:)];
679 if ([defaults objectForKey:@"PrevTrack"] != nil) {
680 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
681 combo:[defaults keyComboForKey:@"PrevTrack"]
682 target:self action:@selector(prevSong:)];
685 if ([defaults objectForKey:@"TrackInfo"] != nil) {
686 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
687 combo:[defaults keyComboForKey:@"TrackInfo"]
688 target:self action:@selector(showCurrentTrackInfo)];
691 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
692 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
693 combo:[defaults keyComboForKey:@"UpcomingSongs"]
694 target:self action:@selector(showUpcomingSongs)];
700 // Show Current Track Info And Show Upcoming Songs Floaters
704 - (void)showCurrentTrackInfo
706 NSString *trackName = [currentRemote currentSongTitle];
707 if (!statusWindow && [trackName length]) {
708 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
709 NSString *stringToShow = @"";
711 if ([defaults boolForKey:@"showName"]) {
712 if ([defaults boolForKey:@"showArtist"]) {
713 NSString *trackArtist = [currentRemote currentSongArtist];
714 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
716 stringToShow = [stringToShow stringByAppendingString:trackName];
717 stringToShow = [stringToShow stringByAppendingString:@"\n"];
720 if ([defaults boolForKey:@"showAlbum"]) {
721 NSString *trackAlbum = [currentRemote currentSongAlbum];
722 if ([trackAlbum length]) {
723 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
724 stringToShow = [stringToShow stringByAppendingString:@"\n"];
728 if ([defaults boolForKey:@"showTime"]) {
729 NSString *trackTime = [currentRemote currentSongLength];
730 if ([trackTime length]) {
731 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
736 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
737 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
739 stringToShow = [stringToShow stringByAppendingString:
740 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
742 stringToShow = [stringToShow stringByAppendingString:
743 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
748 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
751 /*[statusWindow setText:stringToShow];
752 [NSTimer scheduledTimerWithTimeInterval:3.0
754 selector:@selector(fadeAndCloseStatusWindow)
760 - (void)showUpcomingSongs
762 int curPlaylist = [currentRemote currentPlaylistIndex];
764 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
767 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
768 int curTrack = [currentRemote currentSongIndex];
770 NSString *songs = @"";
772 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
774 NSString *curSong = [currentRemote songTitleAtIndex:i];
775 songs = [songs stringByAppendingString:curSong];
776 songs = [songs stringByAppendingString:@"\n"];
781 //SHOW STATUS WINDOW HERE WITH STRING songs
784 /*[statusWindow setText:songs];
785 [NSTimer scheduledTimerWithTimeInterval:3.0
787 selector:@selector(fadeAndCloseStatusWindow)
794 - (void)fadeAndCloseStatusWindow
796 [statusWindow orderOut:self];
799 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
800 onItem:(NSMenuItem *)item
802 unichar charcode = 'a';
804 long cocoaModifiers = 0;
805 static long carbonToCocoa[6][2] =
807 { cmdKey, NSCommandKeyMask },
808 { optionKey, NSAlternateKeyMask },
809 { controlKey, NSControlKeyMask },
810 { shiftKey, NSShiftKeyMask },
813 for (i = 0; i < 6; i++) {
814 if (modifiers & carbonToCocoa[i][0]) {
815 cocoaModifiers += carbonToCocoa[i][1];
818 [item setKeyEquivalentModifierMask:cocoaModifiers];
820 //Missing key combos for some keys. Must find them later.
834 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
835 NSLog(@"%@", menuRef);
836 SetMenuItemCommandKey(menuRef, 0, NO, 49);
837 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
838 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
844 charcode = NSDeleteFunctionKey;
860 charcode = NSF5FunctionKey;
864 charcode = NSF6FunctionKey;
868 charcode = NSF7FunctionKey;
872 charcode = NSF3FunctionKey;
876 charcode = NSF8FunctionKey;
880 charcode = NSF9FunctionKey;
884 charcode = NSF11FunctionKey;
888 charcode = NSF3FunctionKey;
892 charcode = NSF14FunctionKey;
896 charcode = NSF10FunctionKey;
900 charcode = NSF12FunctionKey;
904 charcode = NSF13FunctionKey;
908 charcode = NSInsertFunctionKey;
912 charcode = NSHomeFunctionKey;
916 charcode = NSPageUpFunctionKey;
920 charcode = NSDeleteFunctionKey;
924 charcode = NSF4FunctionKey;
928 charcode = NSEndFunctionKey;
932 charcode = NSF2FunctionKey;
936 charcode = NSPageDownFunctionKey;
940 charcode = NSF1FunctionKey;
944 charcode = NSLeftArrowFunctionKey;
948 charcode = NSRightArrowFunctionKey;
952 charcode = NSDownArrowFunctionKey;
956 charcode = NSUpArrowFunctionKey;
960 if (charcode == 'a') {
966 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
967 keyTrans = KeyTranslate(kchr, code, &state);
969 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
970 } else if (charcode != 'b') {
971 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];