X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/57cbba98e6ff809563b1dff6fd55603761ec995b..a5c365dd668dee7c653dbafee270e5e05025a2ab:/MenuController.m?ds=inline diff --git a/MenuController.m b/MenuController.m index 54f9809..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 @@ -396,38 +402,50 @@ [[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; @@ -468,6 +486,7 @@ - (void)rebuildSubmenus { + NSArray *menu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"]; ITDebugLog(@"Rebuilding all of the submenus."); NS_DURING _currentPlaylist = [[[MainController sharedController] currentRemote] currentPlaylistIndex]; @@ -485,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."); @@ -493,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."); } @@ -681,8 +708,9 @@ [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState]; } [indices release]; - [playlistsMenu addItem:[NSMenuItem separatorItem]]; - [[playlistsMenu addItemWithTitle:NSLocalizedString(@"refresh", @"Refresh") action:@selector(rebuildSubmenus) keyEquivalent:@""] setTarget:self]; + 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; } @@ -727,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] ) @@ -797,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");