3 ¥ Make preferences window pretty
5 - hot keys can't be set when NSBGOnly is on. The window is not key,
6 so the KeyBroadcaster does not pick up key combos
7 - going to need a different way of defining key combos
9 ¥ Apple Events! Apple Events! Apple Events!
13 // #import "MenuTunesView.h"
14 #import "PreferencesController.h"
15 #import "HotKeyCenter.h"
16 #import "StatusWindowController.h"
18 @interface MenuTunes(Private)
19 - (void)registerDefaultsIfNeeded;
21 - (void)rebuildUpcomingSongsMenu;
22 - (void)rebuildPlaylistMenu;
23 - (void)rebuildEQPresetsMenu;
25 - (NSString *)runScriptAndReturnResult:(NSString *)script;
27 - (void)sendAEWithEventClass:(AEEventClass)eventClass andEventID:(AEEventID)eventID;
31 @implementation MenuTunes
33 /*************************************************************************/
35 #pragma mark INITIALIZATION METHODS
36 /*************************************************************************/
38 - (void)applicationDidFinishLaunching:(NSNotification *)note
40 asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
42 [self registerDefaultsIfNeeded];
44 menu = [[NSMenu alloc] initWithTitle:@""];
45 iTunesPSN = [self iTunesPSN]; //Get PSN of iTunes if it's running
47 if (!((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0)))
50 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5
52 selector:@selector(timerUpdate)
58 menu = [[NSMenu alloc] initWithTitle:@""];
59 [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
60 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
61 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
62 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(iTunesLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
66 statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
67 [[[statusItem _button] cell] setType:NSNullCellType];
68 [statusItem setImage:[NSImage imageNamed:@"menu"]];
69 [[statusItem _button] setAlternateImage:[NSImage imageNamed:@"selected_image"]];
70 [statusItem setHighlightMode:YES];
71 [statusItem setMenu:menu];
73 // view = [[MenuTunesView alloc] initWithFrame:[[statusItem view] frame]];
74 // [statusItem setView:view];
78 /*************************************************************************/
80 #pragma mark INSTANCE METHODS
81 /*************************************************************************/
83 - (void)registerDefaultsIfNeeded
85 if (![[NSUserDefaults standardUserDefaults] objectForKey:@"menu"]) {
86 [[NSUserDefaults standardUserDefaults] setObject:
87 [NSArray arrayWithObjects:
100 @"Current Track Info",
101 nil] forKey:@"menu"];
105 //Recreate the status item menu
108 NSArray *myMenu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
112 didHaveAlbumName = ([[self runScriptAndReturnResult:@"return album of current track"] length] > 0);
114 while ([menu numberOfItems] > 0) {
115 [menu removeItemAtIndex:0];
118 playPauseMenuItem = nil;
119 upcomingSongsItem = nil;
121 [playlistMenu release];
127 for (i = 0; i < [myMenu count]; i++) {
128 NSString *item = [myMenu objectAtIndex:i];
129 if ([item isEqualToString:@"Play/Pause"]) {
130 playPauseMenuItem = [menu addItemWithTitle:@"Play"
131 action:@selector(playPause:)
133 [playPauseMenuItem setTarget:self];
134 } else if ([item isEqualToString:@"Next Track"]) {
135 [[menu addItemWithTitle:@"Next Track"
136 action:@selector(nextSong:)
137 keyEquivalent:@""] setTarget:self];
138 } else if ([item isEqualToString:@"Previous Track"]) {
139 [[menu addItemWithTitle:@"Previous Track"
140 action:@selector(prevSong:)
141 keyEquivalent:@""] setTarget:self];
142 } else if ([item isEqualToString:@"Fast Forward"]) {
143 [[menu addItemWithTitle:@"Fast Forward"
144 action:@selector(fastForward:)
145 keyEquivalent:@""] setTarget:self];
146 } else if ([item isEqualToString:@"Rewind"]) {
147 [[menu addItemWithTitle:@"Rewind"
148 action:@selector(rewind:)
149 keyEquivalent:@""] setTarget:self];
150 } else if ([item isEqualToString:@"Upcoming Songs"]) {
151 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
154 } else if ([item isEqualToString:@"Playlists"]) {
155 playlistItem = [menu addItemWithTitle:@"Playlists"
158 } else if ([item isEqualToString:@"EQ Presets"]) {
159 eqItem = [menu addItemWithTitle:@"EQ Presets"
162 } else if ([item isEqualToString:@"PreferencesÉ"]) {
163 [[menu addItemWithTitle:@"PreferencesÉ"
164 action:@selector(showPreferences:)
165 keyEquivalent:@""] setTarget:self];
166 } else if ([item isEqualToString:@"Quit"]) {
167 [[menu addItemWithTitle:@"Quit"
168 action:@selector(quitMenuTunes:)
169 keyEquivalent:@""] setTarget:self];
170 } else if ([item isEqualToString:@"Current Track Info"]) {
171 trackInfoIndex = [menu numberOfItems];
172 [menu addItemWithTitle:@"No Song"
175 } else if ([item isEqualToString:@"<separator>"]) {
176 [menu addItem:[NSMenuItem separatorItem]];
180 curTrackIndex = -1; //Force update of everything
181 [self timerUpdate]; //Updates dynamic info in the menu
187 //Updates the menu with current player state, song, and upcoming songs
190 NSString *curAlbumName = [self runScriptAndReturnResult:@"return album of current track"];
191 NSMenuItem *menuItem;
192 if ((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0)) {
196 if (upcomingSongsItem) {
197 [self rebuildUpcomingSongsMenu];
200 [self rebuildPlaylistMenu];
203 [self rebuildEQPresetsMenu];
206 if (trackInfoIndex > -1)
208 NSString *curSongName;
209 curSongName = [self runScriptAndReturnResult:@"return name of current track"];
210 if ([curSongName length] > 0) {
211 int index = [menu indexOfItemWithTitle:@"Now Playing"];
214 [menu removeItemAtIndex:index + 1];
215 if (didHaveAlbumName) {
216 [menu removeItemAtIndex:index + 1];
219 if (!isPlayingRadio) {
220 if ([curAlbumName length] > 0) {
221 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName]
224 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
228 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName]
231 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
235 menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""];
236 [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]];
237 [menu insertItem:menuItem atIndex:trackInfoIndex];
241 } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) {
242 [menu removeItemAtIndex:trackInfoIndex];
243 [menu removeItemAtIndex:trackInfoIndex];
245 if (didHaveAlbumName) {
246 [menu removeItemAtIndex:trackInfoIndex];
249 menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
250 [menu insertItem:menuItem atIndex:trackInfoIndex];
254 didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO);
257 //Rebuild the upcoming songs submenu. Can be improved a lot.
258 - (void)rebuildUpcomingSongsMenu
260 int numSongs = [[self runScriptAndReturnResult:@"return number of tracks in current playlist"] intValue];
261 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
262 if (!isPlayingRadio) {
264 int curTrack = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
267 [upcomingSongsMenu release];
268 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
269 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
270 [upcomingSongsItem setEnabled:YES];
272 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
274 NSString *curSong = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of track %i of current playlist", i]];
275 NSMenuItem *songItem;
276 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""];
277 [songItem setTarget:self];
278 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
279 [upcomingSongsMenu addItem:songItem];
287 [upcomingSongsItem setSubmenu:nil];
288 [upcomingSongsItem setEnabled:NO];
292 - (void)rebuildPlaylistMenu
294 int numPlaylists = [[self runScriptAndReturnResult:@"return number of playlists"] intValue];
295 int i, curPlaylist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
302 if (playlistMenu && (numPlaylists == [playlistMenu numberOfItems]))
305 [playlistMenu release];
306 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
308 for (i = 1; i <= numPlaylists; i++) {
309 NSString *playlistName = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of playlist %i", i]];
310 NSMenuItem *tempItem;
311 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
312 [tempItem setTarget:self];
313 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
314 [playlistMenu addItem:tempItem];
317 [playlistItem setSubmenu:playlistMenu];
320 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOnState];
324 //Build a menu with the list of all available EQ presets
325 - (void)rebuildEQPresetsMenu
327 int numSets = [[self runScriptAndReturnResult:@"return number of EQ presets"] intValue];
330 if (eqMenu && (numSets == [eqMenu numberOfItems]))
334 eqMenu = [[NSMenu alloc] initWithTitle:@""];
336 for (i = 1; i <= numSets; i++) {
337 NSString *setName = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of EQ preset %i", i]];
338 NSMenuItem *tempItem;
339 tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""];
340 [tempItem setTarget:self];
341 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
342 [eqMenu addItem:tempItem];
345 [eqItem setSubmenu:eqMenu];
347 [[eqMenu itemAtIndex:[[self runScriptAndReturnResult:@"return index of current EQ preset"] intValue] - 1] setState:NSOnState];
352 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
353 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
354 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
355 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
356 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
361 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
363 if ([defaults objectForKey:@"PlayPause"] != nil) {
364 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
365 combo:[defaults keyComboForKey:@"PlayPause"]
366 target:self action:@selector(playPause:)];
369 if ([defaults objectForKey:@"NextTrack"] != nil) {
370 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
371 combo:[defaults keyComboForKey:@"NextTrack"]
372 target:self action:@selector(nextSong:)];
375 if ([defaults objectForKey:@"PrevTrack"] != nil) {
376 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
377 combo:[defaults keyComboForKey:@"PrevTrack"]
378 target:self action:@selector(prevSong:)];
381 if ([defaults objectForKey:@"TrackInfo"] != nil) {
382 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
383 combo:[defaults keyComboForKey:@"TrackInfo"]
384 target:self action:@selector(showCurrentTrackInfo)];
387 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
388 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
389 combo:[defaults keyComboForKey:@"UpcomingSongs"]
390 target:self action:@selector(showUpcomingSongs)];
394 //Runs an AppleScript and returns the result as an NSString after stripping quotes, if needed. It takes in script and automatically adds the tell iTunes and end tell statements.
395 - (NSString *)runScriptAndReturnResult:(NSString *)script
397 AEDesc scriptDesc, resultDesc;
402 script = [NSString stringWithFormat:@"tell application \"iTunes\"\n%@\nend tell", script];
404 AECreateDesc(typeChar, [script cString], [script cStringLength],
407 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
409 length = AEGetDescDataSize(&resultDesc);
410 buffer = malloc(length);
412 AEGetDescData(&resultDesc, buffer, length);
413 AEDisposeDesc(&scriptDesc);
414 AEDisposeDesc(&resultDesc);
415 result = [NSString stringWithCString:buffer length:length];
416 if ( (! [result isEqualToString:@""]) &&
417 ([result characterAtIndex:0] == '\"') &&
418 ([result characterAtIndex:[result length] - 1] == '\"') ) {
419 result = [result substringWithRange:NSMakeRange(1, [result length] - 2)];
426 //Called when the timer fires.
430 if (GetProcessPID(&iTunesPSN, &pid) == noErr) {
431 int trackPlayingIndex = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
433 if (trackPlayingIndex != curTrackIndex) {
434 bool wasPlayingRadio = isPlayingRadio;
435 isPlayingRadio = [[self runScriptAndReturnResult:@"return class of current playlist"] isEqualToString:@"radio tuner playlist"];
436 if (isPlayingRadio && !wasPlayingRadio) {
438 for (i = 0; i < [playlistMenu numberOfItems]; i++)
440 [[playlistMenu itemAtIndex:i] setState:NSOffState];
443 if (wasPlayingRadio) {
444 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
445 [menu insertItem:temp atIndex:trackInfoIndex + 1];
449 curTrackIndex = trackPlayingIndex;
453 int playlist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
454 if (playlist != curPlaylistIndex) {
455 bool wasPlayingRadio = isPlayingRadio;
456 isPlayingRadio = [[self runScriptAndReturnResult:@"return class of current playlist"] isEqualToString:@"radio tuner playlist"];
457 if (isPlayingRadio && !wasPlayingRadio) {
459 for (i = 0; i < [playlistMenu numberOfItems]; i++)
461 [[playlistMenu itemAtIndex:i] setState:NSOffState];
464 if (wasPlayingRadio) {
465 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
466 [menu insertItem:temp atIndex:trackInfoIndex + 1];
470 curTrackIndex = trackPlayingIndex;
471 curPlaylistIndex = playlist;
474 //Update Play/Pause menu item
475 if (playPauseMenuItem){
476 if ([[self runScriptAndReturnResult:@"return player state"] isEqualToString:@"playing"]) {
477 [playPauseMenuItem setTitle:@"Pause"];
479 [playPauseMenuItem setTitle:@"Play"];
484 menu = [[NSMenu alloc] initWithTitle:@""];
485 [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
486 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
487 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
488 [statusItem setMenu:menu];
490 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(iTunesLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
491 [refreshTimer invalidate];
497 - (void)iTunesLaunched:(NSNotification *)note
499 NSDictionary *info = [note userInfo];
501 iTunesPSN.highLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
502 iTunesPSN.lowLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
505 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES];
507 [self rebuildMenu]; //Rebuild the menu since no songs will be playing
508 [statusItem setMenu:menu]; //Set the menu back to the main one
509 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
512 //Return the PSN of iTunes, if it's running
513 - (ProcessSerialNumber)iTunesPSN
515 ProcessSerialNumber procNum;
516 procNum.highLongOfPSN = kNoProcess;
517 procNum.lowLongOfPSN = 0;
519 while ( (GetNextProcess(&procNum) == noErr) ) {
520 CFStringRef procName;
521 if ( (CopyProcessName(&procNum, &procName) == noErr) ) {
522 if ([(NSString *)procName isEqualToString:@"iTunes"]) {
525 [(NSString *)procName release];
531 //Send an AppleEvent with a given event ID
532 - (void)sendAEWithEventClass:(AEEventClass)eventClass
533 andEventID:(AEEventID)eventID
535 OSType iTunesType = 'hook';
536 AppleEvent event, reply;
538 AEBuildAppleEvent(eventClass, eventID, typeApplSignature, &iTunesType, sizeof(iTunesType), kAutoGenerateReturnID, kAnyTransactionID, &event, nil, "");
540 AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, nil, nil);
541 AEDisposeDesc(&event);
542 AEDisposeDesc(&reply);
546 // Selectors - called from status item menu
549 - (void)playTrack:(id)sender
551 [self runScriptAndReturnResult:[NSString stringWithFormat:@"play track %i of current playlist", [[sender representedObject] intValue]]];
555 - (void)selectPlaylist:(id)sender
557 int playlist = [[sender representedObject] intValue];
558 if (!isPlayingRadio) {
559 int curPlaylist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
560 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOffState];
562 [self runScriptAndReturnResult:[NSString stringWithFormat:@"play playlist %i", playlist]];
563 [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
566 - (void)selectEQPreset:(id)sender
568 int curSet = [[self runScriptAndReturnResult:@"return index of current EQ preset"] intValue];
569 int item = [[sender representedObject] intValue];
570 [self runScriptAndReturnResult:[NSString stringWithFormat:@"set current EQ preset to EQ preset %i", item]];
571 [self runScriptAndReturnResult:@"set EQ enabled to 1"];
572 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
573 [[eqMenu itemAtIndex:item - 1] setState:NSOnState];
576 - (void)playPause:(id)sender
578 NSString *state = [self runScriptAndReturnResult:@"return player state"];
579 if ([state isEqualToString:@"playing"]) {
580 [self sendAEWithEventClass:'hook' andEventID:'Paus'];
581 [playPauseMenuItem setTitle:@"Play"];
582 } else if ([state isEqualToString:@"fast forwarding"] || [state
583 isEqualToString:@"rewinding"]) {
584 [self sendAEWithEventClass:'hook' andEventID:'Paus'];
585 [self sendAEWithEventClass:'hook' andEventID:'Play'];
587 [self sendAEWithEventClass:'hook' andEventID:'Play'];
588 [playPauseMenuItem setTitle:@"Pause"];
592 - (void)nextSong:(id)sender
594 [self sendAEWithEventClass:'hook' andEventID:'Next'];
597 - (void)prevSong:(id)sender
599 [self sendAEWithEventClass:'hook' andEventID:'Prev'];
602 - (void)fastForward:(id)sender
604 [self sendAEWithEventClass:'hook' andEventID:'Fast'];
607 - (void)rewind:(id)sender
609 [self sendAEWithEventClass:'hook' andEventID:'Rwnd'];
612 - (void)quitMenuTunes:(id)sender
614 [NSApp terminate:self];
617 - (void)openiTunes:(id)sender
619 [[NSWorkspace sharedWorkspace] launchApplication:@"iTunes"];
622 - (void)showPreferences:(id)sender
624 if (!prefsController) {
625 prefsController = [[PreferencesController alloc] initWithMenuTunes:self];
631 - (void)closePreferences
633 if (!((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0))) {
636 [prefsController release];
637 prefsController = nil;
642 // Show Current Track Info And Show Upcoming Songs Floaters
646 - (void)showCurrentTrackInfo
648 NSString *trackName = [self runScriptAndReturnResult:@"return name of current track"];
649 if (!statusController && [trackName length]) {
650 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
651 NSString *stringToShow = @"";
654 if ([defaults boolForKey:@"showName"]) {
655 if ([defaults boolForKey:@"showArtist"]) {
656 NSString *trackArtist = [self runScriptAndReturnResult:@"return artist of current track"];
657 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
659 stringToShow = [stringToShow stringByAppendingString:trackName];
660 stringToShow = [stringToShow stringByAppendingString:@"\n"];
661 if ([trackName length] > 38) {
667 if ([defaults boolForKey:@"showAlbum"]) {
668 NSString *trackAlbum = [self runScriptAndReturnResult:@"return album of current track"];
669 if ([trackAlbum length]) {
670 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
671 stringToShow = [stringToShow stringByAppendingString:@"\n"];
676 if ([defaults boolForKey:@"showTime"]) {
677 NSString *trackTime = [self runScriptAndReturnResult:@"return time of current track"];
678 if ([trackTime length]) {
679 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
685 int trackTimeLeft = [[self runScriptAndReturnResult:@"return (duration of current track) - player position"] intValue];
686 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
688 stringToShow = [stringToShow stringByAppendingString:
689 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
691 stringToShow = [stringToShow stringByAppendingString:
692 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
696 statusController = [[StatusWindowController alloc] init];
697 [statusController setTrackInfo:stringToShow lines:lines];
698 [NSTimer scheduledTimerWithTimeInterval:3.0
700 selector:@selector(fadeAndCloseStatusWindow)
706 - (void)showUpcomingSongs
708 if (!statusController) {
709 int numSongs = [[self runScriptAndReturnResult:@"return number of tracks in current playlist"] intValue];
712 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
713 int curTrack = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
715 NSString *songs = @"";
717 statusController = [[StatusWindowController alloc] init];
718 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
720 NSString *curSong = [self runScriptAndReturnResult:
721 [NSString stringWithFormat:@"return name of track %i of current playlist", i]];
722 songs = [songs stringByAppendingString:curSong];
723 songs = [songs stringByAppendingString:@"\n"];
726 [statusController setUpcomingSongs:songs numSongs:numSongsInAdvance];
727 [NSTimer scheduledTimerWithTimeInterval:3.0
729 selector:@selector(fadeAndCloseStatusWindow)
736 - (void)fadeAndCloseStatusWindow
738 [statusController fadeWindowOut];
739 [statusController release];
740 statusController = nil;
743 /*************************************************************************/
745 #pragma mark NSApplication DELEGATE METHODS
746 /*************************************************************************/
748 - (void)applicationWillTerminate:(NSNotification *)note
751 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
755 /*************************************************************************/
757 #pragma mark DEALLOCATION METHODS
758 /*************************************************************************/
763 [refreshTimer invalidate];
766 CloseComponent(asComponent);
767 [statusItem release];