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;
156 NSLog(@"applicationTerminated");
159 - (void)applicationTerminated:(NSNotification *)note
161 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
162 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
163 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
164 [notRunningMenu addItem:[NSMenuItem separatorItem]];
165 [notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""];
166 [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""];
168 [refreshTimer invalidate];
169 [refreshTimer release];
172 isAppRunning = ITMTRemotePlayerNotRunning;
174 [ratingMenu release];
176 [statusItem setMenu:[notRunningMenu autorelease]];
180 /*************************************************************************/
182 #pragma mark INSTANCE METHODS
183 /*************************************************************************/
185 - (void)startTimerInNewThread
187 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
188 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
189 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
191 selector:@selector(timerUpdate)
193 repeats:YES] retain];
198 //Recreate the status item menu
201 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
202 NSArray *myMenu = [defaults arrayForKey:@"menu"];
203 int playlist = [currentRemote currentPlaylistIndex];
206 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
211 lastPlaylistIndex = -1;
214 menu = [[NSMenu alloc] initWithTitle:@""];
218 upcomingSongsItem = nil;
219 [upcomingSongsMenu release];
220 upcomingSongsMenu = nil;
223 [ratingItem setSubmenu:nil];
227 [playlistMenu release];
234 //Build the custom menu
235 for (i = 0; i < [myMenu count]; i++) {
236 NSString *item = [myMenu objectAtIndex:i];
237 if ([item isEqualToString:@"Play/Pause"]) {
238 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
239 playPauseItem = [menu addItemWithTitle:@"Play"
240 action:@selector(playPause:)
244 [self setKeyEquivalentForCode:[tempCombo keyCode]
245 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
248 } else if ([item isEqualToString:@"Next Track"]) {
249 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
250 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
251 action:@selector(nextSong:)
255 [self setKeyEquivalentForCode:[tempCombo keyCode]
256 andModifiers:[tempCombo modifiers] onItem:nextTrack];
259 } else if ([item isEqualToString:@"Previous Track"]) {
260 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
261 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
262 action:@selector(prevSong:)
266 [self setKeyEquivalentForCode:[tempCombo keyCode]
267 andModifiers:[tempCombo modifiers] onItem:prevTrack];
270 } else if ([item isEqualToString:@"Fast Forward"]) {
271 [menu addItemWithTitle:@"Fast Forward"
272 action:@selector(fastForward:)
274 } else if ([item isEqualToString:@"Rewind"]) {
275 [menu addItemWithTitle:@"Rewind"
276 action:@selector(rewind:)
278 } else if ([item isEqualToString:@"Show Player"]) {
279 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
280 action:@selector(showPlayer:)
282 } else if ([item isEqualToString:@"Upcoming Songs"]) {
283 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
286 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
287 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
288 [upcomingSongsItem setEnabled:NO];
289 } else if ([item isEqualToString:@"Playlists"]) {
290 playlistItem = [menu addItemWithTitle:@"Playlists"
293 } else if ([item isEqualToString:@"EQ Presets"]) {
294 eqItem = [menu addItemWithTitle:@"EQ Presets"
297 } else if ([item isEqualToString:@"PreferencesÉ"]) {
298 [menu addItemWithTitle:@"PreferencesÉ"
299 action:@selector(showPreferences:)
301 } else if ([item isEqualToString:@"Quit"]) {
302 [menu addItemWithTitle:@"Quit"
303 action:@selector(quitMenuTunes:)
305 } else if ([item isEqualToString:@"Current Track Info"]) {
306 trackInfoIndex = [menu numberOfItems];
307 [menu addItemWithTitle:@"No Song"
310 } else if ([item isEqualToString:@"Song Rating"]) {
311 ratingItem = [menu addItemWithTitle:@"Song Rating"
314 [ratingItem setSubmenu:ratingMenu];
315 } else if ([item isEqualToString:@"<separator>"]) {
316 [menu addItem:[NSMenuItem separatorItem]];
321 [self rebuildPlaylistMenu];
325 [self rebuildEQPresetsMenu];
328 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
330 if (upcomingSongsItem) {
331 [self rebuildUpcomingSongsMenu];
335 if (isPlayingRadio || !playlist) {
336 [ratingItem setEnabled:NO];
338 int currentSongRating = ([currentRemote currentSongRating] * 5);
339 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
340 lastSongRating = currentSongRating;
341 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
342 [ratingItem setEnabled:YES];
346 //Set the new unique song identifier
347 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
349 //If we're in a playlist or radio mode
350 if ( (trackInfoIndex > -1) ) {
353 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) ) {
355 [menu removeItemAtIndex:i];
356 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i-1];
360 title = [currentRemote currentSongTitle];
362 if (!isPlayingRadio) {
363 if ([defaults boolForKey:@"showTime"]) {
364 NSString *length = [currentRemote currentSongLength];
365 char character = [length characterAtIndex:0];
366 if ( (character > '0') && (character < '9') ) {
367 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
371 if ([defaults boolForKey:@"showTrackRating"]) {
372 if (title) { //Check to see if there's a song playing
373 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [[ratingMenu itemAtIndex:[currentRemote currentSongRating] * 5] title]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
377 if ([defaults boolForKey:@"showArtist"]) {
378 NSString *artist = [currentRemote currentSongArtist];
379 if ([artist length] > 0) {
380 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
384 if ([defaults boolForKey:@"showTrackNumber"]) {
385 int track = [currentRemote currentSongTrack];
386 int total = [currentRemote currentAlbumTrackCount];
388 [menu insertItemWithTitle:[NSString stringWithFormat:@" Track %i of %i", track, total] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
392 if ([defaults boolForKey:@"showAlbum"]) {
393 NSString *album = [currentRemote currentSongAlbum];
394 if ([album length] > 0) {
395 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
400 if ([title length] > 0) {
401 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
405 [statusItem setMenu:menu];
411 //Rebuild the upcoming songs submenu. Can be improved a lot.
412 - (void)rebuildUpcomingSongsMenu
414 int curIndex = [currentRemote currentPlaylistIndex];
415 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
416 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
418 if (!isPlayingRadio) {
420 int curTrack = [currentRemote currentSongIndex];
423 [upcomingSongsMenu release];
424 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
425 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
426 [upcomingSongsItem setEnabled:YES];
428 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
430 NSString *curSong = [currentRemote songTitleAtIndex:i];
431 NSMenuItem *songItem;
432 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
433 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
434 [upcomingSongsMenu addItem:songItem];
442 [upcomingSongsItem setSubmenu:nil];
443 [upcomingSongsItem setEnabled:NO];
447 - (void)rebuildPlaylistMenu
449 NSArray *playlists = [currentRemote playlists];
450 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
452 [playlistMenu release];
453 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
455 for (i = 0; i < [playlists count]; i++) {
456 NSString *playlistName = [playlists objectAtIndex:i];
457 NSMenuItem *tempItem;
458 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
459 [tempItem setTag:i + 1];
460 [playlistMenu addItem:tempItem];
463 [playlistItem setSubmenu:playlistMenu];
464 [playlistItem setEnabled:YES];
466 if (!isPlayingRadio && currentPlaylist) {
467 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
471 //Build a menu with the list of all available EQ presets
472 - (void)rebuildEQPresetsMenu
474 NSArray *eqPresets = [currentRemote eqPresets];
477 [eqMenu autorelease];
478 eqMenu = [[NSMenu alloc] initWithTitle:@""];
480 for (i = 0; i < [eqPresets count]; i++) {
482 NSMenuItem *tempItem;
483 if ( ( name = [eqPresets objectAtIndex:i] ) ) {
484 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
486 [eqMenu addItem:tempItem];
487 [tempItem autorelease];
490 [eqItem setSubmenu:eqMenu];
491 [eqItem setEnabled:YES];
493 [[eqMenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
496 - (void)updateRatingMenu
498 int currentSongRating = ([currentRemote currentSongRating] * 5);
499 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
500 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
503 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
504 lastSongRating = currentSongRating;
505 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
511 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
512 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
513 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
517 [self updateRatingMenu];
519 //Update Play/Pause menu item
521 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
522 [playPauseItem setTitle:@"Pause"];
524 [playPauseItem setTitle:@"Play"];
535 - (void)selectSong:(id)sender
537 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
540 - (void)selectPlaylist:(id)sender
542 int playlist = [sender tag];
543 [currentRemote switchToPlaylistAtIndex:playlist];
546 - (void)selectEQPreset:(id)sender
548 int curSet = [currentRemote currentEQPresetIndex];
549 int item = [sender tag];
551 [currentRemote switchToEQAtIndex:item];
552 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
553 [[eqMenu itemAtIndex:item] setState:NSOnState];
556 - (void)selectSongRating:(id)sender
558 int newRating = [sender tag];
559 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
560 [sender setState:NSOnState];
561 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
562 lastSongRating = newRating / 20;
565 - (void)playPause:(id)sender
567 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
569 if (state == ITMTRemotePlayerPlaying) {
570 [currentRemote pause];
571 [playPauseItem setTitle:@"Play"];
572 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
573 [currentRemote pause];
574 [currentRemote play];
576 [currentRemote play];
577 [playPauseItem setTitle:@"Pause"];
581 - (void)nextSong:(id)sender
583 [currentRemote goToNextSong];
586 - (void)prevSong:(id)sender
588 [currentRemote goToPreviousSong];
591 - (void)fastForward:(id)sender
593 [currentRemote forward];
594 [playPauseItem setTitle:@"Play"];
597 - (void)rewind:(id)sender
599 [currentRemote rewind];
600 [playPauseItem setTitle:@"Play"];
605 - (void)quitMenuTunes:(id)sender
607 [NSApp terminate:self];
610 - (void)showPlayer:(id)sender
612 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
613 [currentRemote showPrimaryInterface];
615 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
616 NSLog(@"Error Launching Player");
621 - (void)showPreferences:(id)sender
623 [[PreferencesController sharedPrefs] setController:self];
624 [[PreferencesController sharedPrefs] showPrefsWindow:self];
627 - (void)closePreferences
629 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
634 - (ITMTRemote *)currentRemote
636 return currentRemote;
647 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
648 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
649 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
650 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
651 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
656 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
658 if ([defaults objectForKey:@"PlayPause"] != nil) {
659 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
660 combo:[defaults keyComboForKey:@"PlayPause"]
661 target:self action:@selector(playPause:)];
664 if ([defaults objectForKey:@"NextTrack"] != nil) {
665 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
666 combo:[defaults keyComboForKey:@"NextTrack"]
667 target:self action:@selector(nextSong:)];
670 if ([defaults objectForKey:@"PrevTrack"] != nil) {
671 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
672 combo:[defaults keyComboForKey:@"PrevTrack"]
673 target:self action:@selector(prevSong:)];
676 if ([defaults objectForKey:@"TrackInfo"] != nil) {
677 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
678 combo:[defaults keyComboForKey:@"TrackInfo"]
679 target:self action:@selector(showCurrentTrackInfo)];
682 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
683 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
684 combo:[defaults keyComboForKey:@"UpcomingSongs"]
685 target:self action:@selector(showUpcomingSongs)];
691 // Show Current Track Info And Show Upcoming Songs Floaters
695 - (void)showCurrentTrackInfo
697 NSString *trackName = [currentRemote currentSongTitle];
698 if (!statusWindow && [trackName length]) {
699 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
700 NSString *stringToShow = @"";
702 if ([defaults boolForKey:@"showName"]) {
703 if ([defaults boolForKey:@"showArtist"]) {
704 NSString *trackArtist = [currentRemote currentSongArtist];
705 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
707 stringToShow = [stringToShow stringByAppendingString:trackName];
708 stringToShow = [stringToShow stringByAppendingString:@"\n"];
711 if ([defaults boolForKey:@"showAlbum"]) {
712 NSString *trackAlbum = [currentRemote currentSongAlbum];
713 if ([trackAlbum length]) {
714 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
715 stringToShow = [stringToShow stringByAppendingString:@"\n"];
719 if ([defaults boolForKey:@"showTime"]) {
720 NSString *trackTime = [currentRemote currentSongLength];
721 if ([trackTime length]) {
722 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
727 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
728 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
730 stringToShow = [stringToShow stringByAppendingString:
731 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
733 stringToShow = [stringToShow stringByAppendingString:
734 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
739 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
742 /*[statusWindow setText:stringToShow];
743 [NSTimer scheduledTimerWithTimeInterval:3.0
745 selector:@selector(fadeAndCloseStatusWindow)
751 - (void)showUpcomingSongs
753 int curPlaylist = [currentRemote currentPlaylistIndex];
755 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
758 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
759 int curTrack = [currentRemote currentSongIndex];
761 NSString *songs = @"";
763 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
765 NSString *curSong = [currentRemote songTitleAtIndex:i];
766 songs = [songs stringByAppendingString:curSong];
767 songs = [songs stringByAppendingString:@"\n"];
772 //SHOW STATUS WINDOW HERE WITH STRING songs
775 /*[statusWindow setText:songs];
776 [NSTimer scheduledTimerWithTimeInterval:3.0
778 selector:@selector(fadeAndCloseStatusWindow)
785 - (void)fadeAndCloseStatusWindow
787 [statusWindow orderOut:self];
790 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
791 onItem:(NSMenuItem *)item
793 unichar charcode = 'a';
795 long cocoaModifiers = 0;
796 static long carbonToCocoa[6][2] =
798 { cmdKey, NSCommandKeyMask },
799 { optionKey, NSAlternateKeyMask },
800 { controlKey, NSControlKeyMask },
801 { shiftKey, NSShiftKeyMask },
804 for (i = 0; i < 6; i++) {
805 if (modifiers & carbonToCocoa[i][0]) {
806 cocoaModifiers += carbonToCocoa[i][1];
809 [item setKeyEquivalentModifierMask:cocoaModifiers];
811 //Missing key combos for some keys. Must find them later.
825 // Haven't tested this, though it should work.
827 [[NSString stringWithString:@"Space"] getCharacters:&buffer];
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);
840 charcode = NSDeleteFunctionKey;
856 charcode = NSF5FunctionKey;
860 charcode = NSF6FunctionKey;
864 charcode = NSF7FunctionKey;
868 charcode = NSF3FunctionKey;
872 charcode = NSF8FunctionKey;
876 charcode = NSF9FunctionKey;
880 charcode = NSF11FunctionKey;
884 charcode = NSF3FunctionKey;
888 charcode = NSF14FunctionKey;
892 charcode = NSF10FunctionKey;
896 charcode = NSF12FunctionKey;
900 charcode = NSF13FunctionKey;
904 charcode = NSInsertFunctionKey;
908 charcode = NSHomeFunctionKey;
912 charcode = NSPageUpFunctionKey;
916 charcode = NSDeleteFunctionKey;
920 charcode = NSF4FunctionKey;
924 charcode = NSEndFunctionKey;
928 charcode = NSF2FunctionKey;
932 charcode = NSPageDownFunctionKey;
936 charcode = NSF1FunctionKey;
940 charcode = NSLeftArrowFunctionKey;
944 charcode = NSRightArrowFunctionKey;
948 charcode = NSDownArrowFunctionKey;
952 charcode = NSUpArrowFunctionKey;
956 if (charcode == 'a') {
962 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
963 keyTrans = KeyTranslate(kchr, code, &state);
965 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
966 } else if (charcode != 'b') {
967 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];