+- (void)rebuildSubmenus
+{
+ ITDebugLog(@"Rebuilding all of the submenus.");
+ NS_DURING
+ _currentPlaylist = [[[MainController sharedController] currentRemote] currentPlaylistIndex];
+ _currentTrack = [[[MainController sharedController] currentRemote] currentSongIndex];
+ _playingRadio = ([[[MainController sharedController] currentRemote] currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist);
+ NS_HANDLER
+ [[MainController sharedController] networkError:localException];
+ NS_ENDHANDLER
+ ITDebugLog(@"Releasing old submenus.");
+ [_ratingMenu release];
+ [_upcomingSongsMenu release];
+ [_playlistsMenu release];
+ [_eqMenu release];
+ ITDebugLog(@"Beginning Rebuild of \"Song Rating\" submenu.");
+ _ratingMenu = [self ratingMenu];
+ ITDebugLog(@"Beginning Rebuild of \"Upcoming Songs\" submenu.");
+ _upcomingSongsMenu = [self upcomingSongsMenu];
+ ITDebugLog(@"Beginning Rebuild of \"Playlists\" submenu.");
+ _playlistsMenu = [self playlistsMenu];
+ ITDebugLog(@"Beginning Rebuild of \"EQ Presets\" submenu.");
+ _eqMenu = [self eqMenu];
+ ITDebugLog(@"Done rebuilding all of the submenus.");
+}
+
+- (NSMenu *)ratingMenu
+{
+ NSMenu *ratingMenu = [[NSMenu alloc] initWithTitle:@""];
+ NSEnumerator *itemEnum;
+ id anItem;
+ int itemTag = 0;
+ SEL itemSelector = @selector(performRatingMenuAction:);
+
+ ITDebugLog(@"Building \"Song Rating\" menu.");
+
+ [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"☆☆☆☆☆"] action:nil keyEquivalent:@""];
+ [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★☆☆☆☆"] action:nil keyEquivalent:@""];
+ [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★☆☆☆"] action:nil keyEquivalent:@""];
+ [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★☆☆"] action:nil keyEquivalent:@""];
+ [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★☆"] action:nil keyEquivalent:@""];
+ [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★★"] action:nil keyEquivalent:@""];
+
+ itemEnum = [[ratingMenu itemArray] objectEnumerator];
+ while ( (anItem = [itemEnum nextObject]) ) {
+ ITDebugLog(@"Setting up \"%@\" menu item.", [anItem title]);
+ [anItem setAction:itemSelector];
+ [anItem setTarget:self];
+ [anItem setTag:itemTag];
+ itemTag += 20;
+ }
+ ITDebugLog(@"Done Building \"Song Rating\" menu.");
+ return ratingMenu;
+}
+
+- (NSMenu *)upcomingSongsMenu
+{
+ NSMenu *upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
+ int numSongs, numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
+
+ NS_DURING
+ numSongs = [[[MainController sharedController] currentRemote] numberOfSongsInPlaylistAtIndex:_currentPlaylist];
+ NS_HANDLER
+ [[MainController sharedController] networkError:localException];
+ NS_ENDHANDLER
+
+ ITDebugLog(@"Building \"Upcoming Songs\" menu.");
+ if (_currentPlaylist && !_playingRadio) {
+ if (numSongs > 0) {
+ int i;
+ for (i = _currentTrack + 1; i <= _currentTrack + numSongsInAdvance; i++) {
+ if (i <= numSongs) {
+ NSString *curSong;
+ NS_DURING
+ curSong = [[[MainController sharedController] currentRemote] songTitleAtIndex:i];
+ NS_HANDLER
+ [[MainController sharedController] networkError:localException];
+ NS_ENDHANDLER
+ id <NSMenuItem> songItem;
+ ITDebugLog(@"Adding song: %@", curSong);
+ songItem = [upcomingSongsMenu addItemWithTitle:curSong action:@selector(performUpcomingSongsMenuAction:) keyEquivalent:@""];
+ [songItem setTag:i];
+ [songItem setTarget:self];
+ } else {
+ break;
+ }
+ }
+ }
+
+ if ([upcomingSongsMenu numberOfItems] == 0) {
+ [upcomingSongsMenu addItemWithTitle:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.") action:NULL keyEquivalent:@""];
+ }
+ }
+ ITDebugLog(@"Done Building \"Upcoming Songs\" menu.");
+ return upcomingSongsMenu;
+}
+
+/*- (NSMenu *)playlistsMenu
+{
+ NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""];
+ NSArray *playlists;
+ id <NSMenuItem> tempItem;
+ ITMTRemotePlayerSource source = [[[MainController sharedController] currentRemote] currentSource];
+ int i;
+ NS_DURING
+ playlists = [[[MainController sharedController] currentRemote] playlists];
+ NS_HANDLER
+ [[MainController sharedController] networkError:localException];
+ NS_ENDHANDLER
+
+ ITDebugLog(@"Building \"Playlists\" menu.");
+
+ for (i = 0; i < [playlists count]; i++) {
+ NSString *curPlaylist = [playlists objectAtIndex:i];
+ ITDebugLog(@"Adding playlist: %@", curPlaylist);
+ tempItem = [playlistsMenu addItemWithTitle:curPlaylist action:@selector(performPlaylistMenuAction:) keyEquivalent:@""];
+ [tempItem setTag:i + 1];
+ [tempItem setTarget:self];
+ }
+
+ if (source == ITMTRemoteRadioSource) {
+ [[playlistsMenu addItemWithTitle:NSLocalizedString(@"radio", @"Radio") action:NULL keyEquivalent:@""] setState:NSOnState];
+ } else if (source == ITMTRemoteGenericDeviceSource) {
+ [[playlistsMenu addItemWithTitle:NSLocalizedString(@"genericDevice", @"Generic Device") action:NULL keyEquivalent:@""] setState:NSOnState];
+ } else if (source == ITMTRemoteiPodSource) {
+ [[playlistsMenu addItemWithTitle:NSLocalizedString(@"iPod", @"iPod") action:NULL keyEquivalent:@""] setState:NSOnState];
+ } else if (source == ITMTRemoteCDSource) {
+ [[playlistsMenu addItemWithTitle:NSLocalizedString(@"cd", @"CD") action:NULL keyEquivalent:@""] setState:NSOnState];
+ } else if (source == ITMTRemoteSharedLibrarySource) {
+ [[playlistsMenu addItemWithTitle:NSLocalizedString(@"sharedLibrary", @"Shared Library") action:NULL keyEquivalent:@""] setState:NSOnState];
+ } else if (source == ITMTRemoteLibrarySource && _currentPlaylist) {
+ [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
+ }
+ ITDebugLog(@"Done Building \"Playlists\" menu");
+ return playlistsMenu;
+}*/
+
+
+- (NSMenu *)playlistsMenu
+{
+ NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""];
+ NSArray *playlists;
+ id <NSMenuItem> tempItem;
+ ITMTRemotePlayerSource source = [[[MainController sharedController] currentRemote] currentSource];
+ int i, j;
+ NSMutableArray *indices = [[NSMutableArray alloc] init];
+ NS_DURING
+ playlists = [[[MainController sharedController] currentRemote] playlists];
+ NS_HANDLER
+ [[MainController sharedController] networkError:localException];
+ NS_ENDHANDLER
+ ITDebugLog(@"Building \"Playlists\" menu.");
+ {
+ NSArray *curPlaylist = [playlists objectAtIndex:0];
+ NSString *name = [curPlaylist objectAtIndex:0];
+ ITDebugLog(@"Adding main source: %@", name);
+ for (i = 3; i < [curPlaylist count]; i++) {
+ ITDebugLog(@"Adding playlist: %@", [curPlaylist objectAtIndex:i]);
+ tempItem = [playlistsMenu addItemWithTitle:[curPlaylist objectAtIndex:i] action:@selector(performPlaylistMenuAction:) keyEquivalent:@""];
+ [tempItem setTag:i - 1];
+ [tempItem setTarget:self];
+ }
+ ITDebugLog(@"Adding index to the index array.");
+ [indices addObject:[curPlaylist objectAtIndex:2]];
+ }
+ if ([playlists count] > 1) {
+ if ([[[playlists objectAtIndex:1] objectAtIndex:1] intValue] == ITMTRemoteRadioSource) {
+ [indices addObject:[[playlists objectAtIndex:1] objectAtIndex:2]];
+ if (source == ITMTRemoteRadioSource) {
+ [playlistsMenu addItem:[NSMenuItem separatorItem]];
+ [[playlistsMenu addItemWithTitle:NSLocalizedString(@"radio", @"Radio") action:@selector(performPlaylistMenuAction:) keyEquivalent:@""] setState:NSOnState];
+ }
+ } else {
+ [playlistsMenu addItem:[NSMenuItem separatorItem]];
+ }
+ }
+
+ if ([playlists count] > 1) {
+ for (i = 1; i < [playlists count]; i++) {
+ NSArray *curPlaylist = [playlists objectAtIndex:i];
+ if ([[curPlaylist objectAtIndex:1] intValue] != ITMTRemoteRadioSource) {
+ NSString *name = [curPlaylist objectAtIndex:0];
+ NSMenu *submenu = [[NSMenu alloc] init];
+ ITDebugLog(@"Adding source: %@", name);
+
+ if ( ([[curPlaylist objectAtIndex:1] intValue] == ITMTRemoteiPodSource) && [self iPodWithNameAutomaticallyUpdates:name] ) {
+ ITDebugLog(@"Invalid iPod source.");
+ [playlistsMenu addItemWithTitle:name action:NULL keyEquivalent:@""];
+ } else {
+ for (j = 3; j < [curPlaylist count]; j++) {
+ ITDebugLog(@"Adding playlist: %@", [curPlaylist objectAtIndex:j]);
+ tempItem = [submenu addItemWithTitle:[curPlaylist objectAtIndex:j] action:@selector(performPlaylistMenuAction:) keyEquivalent:@""];
+ [tempItem setTag:(i * 1000) + j - 1];
+ [tempItem setTarget:self];
+ }
+ [[playlistsMenu addItemWithTitle:name action:NULL keyEquivalent:@""] setSubmenu:[submenu autorelease]];
+ }
+ ITDebugLog(@"Adding index to the index array.");
+ [indices addObject:[curPlaylist objectAtIndex:2]];
+ }
+ }
+ }
+ ITDebugLog(@"Checking the current source.");
+ if ( (source == ITMTRemoteSharedLibrarySource) || (source == ITMTRemoteiPodSource) || (source == ITMTRemoteGenericDeviceSource) || (source == ITMTRemoteCDSource) ) {
+ tempItem = [playlistsMenu itemAtIndex:[playlistsMenu numberOfItems] + [indices indexOfObject:[NSNumber numberWithInt:[[[MainController sharedController] currentRemote] currentSourceIndex]]] - [indices count]];
+ [tempItem setState:NSOnState];
+ [[[tempItem submenu] itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
+ } else if (source == ITMTRemoteLibrarySource && _currentPlaylist) {
+ [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
+ }
+ [indices release];
+ ITDebugLog(@"Done Building \"Playlists\" menu");
+ return playlistsMenu;
+}
+
+- (NSMenu *)eqMenu
+{
+ NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""];
+ NSArray *eqPresets;
+ id <NSMenuItem> tempItem;
+ int i;
+
+ NS_DURING
+ eqPresets = [[[MainController sharedController] currentRemote] eqPresets];
+ NS_HANDLER
+ [[MainController sharedController] networkError:localException];
+ NS_ENDHANDLER
+
+ ITDebugLog(@"Building \"EQ Presets\" menu.");
+
+ for (i = 0; i < [eqPresets count]; i++) {
+ NSString *name;
+ if ( ( name = [eqPresets objectAtIndex:i] ) ) {
+ ITDebugLog(@"Adding EQ Preset: %@", name);
+ tempItem = [eqMenu addItemWithTitle:name
+ action:@selector(performEqualizerMenuAction:)
+ keyEquivalent:@""];
+ [tempItem setTag:i];
+ [tempItem setTarget:self];
+ }
+ }
+ ITDebugLog(@"Done Building \"EQ Presets\" menu");
+ return eqMenu;
+}
+