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];
147 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
150 isAppRunning = ITMTRemotePlayerRunning;
154 - (void)applicationTerminated:(NSNotification *)note
156 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
157 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
158 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
159 [notRunningMenu addItem:[NSMenuItem separatorItem]];
160 [notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""];
161 [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""];
163 [refreshTimer invalidate];
164 [refreshTimer release];
167 isAppRunning = ITMTRemotePlayerNotRunning;
169 [ratingMenu release];
171 [statusItem setMenu:[notRunningMenu autorelease]];
175 /*************************************************************************/
177 #pragma mark INSTANCE METHODS
178 /*************************************************************************/
180 - (void)startTimerInNewThread
182 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
183 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
184 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
186 selector:@selector(timerUpdate)
188 repeats:YES] retain];
193 //Recreate the status item menu
196 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
197 NSArray *myMenu = [defaults arrayForKey:@"menu"];
198 int playlist = [currentRemote currentPlaylistIndex];
201 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
206 lastPlaylistIndex = -1;
209 menu = [[NSMenu alloc] initWithTitle:@""];
213 upcomingSongsItem = nil;
214 [upcomingSongsMenu release];
215 upcomingSongsMenu = nil;
218 [ratingItem setSubmenu:nil];
222 [playlistMenu release];
229 //Build the custom menu
230 for (i = 0; i < [myMenu count]; i++) {
231 NSString *item = [myMenu objectAtIndex:i];
232 if ([item isEqualToString:@"Play/Pause"]) {
233 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
234 playPauseItem = [menu addItemWithTitle:@"Play"
235 action:@selector(playPause:)
239 [self setKeyEquivalentForCode:[tempCombo keyCode]
240 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
243 } else if ([item isEqualToString:@"Next Track"]) {
244 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
245 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
246 action:@selector(nextSong:)
250 [self setKeyEquivalentForCode:[tempCombo keyCode]
251 andModifiers:[tempCombo modifiers] onItem:nextTrack];
254 } else if ([item isEqualToString:@"Previous Track"]) {
255 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
256 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
257 action:@selector(prevSong:)
261 [self setKeyEquivalentForCode:[tempCombo keyCode]
262 andModifiers:[tempCombo modifiers] onItem:prevTrack];
265 } else if ([item isEqualToString:@"Fast Forward"]) {
266 [menu addItemWithTitle:@"Fast Forward"
267 action:@selector(fastForward:)
269 } else if ([item isEqualToString:@"Rewind"]) {
270 [menu addItemWithTitle:@"Rewind"
271 action:@selector(rewind:)
273 } else if ([item isEqualToString:@"Show Player"]) {
274 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
275 action:@selector(showPlayer:)
277 } else if ([item isEqualToString:@"Upcoming Songs"]) {
278 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
281 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
282 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
283 [upcomingSongsItem setEnabled:NO];
284 } else if ([item isEqualToString:@"Playlists"]) {
285 playlistItem = [menu addItemWithTitle:@"Playlists"
288 } else if ([item isEqualToString:@"EQ Presets"]) {
289 eqItem = [menu addItemWithTitle:@"EQ Presets"
292 } else if ([item isEqualToString:@"PreferencesÉ"]) {
293 [menu addItemWithTitle:@"PreferencesÉ"
294 action:@selector(showPreferences:)
296 } else if ([item isEqualToString:@"Quit"]) {
297 [menu addItemWithTitle:@"Quit"
298 action:@selector(quitMenuTunes:)
300 } else if ([item isEqualToString:@"Current Track Info"]) {
301 trackInfoIndex = [menu numberOfItems];
302 [menu addItemWithTitle:@"No Song"
305 } else if ([item isEqualToString:@"Song Rating"]) {
306 ratingItem = [menu addItemWithTitle:@"Song Rating"
309 [ratingItem setSubmenu:ratingMenu];
310 } else if ([item isEqualToString:@"<separator>"]) {
311 [menu addItem:[NSMenuItem separatorItem]];
316 [self rebuildPlaylistMenu];
320 [self rebuildEQPresetsMenu];
323 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
325 if (upcomingSongsItem) {
326 [self rebuildUpcomingSongsMenu];
330 if (isPlayingRadio || !playlist) {
331 [ratingItem setEnabled:NO];
333 int currentSongRating = ([currentRemote currentSongRating] * 5);
334 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
335 lastSongRating = currentSongRating;
336 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
337 [ratingItem setEnabled:YES];
341 //Set the new unique song identifier
342 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
344 //If we're in a playlist or radio mode
345 if ( ![lastSongIdentifier isEqualToString:@"0-0"] && (trackInfoIndex > -1) ) {
348 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) ) {
350 [menu removeItemAtIndex:i];
351 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
355 title = [currentRemote currentSongTitle];
357 if (!isPlayingRadio) {
358 if ([defaults boolForKey:@"showTime"]) {
359 NSString *length = [currentRemote currentSongLength];
360 char character = [length characterAtIndex:0];
361 if ( (character > '0') && (character < '9') ) {
362 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
366 if ([defaults boolForKey:@"showTrackRating"]) {
367 if (title) { //Check to see if there's a song playing
368 [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:@"showTrackNumber"]) {
380 int track = [currentRemote currentSongTrack];
381 int total = [currentRemote currentAlbumTrackCount];
383 [menu insertItemWithTitle:[NSString stringWithFormat:@" Track %i of %i", track, total] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
387 if ([defaults boolForKey:@"showAlbum"]) {
388 NSString *album = [currentRemote currentSongAlbum];
389 if ([album length] > 0) {
390 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
395 if ([title length] > 0) {
396 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
400 [statusItem setMenu:menu];
406 //Rebuild the upcoming songs submenu. Can be improved a lot.
407 - (void)rebuildUpcomingSongsMenu
409 int curIndex = [currentRemote currentPlaylistIndex];
410 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
411 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
413 if (!isPlayingRadio) {
415 int curTrack = [currentRemote currentSongIndex];
418 [upcomingSongsMenu release];
419 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
420 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
421 [upcomingSongsItem setEnabled:YES];
423 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
425 NSString *curSong = [currentRemote songTitleAtIndex:i];
426 NSMenuItem *songItem;
427 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
428 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
429 [upcomingSongsMenu addItem:songItem];
437 [upcomingSongsItem setSubmenu:nil];
438 [upcomingSongsItem setEnabled:NO];
442 - (void)rebuildPlaylistMenu
444 NSArray *playlists = [currentRemote playlists];
445 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
447 [playlistMenu release];
448 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
450 for (i = 0; i < [playlists count]; i++) {
451 NSString *playlistName = [playlists objectAtIndex:i];
452 NSMenuItem *tempItem;
453 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
454 [tempItem setTag:i + 1];
455 [playlistMenu addItem:tempItem];
458 [playlistItem setSubmenu:playlistMenu];
459 [playlistItem setEnabled:YES];
461 if (!isPlayingRadio && currentPlaylist) {
462 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
466 //Build a menu with the list of all available EQ presets
467 - (void)rebuildEQPresetsMenu
469 NSArray *eqPresets = [currentRemote eqPresets];
472 [eqMenu autorelease];
473 eqMenu = [[NSMenu alloc] initWithTitle:@""];
475 for (i = 0; i < [eqPresets count]; i++) {
477 NSMenuItem *tempItem;
478 if ( ( name = [eqPresets objectAtIndex:i] ) ) {
479 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
481 [eqMenu addItem:tempItem];
482 [tempItem autorelease];
486 [eqItem setSubmenu:eqMenu];
487 [eqItem setEnabled:YES];
488 [[eqMenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
491 - (void)updateRatingMenu
493 int currentSongRating = ([currentRemote currentSongRating] * 5);
494 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
495 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
498 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
499 lastSongRating = currentSongRating;
500 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
506 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
507 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
508 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
512 [self updateRatingMenu];
514 //Update Play/Pause menu item
516 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
517 [playPauseItem setTitle:@"Pause"];
519 [playPauseItem setTitle:@"Play"];
530 - (void)selectSong:(id)sender
532 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
535 - (void)selectPlaylist:(id)sender
537 int playlist = [sender tag];
538 [currentRemote switchToPlaylistAtIndex:playlist];
541 - (void)selectEQPreset:(id)sender
543 int curSet = [currentRemote currentEQPresetIndex];
544 int item = [sender tag];
546 [currentRemote switchToEQAtIndex:item];
547 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
548 [[eqMenu itemAtIndex:item] setState:NSOnState];
551 - (void)selectSongRating:(id)sender
553 int newRating = [sender tag];
554 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
555 [sender setState:NSOnState];
556 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
557 lastSongRating = newRating / 20;
560 - (void)playPause:(id)sender
562 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
564 if (state == ITMTRemotePlayerPlaying) {
565 [currentRemote pause];
566 [playPauseItem setTitle:@"Play"];
567 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
568 [currentRemote pause];
569 [currentRemote play];
571 [currentRemote play];
572 [playPauseItem setTitle:@"Pause"];
576 - (void)nextSong:(id)sender
578 [currentRemote goToNextSong];
581 - (void)prevSong:(id)sender
583 [currentRemote goToPreviousSong];
586 - (void)fastForward:(id)sender
588 [currentRemote forward];
589 [playPauseItem setTitle:@"Play"];
592 - (void)rewind:(id)sender
594 [currentRemote rewind];
595 [playPauseItem setTitle:@"Play"];
600 - (void)quitMenuTunes:(id)sender
602 [NSApp terminate:self];
605 - (void)showPlayer:(id)sender
607 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
608 [currentRemote showPrimaryInterface];
610 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
611 NSLog(@"Error Launching Player");
616 - (void)showPreferences:(id)sender
618 [[PreferencesController sharedPrefs] setController:self];
619 [[PreferencesController sharedPrefs] showPrefsWindow:self];
622 - (void)closePreferences
624 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
629 - (ITMTRemote *)currentRemote
631 return currentRemote;
642 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
643 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
644 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
645 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
646 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
651 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
653 if ([defaults objectForKey:@"PlayPause"] != nil) {
654 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
655 combo:[defaults keyComboForKey:@"PlayPause"]
656 target:self action:@selector(playPause:)];
659 if ([defaults objectForKey:@"NextTrack"] != nil) {
660 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
661 combo:[defaults keyComboForKey:@"NextTrack"]
662 target:self action:@selector(nextSong:)];
665 if ([defaults objectForKey:@"PrevTrack"] != nil) {
666 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
667 combo:[defaults keyComboForKey:@"PrevTrack"]
668 target:self action:@selector(prevSong:)];
671 if ([defaults objectForKey:@"TrackInfo"] != nil) {
672 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
673 combo:[defaults keyComboForKey:@"TrackInfo"]
674 target:self action:@selector(showCurrentTrackInfo)];
677 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
678 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
679 combo:[defaults keyComboForKey:@"UpcomingSongs"]
680 target:self action:@selector(showUpcomingSongs)];
686 // Show Current Track Info And Show Upcoming Songs Floaters
690 - (void)showCurrentTrackInfo
692 NSString *trackName = [currentRemote currentSongTitle];
693 if (!statusWindow && [trackName length]) {
694 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
695 NSString *stringToShow = @"";
697 if ([defaults boolForKey:@"showName"]) {
698 if ([defaults boolForKey:@"showArtist"]) {
699 NSString *trackArtist = [currentRemote currentSongArtist];
700 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
702 stringToShow = [stringToShow stringByAppendingString:trackName];
703 stringToShow = [stringToShow stringByAppendingString:@"\n"];
706 if ([defaults boolForKey:@"showAlbum"]) {
707 NSString *trackAlbum = [currentRemote currentSongAlbum];
708 if ([trackAlbum length]) {
709 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
710 stringToShow = [stringToShow stringByAppendingString:@"\n"];
714 if ([defaults boolForKey:@"showTime"]) {
715 NSString *trackTime = [currentRemote currentSongLength];
716 if ([trackTime length]) {
717 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
722 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
723 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
725 stringToShow = [stringToShow stringByAppendingString:
726 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
728 stringToShow = [stringToShow stringByAppendingString:
729 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
734 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
737 /*[statusWindow setText:stringToShow];
738 [NSTimer scheduledTimerWithTimeInterval:3.0
740 selector:@selector(fadeAndCloseStatusWindow)
746 - (void)showUpcomingSongs
748 int curPlaylist = [currentRemote currentPlaylistIndex];
750 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
753 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
754 int curTrack = [currentRemote currentSongIndex];
756 NSString *songs = @"";
758 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
760 NSString *curSong = [currentRemote songTitleAtIndex:i];
761 songs = [songs stringByAppendingString:curSong];
762 songs = [songs stringByAppendingString:@"\n"];
767 //SHOW STATUS WINDOW HERE WITH STRING songs
770 /*[statusWindow setText:songs];
771 [NSTimer scheduledTimerWithTimeInterval:3.0
773 selector:@selector(fadeAndCloseStatusWindow)
780 - (void)fadeAndCloseStatusWindow
782 [statusWindow orderOut:self];
785 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
786 onItem:(NSMenuItem *)item
788 unichar charcode = 'a';
790 long cocoaModifiers = 0;
791 static long carbonToCocoa[6][2] =
793 { cmdKey, NSCommandKeyMask },
794 { optionKey, NSAlternateKeyMask },
795 { controlKey, NSControlKeyMask },
796 { shiftKey, NSShiftKeyMask },
799 for (i = 0; i < 6; i++) {
800 if (modifiers & carbonToCocoa[i][0]) {
801 cocoaModifiers += carbonToCocoa[i][1];
804 [item setKeyEquivalentModifierMask:cocoaModifiers];
806 //Missing key combos for some keys. Must find them later.
820 // Haven't tested this, though it should work.
822 [[NSString stringWithString:@"Space"] getCharacters:&buffer];
824 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
825 NSLog(@"%@", menuRef);
826 SetMenuItemCommandKey(menuRef, 0, NO, 49);
827 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
828 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
835 charcode = NSDeleteFunctionKey;
851 charcode = NSF5FunctionKey;
855 charcode = NSF6FunctionKey;
859 charcode = NSF7FunctionKey;
863 charcode = NSF3FunctionKey;
867 charcode = NSF8FunctionKey;
871 charcode = NSF9FunctionKey;
875 charcode = NSF11FunctionKey;
879 charcode = NSF3FunctionKey;
883 charcode = NSF14FunctionKey;
887 charcode = NSF10FunctionKey;
891 charcode = NSF12FunctionKey;
895 charcode = NSF13FunctionKey;
899 charcode = NSInsertFunctionKey;
903 charcode = NSHomeFunctionKey;
907 charcode = NSPageUpFunctionKey;
911 charcode = NSDeleteFunctionKey;
915 charcode = NSF4FunctionKey;
919 charcode = NSEndFunctionKey;
923 charcode = NSF2FunctionKey;
927 charcode = NSPageDownFunctionKey;
931 charcode = NSF1FunctionKey;
935 charcode = NSLeftArrowFunctionKey;
939 charcode = NSRightArrowFunctionKey;
943 charcode = NSDownArrowFunctionKey;
947 charcode = NSUpArrowFunctionKey;
951 if (charcode == 'a') {
957 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
958 keyTrans = KeyTranslate(kchr, code, &state);
960 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
961 } else if (charcode != 'b') {
962 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];