X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/b936ca5ffb6320a3febce6a7d0c2875b072ac6bc..e350c02cdc2d016846056966c9595969aebcf559:/MenuController.m?ds=inline diff --git a/MenuController.m b/MenuController.m index 94dc8c8..cfd2909 100755 --- a/MenuController.m +++ b/MenuController.m @@ -7,9 +7,11 @@ // #import "MenuController.h" -#import "NewMainController.h" -#import "HotKeyCenter.h" -#import "KeyCombo.h" +#import "MainController.h" +#import +#import +#import +#import @interface MenuController (SubmenuMethods) - (NSMenu *)ratingMenu; @@ -39,7 +41,8 @@ NSString *nextObject; NSMenuItem *tempItem; NSEnumerator *itemEnum; - KeyCombo *keyCombo; + ITHotKey *hotKey; + NSArray *hotKeys = [[ITHotKeyCenter sharedCenter] allHotKeys]; //Get the information _currentPlaylist = [currentRemote currentPlaylistIndex]; @@ -65,98 +68,125 @@ //create our menu while ( (nextObject = [enumerator nextObject]) ) { //Main menu items - if ([nextObject isEqualToString:@"Play/Pause"]) { - tempItem = [menu addItemWithTitle:@"Play" + if ([nextObject isEqualToString:@"playPause"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"play", @"Play") action:@selector(performMainMenuAction:) keyEquivalent:@""]; [tempItem setTag:MTMenuPlayPauseItem]; [tempItem setTarget:self]; - if ( (keyCombo = [[HotKeyCenter sharedCenter] keyComboForName:@"PlayPause"]) ) { - [self setKeyEquivalentForCode:[keyCombo keyCode] - andModifiers:[keyCombo modifiers] - onItem:tempItem]; + itemEnum = [hotKeys objectEnumerator]; + while ( (hotKey = [itemEnum nextObject]) ) { + if ([[hotKey name] isEqualToString:@"PlayPause"]) { + ITKeyCombo *combo = [hotKey keyCombo]; + [self setKeyEquivalentForCode:[combo keyCode] + andModifiers:[combo modifiers] + onItem:tempItem]; + } } switch ([currentRemote playerPlayingState]) { case ITMTRemotePlayerPlaying: - [tempItem setTitle:@"Pause"]; + [tempItem setTitle:NSLocalizedString(@"pause", @"Pause")]; break; case ITMTRemotePlayerRewinding: case ITMTRemotePlayerForwarding: - [tempItem setTitle:@"Resume"]; + [tempItem setTitle:NSLocalizedString(@"resume", @"Resume")]; break; default: break; } - } else if ([nextObject isEqualToString:@"Next Track"]) { - tempItem = [menu addItemWithTitle:@"Next Track" + } else if ([nextObject isEqualToString:@"nextTrack"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"nextTrack", @"Next Track") action:@selector(performMainMenuAction:) keyEquivalent:@""]; - if ( (keyCombo = [[HotKeyCenter sharedCenter] keyComboForName:@"NextTrack"]) ) { - [self setKeyEquivalentForCode:[keyCombo keyCode] - andModifiers:[keyCombo modifiers] - onItem:tempItem]; + itemEnum = [hotKeys objectEnumerator]; + while ( (hotKey = [itemEnum nextObject]) ) { + if ([[hotKey name] isEqualToString:@"NextTrack"]) { + ITKeyCombo *combo = [hotKey keyCombo]; + [self setKeyEquivalentForCode:[combo keyCode] + andModifiers:[combo modifiers] + onItem:tempItem]; + } } if (_currentPlaylist) { [tempItem setTag:MTMenuNextTrackItem]; [tempItem setTarget:self]; } - } else if ([nextObject isEqualToString:@"Previous Track"]) { - tempItem = [menu addItemWithTitle:@"Previous Track" + } else if ([nextObject isEqualToString:@"prevTrack"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"prevTrack", @"Previous Track") action:@selector(performMainMenuAction:) keyEquivalent:@""]; - if ( (keyCombo = [[HotKeyCenter sharedCenter] keyComboForName:@"PrevTrack"]) ) { - [self setKeyEquivalentForCode:[keyCombo keyCode] - andModifiers:[keyCombo modifiers] - onItem:tempItem]; + itemEnum = [hotKeys objectEnumerator]; + while ( (hotKey = [itemEnum nextObject]) ) { + if ([[hotKey name] isEqualToString:@"PrevTrack"]) { + ITKeyCombo *combo = [hotKey keyCombo]; + [self setKeyEquivalentForCode:[combo keyCode] + andModifiers:[combo modifiers] + onItem:tempItem]; + } } if (_currentPlaylist) { [tempItem setTag:MTMenuPreviousTrackItem]; [tempItem setTarget:self]; } - } else if ([nextObject isEqualToString:@"Fast Forward"]) { - tempItem = [menu addItemWithTitle:@"Fast Forward" + } else if ([nextObject isEqualToString:@"fastForward"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"fastForward", @"Fast Forward") action:@selector(performMainMenuAction:) keyEquivalent:@""]; if (_currentPlaylist) { [tempItem setTag:MTMenuFastForwardItem]; [tempItem setTarget:self]; } - } else if ([nextObject isEqualToString:@"Rewind"]) { - tempItem = [menu addItemWithTitle:@"Rewind" + } else if ([nextObject isEqualToString:@"rewind"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"rewind", @"Rewind") action:@selector(performMainMenuAction:) keyEquivalent:@""]; if (_currentPlaylist) { [tempItem setTag:MTMenuRewindItem]; [tempItem setTarget:self]; } - } else if ([nextObject isEqualToString:@"Show Player"]) { - tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [[[MainController sharedController] currentRemote] playerSimpleName]] action:@selector(performMainMenuAction:) keyEquivalent:@""]; + } else if ([nextObject isEqualToString:@"showPlayer"]) { + tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", + NSLocalizedString(@"show", @"Show"), + [[[MainController sharedController] currentRemote] playerSimpleName]] + action:@selector(performMainMenuAction:) + keyEquivalent:@""]; + + itemEnum = [hotKeys objectEnumerator]; + while ( (hotKey = [itemEnum nextObject]) ) { + if ([[hotKey name] isEqualToString:@"ShowPlayer"]) { + ITKeyCombo *combo = [hotKey keyCombo]; + [self setKeyEquivalentForCode:[combo keyCode] + andModifiers:[combo modifiers] + onItem:tempItem]; + } + } + [tempItem setTarget:self]; [tempItem setTag:MTMenuShowPlayerItem]; - } else if ([nextObject isEqualToString:@"Preferences"]) { - tempItem = [menu addItemWithTitle:@"Preferences..." + } else if ([nextObject isEqualToString:@"preferences"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"preferences", @"Preferences...") action:@selector(performMainMenuAction:) keyEquivalent:@""]; [tempItem setTag:MTMenuPreferencesItem]; [tempItem setTarget:self]; - } else if ([nextObject isEqualToString:@"Quit"]) { - tempItem = [menu addItemWithTitle:@"Quit" + } else if ([nextObject isEqualToString:@"quit"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"quit", @"Quit") action:@selector(performMainMenuAction:) keyEquivalent:@""]; [tempItem setTag:MTMenuQuitItem]; [tempItem setTarget:self]; - } else if ([nextObject isEqualToString:@"Current Track Info"]) { + } else if ([nextObject isEqualToString:@"trackInfo"]) { //Handle playing radio too if (_currentPlaylist) { NSString *title = [currentRemote currentSongTitle]; - [menu addItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"nowPlaying", @"Now Playing") action:NULL keyEquivalent:@""]; if ([title length] > 0) { [menu addItemWithTitle:[NSString stringWithFormat:@" %@", title] @@ -165,21 +195,30 @@ } if ([defaults boolForKey:@"showAlbum"]) { - [menu addItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongAlbum]] - action:nil - keyEquivalent:@""]; + NSString *curAlbum = [currentRemote currentSongAlbum]; + if ([curAlbum length]) { + [menu addItemWithTitle:[NSString stringWithFormat:@" %@", curAlbum] + action:nil + keyEquivalent:@""]; + } } if ([defaults boolForKey:@"showArtist"]) { - [menu addItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongArtist]] - action:nil - keyEquivalent:@""]; + NSString *curArtist = [currentRemote currentSongArtist]; + if ([curArtist length]) { + [menu addItemWithTitle:[NSString stringWithFormat:@" %@", curArtist] + action:nil + keyEquivalent:@""]; + } } if ([defaults boolForKey:@"showTrackNumber"]) { - [menu addItemWithTitle:[NSString stringWithFormat:@" Track %i", [currentRemote currentSongTrack]] + int track = [currentRemote currentSongTrack]; + if (track) { + [menu addItemWithTitle:[NSString stringWithFormat:@" %@ %i", NSLocalizedString(@"track", @"Track"), track] action:nil keyEquivalent:@""]; + } } if ([defaults boolForKey:@"showTime"]) { @@ -189,18 +228,49 @@ action:nil keyEquivalent:@""]; } + + if ([defaults boolForKey:@"showTrackRating"]) { + NSString *string; + switch ((int)([currentRemote currentSongRating] * 5)) { + case 0: + string = [NSString stringWithUTF8String:"☆☆☆☆☆"]; + break; + case 1: + string = [NSString stringWithUTF8String:"★☆☆☆☆"]; + break; + case 2: + string = [NSString stringWithUTF8String:"★★☆☆☆"]; + break; + case 3: + string = [NSString stringWithUTF8String:"★★★☆☆"]; + break; + case 4: + string = [NSString stringWithUTF8String:"★★★★☆"]; + break; + case 5: + string = [NSString stringWithUTF8String:"★★★★★"]; + break; + } + [menu addItemWithTitle: + [@" " stringByAppendingString:string] + action:nil + keyEquivalent:@""]; + } } else { - [menu addItemWithTitle:@"No Song" action:NULL keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"noSong", @"No Song") action:NULL keyEquivalent:@""]; } - } else if ([nextObject isEqualToString:@""]) { + } else if ([nextObject isEqualToString:@"separator"]) { [menu addItem:[NSMenuItem separatorItem]]; //Submenu items - } else if ([nextObject isEqualToString:@"Song Rating"]) { - tempItem = [menu addItemWithTitle:@"Song Rating" + } else if ([nextObject isEqualToString:@"songRating"]) { + 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]) ) { @@ -208,11 +278,8 @@ } [[_ratingMenu itemAtIndex:([currentRemote currentSongRating] * 5)] setState:NSOnState]; - if (_playingRadio || !_currentPlaylist) { - [tempItem setEnabled:NO]; - } - } else if ([nextObject isEqualToString:@"Upcoming Songs"]) { - tempItem = [menu addItemWithTitle:@"Upcoming Songs" + } else if ([nextObject isEqualToString:@"upcomingSongs"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"upcomingSongs", @"Upcoming Songs") action:nil keyEquivalent:@""]; [tempItem setSubmenu:_upcomingSongsMenu]; @@ -220,14 +287,14 @@ if (_playingRadio || !_currentPlaylist) { [tempItem setEnabled:NO]; } - } else if ([nextObject isEqualToString:@"Playlists"]) { - tempItem = [menu addItemWithTitle:@"Playlists" + } else if ([nextObject isEqualToString:@"playlists"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"playlists", @"Playlists") action:nil keyEquivalent:@""]; [tempItem setSubmenu:_playlistsMenu]; [tempItem setTag:3]; - } else if ([nextObject isEqualToString:@"EQ Presets"]) { - tempItem = [menu addItemWithTitle:@"EQ Presets" + } else if ([nextObject isEqualToString:@"eqPresets"]) { + tempItem = [menu addItemWithTitle:NSLocalizedString(@"eqPresets", @"EQ Presets") action:nil keyEquivalent:@""]; [tempItem setSubmenu:_eqMenu]; @@ -249,14 +316,14 @@ { NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; NSMenuItem *tempItem; - tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [[[MainController sharedController] currentRemote] playerSimpleName]] action:@selector(performMainMenuAction:) keyEquivalent:@""]; + tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"open", @"Open"), [[[MainController sharedController] currentRemote] playerSimpleName]] action:@selector(performMainMenuAction:) keyEquivalent:@""]; [tempItem setTag:MTMenuShowPlayerItem]; [tempItem setTarget:self]; [menu addItem:[NSMenuItem separatorItem]]; - tempItem = [menu addItemWithTitle:@"Preferences" action:@selector(performMainMenuAction:) keyEquivalent:@""]; + tempItem = [menu addItemWithTitle:NSLocalizedString(@"preferences", @"Preferences...") action:@selector(performMainMenuAction:) keyEquivalent:@""]; [tempItem setTag:MTMenuPreferencesItem]; [tempItem setTarget:self]; - tempItem = [menu addItemWithTitle:@"Quit" action:@selector(performMainMenuAction:) keyEquivalent:@""]; + tempItem = [menu addItemWithTitle:NSLocalizedString(@"quit", @"Quit") action:@selector(performMainMenuAction:) keyEquivalent:@""]; [tempItem setTag:MTMenuQuitItem]; [tempItem setTarget:self]; return [menu autorelease]; @@ -282,26 +349,24 @@ - (NSMenu *)ratingMenu { NSMenu *ratingMenu = [[NSMenu alloc] initWithTitle:@""]; - if (_currentPlaylist && !_playingRadio) { - NSEnumerator *itemEnum; - id anItem; - int itemTag = 0; - SEL itemSelector = @selector(performRatingMenuAction:); - - [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]) ) { - [anItem setAction:itemSelector]; - [anItem setTarget:self]; - [anItem setTag:itemTag]; - itemTag += 20; - } + NSEnumerator *itemEnum; + id anItem; + int itemTag = 0; + SEL itemSelector = @selector(performRatingMenuAction:); + + [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]) ) { + [anItem setAction:itemSelector]; + [anItem setTarget:self]; + [anItem setTag:itemTag]; + itemTag += 20; } return ratingMenu; } @@ -374,39 +439,39 @@ switch ( [sender tag] ) { case MTMenuPlayPauseItem: - NSLog(@"MenuController: Play/Pause"); + ITDebugLog(@"MenuController: Play/Pause"); [[MainController sharedController] playPause]; break; case MTMenuFastForwardItem: - NSLog(@"MenuController: Fast Forward"); + ITDebugLog(@"MenuController: Fast Forward"); [[MainController sharedController] fastForward]; break; case MTMenuRewindItem: - NSLog(@"MenuController: Rewind"); + ITDebugLog(@"MenuController: Rewind"); [[MainController sharedController] rewind]; break; case MTMenuPreviousTrackItem: - NSLog(@"MenuController: Previous Track"); + ITDebugLog(@"MenuController: Previous Track"); [[MainController sharedController] prevSong]; break; case MTMenuNextTrackItem: - NSLog(@"MenuController: Next Track"); + ITDebugLog(@"MenuController: Next Track"); [[MainController sharedController] nextSong]; break; case MTMenuShowPlayerItem: - NSLog(@"MainController: Show Main Interface"); + ITDebugLog(@"MainController: Show Main Interface"); [[MainController sharedController] showPlayer]; break; case MTMenuPreferencesItem: - NSLog(@"MenuController: Preferences..."); + ITDebugLog(@"MenuController: Preferences..."); [[MainController sharedController] showPreferences]; break; case MTMenuQuitItem: - NSLog(@"MenuController: Quit"); + ITDebugLog(@"MenuController: Quit"); [[MainController sharedController] quitMenuTunes]; break; default: - NSLog(@"MenuController: Unimplemented Menu Item OR Child-bearing Menu Item"); + ITDebugLog(@"MenuController: Unimplemented Menu Item OR Child-bearing Menu Item"); break; } } @@ -502,7 +567,7 @@ [[NSString stringWithString:@"Space"] getCharacters:&buffer]; charcode = buffer; /*MenuRef menuRef = _NSGetCarbonMenu([item menu]); - NSLog(@"%@", menuRef); + ITDebugLog(@"%@", menuRef); SetMenuItemCommandKey(menuRef, 0, NO, 49); SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier); SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);