3 ¥ Make preferences window pretty
5 ¥ Apple Events! Apple Events! Apple Events!
7 ¥ Finish up registration frontend
11 #import "PreferencesController.h"
12 #import "HotKeyCenter.h"
13 #import "StatusWindow.h"
15 @interface MenuTunes(Private)
16 - (ITMTRemote *)loadRemote;
18 - (void)rebuildUpcomingSongsMenu;
19 - (void)rebuildPlaylistMenu;
20 - (void)rebuildEQPresetsMenu;
23 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
24 onItem:(NSMenuItem *)item;
28 @implementation MenuTunes
30 /*************************************************************************/
32 #pragma mark INITIALIZATION METHODS
33 /*************************************************************************/
37 if ( ( self = [super init] ) ) {
38 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
39 statusWindow = [StatusWindow sharedWindow];
44 - (void)applicationDidFinishLaunching:(NSNotification *)note
46 currentRemote = [self loadRemote];
47 [currentRemote begin];
49 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iTunesTerminated:) name:@"ITMTRemoteAppDidTerminateNotification" object:nil];
50 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iTunesLaunched:) name:@"ITMTRemoteAppDidLaunchNotification" object:nil];
52 [self registerDefaultsIfNeeded];
54 menu = [[NSMenu alloc] initWithTitle:@""];
56 if ([currentRemote isAppRunning]) {
57 [self iTunesLaunched:nil];
59 [self iTunesTerminated:nil];
62 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
63 withLength:NSSquareStatusItemLength];
65 [statusItem setImage:[NSImage imageNamed:@"menu"]];
66 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
67 [statusItem setMenu:menu];
68 // Below line of code is for creating builds for Beta Testers
69 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
72 - (ITMTRemote *)loadRemote
74 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
77 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
78 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
81 while ( (bundlePath = [enumerator nextObject]) ) {
82 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
85 Class remoteClass = [remoteBundle principalClass];
87 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
88 [remoteClass isKindOfClass:[NSObject class]]) {
90 id remote = [remoteClass remote];
91 [remoteArray addObject:remote];
96 // if ( [remoteArray count] > 0 ) {
97 // if ( [remoteArray count] > 1 ) {
98 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
100 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
103 NSLog(@"%@", [remoteArray objectAtIndex:0]);
104 return [remoteArray objectAtIndex:0];
108 /*************************************************************************/
110 #pragma mark INSTANCE METHODS
111 /*************************************************************************/
113 - (void)registerDefaultsIfNeeded
115 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
116 if (![defaults objectForKey:@"menu"]) {
118 NSMutableDictionary *loginwindow;
119 NSMutableArray *loginarray;
123 [NSArray arrayWithObjects:
136 @"Current Track Info",
137 nil] forKey:@"menu"];
139 [defaults synchronize];
140 loginwindow = [[defaults persistentDomainForName:@"loginwindow"] mutableCopy];
141 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
143 for (i = 0; i < [loginarray count]; i++) {
144 NSDictionary *tempDict = [loginarray objectAtIndex:i];
145 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
152 //We must fix it so it is no longer suxy
154 if (NSRunInformationalAlertPanel(@"Auto-launch MenuTunes", @"Would you like MenuTunes to automatically launch at login?", @"Yes", @"No", nil) == NSOKButton) {
155 AEDesc scriptDesc, resultDesc;
156 NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
157 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
159 AECreateDesc(typeChar, [script cString], [script cStringLength],
162 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
164 AEDisposeDesc(&scriptDesc);
165 AEDisposeDesc(&resultDesc);
167 CloseComponent(asComponent);
172 if (![defaults integerForKey:@"SongsInAdvance"])
174 [defaults setInteger:5 forKey:@"SongsInAdvance"];
177 if (![defaults objectForKey:@"showName"]) {
178 [defaults setBool:YES forKey:@"showName"];
181 if (![defaults objectForKey:@"showArtist"]) {
182 [defaults setBool:YES forKey:@"showArtist"];
185 if (![defaults objectForKey:@"showAlbum"]) {
186 [defaults setBool:NO forKey:@"showAlbum"];
189 if (![defaults objectForKey:@"showTime"]) {
190 [defaults setBool:NO forKey:@"showTime"];
194 //Recreate the status item menu
197 NSArray *myMenu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
202 lastPlaylistIndex = -1;
203 didHaveAlbumName = ([[currentRemote currentSongAlbum] length] > 0);
204 didHaveArtistName = ([[currentRemote currentSongArtist] length] > 0);
206 while ([menu numberOfItems] > 0) {
207 [menu removeItemAtIndex:0];
210 playPauseMenuItem = nil;
211 upcomingSongsItem = nil;
213 [playlistMenu release];
219 for (i = 0; i < [myMenu count]; i++) {
220 NSString *item = [myMenu objectAtIndex:i];
221 if ([item isEqualToString:@"Play/Pause"]) {
222 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
223 playPauseMenuItem = [menu addItemWithTitle:@"Play"
224 action:@selector(playPause:)
226 [playPauseMenuItem setTarget:self];
229 [self setKeyEquivalentForCode:[tempCombo keyCode]
230 andModifiers:[tempCombo modifiers] onItem:playPauseMenuItem];
233 } else if ([item isEqualToString:@"Next Track"]) {
234 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
235 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
236 action:@selector(nextSong:)
239 [nextTrack setTarget:self];
241 [self setKeyEquivalentForCode:[tempCombo keyCode]
242 andModifiers:[tempCombo modifiers] onItem:nextTrack];
245 } else if ([item isEqualToString:@"Previous Track"]) {
246 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
247 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
248 action:@selector(prevSong:)
251 [prevTrack setTarget:self];
253 [self setKeyEquivalentForCode:[tempCombo keyCode]
254 andModifiers:[tempCombo modifiers] onItem:prevTrack];
257 } else if ([item isEqualToString:@"Fast Forward"]) {
258 [[menu addItemWithTitle:@"Fast Forward"
259 action:@selector(fastForward:)
260 keyEquivalent:@""] setTarget:self];
261 } else if ([item isEqualToString:@"Rewind"]) {
262 [[menu addItemWithTitle:@"Rewind"
263 action:@selector(rewind:)
264 keyEquivalent:@""] setTarget:self];
265 } else if ([item isEqualToString:@"Upcoming Songs"]) {
266 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
269 } else if ([item isEqualToString:@"Playlists"]) {
270 playlistItem = [menu addItemWithTitle:@"Playlists"
273 } else if ([item isEqualToString:@"EQ Presets"]) {
274 eqItem = [menu addItemWithTitle:@"EQ Presets"
277 } else if ([item isEqualToString:@"PreferencesÉ"]) {
278 [[menu addItemWithTitle:@"PreferencesÉ"
279 action:@selector(showPreferences:)
280 keyEquivalent:@""] setTarget:self];
281 } else if ([item isEqualToString:@"Quit"]) {
282 [[menu addItemWithTitle:@"Quit"
283 action:@selector(quitMenuTunes:)
284 keyEquivalent:@""] setTarget:self];
285 } else if ([item isEqualToString:@"Current Track Info"]) {
286 trackInfoIndex = [menu numberOfItems];
287 [menu addItemWithTitle:@"No Song"
290 } else if ([item isEqualToString:@"<separator>"]) {
291 [menu addItem:[NSMenuItem separatorItem]];
295 [self timerUpdate]; //Updates dynamic info in the menu
301 //Updates the menu with current player state, song, and upcoming songs
304 NSMenuItem *menuItem;
305 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
311 if (upcomingSongsItem) {
312 [self rebuildUpcomingSongsMenu];
316 [self rebuildPlaylistMenu];
320 [self rebuildEQPresetsMenu];
323 if (trackInfoIndex > -1) {
324 NSString *curSongName, *curAlbumName = @"", *curArtistName = @"";
325 curSongName = [currentRemote currentSongTitle];
327 if ([defaults boolForKey:@"showAlbum"]) {
328 curAlbumName = [currentRemote currentSongAlbum];
331 if ([defaults boolForKey:@"showArtist"]) {
332 curArtistName = [currentRemote currentSongArtist];
335 if ([curSongName length] > 0) {
336 int index = [menu indexOfItemWithTitle:@"Now Playing"];
338 if ([defaults boolForKey:@"showName"]) {
339 [menu removeItemAtIndex:index + 1];
341 if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
342 [menu removeItemAtIndex:index + 1];
344 if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) {
345 [menu removeItemAtIndex:index + 1];
347 if ([defaults boolForKey:@"showTime"]) {
348 [menu removeItemAtIndex:index + 1];
352 if (!isPlayingRadio) {
353 if ([defaults boolForKey:@"showTime"]) {
354 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]]
357 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
361 if ([curArtistName length] > 0) {
362 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curArtistName]
365 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
369 if ([curAlbumName length] > 0) {
370 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName]
373 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
378 if ([defaults boolForKey:@"showName"]) {
379 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName]
382 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
387 menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""];
388 [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]];
389 [menu insertItem:menuItem atIndex:trackInfoIndex];
392 } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) {
393 [menu removeItemAtIndex:trackInfoIndex];
395 if ([defaults boolForKey:@"showName"] == YES) {
396 [menu removeItemAtIndex:trackInfoIndex];
399 if ([defaults boolForKey:@"showTime"] == YES) {
400 [menu removeItemAtIndex:trackInfoIndex];
403 if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) {
404 [menu removeItemAtIndex:trackInfoIndex];
407 if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
408 [menu removeItemAtIndex:trackInfoIndex];
411 menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
412 [menu insertItem:menuItem atIndex:trackInfoIndex];
416 if ([defaults boolForKey:@"showArtist"]) {
417 didHaveArtistName = (([curArtistName length] > 0) ? YES : NO);
420 if ([defaults boolForKey:@"showAlbum"]) {
421 didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO);
426 //Rebuild the upcoming songs submenu. Can be improved a lot.
427 - (void)rebuildUpcomingSongsMenu
429 int curIndex = [currentRemote currentPlaylistIndex];
430 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
431 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
433 if (!isPlayingRadio) {
435 int curTrack = [currentRemote currentSongIndex];
438 [upcomingSongsMenu release];
439 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
440 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
441 [upcomingSongsItem setEnabled:YES];
443 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
445 NSString *curSong = [currentRemote songTitleAtIndex:i];
446 NSMenuItem *songItem;
447 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""];
448 [songItem setTarget:self];
449 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
450 [upcomingSongsMenu addItem:songItem];
458 [upcomingSongsItem setSubmenu:nil];
459 [upcomingSongsItem setEnabled:NO];
463 - (void)rebuildPlaylistMenu
465 NSArray *playlists = [currentRemote playlists];
466 int i, curPlaylist = [currentRemote currentPlaylistIndex];
468 if (isPlayingRadio) {
471 if (playlistMenu && ([playlists count] == [playlistMenu numberOfItems]))
474 [playlistMenu release];
475 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
477 for (i = 0; i < [playlists count]; i++) {
478 NSString *playlistName = [playlists objectAtIndex:i];
479 NSMenuItem *tempItem;
480 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
481 [tempItem setTarget:self];
482 [tempItem setRepresentedObject:[NSNumber numberWithInt:i + 1]];
483 [playlistMenu addItem:tempItem];
486 [playlistItem setSubmenu:playlistMenu];
487 [playlistItem setEnabled:YES];
490 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOnState];
494 //Build a menu with the list of all available EQ presets
495 - (void)rebuildEQPresetsMenu
497 NSArray *eqPresets = [currentRemote eqPresets];
500 if (eqMenu && ([[currentRemote eqPresets] count] == [eqMenu numberOfItems]))
504 eqMenu = [[NSMenu alloc] initWithTitle:@""];
506 for (i = 0; i < [eqPresets count]; i++) {
507 NSString *setName = [eqPresets objectAtIndex:i];
508 NSMenuItem *tempItem;
510 tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""];
511 [tempItem setTarget:self];
512 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
513 [eqMenu addItem:tempItem];
517 [eqItem setSubmenu:eqMenu];
519 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] - 1] setState:NSOnState];
524 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
525 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
526 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
527 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
528 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
533 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
535 if ([defaults objectForKey:@"PlayPause"] != nil) {
536 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
537 combo:[defaults keyComboForKey:@"PlayPause"]
538 target:self action:@selector(playPause:)];
541 if ([defaults objectForKey:@"NextTrack"] != nil) {
542 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
543 combo:[defaults keyComboForKey:@"NextTrack"]
544 target:self action:@selector(nextSong:)];
547 if ([defaults objectForKey:@"PrevTrack"] != nil) {
548 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
549 combo:[defaults keyComboForKey:@"PrevTrack"]
550 target:self action:@selector(prevSong:)];
553 if ([defaults objectForKey:@"TrackInfo"] != nil) {
554 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
555 combo:[defaults keyComboForKey:@"TrackInfo"]
556 target:self action:@selector(showCurrentTrackInfo)];
559 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
560 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
561 combo:[defaults keyComboForKey:@"UpcomingSongs"]
562 target:self action:@selector(showUpcomingSongs)];
566 //Called when the timer fires.
569 int playlist = [currentRemote currentPlaylistIndex];
570 PlayerState playerState = [currentRemote playerState];
572 if ((playlist > 0) || playerState != stopped) {
573 int trackPlayingIndex = [currentRemote currentSongIndex];
575 if (trackPlayingIndex != lastSongIndex) {
576 BOOL wasPlayingRadio = isPlayingRadio;
577 isPlayingRadio = [[currentRemote classOfPlaylistAtIndex:playlist] isEqualToString:@"radio tuner playlist"];
579 if (isPlayingRadio && !wasPlayingRadio) {
581 for (i = 0; i < [playlistMenu numberOfItems]; i++)
583 [[playlistMenu itemAtIndex:i] setState:NSOffState];
586 [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
589 if (wasPlayingRadio) {
590 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
591 [menu insertItem:temp atIndex:trackInfoIndex + 1];
596 lastSongIndex = trackPlayingIndex;
598 if (playlist != lastPlaylistIndex) {
599 BOOL wasPlayingRadio = isPlayingRadio;
600 isPlayingRadio = [[currentRemote classOfPlaylistAtIndex:playlist] isEqualToString:@"radio tuner playlist"];
602 if (isPlayingRadio && !wasPlayingRadio) {
604 for (i = 0; i < [playlistMenu numberOfItems]; i++) {
605 [[playlistMenu itemAtIndex:i] setState:NSOffState];
609 if (wasPlayingRadio) {
610 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
611 [menu insertItem:temp atIndex:trackInfoIndex + 1];
615 if (!isPlayingRadio) {
617 for (i = 0; i < [playlistMenu numberOfItems]; i++)
619 [[playlistMenu itemAtIndex:i] setState:NSOffState];
621 [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
625 lastSongIndex = trackPlayingIndex;
626 lastPlaylistIndex = playlist;
629 //Update Play/Pause menu item
630 if (playPauseMenuItem){
631 if (playerState == playing) {
632 [playPauseMenuItem setTitle:@"Pause"];
634 [playPauseMenuItem setTitle:@"Play"];
640 - (void)iTunesLaunched:(NSNotification *)note
645 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES];
647 [self rebuildMenu]; //Rebuild the menu since no songs will be playing
648 [self rebuildPlaylistMenu];
649 [statusItem setMenu:menu]; //Set the menu back to the main one
652 - (void)iTunesTerminated:(NSNotification *)note
657 menu = [[NSMenu alloc] initWithTitle:@""];
658 [menu addItemWithTitle:@"Audio Player" action:NULL keyEquivalent:@""];
659 [menu addItemWithTitle:@"Not Running" action:NULL keyEquivalent:@""];
660 [menu addItem:[NSMenuItem separatorItem]];
661 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
662 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
663 [statusItem setMenu:menu];
665 [refreshTimer invalidate];
672 // Selectors - called from status item menu
676 // Plugin dependent selectors
678 - (void)playTrack:(id)sender
680 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
684 - (void)selectPlaylist:(id)sender
686 int playlist = [[sender representedObject] intValue];
687 if (!isPlayingRadio) {
688 int curPlaylist = [currentRemote currentPlaylistIndex];
689 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOffState];
691 [currentRemote switchToPlaylistAtIndex:playlist];
692 [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
696 - (void)selectEQPreset:(id)sender
698 int curSet = [currentRemote currentEQPresetIndex];
699 int item = [[sender representedObject] intValue];
700 [currentRemote switchToEQAtIndex:item];
701 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
702 [[eqMenu itemAtIndex:item - 1] setState:NSOnState];
705 - (void)playPause:(id)sender
707 PlayerState state = [currentRemote playerState];
709 if (state == playing) {
710 [currentRemote pause];
711 [playPauseMenuItem setTitle:@"Play"];
712 } else if ((state == forwarding) || (state == rewinding)) {
713 [currentRemote pause];
714 [currentRemote play];
716 [currentRemote play];
717 [playPauseMenuItem setTitle:@"Pause"];
721 - (void)nextSong:(id)sender
723 [currentRemote goToNextSong];
726 - (void)prevSong:(id)sender
728 [currentRemote goToPreviousSong];
731 - (void)fastForward:(id)sender
733 [currentRemote fastForward];
734 [playPauseMenuItem setTitle:@"Play"];
737 - (void)rewind:(id)sender
739 [currentRemote rewind];
740 [playPauseMenuItem setTitle:@"Play"];
745 // Plugin independent selectors
748 - (void)quitMenuTunes:(id)sender
750 [NSApp terminate:self];
753 - (void)showPreferences:(id)sender
755 if (!prefsController) {
756 prefsController = [[PreferencesController alloc] initWithMenuTunes:self];
761 - (void)closePreferences
766 [prefsController release];
767 prefsController = nil;
772 // Show Current Track Info And Show Upcoming Songs Floaters
776 - (void)showCurrentTrackInfo
778 NSString *trackName = [currentRemote currentSongTitle];
779 if (!statusWindow && [trackName length]) {
780 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
781 NSString *stringToShow = @"";
783 if ([defaults boolForKey:@"showName"]) {
784 if ([defaults boolForKey:@"showArtist"]) {
785 NSString *trackArtist = [currentRemote currentSongArtist];
786 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
788 stringToShow = [stringToShow stringByAppendingString:trackName];
789 stringToShow = [stringToShow stringByAppendingString:@"\n"];
792 if ([defaults boolForKey:@"showAlbum"]) {
793 NSString *trackAlbum = [currentRemote currentSongAlbum];
794 if ([trackAlbum length]) {
795 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
796 stringToShow = [stringToShow stringByAppendingString:@"\n"];
800 if ([defaults boolForKey:@"showTime"]) {
801 NSString *trackTime = [currentRemote currentSongLength];
802 if ([trackTime length]) {
803 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
808 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
809 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
811 stringToShow = [stringToShow stringByAppendingString:
812 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
814 stringToShow = [stringToShow stringByAppendingString:
815 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
819 [statusWindow setText:stringToShow];
820 [NSTimer scheduledTimerWithTimeInterval:3.0
822 selector:@selector(fadeAndCloseStatusWindow)
828 - (void)showUpcomingSongs
830 int curPlaylist = [currentRemote currentPlaylistIndex];
832 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
835 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
836 int curTrack = [currentRemote currentSongIndex];
838 NSString *songs = @"";
840 statusWindow = [ITTransientStatusWindow sharedWindow];
841 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
843 NSString *curSong = [currentRemote songTitleAtIndex:i];
844 songs = [songs stringByAppendingString:curSong];
845 songs = [songs stringByAppendingString:@"\n"];
848 [statusWindow setText:songs];
849 [NSTimer scheduledTimerWithTimeInterval:3.0
851 selector:@selector(fadeAndCloseStatusWindow)
858 - (void)fadeAndCloseStatusWindow
860 [statusWindow orderOut:self];
863 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
864 onItem:(NSMenuItem *)item
866 unichar charcode = 'a';
868 long cocoaModifiers = 0;
869 static long carbonToCocoa[6][2] =
871 { cmdKey, NSCommandKeyMask },
872 { optionKey, NSAlternateKeyMask },
873 { controlKey, NSControlKeyMask },
874 { shiftKey, NSShiftKeyMask },
877 for (i = 0; i < 6; i++) {
878 if (modifiers & carbonToCocoa[i][0]) {
879 cocoaModifiers += carbonToCocoa[i][1];
882 [item setKeyEquivalentModifierMask:cocoaModifiers];
884 //Missing key combos for some keys. Must find them later.
898 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
899 NSLog(@"%@", menuRef);
900 SetMenuItemCommandKey(menuRef, 0, NO, 49);
901 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
902 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
908 charcode = NSDeleteFunctionKey;
924 charcode = NSF5FunctionKey;
928 charcode = NSF6FunctionKey;
932 charcode = NSF7FunctionKey;
936 charcode = NSF3FunctionKey;
940 charcode = NSF8FunctionKey;
944 charcode = NSF9FunctionKey;
948 charcode = NSF11FunctionKey;
952 charcode = NSF3FunctionKey;
956 charcode = NSF14FunctionKey;
960 charcode = NSF10FunctionKey;
964 charcode = NSF12FunctionKey;
968 charcode = NSF13FunctionKey;
972 charcode = NSInsertFunctionKey;
976 charcode = NSHomeFunctionKey;
980 charcode = NSPageUpFunctionKey;
984 charcode = NSDeleteFunctionKey;
988 charcode = NSF4FunctionKey;
992 charcode = NSEndFunctionKey;
996 charcode = NSF2FunctionKey;
1000 charcode = NSPageDownFunctionKey;
1004 charcode = NSF1FunctionKey;
1008 charcode = NSLeftArrowFunctionKey;
1012 charcode = NSRightArrowFunctionKey;
1016 charcode = NSDownArrowFunctionKey;
1020 charcode = NSUpArrowFunctionKey;
1024 if (charcode == 'a') {
1025 unsigned long state;
1030 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
1031 keyTrans = KeyTranslate(kchr, code, &state);
1032 charCode = keyTrans;
1033 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
1034 } else if (charcode != 'b') {
1035 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];
1039 /*************************************************************************/
1041 #pragma mark NSApplication DELEGATE METHODS
1042 /*************************************************************************/
1044 - (void)applicationWillTerminate:(NSNotification *)note
1046 [self clearHotKeys];
1047 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
1051 /*************************************************************************/
1053 #pragma mark DEALLOCATION METHODS
1054 /*************************************************************************/
1059 [refreshTimer invalidate];
1062 [currentRemote halt];
1063 [statusItem release];