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"
14 @interface MenuTunes(Private)
15 - (ITMTRemote *)loadRemote;
17 - (void)rebuildUpcomingSongsMenu;
18 - (void)rebuildPlaylistMenu;
19 - (void)rebuildEQPresetsMenu;
22 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
23 onItem:(NSMenuItem *)item;
27 @implementation MenuTunes
29 /*************************************************************************/
31 #pragma mark INITIALIZATION METHODS
32 /*************************************************************************/
36 if ( ( self = [super init] ) ) {
37 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
38 statusWindow = [ITTransientStatusWindow sharedWindow];
43 - (void)applicationDidFinishLaunching:(NSNotification *)note
45 currentRemote = [self loadRemote];
46 [currentRemote begin];
48 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iTunesTerminated:) name:@"ITMTRemoteAppDidTerminateNotification" object:nil];
49 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iTunesLaunched:) name:@"ITMTRemoteAppDidLaunchNotification" object:nil];
51 [self registerDefaultsIfNeeded];
53 menu = [[NSMenu alloc] initWithTitle:@""];
55 isAppRunning = [currentRemote isAppRunning];
59 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5
61 selector:@selector(timerUpdate)
67 menu = [[NSMenu alloc] initWithTitle:@""];
68 [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
69 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
70 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
74 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
75 withLength:NSSquareStatusItemLength];
77 [statusItem setImage:[NSImage imageNamed:@"menu"]];
78 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
79 [statusItem setMenu:menu];
80 // Below line of code is for creating builds for Beta Testers
81 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
84 - (ITMTRemote *)loadRemote
86 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
89 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
90 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
93 while ( (bundlePath = [enumerator nextObject]) ) {
94 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
97 Class remoteClass = [remoteBundle principalClass];
99 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
100 [remoteClass isKindOfClass:[NSObject class]]) {
102 id remote = [remoteClass remote];
103 [remoteArray addObject:remote];
108 // if ( [remoteArray count] > 0 ) {
109 // if ( [remoteArray count] > 1 ) {
110 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
112 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
115 NSLog(@"%@", [remoteArray objectAtIndex:0]);
116 return [remoteArray objectAtIndex:0];
120 /*************************************************************************/
122 #pragma mark INSTANCE METHODS
123 /*************************************************************************/
125 - (void)registerDefaultsIfNeeded
127 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
128 if (![defaults objectForKey:@"menu"]) {
130 NSMutableDictionary *loginwindow;
131 NSMutableArray *loginarray;
135 [NSArray arrayWithObjects:
148 @"Current Track Info",
149 nil] forKey:@"menu"];
151 [defaults synchronize];
152 loginwindow = [[defaults persistentDomainForName:@"loginwindow"] mutableCopy];
153 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
155 for (i = 0; i < [loginarray count]; i++) {
156 NSDictionary *tempDict = [loginarray objectAtIndex:i];
157 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
164 //We must fix it so it is no longer suxy
166 if (NSRunInformationalAlertPanel(@"Auto-launch MenuTunes", @"Would you like MenuTunes to automatically launch at login?", @"Yes", @"No", nil) == NSOKButton) {
167 AEDesc scriptDesc, resultDesc;
168 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]];
169 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
171 AECreateDesc(typeChar, [script cString], [script cStringLength],
174 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
176 AEDisposeDesc(&scriptDesc);
177 AEDisposeDesc(&resultDesc);
179 CloseComponent(asComponent);
184 if (![defaults integerForKey:@"SongsInAdvance"])
186 [defaults setInteger:5 forKey:@"SongsInAdvance"];
189 if (![defaults objectForKey:@"showName"]) {
190 [defaults setBool:YES forKey:@"showName"];
193 if (![defaults objectForKey:@"showArtist"]) {
194 [defaults setBool:YES forKey:@"showArtist"];
197 if (![defaults objectForKey:@"showAlbum"]) {
198 [defaults setBool:NO forKey:@"showAlbum"];
201 if (![defaults objectForKey:@"showTime"]) {
202 [defaults setBool:NO forKey:@"showTime"];
206 //Recreate the status item menu
209 NSArray *myMenu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
214 didHaveAlbumName = ([[currentRemote currentSongAlbum] length] > 0);
215 didHaveArtistName = ([[currentRemote currentSongArtist] length] > 0);
217 while ([menu numberOfItems] > 0) {
218 [menu removeItemAtIndex:0];
221 playPauseMenuItem = nil;
222 upcomingSongsItem = nil;
224 [playlistMenu release];
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 playPauseMenuItem = [menu addItemWithTitle:@"Play"
235 action:@selector(playPause:)
237 [playPauseMenuItem setTarget:self];
241 [self setKeyEquivalentForCode:[tempCombo keyCode]
242 andModifiers:[tempCombo modifiers] onItem:playPauseMenuItem];
245 } else if ([item isEqualToString:@"Next Track"]) {
246 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
247 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
248 action:@selector(nextSong:)
251 [nextTrack setTarget:self];
254 [self setKeyEquivalentForCode:[tempCombo keyCode]
255 andModifiers:[tempCombo modifiers] onItem:nextTrack];
258 } else if ([item isEqualToString:@"Previous Track"]) {
259 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
260 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
261 action:@selector(prevSong:)
264 [prevTrack setTarget:self];
267 [self setKeyEquivalentForCode:[tempCombo keyCode]
268 andModifiers:[tempCombo modifiers] onItem:prevTrack];
271 } else if ([item isEqualToString:@"Fast Forward"]) {
272 [[menu addItemWithTitle:@"Fast Forward"
273 action:@selector(fastForward:)
274 keyEquivalent:@""] setTarget:self];
275 } else if ([item isEqualToString:@"Rewind"]) {
276 [[menu addItemWithTitle:@"Rewind"
277 action:@selector(rewind:)
278 keyEquivalent:@""] setTarget:self];
279 } else if ([item isEqualToString:@"Upcoming Songs"]) {
280 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
283 } else if ([item isEqualToString:@"Playlists"]) {
284 playlistItem = [menu addItemWithTitle:@"Playlists"
287 } else if ([item isEqualToString:@"EQ Presets"]) {
288 eqItem = [menu addItemWithTitle:@"EQ Presets"
291 } else if ([item isEqualToString:@"PreferencesÉ"]) {
292 [[menu addItemWithTitle:@"PreferencesÉ"
293 action:@selector(showPreferences:)
294 keyEquivalent:@""] setTarget:self];
295 } else if ([item isEqualToString:@"Quit"]) {
296 [[menu addItemWithTitle:@"Quit"
297 action:@selector(quitMenuTunes:)
298 keyEquivalent:@""] setTarget:self];
299 } else if ([item isEqualToString:@"Current Track Info"]) {
300 trackInfoIndex = [menu numberOfItems];
301 [menu addItemWithTitle:@"No Song"
304 } else if ([item isEqualToString:@"<separator>"]) {
305 [menu addItem:[NSMenuItem separatorItem]];
309 [self timerUpdate]; //Updates dynamic info in the menu
315 //Updates the menu with current player state, song, and upcoming songs
318 NSMenuItem *menuItem;
319 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
325 if (upcomingSongsItem) {
326 [self rebuildUpcomingSongsMenu];
330 [self rebuildPlaylistMenu];
334 [self rebuildEQPresetsMenu];
337 if (trackInfoIndex > -1)
339 NSString *curSongName, *curAlbumName = @"", *curArtistName = @"";
340 curSongName = [currentRemote currentSongTitle];
342 if ([defaults boolForKey:@"showAlbum"]) {
343 curAlbumName = [currentRemote currentSongAlbum];
346 if ([defaults boolForKey:@"showArtist"]) {
347 curArtistName = [currentRemote currentSongArtist];
350 if ([curSongName length] > 0) {
351 int index = [menu indexOfItemWithTitle:@"Now Playing"];
353 if ([defaults boolForKey:@"showName"]) {
354 [menu removeItemAtIndex:index + 1];
356 if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
357 [menu removeItemAtIndex:index + 1];
359 if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) {
360 [menu removeItemAtIndex:index + 1];
362 if ([defaults boolForKey:@"showTime"]) {
363 [menu removeItemAtIndex:index + 1];
367 if (!isPlayingRadio) {
368 if ([defaults boolForKey:@"showTime"]) {
369 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]]
372 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
376 if ([curArtistName length] > 0) {
377 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curArtistName]
380 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
384 if ([curAlbumName length] > 0) {
385 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName]
388 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
393 if ([defaults boolForKey:@"showName"]) {
394 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName]
397 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
402 menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""];
403 [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]];
404 [menu insertItem:menuItem atIndex:trackInfoIndex];
407 } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) {
408 [menu removeItemAtIndex:trackInfoIndex];
410 if ([defaults boolForKey:@"showName"] == YES) {
411 [menu removeItemAtIndex:trackInfoIndex];
414 if ([defaults boolForKey:@"showTime"] == YES) {
415 [menu removeItemAtIndex:trackInfoIndex];
418 if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) {
419 [menu removeItemAtIndex:trackInfoIndex];
422 if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
423 [menu removeItemAtIndex:trackInfoIndex];
426 menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
427 [menu insertItem:menuItem atIndex:trackInfoIndex];
431 if ([defaults boolForKey:@"showArtist"]) {
432 didHaveArtistName = (([curArtistName length] > 0) ? YES : NO);
435 if ([defaults boolForKey:@"showAlbum"]) {
436 didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO);
441 //Rebuild the upcoming songs submenu. Can be improved a lot.
442 - (void)rebuildUpcomingSongsMenu
444 int curIndex = [currentRemote currentPlaylistIndex];
445 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
446 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
448 if (!isPlayingRadio) {
450 int curTrack = [currentRemote currentSongIndex];
453 [upcomingSongsMenu release];
454 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
455 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
456 [upcomingSongsItem setEnabled:YES];
458 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
460 NSString *curSong = [currentRemote songTitleAtIndex:i];
461 NSMenuItem *songItem;
462 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""];
463 [songItem setTarget:self];
464 [songItem setRepresentedObject:[NSNumber numberWithInt:i + 1]];
465 [upcomingSongsMenu addItem:songItem];
473 [upcomingSongsItem setSubmenu:nil];
474 [upcomingSongsItem setEnabled:NO];
478 - (void)rebuildPlaylistMenu
480 NSArray *playlists = [currentRemote playlists];
481 int i, curPlaylist = [currentRemote currentPlaylistIndex];
487 if (playlistMenu && ([playlists count] == [playlistMenu numberOfItems]))
490 [playlistMenu release];
491 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
493 for (i = 0; i < [playlists count]; i++) {
494 NSString *playlistName = [playlists objectAtIndex:i];
495 NSMenuItem *tempItem;
496 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
497 [tempItem setTarget:self];
498 [tempItem setRepresentedObject:[NSNumber numberWithInt:i + 1]];
499 [playlistMenu addItem:tempItem];
502 [playlistItem setSubmenu:playlistMenu];
505 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOnState];
509 //Build a menu with the list of all available EQ presets
510 - (void)rebuildEQPresetsMenu
512 NSArray *eqPresets = [currentRemote eqPresets];
515 if (eqMenu && ([[currentRemote eqPresets] count] == [eqMenu numberOfItems]))
519 eqMenu = [[NSMenu alloc] initWithTitle:@""];
521 for (i = 0; i < [eqPresets count]; i++) {
522 NSString *setName = [eqPresets objectAtIndex:i];
523 NSMenuItem *tempItem;
524 tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""];
525 [tempItem setTarget:self];
526 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
527 [eqMenu addItem:tempItem];
530 [eqItem setSubmenu:eqMenu];
532 [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] - 1] setState:NSOnState];
537 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
538 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
539 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
540 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
541 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
546 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
548 if ([defaults objectForKey:@"PlayPause"] != nil) {
549 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
550 combo:[defaults keyComboForKey:@"PlayPause"]
551 target:self action:@selector(playPause:)];
554 if ([defaults objectForKey:@"NextTrack"] != nil) {
555 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
556 combo:[defaults keyComboForKey:@"NextTrack"]
557 target:self action:@selector(nextSong:)];
560 if ([defaults objectForKey:@"PrevTrack"] != nil) {
561 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
562 combo:[defaults keyComboForKey:@"PrevTrack"]
563 target:self action:@selector(prevSong:)];
566 if ([defaults objectForKey:@"TrackInfo"] != nil) {
567 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
568 combo:[defaults keyComboForKey:@"TrackInfo"]
569 target:self action:@selector(showCurrentTrackInfo)];
572 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
573 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
574 combo:[defaults keyComboForKey:@"UpcomingSongs"]
575 target:self action:@selector(showUpcomingSongs)];
579 //Called when the timer fires.
582 NSLog(@"%i", [currentRemote playerState]);
583 if ([currentRemote playerState] != stopped) {
584 int trackPlayingIndex = [currentRemote currentSongIndex];
585 int playlist = [currentRemote currentPlaylistIndex];
587 if (trackPlayingIndex != lastSongIndex) {
588 BOOL wasPlayingRadio = isPlayingRadio;
589 isPlayingRadio = [[currentRemote classOfPlaylistAtIndex:playlist] isEqualToString:@"radio tuner playlist"];
590 if (isPlayingRadio && !wasPlayingRadio) {
592 for (i = 0; i < [playlistMenu numberOfItems]; i++)
594 [[playlistMenu itemAtIndex:i] setState:NSOffState];
597 if (wasPlayingRadio) {
598 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
599 [menu insertItem:temp atIndex:trackInfoIndex + 1];
604 lastSongIndex = trackPlayingIndex;
608 if (playlist != [currentRemote currentPlaylistIndex]) {
609 BOOL wasPlayingRadio = isPlayingRadio;
610 isPlayingRadio = [[currentRemote classOfPlaylistAtIndex:playlist] isEqualToString:@"radio tuner playlist"];
611 if (isPlayingRadio && !wasPlayingRadio) {
613 for (i = 0; i < [playlistMenu numberOfItems]; i++)
615 [[playlistMenu itemAtIndex:i] setState:NSOffState];
618 if (wasPlayingRadio) {
619 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
620 [menu insertItem:temp atIndex:trackInfoIndex + 1];
624 lastSongIndex = trackPlayingIndex;
627 //Update Play/Pause menu item
628 if (playPauseMenuItem){
629 if ([currentRemote playerState] == playing) {
630 [playPauseMenuItem setTitle:@"Pause"];
632 [playPauseMenuItem setTitle:@"Play"];
638 - (void)iTunesLaunched:(NSNotification *)note
643 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES];
645 [self rebuildMenu]; //Rebuild the menu since no songs will be playing
646 [statusItem setMenu:menu]; //Set the menu back to the main one
649 - (void)iTunesTerminated:(NSNotification *)note
654 menu = [[NSMenu alloc] initWithTitle:@""];
655 [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
656 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
657 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
658 [statusItem setMenu:menu];
660 [refreshTimer invalidate];
667 // Selectors - called from status item menu
671 // Plugin dependent selectors
673 - (void)playTrack:(id)sender
675 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
679 - (void)selectPlaylist:(id)sender
681 int playlist = [[sender representedObject] intValue];
682 if (!isPlayingRadio) {
683 int curPlaylist = [currentRemote currentPlaylistIndex];
684 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOffState];
686 [currentRemote switchToPlaylistAtIndex:playlist];
687 [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
691 - (void)selectEQPreset:(id)sender
693 int curSet = [currentRemote currentEQPresetIndex];
694 int item = [[sender representedObject] intValue];
695 [currentRemote switchToEQAtIndex:item];
696 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
697 [[eqMenu itemAtIndex:item - 1] setState:NSOnState];
700 - (void)playPause:(id)sender
702 PlayerState state = [currentRemote playerState];
703 if (state == playing) {
704 [currentRemote pause];
705 [playPauseMenuItem setTitle:@"Play"];
706 } else if ((state == forwarding) || (state == rewinding)) {
707 [currentRemote pause];
708 [currentRemote play];
710 [currentRemote play];
711 [playPauseMenuItem setTitle:@"Pause"];
715 - (void)nextSong:(id)sender
717 [currentRemote goToNextSong];
720 - (void)prevSong:(id)sender
722 [currentRemote goToPreviousSong];
725 - (void)fastForward:(id)sender
727 [currentRemote fastForward];
728 [playPauseMenuItem setTitle:@"Play"];
731 - (void)rewind:(id)sender
733 [currentRemote rewind];
734 [playPauseMenuItem setTitle:@"Play"];
739 // Plugin independent selectors
742 - (void)quitMenuTunes:(id)sender
744 [NSApp terminate:self];
747 //How is this going to work, now that we're pluginized?
748 - (void)openiTunes:(id)sender
750 [[NSWorkspace sharedWorkspace] launchApplication:@"iTunes"];
753 - (void)showPreferences:(id)sender
755 if (!prefsController) {
756 prefsController = [[PreferencesController alloc] initWithMenuTunes:self];
762 - (void)closePreferences
767 [prefsController release];
768 prefsController = nil;
773 // Show Current Track Info And Show Upcoming Songs Floaters
777 - (void)showCurrentTrackInfo
779 NSString *trackName = [currentRemote currentSongTitle];
780 if (!statusWindow && [trackName length]) {
781 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
782 NSString *stringToShow = @"";
784 if ([defaults boolForKey:@"showName"]) {
785 if ([defaults boolForKey:@"showArtist"]) {
786 NSString *trackArtist = [currentRemote currentSongArtist];
787 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
789 stringToShow = [stringToShow stringByAppendingString:trackName];
790 stringToShow = [stringToShow stringByAppendingString:@"\n"];
793 if ([defaults boolForKey:@"showAlbum"]) {
794 NSString *trackAlbum = [currentRemote currentSongAlbum];
795 if ([trackAlbum length]) {
796 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
797 stringToShow = [stringToShow stringByAppendingString:@"\n"];
801 if ([defaults boolForKey:@"showTime"]) {
802 NSString *trackTime = [currentRemote currentSongLength];
803 if ([trackTime length]) {
804 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
809 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
810 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
812 stringToShow = [stringToShow stringByAppendingString:
813 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
815 stringToShow = [stringToShow stringByAppendingString:
816 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
820 [statusWindow setTrackInfo:stringToShow];
821 [NSTimer scheduledTimerWithTimeInterval:3.0
823 selector:@selector(fadeAndCloseStatusWindow)
829 - (void)showUpcomingSongs
831 int curPlaylist = [currentRemote currentPlaylistIndex];
833 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
836 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
837 int curTrack = [currentRemote currentSongIndex];
839 NSString *songs = @"";
841 statusWindow = [ITTransientStatusWindow sharedWindow];
842 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
844 NSString *curSong = [currentRemote songTitleAtIndex:i];
845 songs = [songs stringByAppendingString:curSong];
846 songs = [songs stringByAppendingString:@"\n"];
849 [statusWindow setUpcomingSongs:songs];
850 [NSTimer scheduledTimerWithTimeInterval:3.0
852 selector:@selector(fadeAndCloseStatusWindow)
859 - (void)fadeAndCloseStatusWindow
861 [statusWindow orderOut:self];
864 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
865 onItem:(NSMenuItem *)item
867 unichar charcode = 'a';
869 long cocoaModifiers = 0;
870 static long carbonToCocoa[6][2] =
872 { cmdKey, NSCommandKeyMask },
873 { optionKey, NSAlternateKeyMask },
874 { controlKey, NSControlKeyMask },
875 { shiftKey, NSShiftKeyMask },
878 for (i = 0; i < 6; i++)
880 if (modifiers & carbonToCocoa[i][0])
882 cocoaModifiers += carbonToCocoa[i][1];
885 [item setKeyEquivalentModifierMask:cocoaModifiers];
887 //Missing key combos for some keys. Must find them later.
901 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
902 NSLog(@"%@", menuRef);
903 SetMenuItemCommandKey(menuRef, 0, NO, 49);
904 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
905 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
911 charcode = NSDeleteFunctionKey;
927 charcode = NSF5FunctionKey;
931 charcode = NSF6FunctionKey;
935 charcode = NSF7FunctionKey;
939 charcode = NSF3FunctionKey;
943 charcode = NSF8FunctionKey;
947 charcode = NSF9FunctionKey;
951 charcode = NSF11FunctionKey;
955 charcode = NSF3FunctionKey;
959 charcode = NSF14FunctionKey;
963 charcode = NSF10FunctionKey;
967 charcode = NSF12FunctionKey;
971 charcode = NSF13FunctionKey;
975 charcode = NSInsertFunctionKey;
979 charcode = NSHomeFunctionKey;
983 charcode = NSPageUpFunctionKey;
987 charcode = NSDeleteFunctionKey;
991 charcode = NSF4FunctionKey;
995 charcode = NSEndFunctionKey;
999 charcode = NSF2FunctionKey;
1003 charcode = NSPageDownFunctionKey;
1007 charcode = NSF1FunctionKey;
1011 charcode = NSLeftArrowFunctionKey;
1015 charcode = NSRightArrowFunctionKey;
1019 charcode = NSDownArrowFunctionKey;
1023 charcode = NSUpArrowFunctionKey;
1027 if (charcode == 'a') {
1028 unsigned long state;
1033 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
1034 keyTrans = KeyTranslate(kchr, code, &state);
1035 charCode = keyTrans;
1036 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
1037 } else if (charcode != 'b') {
1038 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];
1042 /*************************************************************************/
1044 #pragma mark NSApplication DELEGATE METHODS
1045 /*************************************************************************/
1047 - (void)applicationWillTerminate:(NSNotification *)note
1049 [self clearHotKeys];
1050 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
1054 /*************************************************************************/
1056 #pragma mark DEALLOCATION METHODS
1057 /*************************************************************************/
1062 [refreshTimer invalidate];
1065 [currentRemote halt];
1066 [statusItem release];