-//Called when the timer fires.
-- (void)timerUpdate
-{
- int playlist = [currentRemote currentPlaylistIndex];
- ITMTRemotePlayerPlayingState playerPlayingState = [currentRemote playerPlayingState];
-
- if ((playlist > 0) || playerPlayingState != ITMTRemotePlayerStopped) {
- int trackPlayingIndex = [currentRemote currentSongIndex];
-
- if (trackPlayingIndex != lastSongIndex) {
- BOOL wasPlayingRadio = isPlayingRadio;
- isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
-
- if (isPlayingRadio && !wasPlayingRadio) {
- int i;
- for (i = 0; i < [playlistMenu numberOfItems]; i++)
- {
- [[playlistMenu itemAtIndex:i] setState:NSOffState];
- }
- } else {
- [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
- }
-
- if (wasPlayingRadio) {
- NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
- [menu insertItem:temp atIndex:trackInfoIndex + 1];
- [temp release];
- }
-
- [self updateMenu];
- lastSongIndex = trackPlayingIndex;
- } else {
- if (playlist != lastPlaylistIndex) {
- BOOL wasPlayingRadio = isPlayingRadio;
- isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
-
- if (isPlayingRadio && !wasPlayingRadio) {
- int i;
- for (i = 0; i < [playlistMenu numberOfItems]; i++) {
- [[playlistMenu itemAtIndex:i] setState:NSOffState];
- }
- }
-
- if (wasPlayingRadio) {
- NSMenuItem *temp = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
- [menu insertItem:temp atIndex:trackInfoIndex + 1];
- [temp release];
- }
-
- if (!isPlayingRadio) {
- int i;
- for (i = 0; i < [playlistMenu numberOfItems]; i++)
- {
- [[playlistMenu itemAtIndex:i] setState:NSOffState];
- }
- [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState];
- }
-
- [self updateMenu];
- lastSongIndex = trackPlayingIndex;
- lastPlaylistIndex = playlist;
- }
- }
- //Update Play/Pause menu item
- if (playPauseMenuItem){
- if (playerPlayingState == ITMTRemotePlayerPlaying) {
- [playPauseMenuItem setTitle:@"Pause"];
- } else {
- [playPauseMenuItem setTitle:@"Play"];
- }
- }
- } else if ((lastPlaylistIndex > 0) && (playlist == 0)) {
- NSMenuItem *menuItem;
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- //Remote the now playing item and add no song item
- [menu removeItemAtIndex:trackInfoIndex];
-
- if ([defaults boolForKey:@"showName"] == YES) {
- [menu removeItemAtIndex:trackInfoIndex];
- }
-
- if ([defaults boolForKey:@"showTime"] == YES) {
- [menu removeItemAtIndex:trackInfoIndex];
- }
-
- if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) {
- [menu removeItemAtIndex:trackInfoIndex];
- }
-
- if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
- [menu removeItemAtIndex:trackInfoIndex];
- }
-
- [playPauseMenuItem setTitle:@"Play"];
-
- didHaveArtistName = NO;
- didHaveAlbumName = NO;
- lastPlaylistIndex = -1;
- lastSongIndex = -1;
-
- [upcomingSongsItem setSubmenu:nil];
- [upcomingSongsItem setEnabled:NO];
-
- [songRatingMenuItem setSubmenu:nil];
- [songRatingMenuItem setEnabled:NO];
-
- menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
- [menu insertItem:menuItem atIndex:trackInfoIndex];
- [menuItem release];
- }
-}
-
-- (void)remotePlayerLaunched:(NSNotification *)note
-{
- isAppRunning = ITMTRemotePlayerRunning;
-
- //Restart the timer
- [NSThread detachNewThreadSelector:@selector(runTimerInNewThread) toTarget:self withObject:nil];
-
- [self rebuildMenu]; //Rebuild the menu since no songs will be playing
- if (playlistItem) {
- [self rebuildPlaylistMenu];
- }
- if (eqItem) {
- [self rebuildEQPresetsMenu];
- }
- [statusItem setMenu:menu]; //Set the menu back to the main one
-}
-
-- (void)runTimerInNewThread
-{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
- refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES] retain];
- [runLoop run];
- [pool release];
-}
-
-- (void)remotePlayerTerminated:(NSNotification *)note
-{
- isAppRunning = ITMTRemotePlayerNotRunning;
-
- [menu release];
- menu = [[NSMenu alloc] initWithTitle:@""];
- [[menu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""] setTarget:self];
- [menu addItem:[NSMenuItem separatorItem]];
- [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
- [[menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
- [statusItem setMenu:menu];
-
- [refreshTimer invalidate];
- [refreshTimer release];
- refreshTimer = nil;
- [self clearHotKeys];
-}
-
-//