X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/bc4fa9cf6435c18c42de06c478480c6f6673ca4b..a5c365dd668dee7c653dbafee270e5e05025a2ab:/MenuController.m?ds=inline diff --git a/MenuController.m b/MenuController.m index 0190406..88a94ba 100755 --- a/MenuController.m +++ b/MenuController.m @@ -21,6 +21,7 @@ - (NSMenu *)upcomingSongsMenu; - (NSMenu *)playlistsMenu; - (NSMenu *)eqMenu; +- (NSMenu *)artistsMenu; - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers onItem:(id )item; - (BOOL)iPodWithNameAutomaticallyUpdates:(NSString *)name; @@ -82,6 +83,11 @@ [tempItem setSubmenu:nil]; } + if ( (tempItem = [_currentMenu itemWithTag:5]) ) { + ITDebugLog(@"Removing \"Artists\" submenu."); + [tempItem setSubmenu:nil]; + } + ITDebugLog(@"Begin building menu."); //create our menu @@ -312,6 +318,9 @@ if (!_playingRadio) { NS_DURING + 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)([mtr currentSongRating] * 5)) { @@ -386,43 +395,57 @@ [tempItem setState:NSOffState]; } NS_DURING + [[_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 } else if ([nextObject isEqualToString:@"songRating"] && currentSongRating) { - ITDebugLog(@"Add \"Song Rating\" submenu."); - tempItem = [menu addItemWithTitle:NSLocalizedString(@"songRating", @"Song Rating") - action:nil - keyEquivalent:@""]; - [tempItem setSubmenu:_ratingMenu]; - [tempItem setTag:1]; - if (_playingRadio || !_currentPlaylist) { - [tempItem setEnabled:NO]; - } - - itemEnum = [[_ratingMenu itemArray] objectEnumerator]; - while ( (tempItem = [itemEnum nextObject]) ) { - [tempItem setState:NSOffState]; - } - - NS_DURING - [[_ratingMenu itemAtIndex:([mtr currentSongRating] * 5)] setState:NSOnState]; - NS_HANDLER - [[MainController sharedController] networkError:localException]; - NS_ENDHANDLER - } else if ([nextObject isEqualToString:@"upcomingSongs"]) { - ITDebugLog(@"Add \"Upcoming Songs\" submenu."); - tempItem = [menu addItemWithTitle:NSLocalizedString(@"upcomingSongs", @"Upcoming Songs") - action:nil - keyEquivalent:@""]; - [tempItem setSubmenu:_upcomingSongsMenu]; - [tempItem setTag:2]; - if (_playingRadio || !_currentPlaylist) { - [tempItem setEnabled:NO]; - } + ITDebugLog(@"Add \"Song Rating\" submenu."); + tempItem = [menu addItemWithTitle:NSLocalizedString(@"songRating", @"Song Rating") + action:nil + keyEquivalent:@""]; + [tempItem setSubmenu:_ratingMenu]; + [tempItem setTag:1]; + if (_playingRadio || !_currentPlaylist) { + [tempItem setEnabled:NO]; + } + + itemEnum = [[_ratingMenu itemArray] objectEnumerator]; + while ( (tempItem = [itemEnum nextObject]) ) { + [tempItem setState:NSOffState]; + } + + NS_DURING + [[_ratingMenu itemAtIndex:([mtr currentSongRating] * 5)] setState:NSOnState]; + NS_HANDLER + [[MainController sharedController] networkError:localException]; + NS_ENDHANDLER + } else if ([nextObject isEqualToString:@"upcomingSongs"]) { + ITDebugLog(@"Add \"Upcoming Songs\" submenu."); + tempItem = [menu addItemWithTitle:NSLocalizedString(@"upcomingSongs", @"Upcoming Songs") + action:nil + keyEquivalent:@""]; + [tempItem setSubmenu:_upcomingSongsMenu]; + [tempItem setTag:2]; + if (_playingRadio || !_currentPlaylist) { + [tempItem setEnabled:NO]; + } + } else if ([nextObject isEqualToString:@"artists"]) { + ITDebugLog(@"Add \"Artists\" submenu."); + tempItem = [menu addItemWithTitle:NSLocalizedString(@"artists", @"Artists") + action:nil + keyEquivalent:@""]; + [tempItem setSubmenu:_artistsMenu]; + [tempItem setTag:5]; + + itemEnum = [[_eqMenu itemArray] objectEnumerator]; + while ( (tempItem = [itemEnum nextObject]) ) { + [tempItem setState:NSOffState]; } } + } ITDebugLog(@"Finished building menu."); [_currentMenu release]; _currentMenu = menu; @@ -463,6 +486,7 @@ - (void)rebuildSubmenus { + NSArray *menu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"]; ITDebugLog(@"Rebuilding all of the submenus."); NS_DURING _currentPlaylist = [[[MainController sharedController] currentRemote] currentPlaylistIndex]; @@ -480,6 +504,7 @@ [_playlistsMenu release]; ITDebugLog(@" - EQ menu"); [_eqMenu release]; + ITDebugLog(@"Beginning Rebuild of \"Song Rating\" submenu."); _ratingMenu = [self ratingMenu]; ITDebugLog(@"Beginning Rebuild of \"Upcoming Songs\" submenu."); @@ -488,6 +513,13 @@ _playlistsMenu = [self playlistsMenu]; ITDebugLog(@"Beginning Rebuild of \"EQ Presets\" submenu."); _eqMenu = [self eqMenu]; + + if ([menu containsObject:@"artists"]) { + ITDebugLog(@"Releasing artists menu"); + [_artistsMenu release]; + ITDebugLog(@"Beginning Rebuild of \"Artists\" submenu."); + _artistsMenu = [self artistsMenu]; + } ITDebugLog(@"Done rebuilding all of the submenus."); } @@ -676,6 +708,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; } @@ -695,6 +730,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] ) ) { @@ -710,6 +755,27 @@ return eqMenu; } +- (NSMenu *)artistsMenu +{ + NSMenu *artistsMenu = [[NSMenu alloc] initWithTitle:@""]; + NSEnumerator *artistsEnumerator; + NSString *nextArtist; + id tempItem; + ITDebugLog(@"Building \"Artists\" menu."); + NS_DURING + artistsEnumerator = [[[[MainController sharedController] currentRemote] artists] objectEnumerator]; + while ( (nextArtist = [artistsEnumerator nextObject]) ) { + tempItem = [artistsMenu addItemWithTitle:nextArtist action:@selector(performArtistsMenuAction:) keyEquivalent:@""]; + [tempItem setRepresentedObject:nextArtist]; + [tempItem setTarget:self]; + } + NS_HANDLER + [[MainController sharedController] networkError:localException]; + NS_ENDHANDLER + ITDebugLog(@"Done Building \"Artists\" menu"); + return artistsMenu; +} + - (void)performMainMenuAction:(id)sender { switch ( [sender tag] ) @@ -780,6 +846,17 @@ [[MainController sharedController] selectSongAtIndex:[sender tag]]; } +- (void)performArtistsMenuAction:(id)sender +{ + ITDebugLog(@"Artist action selected on item with object %i", [sender representedObject]); + /* + ** 1 - Artist + ** 2 - Album + ** 3 - Genre? + */ + [[MainController sharedController] makePlaylistWithTerm:[sender representedObject] ofType:1]; +} + - (void)updateMenu { ITDebugLog(@"Update Menu");