X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/d8c90094f595a5f513d844ea316e2fb8b1e479b7..97a75b2b15c91605969af322f4ed92559e7192d3:/MenuController.m diff --git a/MenuController.m b/MenuController.m index f1e96fb..0bc8c2d 100755 --- a/MenuController.m +++ b/MenuController.m @@ -47,13 +47,14 @@ NSEnumerator *itemEnum; ITHotKey *hotKey; NSArray *hotKeys = [[ITHotKeyCenter sharedCenter] allHotKeys]; - int currentSongRating; + ITMTRemote *mtr = [[MainController sharedController] currentRemote]; + int currentSongRating = 0; //Get the information NS_DURING - _currentPlaylist = [[[MainController sharedController] currentRemote] currentPlaylistIndex]; - _playingRadio = ([[[MainController sharedController] currentRemote] currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist); - currentSongRating = ( [[[MainController sharedController] currentRemote] currentSongRating] != -1 ); + _currentPlaylist = [mtr currentPlaylistIndex]; + _playingRadio = ([mtr currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist); + currentSongRating = ( [mtr currentSongRating] != -1 ); NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -106,7 +107,7 @@ ITDebugLog(@"Set \"Play\"/\"Pause\" menu item's title to correct state."); NS_DURING - switch ([[[MainController sharedController] currentRemote] playerPlayingState]) { + switch ([mtr playerPlayingState]) { case ITMTRemotePlayerPlaying: [tempItem setTitle:NSLocalizedString(@"pause", @"Pause")]; break; @@ -183,7 +184,7 @@ NS_DURING tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), - [[[MainController sharedController] currentRemote] playerSimpleName]] + [mtr playerSimpleName]] action:@selector(performMainMenuAction:) keyEquivalent:@""]; NS_HANDLER @@ -226,9 +227,9 @@ ITDebugLog(@"Check to see if a Track is playing..."); //Handle playing radio too if (_currentPlaylist) { - NSString *title; + NSString *title = nil; NS_DURING - title = [[[MainController sharedController] currentRemote] currentSongTitle]; + title = [mtr currentSongTitle]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -244,9 +245,9 @@ if (!_playingRadio) { if ([defaults boolForKey:@"showAlbum"]) { - NSString *curAlbum; + NSString *curAlbum = nil; NS_DURING - curAlbum = [[[MainController sharedController] currentRemote] currentSongAlbum]; + curAlbum = [mtr currentSongAlbum]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -258,9 +259,9 @@ } if ([defaults boolForKey:@"showArtist"]) { - NSString *curArtist; + NSString *curArtist = nil; NS_DURING - curArtist = [[[MainController sharedController] currentRemote] currentSongArtist]; + curArtist = [mtr currentSongArtist]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -272,9 +273,9 @@ } if ([defaults boolForKey:@"showComposer"]) { - NSString *curComposer; + NSString *curComposer = nil; NS_DURING - curComposer = [[[MainController sharedController] currentRemote] currentSongComposer]; + curComposer = [mtr currentSongComposer]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -286,9 +287,9 @@ } if ([defaults boolForKey:@"showTrackNumber"]) { - int track; + int track = 0; NS_DURING - track = [[[MainController sharedController] currentRemote] currentSongTrack]; + track = [mtr currentSongTrack]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -301,9 +302,9 @@ } NS_DURING - if ([defaults boolForKey:@"showTime"] && ( ([[[MainController sharedController] currentRemote] currentSongElapsed] != nil) || ([[[MainController sharedController] currentRemote] currentSongLength] != nil) )) { - ITDebugLog(@"Add Track Elapsed (\"%@/%@\") menu item.", [[[MainController sharedController] currentRemote] currentSongElapsed], [[[MainController sharedController] currentRemote] currentSongLength]); - [menu indentItem:[menu addItemWithTitle:[NSString stringWithFormat:@"%@/%@", [[[MainController sharedController] currentRemote] currentSongElapsed], [[[MainController sharedController] currentRemote] currentSongLength]] action:nil keyEquivalent:@""]]; + if ([defaults boolForKey:@"showTime"] && ( ([mtr currentSongElapsed] != nil) || ([mtr currentSongLength] != nil) )) { + ITDebugLog(@"Add Track Elapsed (\"%@/%@\") menu item.", [mtr currentSongElapsed], [mtr currentSongLength]); + [menu indentItem:[menu addItemWithTitle:[NSString stringWithFormat:@"%@/%@", [mtr currentSongElapsed], [mtr currentSongLength]] action:nil keyEquivalent:@""]]; } NS_HANDLER [[MainController sharedController] networkError:localException]; @@ -311,9 +312,12 @@ if (!_playingRadio) { NS_DURING - if ([defaults boolForKey:@"showTrackRating"] && ( [[[MainController sharedController] currentRemote] currentSongRating] != -1.0 )) { + if ([defaults boolForKey:@"showPlayCount"] && [mtr currentSource] == ITMTRemoteLibrarySource) { + [menu indentItem:[menu addItemWithTitle:[NSString stringWithFormat:@"Play Count: %i", [mtr currentSongPlayCount]] action:nil keyEquivalent:@""]]; + } + if ([defaults boolForKey:@"showTrackRating"] && ( [mtr currentSongRating] != -1.0 )) { NSString *string = nil; - switch ((int)([[[MainController sharedController] currentRemote] currentSongRating] * 5)) { + switch ((int)([mtr currentSongRating] * 5)) { case 0: string = [NSString stringWithUTF8String:"☆☆☆☆☆"]; break; @@ -340,8 +344,8 @@ [[MainController sharedController] networkError:localException]; NS_ENDHANDLER - if ([tempItem respondsToSelector:@selector(setAttributedTitle:)] && [defaults boolForKey:@"showAlbumArtwork"] && ![[NetworkController sharedController] isConnectedToServer]) { - NSImage *image = [[[MainController sharedController] currentRemote] currentSongAlbumArt]; + /*if ([tempItem respondsToSelector:@selector(setAttributedTitle:)] && [defaults boolForKey:@"showAlbumArtwork"] && ![[NetworkController sharedController] isConnectedToServer]) { + NSImage *image = [mtr currentSongAlbumArt]; if (image) { NSSize oldSize, newSize; oldSize = [image size]; @@ -355,7 +359,7 @@ NSAttributedString *attrString = [NSAttributedString attributedStringWithAttachment:attachment]; [tempItem setAttributedTitle:attrString]; } - } + }*/ } } else { ITDebugLog(@"No Track is Playing, Add \"No Song\" menu item."); @@ -385,7 +389,9 @@ [tempItem setState:NSOffState]; } NS_DURING - [[_eqMenu itemAtIndex:([[[MainController sharedController] currentRemote] currentEQPresetIndex] - 1)] setState:NSOnState]; + [[_eqMenu itemAtIndex:0] setState:[mtr equalizerEnabled] ? NSOnState : NSOffState]; + [[_eqMenu itemAtIndex:([mtr currentEQPresetIndex] + 1)] setState:NSOnState]; + [[_eqMenu itemAtIndex:([mtr currentEQPresetIndex] - 1)] setState:NSOnState]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -406,7 +412,7 @@ } NS_DURING - [[_ratingMenu itemAtIndex:([[[MainController sharedController] currentRemote] currentSongRating] * 5)] setState:NSOnState]; + [[_ratingMenu itemAtIndex:([mtr currentSongRating] * 5)] setState:NSOnState]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -431,7 +437,7 @@ - (NSMenu *)menuForNoPlayer { NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; - id tempItem; + id tempItem = nil; ITDebugLog(@"Creating menu for when player isn't running."); NS_DURING ITDebugLog(@"Add \"Open %@\" menu item.", [[[MainController sharedController] currentRemote] playerSimpleName]); @@ -471,9 +477,13 @@ [[MainController sharedController] networkError:localException]; NS_ENDHANDLER ITDebugLog(@"Releasing old submenus."); + ITDebugLog(@" - Rating menu"); [_ratingMenu release]; + ITDebugLog(@" - Upcoming songs menu"); [_upcomingSongsMenu release]; + ITDebugLog(@" - Playlists menu"); [_playlistsMenu release]; + ITDebugLog(@" - EQ menu"); [_eqMenu release]; ITDebugLog(@"Beginning Rebuild of \"Song Rating\" submenu."); _ratingMenu = [self ratingMenu]; @@ -518,7 +528,7 @@ - (NSMenu *)upcomingSongsMenu { NSMenu *upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""]; - int numSongs, numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"]; + int numSongs = 0, numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"]; NS_DURING numSongs = [[[MainController sharedController] currentRemote] numberOfSongsInPlaylistAtIndex:_currentPlaylist]; @@ -532,7 +542,7 @@ int i; for (i = _currentTrack + 1; i <= _currentTrack + numSongsInAdvance; i++) { if (i <= numSongs) { - NSString *curSong; + NSString *curSong = nil; NS_DURING curSong = [[[MainController sharedController] currentRemote] songTitleAtIndex:i]; NS_HANDLER @@ -601,7 +611,7 @@ - (NSMenu *)playlistsMenu { NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""]; - NSArray *playlists; + NSArray *playlists = nil; id tempItem; ITMTRemotePlayerSource source = [[[MainController sharedController] currentRemote] currentSource]; int i, j; @@ -671,6 +681,9 @@ [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState]; } [indices release]; + tempItem = [playlistsMenu addItemWithTitle:NSLocalizedString(@"refresh", @"Refresh") action:@selector(rebuildSubmenus) keyEquivalent:@""]; + [tempItem setTarget:self]; + [tempItem setImage:[NSImage imageNamed:@"ChasingArrow"]]; ITDebugLog(@"Done Building \"Playlists\" menu"); return playlistsMenu; } @@ -678,7 +691,7 @@ - (NSMenu *)eqMenu { NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""]; - NSArray *eqPresets; + NSArray *eqPresets = nil; id tempItem; int i; @@ -690,6 +703,16 @@ ITDebugLog(@"Building \"EQ Presets\" menu."); + tempItem = [eqMenu addItemWithTitle:@"Enabled" action:@selector(performEqualizerMenuAction:) keyEquivalent:@""]; + [tempItem setTag:-1]; + [tempItem setTarget:self]; + NS_DURING + [tempItem setState:[[[MainController sharedController] currentRemote] equalizerEnabled] ? NSOnState : NSOffState]; + NS_HANDLER + [[MainController sharedController] networkError:localException]; + NS_ENDHANDLER + [eqMenu addItem:[NSMenuItem separatorItem]]; + for (i = 0; i < [eqPresets count]; i++) { NSString *name; if ( ( name = [eqPresets objectAtIndex:i] ) ) {