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];
72 // Below line of code is for creating builds for Beta Testers
73 // [statusItem setToolTip:@"This Nontransferable Beta (Built on __DATE__) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com)."];
75 // view = [[MenuTunesView alloc] initWithFrame:[[statusItem view] frame]];
76 // [statusItem setView:view];
80 /*************************************************************************/
82 #pragma mark INSTANCE METHODS
83 /*************************************************************************/
85 - (void)registerDefaultsIfNeeded
87 if (![[NSUserDefaults standardUserDefaults] objectForKey:@"menu"]) {
88 [[NSUserDefaults standardUserDefaults] setObject:
89 [NSArray arrayWithObjects:
102 @"Current Track Info",
103 nil] forKey:@"menu"];
107 //Recreate the status item menu
110 NSArray *myMenu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
114 didHaveAlbumName = ([[self runScriptAndReturnResult:@"return album of current track"] length] > 0);
116 while ([menu numberOfItems] > 0) {
117 [menu removeItemAtIndex:0];
120 playPauseMenuItem = nil;
121 upcomingSongsItem = nil;
123 [playlistMenu release];
129 for (i = 0; i < [myMenu count]; i++) {
130 NSString *item = [myMenu objectAtIndex:i];
131 if ([item isEqualToString:@"Play/Pause"]) {
132 playPauseMenuItem = [menu addItemWithTitle:@"Play"
133 action:@selector(playPause:)
135 [playPauseMenuItem setTarget:self];
136 } else if ([item isEqualToString:@"Next Track"]) {
137 [[menu addItemWithTitle:@"Next Track"
138 action:@selector(nextSong:)
139 keyEquivalent:@""] setTarget:self];
140 } else if ([item isEqualToString:@"Previous Track"]) {
141 [[menu addItemWithTitle:@"Previous Track"
142 action:@selector(prevSong:)
143 keyEquivalent:@""] setTarget:self];
144 } else if ([item isEqualToString:@"Fast Forward"]) {
145 [[menu addItemWithTitle:@"Fast Forward"
146 action:@selector(fastForward:)
147 keyEquivalent:@""] setTarget:self];
148 } else if ([item isEqualToString:@"Rewind"]) {
149 [[menu addItemWithTitle:@"Rewind"
150 action:@selector(rewind:)
151 keyEquivalent:@""] setTarget:self];
152 } else if ([item isEqualToString:@"Upcoming Songs"]) {
153 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
156 } else if ([item isEqualToString:@"Playlists"]) {
157 playlistItem = [menu addItemWithTitle:@"Playlists"
160 } else if ([item isEqualToString:@"EQ Presets"]) {
161 eqItem = [menu addItemWithTitle:@"EQ Presets"
164 } else if ([item isEqualToString:@"PreferencesÉ"]) {
165 [[menu addItemWithTitle:@"PreferencesÉ"
166 action:@selector(showPreferences:)
167 keyEquivalent:@""] setTarget:self];
168 } else if ([item isEqualToString:@"Quit"]) {
169 [[menu addItemWithTitle:@"Quit"
170 action:@selector(quitMenuTunes:)
171 keyEquivalent:@""] setTarget:self];
172 } else if ([item isEqualToString:@"Current Track Info"]) {
173 trackInfoIndex = [menu numberOfItems];
174 [menu addItemWithTitle:@"No Song"
177 } else if ([item isEqualToString:@"<separator>"]) {
178 [menu addItem:[NSMenuItem separatorItem]];
182 curTrackIndex = -1; //Force update of everything
183 [self timerUpdate]; //Updates dynamic info in the menu
189 //Updates the menu with current player state, song, and upcoming songs
192 NSString *curAlbumName = [self runScriptAndReturnResult:@"return album of current track"];
193 NSMenuItem *menuItem;
194 if ((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0)) {
198 if (upcomingSongsItem) {
199 [self rebuildUpcomingSongsMenu];
202 [self rebuildPlaylistMenu];
205 [self rebuildEQPresetsMenu];
208 if (trackInfoIndex > -1)
210 NSString *curSongName;
211 curSongName = [self runScriptAndReturnResult:@"return name of current track"];
212 if ([curSongName length] > 0) {
213 int index = [menu indexOfItemWithTitle:@"Now Playing"];
216 [menu removeItemAtIndex:index + 1];
217 if (didHaveAlbumName) {
218 [menu removeItemAtIndex:index + 1];
221 if (!isPlayingRadio) {
222 if ([curAlbumName length] > 0) {
223 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName]
226 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
230 menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName]
233 [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
237 menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""];
238 [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]];
239 [menu insertItem:menuItem atIndex:trackInfoIndex];
243 } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) {
244 [menu removeItemAtIndex:trackInfoIndex];
245 [menu removeItemAtIndex:trackInfoIndex];
247 if (didHaveAlbumName) {
248 [menu removeItemAtIndex:trackInfoIndex];
251 menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
252 [menu insertItem:menuItem atIndex:trackInfoIndex];
256 didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO);
259 //Rebuild the upcoming songs submenu. Can be improved a lot.
260 - (void)rebuildUpcomingSongsMenu
262 int numSongs = [[self runScriptAndReturnResult:@"return number of tracks in current playlist"] intValue];
263 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
264 if (!isPlayingRadio) {
266 int curTrack = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
269 [upcomingSongsMenu release];
270 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
271 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
272 [upcomingSongsItem setEnabled:YES];
274 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
276 NSString *curSong = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of track %i of current playlist", i]];
277 NSMenuItem *songItem;
278 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""];
279 [songItem setTarget:self];
280 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
281 [upcomingSongsMenu addItem:songItem];
289 [upcomingSongsItem setSubmenu:nil];
290 [upcomingSongsItem setEnabled:NO];
294 - (void)rebuildPlaylistMenu
296 int numPlaylists = [[self runScriptAndReturnResult:@"return number of playlists"] intValue];
297 int i, curPlaylist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
304 if (playlistMenu && (numPlaylists == [playlistMenu numberOfItems]))
307 [playlistMenu release];
308 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
310 for (i = 1; i <= numPlaylists; i++) {
311 NSString *playlistName = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of playlist %i", i]];
312 NSMenuItem *tempItem;
313 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
314 [tempItem setTarget:self];
315 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
316 [playlistMenu addItem:tempItem];
319 [playlistItem setSubmenu:playlistMenu];
322 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOnState];
326 //Build a menu with the list of all available EQ presets
327 - (void)rebuildEQPresetsMenu
329 int numSets = [[self runScriptAndReturnResult:@"return number of EQ presets"] intValue];
332 if (eqMenu && (numSets == [eqMenu numberOfItems]))
336 eqMenu = [[NSMenu alloc] initWithTitle:@""];
338 for (i = 1; i <= numSets; i++) {
339 NSString *setName = [self runScriptAndReturnResult:[NSString stringWithFormat:@"return name of EQ preset %i", i]];
340 NSMenuItem *tempItem;
341 tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""];
342 [tempItem setTarget:self];
343 [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
344 [eqMenu addItem:tempItem];
347 [eqItem setSubmenu:eqMenu];
349 [[eqMenu itemAtIndex:[[self runScriptAndReturnResult:@"return index of current EQ preset"] intValue] - 1] setState:NSOnState];
354 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
355 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
356 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
357 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
358 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
363 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
365 if ([defaults objectForKey:@"PlayPause"] != nil) {
366 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
367 combo:[defaults keyComboForKey:@"PlayPause"]
368 target:self action:@selector(playPause:)];
371 if ([defaults objectForKey:@"NextTrack"] != nil) {
372 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
373 combo:[defaults keyComboForKey:@"NextTrack"]
374 target:self action:@selector(nextSong:)];
377 if ([defaults objectForKey:@"PrevTrack"] != nil) {
378 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
379 combo:[defaults keyComboForKey:@"PrevTrack"]
380 target:self action:@selector(prevSong:)];
383 if ([defaults objectForKey:@"TrackInfo"] != nil) {
384 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
385 combo:[defaults keyComboForKey:@"TrackInfo"]
386 target:self action:@selector(showCurrentTrackInfo)];
389 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
390 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
391 combo:[defaults keyComboForKey:@"UpcomingSongs"]
392 target:self action:@selector(showUpcomingSongs)];
396 //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.
397 - (NSString *)runScriptAndReturnResult:(NSString *)script
399 AEDesc scriptDesc, resultDesc;
404 script = [NSString stringWithFormat:@"tell application \"iTunes\"\n%@\nend tell", script];
406 AECreateDesc(typeChar, [script cString], [script cStringLength],
409 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
411 length = AEGetDescDataSize(&resultDesc);
412 buffer = malloc(length);
414 AEGetDescData(&resultDesc, buffer, length);
415 AEDisposeDesc(&scriptDesc);
416 AEDisposeDesc(&resultDesc);
417 result = [NSString stringWithCString:buffer length:length];
418 if ( (! [result isEqualToString:@""]) &&
419 ([result characterAtIndex:0] == '\"') &&
420 ([result characterAtIndex:[result length] - 1] == '\"') ) {
421 result = [result substringWithRange:NSMakeRange(1, [result length] - 2)];
428 //Called when the timer fires.
432 if (GetProcessPID(&iTunesPSN, &pid) == noErr) {
433 int trackPlayingIndex = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
435 if (trackPlayingIndex != curTrackIndex) {
436 bool wasPlayingRadio = isPlayingRadio;
437 isPlayingRadio = [[self runScriptAndReturnResult:@"return class of current playlist"] isEqualToString:@"radio tuner playlist"];
438 if (isPlayingRadio && !wasPlayingRadio) {
440 for (i = 0; i < [playlistMenu numberOfItems]; i++)
442 [[playlistMenu itemAtIndex:i] setState:NSOffState];
445 if (wasPlayingRadio) {
446 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
447 [menu insertItem:temp atIndex:trackInfoIndex + 1];
451 curTrackIndex = trackPlayingIndex;
455 int playlist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
456 if (playlist != curPlaylistIndex) {
457 bool wasPlayingRadio = isPlayingRadio;
458 isPlayingRadio = [[self runScriptAndReturnResult:@"return class of current playlist"] isEqualToString:@"radio tuner playlist"];
459 if (isPlayingRadio && !wasPlayingRadio) {
461 for (i = 0; i < [playlistMenu numberOfItems]; i++)
463 [[playlistMenu itemAtIndex:i] setState:NSOffState];
466 if (wasPlayingRadio) {
467 NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
468 [menu insertItem:temp atIndex:trackInfoIndex + 1];
472 curTrackIndex = trackPlayingIndex;
473 curPlaylistIndex = playlist;
476 //Update Play/Pause menu item
477 if (playPauseMenuItem){
478 if ([[self runScriptAndReturnResult:@"return player state"] isEqualToString:@"playing"]) {
479 [playPauseMenuItem setTitle:@"Pause"];
481 [playPauseMenuItem setTitle:@"Play"];
486 menu = [[NSMenu alloc] initWithTitle:@""];
487 [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
488 [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
489 [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
490 [statusItem setMenu:menu];
492 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(iTunesLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
493 [refreshTimer invalidate];
499 - (void)iTunesLaunched:(NSNotification *)note
501 NSDictionary *info = [note userInfo];
503 iTunesPSN.highLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
504 iTunesPSN.lowLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
507 refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES];
509 [self rebuildMenu]; //Rebuild the menu since no songs will be playing
510 [statusItem setMenu:menu]; //Set the menu back to the main one
511 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
514 //Return the PSN of iTunes, if it's running
515 - (ProcessSerialNumber)iTunesPSN
517 ProcessSerialNumber procNum;
518 procNum.highLongOfPSN = kNoProcess;
519 procNum.lowLongOfPSN = 0;
521 while ( (GetNextProcess(&procNum) == noErr) ) {
522 CFStringRef procName;
523 if ( (CopyProcessName(&procNum, &procName) == noErr) ) {
524 if ([(NSString *)procName isEqualToString:@"iTunes"]) {
527 [(NSString *)procName release];
533 //Send an AppleEvent with a given event ID
534 - (void)sendAEWithEventClass:(AEEventClass)eventClass
535 andEventID:(AEEventID)eventID
537 OSType iTunesType = 'hook';
538 AppleEvent event, reply;
540 AEBuildAppleEvent(eventClass, eventID, typeApplSignature, &iTunesType, sizeof(iTunesType), kAutoGenerateReturnID, kAnyTransactionID, &event, nil, "");
542 AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, nil, nil);
543 AEDisposeDesc(&event);
544 AEDisposeDesc(&reply);
548 // Selectors - called from status item menu
551 - (void)playTrack:(id)sender
553 [self runScriptAndReturnResult:[NSString stringWithFormat:@"play track %i of current playlist", [[sender representedObject] intValue]]];
557 - (void)selectPlaylist:(id)sender
559 int playlist = [[sender representedObject] intValue];
560 if (!isPlayingRadio) {
561 int curPlaylist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue];
562 [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOffState];
564 [self runScriptAndReturnResult:[NSString stringWithFormat:@"play playlist %i", playlist]];
565 [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
568 - (void)selectEQPreset:(id)sender
570 int curSet = [[self runScriptAndReturnResult:@"return index of current EQ preset"] intValue];
571 int item = [[sender representedObject] intValue];
572 [self runScriptAndReturnResult:[NSString stringWithFormat:@"set current EQ preset to EQ preset %i", item]];
573 [self runScriptAndReturnResult:@"set EQ enabled to 1"];
574 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
575 [[eqMenu itemAtIndex:item - 1] setState:NSOnState];
578 - (void)playPause:(id)sender
580 NSString *state = [self runScriptAndReturnResult:@"return player state"];
581 if ([state isEqualToString:@"playing"]) {
582 [self sendAEWithEventClass:'hook' andEventID:'Paus'];
583 [playPauseMenuItem setTitle:@"Play"];
584 } else if ([state isEqualToString:@"fast forwarding"] || [state
585 isEqualToString:@"rewinding"]) {
586 [self sendAEWithEventClass:'hook' andEventID:'Paus'];
587 [self sendAEWithEventClass:'hook' andEventID:'Play'];
589 [self sendAEWithEventClass:'hook' andEventID:'Play'];
590 [playPauseMenuItem setTitle:@"Pause"];
594 - (void)nextSong:(id)sender
596 [self sendAEWithEventClass:'hook' andEventID:'Next'];
599 - (void)prevSong:(id)sender
601 [self sendAEWithEventClass:'hook' andEventID:'Prev'];
604 - (void)fastForward:(id)sender
606 [self sendAEWithEventClass:'hook' andEventID:'Fast'];
609 - (void)rewind:(id)sender
611 [self sendAEWithEventClass:'hook' andEventID:'Rwnd'];
614 - (void)quitMenuTunes:(id)sender
616 [NSApp terminate:self];
619 - (void)openiTunes:(id)sender
621 [[NSWorkspace sharedWorkspace] launchApplication:@"iTunes"];
624 - (void)showPreferences:(id)sender
626 if (!prefsController) {
627 prefsController = [[PreferencesController alloc] initWithMenuTunes:self];
633 - (void)closePreferences
635 if (!((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0))) {
638 [prefsController release];
639 prefsController = nil;
644 // Show Current Track Info And Show Upcoming Songs Floaters
648 - (void)showCurrentTrackInfo
650 NSString *trackName = [self runScriptAndReturnResult:@"return name of current track"];
651 if (!statusController && [trackName length]) {
652 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
653 NSString *stringToShow = @"";
656 if ([defaults boolForKey:@"showName"]) {
657 if ([defaults boolForKey:@"showArtist"]) {
658 NSString *trackArtist = [self runScriptAndReturnResult:@"return artist of current track"];
659 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
661 stringToShow = [stringToShow stringByAppendingString:trackName];
662 stringToShow = [stringToShow stringByAppendingString:@"\n"];
663 if ([trackName length] > 38) {
669 if ([defaults boolForKey:@"showAlbum"]) {
670 NSString *trackAlbum = [self runScriptAndReturnResult:@"return album of current track"];
671 if ([trackAlbum length]) {
672 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
673 stringToShow = [stringToShow stringByAppendingString:@"\n"];
678 if ([defaults boolForKey:@"showTime"]) {
679 NSString *trackTime = [self runScriptAndReturnResult:@"return time of current track"];
680 if ([trackTime length]) {
681 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
687 int trackTimeLeft = [[self runScriptAndReturnResult:@"return (duration of current track) - player position"] intValue];
688 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
690 stringToShow = [stringToShow stringByAppendingString:
691 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
693 stringToShow = [stringToShow stringByAppendingString:
694 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
698 statusController = [[StatusWindowController alloc] init];
699 [statusController setTrackInfo:stringToShow lines:lines];
700 [NSTimer scheduledTimerWithTimeInterval:3.0
702 selector:@selector(fadeAndCloseStatusWindow)
708 - (void)showUpcomingSongs
710 if (!statusController) {
711 int numSongs = [[self runScriptAndReturnResult:@"return number of tracks in current playlist"] intValue];
714 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
715 int curTrack = [[self runScriptAndReturnResult:@"return index of current track"] intValue];
717 NSString *songs = @"";
719 statusController = [[StatusWindowController alloc] init];
720 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
722 NSString *curSong = [self runScriptAndReturnResult:
723 [NSString stringWithFormat:@"return name of track %i of current playlist", i]];
724 songs = [songs stringByAppendingString:curSong];
725 songs = [songs stringByAppendingString:@"\n"];
728 [statusController setUpcomingSongs:songs numSongs:numSongsInAdvance];
729 [NSTimer scheduledTimerWithTimeInterval:3.0
731 selector:@selector(fadeAndCloseStatusWindow)
738 - (void)fadeAndCloseStatusWindow
740 [statusController fadeWindowOut];
741 [statusController release];
742 statusController = nil;
745 /*************************************************************************/
747 #pragma mark NSApplication DELEGATE METHODS
748 /*************************************************************************/
750 - (void)applicationWillTerminate:(NSNotification *)note
753 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
757 /*************************************************************************/
759 #pragma mark DEALLOCATION METHODS
760 /*************************************************************************/
765 [refreshTimer invalidate];
768 CloseComponent(asComponent);
769 [statusItem release];