+- (NSMenu *)menuForNoPlayer
+{
+ NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
+ NSMenuItem *tempItem;
+ ITDebugLog(@"Creating menu for when player isn't running.");
+ ITDebugLog(@"Add \"Open %@\" menu item.", [[[MainController sharedController] currentRemote] playerSimpleName]);
+ tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"open", @"Open"), [[[MainController sharedController] currentRemote] playerSimpleName]] action:@selector(performMainMenuAction:) keyEquivalent:@""];
+ [tempItem setTag:MTMenuShowPlayerItem];
+ [tempItem setTarget:self];
+ ITDebugLog(@"Add a separator menu item.");
+ [menu addItem:[NSMenuItem separatorItem]];
+ ITDebugLog(@"Add \"Preferences...\" menu item.");
+ tempItem = [menu addItemWithTitle:NSLocalizedString(@"preferences", @"Preferences...") action:@selector(performMainMenuAction:) keyEquivalent:@""];
+ [tempItem setTag:MTMenuPreferencesItem];
+ [tempItem setTarget:self];
+ if ([[MainController sharedController] blingBling] == NO) {
+ ITDebugLog(@"Add \"Register MenuTunes...\" menu item.");
+ tempItem = [menu addItemWithTitle:NSLocalizedString(@"register", @"Register MenuTunes...") action:@selector(performMainMenuAction:) keyEquivalent:@""];
+ [tempItem setTag:MTMenuRegisterItem];
+ [tempItem setTarget:self];
+ }
+ ITDebugLog(@"Add \"Quit\" menu item.");
+ tempItem = [menu addItemWithTitle:NSLocalizedString(@"quit", @"Quit") action:@selector(performMainMenuAction:) keyEquivalent:@""];
+ [tempItem setTag:MTMenuQuitItem];
+ [tempItem setTarget:self];
+ return [menu autorelease];
+}
+
+- (void)rebuildSubmenus
+{
+ ITDebugLog(@"Rebuilding all of the submenus.");
+
+ currentRemote = [[MainController sharedController] currentRemote];
+ _currentPlaylist = [currentRemote currentPlaylistIndex];
+ _currentTrack = [currentRemote currentSongIndex];
+ _playingRadio = ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist);
+
+ [_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 = [currentRemote numberOfSongsInPlaylistAtIndex:_currentPlaylist];
+ int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
+
+ 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 = [currentRemote songTitleAtIndex:i];
+ NSMenuItem *songItem;
+ ITDebugLog(@"Adding song: %@", curSong);
+ songItem = [upcomingSongsMenu addItemWithTitle:curSong action:@selector(performUpcomingSongsMenuAction:) keyEquivalent:@""];
+ [songItem setTag:i];
+ [songItem setTarget:self];
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ ITDebugLog(@"Done Building \"Upcoming Songs\" menu.");
+ return upcomingSongsMenu;
+}
+
+- (NSMenu *)playlistsMenu
+{
+ NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""];
+ NSArray *playlists = [currentRemote playlists];
+ NSMenuItem *tempItem;
+ int i;
+
+ 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 (!_playingRadio && _currentPlaylist) {
+ [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
+ }
+ ITDebugLog(@"Done Building \"Playlists\" menu");
+ return playlistsMenu;
+}
+
+- (NSMenu *)eqMenu
+{
+ NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""];
+ NSArray *eqPresets = [currentRemote eqPresets];
+ NSMenuItem *tempItem;
+ int i;
+
+ 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;
+}
+