3 ¥ Make preferences window pretty
5 ¥ Apple Events! Apple Events! Apple Events!
9 // #import "MenuTunesView.h"
10 #import "PreferencesController.h"
11 #import "HotKeyCenter.h"
12 #import "StatusWindowController.h"
14 @interface MenuTunes(Private)
15 - (void)registerDefaultsIfNeeded;
17 - (void)rebuildUpcomingSongsMenu;
18 - (void)rebuildPlaylistMenu;
19 - (void)rebuildEQPresetsMenu;
21 - (NSString *)runScriptAndReturnResult:(NSString *)script;
23 - (void)sendAEWithEventClass:(AEEventClass)eventClass andEventID:(AEEventID)eventID;
27 @implementation MenuTunes
29 /*************************************************************************/
31 #pragma mark INITIALIZATION METHODS
32 /*************************************************************************/
34 - (void)applicationDidFinishLaunching:(NSNotification *)note
36 asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
38 [self registerDefaultsIfNeeded];
40 menu = [[NSMenu alloc] initWithTitle:@""];
41 iTunesPSN = [self iTunesPSN]; //Get PSN of iTunes if it's running
43 if (!((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0)))
46 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5
48 selector:@selector(timerUpdate)
54 menu = [[NSMenu alloc] initWithTitle:@""];
55 [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
56 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
57 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
58 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(iTunesLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
62 statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
63 [[[statusItem _button] cell] setType:NSNullCellType];
64 [statusItem setImage:[NSImage imageNamed:@"menu"]];
65 [[statusItem _button] setAlternateImage:[NSImage imageNamed:@"selected_image"]];
66 [statusItem setHighlightMode:YES];
67 [statusItem setMenu:menu];
68 // Below line of code is for creating builds for Beta Testers
69 // [statusItem setToolTip:@"This Nontransferable Beta (Built on __DATE__) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com)."];
71 // view = [[MenuTunesView alloc] initWithFrame:[[statusItem view] frame]];
72 // [statusItem setView:view];
76 /*************************************************************************/
78 #pragma mark INSTANCE METHODS
79 /*************************************************************************/
81 - (void)registerDefaultsIfNeeded
83 if (![[NSUserDefaults standardUserDefaults] objectForKey:@"menu"]) {
84 [[NSUserDefaults standardUserDefaults] setObject:
85 [NSArray arrayWithObjects:
98 @"Current Track Info",
103 //Recreate the status item menu
106 NSArray *myMenu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
110 didHaveAlbumName = ([[self runScriptAndReturnResult:@"return album of current track"] length] > 0);
112 while ([menu numberOfItems] > 0) {
113 [menu removeItemAtIndex:0];
116 playPauseMenuItem = nil;
117 upcomingSongsItem = nil;
119 [playlistMenu release];
125 for (i = 0; i < [myMenu count]; i++) {
126 NSString *item = [myMenu objectAtIndex:i];
127 if ([item isEqualToString:@"Play/Pause"]) {
128 playPauseMenuItem = [menu addItemWithTitle:@"Play"
129 action:@selector(playPause:)
131 [playPauseMenuItem setTarget:self];
132 } else if ([item isEqualToString:@"Next Track"]) {
133 [[menu addItemWithTitle:@"Next Track"
134 action:@selector(nextSong:)
135 keyEquivalent:@""] setTarget:self];
136 } else if ([item isEqualToString:@"Previous Track"]) {
137 [[menu addItemWithTitle:@"Previous Track"
138 action:@selector(prevSong:)
139 keyEquivalent:@""] setTarget:self];
140 } else if ([item isEqualToString:@"Fast Forward"]) {
141 [[menu addItemWithTitle:@"Fast Forward"
142 action:@selector(fastForward:)
143 keyEquivalent:@""] setTarget:self];
144 } else if ([item isEqualToString:@"Rewind"]) {
145 [[menu addItemWithTitle:@"Rewind"
146 action:@selector(rewind:)
147 keyEquivalent:@""] setTarget:self];
148 } else if ([item isEqualToString:@"Upcoming Songs"]) {
149 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
152 } else if ([item isEqualToString:@"Playlists"]) {
153 playlistItem = [menu addItemWithTitle:@"Playlists"
156 } else if ([item isEqualToString:@"EQ Presets"]) {
157 eqItem = [menu addItemWithTitle:@"EQ Presets"
160 } else if ([item isEqualToString:@"PreferencesÉ"]) {
161 [[menu addItemWithTitle:@"PreferencesÉ"
162 action:@selector(showPreferences:)
163 keyEquivalent:@""] setTarget:self];
164 } else if ([item isEqualToString:@"Quit"]) {
165 [[menu addItemWithTitle:@"Quit"
166 action:@selector(quitMenuTunes:)
167 keyEquivalent:@""] setTarget:self];
168 } else if ([item isEqualToString:@"Current Track Info"]) {
169 trackInfoIndex = [menu numberOfItems];
170 [menu addItemWithTitle:@"No Song"
173 } else if ([item isEqualToString:@"<separator>"]) {
174 [menu addItem:[NSMenuItem separatorItem]];
178 curTrackIndex = -1; //Force update of everything
179 [self timerUpdate]; //Updates dynamic info in the menu
185 //Updates the menu with current player state, song, and upcoming songs
188 NSString *curAlbumName = [self runScriptAndReturnResult:@"return album of current track"];
189 NSMenuItem *menuItem;
190 if ((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0)) {
194 if (upcomingSongsItem) {
195 [self rebuildUpcomingSongsMenu];
198 [self rebuildPlaylistMenu];
201 [self rebuildEQPresetsMenu];
204 if (trackInfoIndex > -1)
206 NSString *curSongName;
207 curSongName = [self runScriptAndReturnResult:@"return name of current track"];
208 if ([curSongName length] > 0) {
209 int index = [menu indexOfItemWithTitle:@"Now Playing"];
212 [menu removeItemAtIndex:index + 1];
213 if (didHaveAlbumName) {
214 [menu removeItemAtIndex:index + 1];
217 if (!isPlayingRadio) {
218 if ([curAlbumName length] > 0) {
219 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName]
222 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
226 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName]
229 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
233 menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""];
234 [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]];
235 [menu insertItem:menuItem atIndex:trackInfoIndex];
239 } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) {
240 [menu removeItemAtIndex:trackInfoIndex];
241 [menu removeItemAtIndex:trackInfoIndex];
243 if (didHaveAlbumName) {
244 [menu removeItemAtIndex:trackInfoIndex];
247 menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
248 [menu insertItem:menuItem atIndex:trackInfoIndex];
252 didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO);
255 //Rebuild the upcoming songs submenu. Can be improved a lot.
256 - (void)rebuildUpcomingSongsMenu
258 int numSongs = [[self runScriptAndReturnResult:@"return number of tracks in current playlist"] intValue];
259 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
260 if (!isPlayingRadio) {
262 int curTrack = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
265 [upcomingSongsMenu release];
266 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
267 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
268 [upcomingSongsItem setEnabled:YES];
270 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
272 NSString *curSong = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of track %i of current playlist", i]];
273 NSMenuItem *songItem;
274 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""];
275 [songItem setTarget:self];
276 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
277 [upcomingSongsMenu addItem:songItem];
285 [upcomingSongsItem setSubmenu:nil];
286 [upcomingSongsItem setEnabled:NO];
290 - (void)rebuildPlaylistMenu
292 int numPlaylists = [[self runScriptAndReturnResult:@"return number of playlists"] intValue];
293 int i, curPlaylist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
300 if (playlistMenu && (numPlaylists == [playlistMenu numberOfItems]))
303 [playlistMenu release];
304 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
306 for (i = 1; i <= numPlaylists; i++) {
307 NSString *playlistName = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of playlist %i", i]];
308 NSMenuItem *tempItem;
309 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
310 [tempItem setTarget:self];
311 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
312 [playlistMenu addItem:tempItem];
315 [playlistItem setSubmenu:playlistMenu];
318 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOnState];
322 //Build a menu with the list of all available EQ presets
323 - (void)rebuildEQPresetsMenu
325 int numSets = [[self runScriptAndReturnResult:@"return number of EQ presets"] intValue];
328 if (eqMenu && (numSets == [eqMenu numberOfItems]))
332 eqMenu = [[NSMenu alloc] initWithTitle:@""];
334 for (i = 1; i <= numSets; i++) {
335 NSString *setName = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of EQ preset %i", i]];
336 NSMenuItem *tempItem;
337 tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""];
338 [tempItem setTarget:self];
339 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
340 [eqMenu addItem:tempItem];
343 [eqItem setSubmenu:eqMenu];
345 [[eqMenu itemAtIndex:[[self runScriptAndReturnResult:@"return index of current EQ preset"] intValue] - 1] setState:NSOnState];
350 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
351 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
352 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
353 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
354 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
359 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
361 if ([defaults objectForKey:@"PlayPause"] != nil) {
362 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
363 combo:[defaults keyComboForKey:@"PlayPause"]
364 target:self action:@selector(playPause:)];
367 if ([defaults objectForKey:@"NextTrack"] != nil) {
368 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
369 combo:[defaults keyComboForKey:@"NextTrack"]
370 target:self action:@selector(nextSong:)];
373 if ([defaults objectForKey:@"PrevTrack"] != nil) {
374 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
375 combo:[defaults keyComboForKey:@"PrevTrack"]
376 target:self action:@selector(prevSong:)];
379 if ([defaults objectForKey:@"TrackInfo"] != nil) {
380 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
381 combo:[defaults keyComboForKey:@"TrackInfo"]
382 target:self action:@selector(showCurrentTrackInfo)];
385 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
386 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
387 combo:[defaults keyComboForKey:@"UpcomingSongs"]
388 target:self action:@selector(showUpcomingSongs)];
392 //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.
393 - (NSString *)runScriptAndReturnResult:(NSString *)script
395 AEDesc scriptDesc, resultDesc;
400 script = [NSString stringWithFormat:@"tell application \"iTunes\"\n%@\nend tell", script];
402 AECreateDesc(typeChar, [script cString], [script cStringLength],
405 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
407 length = AEGetDescDataSize(&resultDesc);
408 buffer = malloc(length);
410 AEGetDescData(&resultDesc, buffer, length);
411 AEDisposeDesc(&scriptDesc);
412 AEDisposeDesc(&resultDesc);
413 result = [NSString stringWithCString:buffer length:length];
414 if ( (! [result isEqualToString:@""]) &&
415 ([result characterAtIndex:0] == '\"') &&
416 ([result characterAtIndex:[result length] - 1] == '\"') ) {
417 result = [result substringWithRange:NSMakeRange(1, [result length] - 2)];
424 //Called when the timer fires.
428 if (GetProcessPID(&iTunesPSN, &pid) == noErr) {
429 int trackPlayingIndex = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
431 if (trackPlayingIndex != curTrackIndex) {
432 bool wasPlayingRadio = isPlayingRadio;
433 isPlayingRadio = [[self runScriptAndReturnResult:@"return class of current playlist"] isEqualToString:@"radio tuner playlist"];
434 if (isPlayingRadio && !wasPlayingRadio) {
436 for (i = 0; i < [playlistMenu numberOfItems]; i++)
438 [[playlistMenu itemAtIndex:i] setState:NSOffState];
441 if (wasPlayingRadio) {
442 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
443 [menu insertItem:temp atIndex:trackInfoIndex + 1];
447 curTrackIndex = trackPlayingIndex;
451 int playlist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
452 if (playlist != curPlaylistIndex) {
453 bool wasPlayingRadio = isPlayingRadio;
454 isPlayingRadio = [[self runScriptAndReturnResult:@"return class of current playlist"] isEqualToString:@"radio tuner playlist"];
455 if (isPlayingRadio && !wasPlayingRadio) {
457 for (i = 0; i < [playlistMenu numberOfItems]; i++)
459 [[playlistMenu itemAtIndex:i] setState:NSOffState];
462 if (wasPlayingRadio) {
463 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
464 [menu insertItem:temp atIndex:trackInfoIndex + 1];
468 curTrackIndex = trackPlayingIndex;
469 curPlaylistIndex = playlist;
472 //Update Play/Pause menu item
473 if (playPauseMenuItem){
474 if ([[self runScriptAndReturnResult:@"return player state"] isEqualToString:@"playing"]) {
475 [playPauseMenuItem setTitle:@"Pause"];
477 [playPauseMenuItem setTitle:@"Play"];
482 menu = [[NSMenu alloc] initWithTitle:@""];
483 [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
484 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
485 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
486 [statusItem setMenu:menu];
488 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(iTunesLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
489 [refreshTimer invalidate];
495 - (void)iTunesLaunched:(NSNotification *)note
497 NSDictionary *info = [note userInfo];
499 iTunesPSN.highLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
500 iTunesPSN.lowLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
503 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES];
505 [self rebuildMenu]; //Rebuild the menu since no songs will be playing
506 [statusItem setMenu:menu]; //Set the menu back to the main one
507 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
510 //Return the PSN of iTunes, if it's running
511 - (ProcessSerialNumber)iTunesPSN
513 ProcessSerialNumber procNum;
514 procNum.highLongOfPSN = kNoProcess;
515 procNum.lowLongOfPSN = 0;
517 while ( (GetNextProcess(&procNum) == noErr) ) {
518 CFStringRef procName;
519 if ( (CopyProcessName(&procNum, &procName) == noErr) ) {
520 if ([(NSString *)procName isEqualToString:@"iTunes"]) {
523 [(NSString *)procName release];
529 //Send an AppleEvent with a given event ID
530 - (void)sendAEWithEventClass:(AEEventClass)eventClass
531 andEventID:(AEEventID)eventID
533 OSType iTunesType = 'hook';
534 AppleEvent event, reply;
536 AEBuildAppleEvent(eventClass, eventID, typeApplSignature, &iTunesType, sizeof(iTunesType), kAutoGenerateReturnID, kAnyTransactionID, &event, nil, "");
538 AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, nil, nil);
539 AEDisposeDesc(&event);
540 AEDisposeDesc(&reply);
544 // Selectors - called from status item menu
547 - (void)playTrack:(id)sender
549 [self runScriptAndReturnResult:[NSString stringWithFormat:@"play track %i of current playlist", [[sender representedObject] intValue]]];
553 - (void)selectPlaylist:(id)sender
555 int playlist = [[sender representedObject] intValue];
556 if (!isPlayingRadio) {
557 int curPlaylist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
558 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOffState];
560 [self runScriptAndReturnResult:[NSString stringWithFormat:@"play playlist %i", playlist]];
561 [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
564 - (void)selectEQPreset:(id)sender
566 int curSet = [[self runScriptAndReturnResult:@"return index of current EQ preset"] intValue];
567 int item = [[sender representedObject] intValue];
568 [self runScriptAndReturnResult:[NSString stringWithFormat:@"set current EQ preset to EQ preset %i", item]];
569 [self runScriptAndReturnResult:@"set EQ enabled to 1"];
570 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
571 [[eqMenu itemAtIndex:item - 1] setState:NSOnState];
574 - (void)playPause:(id)sender
576 NSString *state = [self runScriptAndReturnResult:@"return player state"];
577 if ([state isEqualToString:@"playing"]) {
578 [self sendAEWithEventClass:'hook' andEventID:'Paus'];
579 [playPauseMenuItem setTitle:@"Play"];
580 } else if ([state isEqualToString:@"fast forwarding"] || [state
581 isEqualToString:@"rewinding"]) {
582 [self sendAEWithEventClass:'hook' andEventID:'Paus'];
583 [self sendAEWithEventClass:'hook' andEventID:'Play'];
585 [self sendAEWithEventClass:'hook' andEventID:'Play'];
586 [playPauseMenuItem setTitle:@"Pause"];
590 - (void)nextSong:(id)sender
592 [self sendAEWithEventClass:'hook' andEventID:'Next'];
595 - (void)prevSong:(id)sender
597 [self sendAEWithEventClass:'hook' andEventID:'Prev'];
600 - (void)fastForward:(id)sender
602 [self sendAEWithEventClass:'hook' andEventID:'Fast'];
605 - (void)rewind:(id)sender
607 [self sendAEWithEventClass:'hook' andEventID:'Rwnd'];
610 - (void)quitMenuTunes:(id)sender
612 [NSApp terminate:self];
615 - (void)openiTunes:(id)sender
617 [[NSWorkspace sharedWorkspace] launchApplication:@"iTunes"];
620 - (void)showPreferences:(id)sender
622 if (!prefsController) {
623 prefsController = [[PreferencesController alloc] initWithMenuTunes:self];
629 - (void)closePreferences
631 if (!((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0))) {
634 [prefsController release];
635 prefsController = nil;
640 // Show Current Track Info And Show Upcoming Songs Floaters
644 - (void)showCurrentTrackInfo
646 NSString *trackName = [self runScriptAndReturnResult:@"return name of current track"];
647 if (!statusController && [trackName length]) {
648 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
649 NSString *stringToShow = @"";
652 if ([defaults boolForKey:@"showName"]) {
653 if ([defaults boolForKey:@"showArtist"]) {
654 NSString *trackArtist = [self runScriptAndReturnResult:@"return artist of current track"];
655 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
657 stringToShow = [stringToShow stringByAppendingString:trackName];
658 stringToShow = [stringToShow stringByAppendingString:@"\n"];
659 if ([trackName length] > 38) {
665 if ([defaults boolForKey:@"showAlbum"]) {
666 NSString *trackAlbum = [self runScriptAndReturnResult:@"return album of current track"];
667 if ([trackAlbum length]) {
668 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
669 stringToShow = [stringToShow stringByAppendingString:@"\n"];
674 if ([defaults boolForKey:@"showTime"]) {
675 NSString *trackTime = [self runScriptAndReturnResult:@"return time of current track"];
676 if ([trackTime length]) {
677 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
683 int trackTimeLeft = [[self runScriptAndReturnResult:@"return (duration of current track) - player position"] intValue];
684 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
686 stringToShow = [stringToShow stringByAppendingString:
687 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
689 stringToShow = [stringToShow stringByAppendingString:
690 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
694 statusController = [[StatusWindowController alloc] init];
695 [statusController setTrackInfo:stringToShow lines:lines];
696 [NSTimer scheduledTimerWithTimeInterval:3.0
698 selector:@selector(fadeAndCloseStatusWindow)
704 - (void)showUpcomingSongs
706 if (!statusController) {
707 int numSongs = [[self runScriptAndReturnResult:@"return number of tracks in current playlist"] intValue];
710 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
711 int curTrack = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
713 NSString *songs = @"";
715 statusController = [[StatusWindowController alloc] init];
716 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
718 NSString *curSong = [self runScriptAndReturnResult:
719 [NSString stringWithFormat:@"return name of track %i of current playlist", i]];
720 songs = [songs stringByAppendingString:curSong];
721 songs = [songs stringByAppendingString:@"\n"];
724 [statusController setUpcomingSongs:songs numSongs:numSongsInAdvance];
725 [NSTimer scheduledTimerWithTimeInterval:3.0
727 selector:@selector(fadeAndCloseStatusWindow)
734 - (void)fadeAndCloseStatusWindow
736 [statusController fadeWindowOut];
737 [statusController release];
738 statusController = nil;
741 /*************************************************************************/
743 #pragma mark NSApplication DELEGATE METHODS
744 /*************************************************************************/
746 - (void)applicationWillTerminate:(NSNotification *)note
749 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
753 /*************************************************************************/
755 #pragma mark DEALLOCATION METHODS
756 /*************************************************************************/
761 [refreshTimer invalidate];
764 CloseComponent(asComponent);
765 [statusItem release];