Should disable the status item when iTunes is locked.
[MenuTunes.git] / MenuController.m
index c207e66..7cc59fb 100755 (executable)
@@ -22,6 +22,7 @@
 - (NSMenu *)playlistsMenu;
 - (NSMenu *)eqMenu;
 - (NSMenu *)artistsMenu;
 - (NSMenu *)playlistsMenu;
 - (NSMenu *)eqMenu;
 - (NSMenu *)artistsMenu;
+- (NSMenu *)albumsMenu;
 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
         onItem:(id <NSMenuItem>)item;
 - (BOOL)iPodWithNameAutomaticallyUpdates:(NSString *)name;
 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
         onItem:(id <NSMenuItem>)item;
 - (BOOL)iPodWithNameAutomaticallyUpdates:(NSString *)name;
         [tempItem setSubmenu:nil];
     }
     
         [tempItem setSubmenu:nil];
     }
     
+    if ( (tempItem = [_currentMenu itemWithTag:6]) ) {
+        ITDebugLog(@"Removing \"Albums\" submenu.");
+        [tempItem setSubmenu:nil];
+    }
+    
     ITDebugLog(@"Begin building menu.");
     
     //create our menu
     ITDebugLog(@"Begin building menu.");
     
     //create our menu
             NS_DURING
                 [[_eqMenu itemAtIndex:0] setState:[mtr equalizerEnabled] ? NSOnState : NSOffState];
                 [[_eqMenu itemAtIndex:([mtr currentEQPresetIndex] + 1)] setState:NSOnState];
             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
             NS_HANDLER
                 [[MainController sharedController] networkError:localException];
             NS_ENDHANDLER
                     keyEquivalent:@""];
             [tempItem setSubmenu:_artistsMenu];
             [tempItem setTag:5];
                     keyEquivalent:@""];
             [tempItem setSubmenu:_artistsMenu];
             [tempItem setTag:5];
-            
-            itemEnum = [[_eqMenu itemArray] objectEnumerator];
-            while ( (tempItem = [itemEnum nextObject]) ) {
-                [tempItem setState:NSOffState];
-            }
+        } else if ([nextObject isEqualToString:@"albums"]) {
+            ITDebugLog(@"Add \"Albums\" submenu.");
+            tempItem = [menu addItemWithTitle:NSLocalizedString(@"albums", @"Albums")
+                    action:nil
+                    keyEquivalent:@""];
+            [tempItem setSubmenu:_albumsMenu];
+            [tempItem setTag:6];
         }
     }
     ITDebugLog(@"Finished building menu.");
         }
     }
     ITDebugLog(@"Finished building menu.");
         ITDebugLog(@"Beginning Rebuild of \"Artists\" submenu.");
         _artistsMenu = [self artistsMenu];
     }
         ITDebugLog(@"Beginning Rebuild of \"Artists\" submenu.");
         _artistsMenu = [self artistsMenu];
     }
+    
+    if ([menu containsObject:@"albums"]) {
+        ITDebugLog(@"Releasing albums menu");
+        [_albumsMenu release];
+        ITDebugLog(@"Beginning Rebuild of \"Albums\" submenu.");
+        _albumsMenu = [self albumsMenu];
+    }
     ITDebugLog(@"Done rebuilding all of the submenus.");
 }
 
     ITDebugLog(@"Done rebuilding all of the submenus.");
 }
 
     tempItem = [eqMenu addItemWithTitle:@"Enabled" action:@selector(performEqualizerMenuAction:) keyEquivalent:@""];
     [tempItem setTag:-1];
     [tempItem setTarget:self];
     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++) {
     [eqMenu addItem:[NSMenuItem separatorItem]];
     
     for (i = 0; i < [eqPresets count]; i++) {
 
 - (NSMenu *)artistsMenu
 {
 
 - (NSMenu *)artistsMenu
 {
-    NSMenu *artistsMenu = [[NSMenu alloc] initWithTitle:@""];
+    NSMenu *artistsMenu = [[NSMenu alloc] initWithTitle:@"Artists"];
     NSEnumerator *artistsEnumerator;
     NSString *nextArtist;
     id <NSMenuItem> tempItem;
     NSEnumerator *artistsEnumerator;
     NSString *nextArtist;
     id <NSMenuItem> tempItem;
     NS_DURING
         artistsEnumerator = [[[[MainController sharedController] currentRemote] artists] objectEnumerator];
         while ( (nextArtist = [artistsEnumerator nextObject]) ) {
     NS_DURING
         artistsEnumerator = [[[[MainController sharedController] currentRemote] artists] objectEnumerator];
         while ( (nextArtist = [artistsEnumerator nextObject]) ) {
-            tempItem = [artistsMenu addItemWithTitle:nextArtist action:@selector(performArtistsMenuAction:) keyEquivalent:@""];
-            [tempItem setRepresentedObject:nextArtist];
+            tempItem = [artistsMenu addItemWithTitle:nextArtist action:@selector(performBrowseMenuAction:) keyEquivalent:@""];
             [tempItem setTarget:self];
         }
     NS_HANDLER
             [tempItem setTarget:self];
         }
     NS_HANDLER
     return artistsMenu;
 }
 
     return artistsMenu;
 }
 
+- (NSMenu *)albumsMenu
+{
+    NSMenu *albumsMenu = [[NSMenu alloc] initWithTitle:@"Albums"];
+    NSEnumerator *albumsEnumerator;
+    NSString *nextAlbum;
+    id <NSMenuItem> tempItem;
+    ITDebugLog(@"Building \"Albums\" menu.");
+    NS_DURING
+        albumsEnumerator = [[[[MainController sharedController] currentRemote] albums] objectEnumerator];
+        while ( (nextAlbum = [albumsEnumerator nextObject]) ) {
+            tempItem = [albumsMenu addItemWithTitle:nextAlbum action:@selector(performBrowseMenuAction:) keyEquivalent:@""];
+            [tempItem setTarget:self];
+        }
+    NS_HANDLER
+        [[MainController sharedController] networkError:localException];
+    NS_ENDHANDLER
+    ITDebugLog(@"Done Building \"Albums\" menu");
+    return albumsMenu;
+}
+
 - (void)performMainMenuAction:(id)sender
 {
     switch ( [sender tag] )
 - (void)performMainMenuAction:(id)sender
 {
     switch ( [sender tag] )
     [[MainController sharedController] selectSongAtIndex:[sender tag]];
 }
 
     [[MainController sharedController] selectSongAtIndex:[sender tag]];
 }
 
-- (void)performArtistsMenuAction:(id)sender
+- (void)performBrowseMenuAction:(id)sender
 {
 {
-    ITDebugLog(@"Artist action selected on item with object %i", [sender representedObject]);
+    ITDebugLog(@"Browse action selected on item named %@", [sender title]);
     /*
     ** 1 - Artist
     ** 2 - Album
     ** 3 - Genre?
     */
     /*
     ** 1 - Artist
     ** 2 - Album
     ** 3 - Genre?
     */
-    //[[MainController sharedController] createAndPlayPlaylistWithTerm:[sender representedObject] ofType:1];
+    [[MainController sharedController] makePlaylistWithTerm:[sender title] ofType:(([[[sender menu] title] isEqualToString:@"Artists"]) ? 1 : 2)];
 }
 
 - (void)updateMenu
 }
 
 - (void)updateMenu