- (void)selectSongAtIndex:(int)index;
- (void)selectSongRating:(int)rating;
- (void)selectEQPresetAtIndex:(int)index;
+- (void)showPlayer;
- (void)showPreferences;
- (void)quitMenuTunes;
- (void)timerUpdate;
- (void)setLatestSongIdentifier:(NSString *)newIdentifier;
- (void)showCurrentTrackInfo;
+
+- (void)applicationLaunched:(NSNotification *)note;
+- (void)applicationTerminated:(NSNotification *)note;
@end
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];
}
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"]];
}
- (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]];
if ( [df boolForKey:@"showSongInfoOnChange"] ) {
[self showCurrentTrackInfo];
}
- }
+ }*/
}
- (void)menuClicked
[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];
//
//
-- (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) ) {
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) {
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
- (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;
//
#import <Cocoa/Cocoa.h>
+#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
MTMenuRewindItem,
MTMenuPreviousTrackItem,
MTMenuNextTrackItem,
+ MTMenuShowPlayerItem,
MTMenuPreferencesItem,
MTMenuQuitItem
} MTMenuItemTag;
{
NSMutableArray *_menuLayout;
NSMenu *_currentMenu;
+
+ ITMTRemote *currentRemote;
+ int _currentPlaylist, _currentTrack;
+ BOOL _playingRadio;
}
- (NSMenu *)menu;
#import "MenuController.h"
#import "NewMainController.h"
-#import "ITMTRemote.h"
+
+@interface MenuController (SubmenuMethods)
+- (NSMenu *)ratingMenu;
+- (NSMenu *)upcomingSongsMenu;
+- (NSMenu *)playlistsMenu;
+- (NSMenu *)eqMenu;
+@end
@implementation MenuController
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]) ) {
tempItem = [menu addItemWithTitle:@"Next Track"
action:@selector(performMainMenuAction:)
keyEquivalent:@""];
- if (playlistIndex) {
+ if (_currentPlaylist) {
[tempItem setTag:MTMenuNextTrackItem];
[tempItem setTarget:self];
}
tempItem = [menu addItemWithTitle:@"Previous Track"
action:@selector(performMainMenuAction:)
keyEquivalent:@""];
- if (playlistIndex) {
+ if (_currentPlaylist) {
[tempItem setTag:MTMenuPreviousTrackItem];
[tempItem setTarget:self];
}
tempItem = [menu addItemWithTitle:@"Fast Forward"
action:@selector(performMainMenuAction:)
keyEquivalent:@""];
- if (playlistIndex) {
+ if (_currentPlaylist) {
[tempItem setTag:MTMenuFastForwardItem];
[tempItem setTarget:self];
}
tempItem = [menu addItemWithTitle:@"Rewind"
action:@selector(performMainMenuAction:)
keyEquivalent:@""];
- if (playlistIndex) {
+ if (_currentPlaylist) {
[tempItem setTag:MTMenuRewindItem];
[tempItem setTarget:self];
}
[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:@""];
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:@""];
}
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]];
}
}
{
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];
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] )
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];