From: Kent Sutherland Date: Sat, 10 May 2003 16:00:19 +0000 (+0000) Subject: Added more to MenuController X-Git-Tag: v1.0~108 X-Git-Url: http://git.ithinksw.org/MenuTunes.git/commitdiff_plain/545c9e281e8ac3ce259afc85d6a554849d8efe86 Added more to MenuController --- diff --git a/MainController.h b/MainController.h index 8438c82..4b9c14f 100755 --- a/MainController.h +++ b/MainController.h @@ -51,6 +51,7 @@ - (void)selectSongAtIndex:(int)index; - (void)selectSongRating:(int)rating; - (void)selectEQPresetAtIndex:(int)index; +- (void)showPlayer; - (void)showPreferences; - (void)quitMenuTunes; diff --git a/MainController.m b/MainController.m index 3cf10ab..48ec66a 100755 --- a/MainController.m +++ b/MainController.m @@ -11,6 +11,9 @@ - (void)timerUpdate; - (void)setLatestSongIdentifier:(NSString *)newIdentifier; - (void)showCurrentTrackInfo; + +- (void)applicationLaunched:(NSNotification *)note; +- (void)applicationTerminated:(NSNotification *)note; @end static MainController *sharedController; @@ -58,7 +61,7 @@ static MainController *sharedController; selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]; - + if ( ! [df objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered. [[PreferencesController sharedPrefs] registerDefaults]; } @@ -68,6 +71,12 @@ static MainController *sharedController; initWithStatusBar:[NSStatusBar systemStatusBar] withLength:NSSquareStatusItemLength]; + if ([currentRemote playerRunningState] == ITMTRemotePlayerRunning) { + [self applicationLaunched:nil]; + } else { + [self applicationTerminated:nil]; + } + [statusItem setImage:[NSImage imageNamed:@"menu"]]; [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]]; } @@ -153,7 +162,8 @@ static MainController *sharedController; - (void)timerUpdate { - if ( ( [self songChanged] ) || + //We're quite worthless now, aren't we? Just used to showing the status windows. + /*if ( ( [self songChanged] ) || ( ([self radioIsPlaying]) && (latestPlaylistClass != ITMTRemotePlayerRadioPlaylist) ) || ( (! [self radioIsPlaying]) && (latestPlaylistClass == ITMTRemotePlayerRadioPlaylist) ) ) { [self setLatestSongIdentifier:[currentRemote currentSongUniqueIdentifier]]; @@ -162,7 +172,7 @@ static MainController *sharedController; if ( [df boolForKey:@"showSongInfoOnChange"] ) { [self showCurrentTrackInfo]; } - } + }*/ } - (void)menuClicked @@ -234,6 +244,17 @@ static MainController *sharedController; [currentRemote switchToEQAtIndex:index]; } +- (void)showPlayer +{ + if ( ( playerRunningState == ITMTRemotePlayerRunning) ) { + [currentRemote showPrimaryInterface]; + } else { + if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) { + NSLog(@"Error Launching Player"); + } + } +} + - (void)showPreferences { [[PreferencesController sharedPrefs] setController:self]; @@ -248,17 +269,6 @@ static MainController *sharedController; // // -- (void)showPlayer:(id)sender -{ - if ( ( playerRunningState == ITMTRemotePlayerRunning) ) { - [currentRemote showPrimaryInterface]; - } else { - if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) { - NSLog(@"Error Launching Player"); - } - } -} - - (void)closePreferences { if ( ( playerRunningState == ITMTRemotePlayerRunning) ) { @@ -297,19 +307,19 @@ static MainController *sharedController; if ([df objectForKey:@"PlayPause"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" combo:[df keyComboForKey:@"PlayPause"] - target:self action:@selector(playPause:)]; + target:self action:@selector(playPause)]; } if ([df objectForKey:@"NextTrack"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" combo:[df keyComboForKey:@"NextTrack"] - target:self action:@selector(nextSong:)]; + target:self action:@selector(nextSong)]; } if ([df objectForKey:@"PrevTrack"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" combo:[df keyComboForKey:@"PrevTrack"] - target:self action:@selector(prevSong:)]; + target:self action:@selector(prevSong)]; } if ([df objectForKey:@"TrackInfo"] != nil) { @@ -324,41 +334,41 @@ static MainController *sharedController; target:self action:@selector(showUpcomingSongs)]; } - if ([df objectForKey:@"ToggleLoop"] != nil) { +/* if ([df objectForKey:@"ToggleLoop"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" combo:[df keyComboForKey:@"ToggleLoop"] - target:self action:NULL/*Set this to something*/]; + target:self action:NULL]; } if ([df objectForKey:@"ToggleShuffle"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" combo:[df keyComboForKey:@"ToggleShuffle"] - target:self action:NULL/*Set this to something*/]; + target:self action:NULL]; } if ([df objectForKey:@"IncrementVolume"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" combo:[df keyComboForKey:@"IncrementVolume"] - target:self action:NULL/*Set this to something*/]; + target:self action:NULL]; } if ([df objectForKey:@"DecrementVolume"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" combo:[df keyComboForKey:@"DecrementVolume"] - target:self action:NULL/*Set this to something*/]; + target:self action:NULL]; } if ([df objectForKey:@"IncrementRating"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" combo:[df keyComboForKey:@"IncrementRating"] - target:self action:NULL/*Set this to something*/]; + target:self action:NULL]; } if ([df objectForKey:@"DecrementRating"] != nil) { [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" combo:[df keyComboForKey:@"DecrementRating"] - target:self action:NULL/*Set this to something*/]; - } + target:self action:NULL]; + }*/ } - (void)showCurrentTrackInfo @@ -454,13 +464,6 @@ static MainController *sharedController; - (void)applicationTerminated:(NSNotification *)note { if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) { -/* - NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""]; - [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""]; - [notRunningMenu addItem:[NSMenuItem separatorItem]]; - [notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""]; - [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""]; -*/ [refreshTimer invalidate]; [refreshTimer release]; refreshTimer = nil; diff --git a/MenuController.h b/MenuController.h index 6163bb1..83d55bc 100755 --- a/MenuController.h +++ b/MenuController.h @@ -7,6 +7,7 @@ // #import +#import "ITMTRemote.h" // Internal: To be used with NSMenuItems as their tag, for use with the NSMenuValidation stuff. // Also will be used in supplying the controller with the layout to use for the MenuItems, unless @@ -32,6 +33,7 @@ typedef enum { MTMenuRewindItem, MTMenuPreviousTrackItem, MTMenuNextTrackItem, + MTMenuShowPlayerItem, MTMenuPreferencesItem, MTMenuQuitItem } MTMenuItemTag; @@ -40,6 +42,10 @@ typedef enum { { NSMutableArray *_menuLayout; NSMenu *_currentMenu; + + ITMTRemote *currentRemote; + int _currentPlaylist, _currentTrack; + BOOL _playingRadio; } - (NSMenu *)menu; diff --git a/MenuController.m b/MenuController.m index 4317dec..72bee7a 100755 --- a/MenuController.m +++ b/MenuController.m @@ -8,7 +8,13 @@ #import "MenuController.h" #import "NewMainController.h" -#import "ITMTRemote.h" + +@interface MenuController (SubmenuMethods) +- (NSMenu *)ratingMenu; +- (NSMenu *)upcomingSongsMenu; +- (NSMenu *)playlistsMenu; +- (NSMenu *)eqMenu; +@end @implementation MenuController @@ -26,12 +32,13 @@ NSArray *menuArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"]; NSEnumerator *enumerator = [menuArray objectEnumerator]; NSString *nextObject; - ITMTRemote *currentRemote = [[MainController sharedController] currentRemote]; NSMenuItem *tempItem; //Get the current playlist, track index, etc. - int playlistIndex = [currentRemote currentPlaylistIndex]; - //int trackIndex = [currentRemote currentSongIndex]; + currentRemote = [[MainController sharedController] currentRemote]; + _currentPlaylist = [currentRemote currentPlaylistIndex]; + _currentTrack = [currentRemote currentSongIndex]; + _playingRadio = ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist); //create our menu while ( (nextObject = [enumerator nextObject]) ) { @@ -58,7 +65,7 @@ tempItem = [menu addItemWithTitle:@"Next Track" action:@selector(performMainMenuAction:) keyEquivalent:@""]; - if (playlistIndex) { + if (_currentPlaylist) { [tempItem setTag:MTMenuNextTrackItem]; [tempItem setTarget:self]; } @@ -66,7 +73,7 @@ tempItem = [menu addItemWithTitle:@"Previous Track" action:@selector(performMainMenuAction:) keyEquivalent:@""]; - if (playlistIndex) { + if (_currentPlaylist) { [tempItem setTag:MTMenuPreviousTrackItem]; [tempItem setTarget:self]; } @@ -74,7 +81,7 @@ tempItem = [menu addItemWithTitle:@"Fast Forward" action:@selector(performMainMenuAction:) keyEquivalent:@""]; - if (playlistIndex) { + if (_currentPlaylist) { [tempItem setTag:MTMenuFastForwardItem]; [tempItem setTarget:self]; } @@ -82,7 +89,7 @@ tempItem = [menu addItemWithTitle:@"Rewind" action:@selector(performMainMenuAction:) keyEquivalent:@""]; - if (playlistIndex) { + if (_currentPlaylist) { [tempItem setTag:MTMenuRewindItem]; [tempItem setTarget:self]; } @@ -99,7 +106,7 @@ [tempItem setTag:MTMenuQuitItem]; [tempItem setTarget:self]; } else if ([nextObject isEqualToString:@"Current Track Info"]) { - if (playlistIndex) { + if (_currentPlaylist) { NSString *title = [currentRemote currentSongTitle]; [menu addItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@""]; @@ -107,6 +114,7 @@ if ([title length] > 0) { [menu addItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@""]; } + //Gotta add artist, album, track, time, etc, blah, blah, blah... } else { [menu addItemWithTitle:@"No Song" action:NULL keyEquivalent:@""]; } @@ -117,22 +125,22 @@ tempItem = [menu addItemWithTitle:@"Song Rating" action:nil keyEquivalent:@""]; - //[tempItem setSubmenu:[self ratingMenu]]; + [tempItem setSubmenu:[self ratingMenu]]; } else if ([nextObject isEqualToString:@"Upcoming Songs"]) { tempItem = [menu addItemWithTitle:@"Upcoming Songs" action:nil keyEquivalent:@""]; - //[tempItem setSubmenu:[self upcomingSongsMenu]]; + [tempItem setSubmenu:[self upcomingSongsMenu]]; } else if ([nextObject isEqualToString:@"Playlists"]) { tempItem = [menu addItemWithTitle:@"Playlists" action:nil keyEquivalent:@""]; - //[tempItem setSubmenu:[self playlistsMenu]]; + [tempItem setSubmenu:[self playlistsMenu]]; } else if ([nextObject isEqualToString:@"EQ Presets"]) { tempItem = [menu addItemWithTitle:@"EQ Presets" action:nil keyEquivalent:@""]; - //[tempItem setSubmenu:[self eqMenu]]; + [tempItem setSubmenu:[self eqMenu]]; } } @@ -145,7 +153,9 @@ { NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; NSMenuItem *tempItem; - [menu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [[[MainController sharedController] currentRemote] playerSimpleName]] action:@selector(performMainMenuAction:) keyEquivalent:@""]; + tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"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 setTag:MTMenuPreferencesItem]; @@ -156,6 +166,50 @@ return [menu autorelease]; } +- (NSMenu *)ratingMenu +{ + NSMenu *ratingMenu = [[NSMenu alloc] initWithTitle:@""]; + return [ratingMenu autorelease]; +} + +- (NSMenu *)upcomingSongsMenu +{ + NSMenu *upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""]; + int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:_currentPlaylist]; + int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"]; + + 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; + songItem = [upcomingSongsMenu addItemWithTitle:curSong action:@selector(performUpcomingSongsMenuAction:) keyEquivalent:@""]; + [songItem setTag:i]; + [songItem setTarget:self]; + } else { + break; + } + } + } + } + return [upcomingSongsMenu autorelease]; +} + +- (NSMenu *)playlistsMenu +{ + NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""]; + return [playlistsMenu autorelease]; +} + +- (NSMenu *)eqMenu +{ + NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""]; + return [eqMenu autorelease]; +} + - (void)performMainMenuAction:(id)sender { switch ( [sender tag] ) @@ -183,6 +237,10 @@ NSLog(@"MenuController: Next Track"); [[MainController sharedController] nextSong]; break; + case MTMenuShowPlayerItem: + NSLog(@"MainController: Show Main Interface"); + [[MainController sharedController] showPlayer]; + break; case MTMenuPreferencesItem: NSLog(@"MenuController: Preferences..."); [[MainController sharedController] showPreferences];