From: Kent Sutherland Date: Sat, 5 Apr 2003 18:40:39 +0000 (+0000) Subject: More changes, bug fixes. X-Git-Tag: v1.0~166 X-Git-Url: http://git.ithinksw.org/MenuTunes.git/commitdiff_plain/8fe29f5b163e9acbda7b317b406a5835bac8a95d More changes, bug fixes. Problems: Rating stars don't show up after playlist is started. I'll work on that. Untested with Radio Tuner, I'll work on that --- diff --git a/OldMainController.m b/OldMainController.m index 0d22d9a..ff98908 100755 --- a/OldMainController.m +++ b/OldMainController.m @@ -20,7 +20,7 @@ /*************************************************************************/ #pragma mark - -#pragma mark INITIALIZATION METHODS +#pragma mark INITIALIZATION/DEALLOCATION METHODS /*************************************************************************/ - (id)init @@ -32,34 +32,62 @@ return self; } +- (void)dealloc +{ + if (refreshTimer) { + [refreshTimer invalidate]; + [refreshTimer release]; + refreshTimer = nil; + } + [currentRemote halt]; + [statusItem release]; + [menu release]; + [super dealloc]; +} + - (void)applicationDidFinishLaunching:(NSNotification *)note { currentRemote = [self loadRemote]; [currentRemote begin]; //Setup for notification of the remote player launching or quitting - [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]; + [[[NSWorkspace sharedWorkspace] notificationCenter] + addObserver:self + selector:@selector(applicationTerminated:) + name:NSWorkspaceDidTerminateApplicationNotification + object:nil]; + + [[[NSWorkspace sharedWorkspace] notificationCenter] + addObserver:self + selector:@selector(applicationLaunched:) + name:NSWorkspaceDidLaunchApplicationNotification + object:nil]; [self registerDefaults]; - menu = [[NSMenu alloc] initWithTitle:@""]; + statusItem = [[ITStatusItem alloc] + initWithStatusBar:[NSStatusBar systemStatusBar] + withLength:NSSquareStatusItemLength]; + menu = [[NSMenu alloc] initWithTitle:@""]; if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) { [self applicationLaunched:nil]; } else { [self applicationTerminated:nil]; } - statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar] withLength:NSSquareStatusItemLength]; - [statusItem setImage:[NSImage imageNamed:@"menu"]]; [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]]; - [statusItem setMenu:menu]; // Below line of code is for creating builds for Beta Testers // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]]; } +- (void)applicationWillTerminate:(NSNotification *)note +{ + [self clearHotKeys]; + [[NSStatusBar systemStatusBar] removeStatusItem:statusItem]; +} + - (ITMTRemote *)loadRemote { NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath]; @@ -121,7 +149,7 @@ [notRunningMenu addItem:[NSMenuItem separatorItem]]; [[notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self]; [[notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self]; - [statusItem setMenu:[menu autorelease]]; + [statusItem setMenu:[notRunningMenu autorelease]]; [refreshTimer invalidate]; [refreshTimer release]; @@ -132,15 +160,6 @@ } } -- (void)startTimerInNewThread -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES] retain]; - [runLoop run]; - [pool release]; -} - /*************************************************************************/ #pragma mark - #pragma mark INSTANCE METHODS @@ -179,7 +198,8 @@ for (i = 0; i < [loginarray count]; i++) { NSDictionary *tempDict = [loginarray objectAtIndex:i]; - if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString: + [[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { found = YES; } } @@ -228,6 +248,19 @@ } } +- (void)startTimerInNewThread +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 + target:self + selector:@selector(timerUpdate) + userInfo:nil + repeats:YES] retain]; + [runLoop run]; + [pool release]; +} + //Recreate the status item menu - (void)rebuildMenu { @@ -261,7 +294,6 @@ playPauseMenuItem = [menu addItemWithTitle:@"Play" action:@selector(playPause:) keyEquivalent:@""]; - [playPauseMenuItem setTarget:self]; if (tempCombo) { [self setKeyEquivalentForCode:[tempCombo keyCode] @@ -274,7 +306,6 @@ action:@selector(nextSong:) keyEquivalent:@""]; - [nextTrack setTarget:self]; if (tempCombo) { [self setKeyEquivalentForCode:[tempCombo keyCode] andModifiers:[tempCombo modifiers] onItem:nextTrack]; @@ -286,20 +317,19 @@ action:@selector(prevSong:) keyEquivalent:@""]; - [prevTrack setTarget:self]; if (tempCombo) { [self setKeyEquivalentForCode:[tempCombo keyCode] andModifiers:[tempCombo modifiers] onItem:prevTrack]; [tempCombo release]; } } else if ([item isEqualToString:@"Fast Forward"]) { - [[menu addItemWithTitle:@"Fast Forward" + [menu addItemWithTitle:@"Fast Forward" action:@selector(fastForward:) - keyEquivalent:@""] setTarget:self]; + keyEquivalent:@""]; } else if ([item isEqualToString:@"Rewind"]) { - [[menu addItemWithTitle:@"Rewind" + [menu addItemWithTitle:@"Rewind" action:@selector(rewind:) - keyEquivalent:@""] setTarget:self]; + keyEquivalent:@""]; } else if ([item isEqualToString:@"Upcoming Songs"]) { upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs" action:nil @@ -313,13 +343,13 @@ action:nil keyEquivalent:@""]; } else if ([item isEqualToString:@"PreferencesÉ"]) { - [[menu addItemWithTitle:@"PreferencesÉ" + [menu addItemWithTitle:@"PreferencesÉ" action:@selector(showPreferences:) - keyEquivalent:@""] setTarget:self]; + keyEquivalent:@""]; } else if ([item isEqualToString:@"Quit"]) { - [[menu addItemWithTitle:@"Quit" + [menu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) - keyEquivalent:@""] setTarget:self]; + keyEquivalent:@""]; } else if ([item isEqualToString:@"Current Track Info"]) { trackInfoIndex = [menu numberOfItems]; [menu addItemWithTitle:@"No Song" @@ -339,177 +369,34 @@ ratingMenu = [[NSMenu alloc] initWithTitle:@""]; item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""]; - [item setTarget:self]; [item setTag:0]; item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""]; - [item setTarget:self]; [item setTag:20]; item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""]; - [item setTarget:self]; [item setTag:40]; item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""]; - [item setTarget:self]; [item setTag:60]; item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""]; - [item setTarget:self]; [item setTag:80]; item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""]; - [item setTarget:self]; [item setTag:100]; } else if ([item isEqualToString:@""]) { [menu addItem:[NSMenuItem separatorItem]]; } } - [self timerUpdate]; //Updates dynamic info in the menu + [self updateMenu]; + //[self timerUpdate]; //Updates dynamic info in the menu [self clearHotKeys]; [self setupHotKeys]; } -//Updates the menu with current player state, song, and upcoming songs -- (void)updateMenu -{ - NSMenuItem *menuItem; - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - - if ( ( isAppRunning == ITMTRemotePlayerNotRunning ) ) { - return; - } - - if (upcomingSongsItem) { - [self rebuildUpcomingSongsMenu]; - } - - if (playlistItem) { - [self rebuildPlaylistMenu]; - } - - if (eqItem) { - [self rebuildEQPresetsMenu]; - } - if (trackInfoIndex > -1) { - NSString *curSongName, *curAlbumName = @"", *curArtistName = @""; - curSongName = [currentRemote currentSongTitle]; - - if ([defaults boolForKey:@"showAlbum"]) { - curAlbumName = [currentRemote currentSongAlbum]; - } - - if ([defaults boolForKey:@"showArtist"]) { - curArtistName = [currentRemote currentSongArtist]; - } - - if ([curSongName length] > 0) { - int index = [menu indexOfItemWithTitle:@"Now Playing"]; - if (index > -1) { - if ([defaults boolForKey:@"showName"]) { - [menu removeItemAtIndex:index + 1]; - } - if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) { - [menu removeItemAtIndex:index + 1]; - } - if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) { - [menu removeItemAtIndex:index + 1]; - } - if ([defaults boolForKey:@"showTime"]) { - [menu removeItemAtIndex:index + 1]; - } - } - - if (!isPlayingRadio) { - if ([defaults boolForKey:@"showTime"]) { - menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] - action:nil - keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; - [menuItem release]; - } - - if ([curArtistName length] > 0) { - menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curArtistName] - action:nil - keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; - [menuItem release]; - } - - if ([curAlbumName length] > 0) { - menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName] - action:nil - keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; - [menuItem release]; - } - - if (songRatingMenuItem) { - int rating = (int)[currentRemote currentSongRating] * 10; - int i; - for (i = 0; i < 5; i++) { - [[ratingMenu itemAtIndex:i] setState:NSOffState]; - [[ratingMenu itemAtIndex:i] setTarget:self]; - } - [[ratingMenu itemAtIndex:rating / 2] setState:NSOnState]; - } - } - - if ([defaults boolForKey:@"showName"]) { - menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName] - action:nil - keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; - [menuItem release]; - } - - if (index == -1) { - menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""]; - [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]]; - [menu insertItem:menuItem atIndex:trackInfoIndex]; - [menuItem release]; - - [songRatingMenuItem setSubmenu:ratingMenu]; - [songRatingMenuItem setEnabled:YES]; - } - } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) { - [menu removeItemAtIndex:trackInfoIndex]; - - if ([defaults boolForKey:@"showName"] == YES) { - [menu removeItemAtIndex:trackInfoIndex]; - } - - if ([defaults boolForKey:@"showTime"] == YES) { - [menu removeItemAtIndex:trackInfoIndex]; - } - - if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) { - [menu removeItemAtIndex:trackInfoIndex]; - } - - if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) { - [menu removeItemAtIndex:trackInfoIndex]; - } - - menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex]; - [menuItem release]; - } - - if ([defaults boolForKey:@"showArtist"]) { - didHaveArtistName = (([curArtistName length] > 0) ? YES : NO); - } - - if ([defaults boolForKey:@"showAlbum"]) { - didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO); - } - } - [menu update]; -} - //Rebuild the upcoming songs submenu. Can be improved a lot. - (void)rebuildUpcomingSongsMenu { @@ -531,8 +418,7 @@ if (i <= numSongs) { NSString *curSong = [currentRemote songTitleAtIndex:i]; NSMenuItem *songItem; - songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""]; - [songItem setTarget:self]; + songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""]; [songItem setRepresentedObject:[NSNumber numberWithInt:i]]; [upcomingSongsMenu addItem:songItem]; [songItem release]; @@ -565,7 +451,6 @@ NSString *playlistName = [playlists objectAtIndex:i]; NSMenuItem *tempItem; tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""]; - [tempItem setTarget:self]; [tempItem setRepresentedObject:[NSNumber numberWithInt:i + 1]]; [playlistMenu addItem:tempItem]; [tempItem release]; @@ -591,11 +476,12 @@ [eqMenu release]; eqMenu = [[NSMenu alloc] initWithTitle:@""]; - enabledItem = [eqMenu addItemWithTitle:@"Disabled" - action:@selector(toggleEqualizer) + enabledItem = [eqMenu addItemWithTitle:@"Enabled" + action:@selector(selectEQPreset:) keyEquivalent:@""]; + [enabledItem setTag:-1]; - if ([currentRemote equalizerEnabled] == NO) { + if ([currentRemote equalizerEnabled]) { [enabledItem setState:NSOnState]; } @@ -606,8 +492,7 @@ NSMenuItem *tempItem; if (setName) { tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""]; - [tempItem setTarget:self]; - [tempItem setRepresentedObject:[NSNumber numberWithInt:i]]; + [tempItem setTag:i]; [eqMenu addItem:tempItem]; [tempItem release]; } @@ -617,57 +502,13 @@ [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState]; } -- (void)clearHotKeys -{ - [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"]; -} - -- (void)setupHotKeys -{ - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - - if ([defaults objectForKey:@"PlayPause"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" - combo:[defaults keyComboForKey:@"PlayPause"] - target:self action:@selector(playPause:)]; - } - - if ([defaults objectForKey:@"NextTrack"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" - combo:[defaults keyComboForKey:@"NextTrack"] - target:self action:@selector(nextSong:)]; - } - - if ([defaults objectForKey:@"PrevTrack"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" - combo:[defaults keyComboForKey:@"PrevTrack"] - target:self action:@selector(prevSong:)]; - } - - if ([defaults objectForKey:@"TrackInfo"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" - combo:[defaults keyComboForKey:@"TrackInfo"] - target:self action:@selector(showCurrentTrackInfo)]; - } - - if ([defaults objectForKey:@"UpcomingSongs"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" - combo:[defaults keyComboForKey:@"UpcomingSongs"] - target:self action:@selector(showUpcomingSongs)]; - } -} - //Called when the timer fires. - (void)timerUpdate { int playlist = [currentRemote currentPlaylistIndex]; - ITMTRemotePlayerPlayingState playerPlayingState = [currentRemote playerPlayingState]; + ITMTRemotePlayerPlayingState playerState = [currentRemote playerPlayingState]; - if ((playlist > 0) || playerPlayingState != ITMTRemotePlayerStopped) { + if ((playlist > 0) || playerState != ITMTRemotePlayerStopped) { int trackPlayingIndex = [currentRemote currentSongIndex]; if (trackPlayingIndex != lastSongIndex) { @@ -689,7 +530,6 @@ [menu insertItem:temp atIndex:trackInfoIndex + 1]; [temp release]; } - [self updateMenu]; lastSongIndex = trackPlayingIndex; } else { @@ -726,7 +566,7 @@ } //Update Play/Pause menu item if (playPauseMenuItem){ - if (playerPlayingState == ITMTRemotePlayerPlaying) { + if (playerState == ITMTRemotePlayerPlaying) { [playPauseMenuItem setTitle:@"Pause"]; } else { [playPauseMenuItem setTitle:@"Play"]; @@ -737,7 +577,6 @@ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; //Remote the now playing item and add no song item [menu removeItemAtIndex:trackInfoIndex]; - if ([defaults boolForKey:@"showName"] == YES) { [menu removeItemAtIndex:trackInfoIndex]; } @@ -773,15 +612,151 @@ } } +//Updates the menu with current player state, song, and upcoming songs +- (void)updateMenu +{ + NSMenuItem *menuItem; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + if ( ( isAppRunning == ITMTRemotePlayerNotRunning ) ) { + return; + } + + if (upcomingSongsItem) { + [self rebuildUpcomingSongsMenu]; + } + + if (playlistItem) { + [self rebuildPlaylistMenu]; + } + + if (eqItem) { + [self rebuildEQPresetsMenu]; + } + if (trackInfoIndex > -1) { + NSString *curSongName, *curAlbumName = @"", *curArtistName = @""; + curSongName = [currentRemote currentSongTitle]; + + if ([defaults boolForKey:@"showAlbum"]) { + curAlbumName = [currentRemote currentSongAlbum]; + } + + if ([defaults boolForKey:@"showArtist"]) { + curArtistName = [currentRemote currentSongArtist]; + } + + if ([curSongName length] > 0) { + int index = [menu indexOfItemWithTitle:@"Now Playing"]; + if (index > -1) { + if ([defaults boolForKey:@"showName"]) { + [menu removeItemAtIndex:index + 1]; + } + if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) { + [menu removeItemAtIndex:index + 1]; + } + if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) { + [menu removeItemAtIndex:index + 1]; + } + if ([defaults boolForKey:@"showTime"]) { + [menu removeItemAtIndex:index + 1]; + } + } + + if (!isPlayingRadio) { + if ([defaults boolForKey:@"showTime"]) { + menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] + action:nil + keyEquivalent:@""]; + [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; + [menuItem release]; + } + + if ([curArtistName length] > 0) { + menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curArtistName] + action:nil + keyEquivalent:@""]; + [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; + [menuItem release]; + } + + if ([curAlbumName length] > 0) { + menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName] + action:nil + keyEquivalent:@""]; + [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; + [menuItem release]; + } + + if (songRatingMenuItem) { + int rating = (int)[currentRemote currentSongRating] * 10; + int i; + for (i = 0; i < 5; i++) { + [[ratingMenu itemAtIndex:i] setState:NSOffState]; + [[ratingMenu itemAtIndex:i] setTarget:self]; + } + [[ratingMenu itemAtIndex:rating / 2] setState:NSOnState]; + } + } + + if ([defaults boolForKey:@"showName"]) { + menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName] + action:nil + keyEquivalent:@""]; + [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; + [menuItem release]; + } + + if (index == -1) { + menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""]; + [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]]; + [menu insertItem:menuItem atIndex:trackInfoIndex]; + [menuItem release]; + + [songRatingMenuItem setSubmenu:ratingMenu]; + [songRatingMenuItem setEnabled:YES]; + } + } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) { + [menu removeItemAtIndex:trackInfoIndex]; + + if ([defaults boolForKey:@"showName"] == YES) { + [menu removeItemAtIndex:trackInfoIndex]; + } + + if ([defaults boolForKey:@"showTime"] == YES) { + [menu removeItemAtIndex:trackInfoIndex]; + } + + if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) { + [menu removeItemAtIndex:trackInfoIndex]; + } + + if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) { + [menu removeItemAtIndex:trackInfoIndex]; + } + + menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""]; + [menu insertItem:menuItem atIndex:trackInfoIndex]; + [menuItem release]; + } + + if ([defaults boolForKey:@"showArtist"]) { + didHaveArtistName = (([curArtistName length] > 0) ? YES : NO); + } + + if ([defaults boolForKey:@"showAlbum"]) { + didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO); + } + } + [menu update]; +} + // // -// Selectors - called from status item menu +// Menu Selectors // // -// Plugin dependent selectors - -- (void)playTrack:(id)sender +- (void)selectSong:(id)sender { [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]]; } @@ -803,10 +778,23 @@ - (void)selectEQPreset:(id)sender { int curSet = [currentRemote currentEQPresetIndex]; - int item = [[sender representedObject] intValue]; - [currentRemote switchToEQAtIndex:item]; - [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState]; - [[eqMenu itemAtIndex:item + 2] setState:NSOnState]; + int item = [sender tag]; + + if (item == -1) { + [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]]; + } else { + [currentRemote setEqualizerEnabled:YES]; + [currentRemote switchToEQAtIndex:item]; + [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState]; + [[eqMenu itemAtIndex:item + 2] setState:NSOnState]; + } +} + +- (void)selectSongRating:(id)sender +{ + [[ratingMenu itemAtIndex:([currentRemote currentSongRating] / 20)] setState:NSOffState]; + [currentRemote setCurrentSongRating:(float)[sender tag] / 100.0]; + [sender setState:NSOnState]; } - (void)playPause:(id)sender @@ -847,21 +835,6 @@ [playPauseMenuItem setTitle:@"Play"]; } -- (void)toggleEqualizer -{ - [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]]; -} - -- (void)selectSongRating:(id)sender -{ - [[ratingMenu itemAtIndex:([currentRemote currentSongRating] / 20)] setState:NSOffState]; - [currentRemote setCurrentSongRating:(float)[sender tag] / 100.0]; - [sender setState:NSOnState]; -} - -// -// -// Plugin independent selectors // // - (void)quitMenuTunes:(id)sender @@ -869,6 +842,17 @@ [NSApp terminate:self]; } +- (void)showPlayer:(id)sender +{ + if ( ( isAppRunning == ITMTRemotePlayerRunning) ) { + [currentRemote showPrimaryInterface]; + } else { + if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) { + NSLog(@"Error Launching Player"); + } + } +} + - (void)showPreferences:(id)sender { if (!prefsController) { @@ -886,17 +870,56 @@ prefsController = nil; } -- (void)showPlayer:(id)sender + +// +// +// Hot key setup +// +// + +- (void)clearHotKeys { - if ( ( isAppRunning == ITMTRemotePlayerRunning) ) { - [currentRemote showPrimaryInterface]; - } else { - if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) { - NSLog(@"Error Launching Player"); - } + [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"]; + [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"]; + [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"]; + [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"]; + [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"]; +} + +- (void)setupHotKeys +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + if ([defaults objectForKey:@"PlayPause"] != nil) { + [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" + combo:[defaults keyComboForKey:@"PlayPause"] + target:self action:@selector(playPause:)]; + } + + if ([defaults objectForKey:@"NextTrack"] != nil) { + [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" + combo:[defaults keyComboForKey:@"NextTrack"] + target:self action:@selector(nextSong:)]; + } + + if ([defaults objectForKey:@"PrevTrack"] != nil) { + [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" + combo:[defaults keyComboForKey:@"PrevTrack"] + target:self action:@selector(prevSong:)]; + } + + if ([defaults objectForKey:@"TrackInfo"] != nil) { + [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" + combo:[defaults keyComboForKey:@"TrackInfo"] + target:self action:@selector(showCurrentTrackInfo)]; + } + + if ([defaults objectForKey:@"UpcomingSongs"] != nil) { + [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" + combo:[defaults keyComboForKey:@"UpcomingSongs"] + target:self action:@selector(showUpcomingSongs)]; } } - // // @@ -1167,35 +1190,4 @@ } } -/*************************************************************************/ -#pragma mark - -#pragma mark NSApplication DELEGATE METHODS -/*************************************************************************/ - -- (void)applicationWillTerminate:(NSNotification *)note -{ - [self clearHotKeys]; - [[NSStatusBar systemStatusBar] removeStatusItem:statusItem]; -} - - -/*************************************************************************/ -#pragma mark - -#pragma mark DEALLOCATION METHODS -/*************************************************************************/ - -- (void)dealloc -{ - if (refreshTimer) { - [refreshTimer invalidate]; - [refreshTimer release]; - refreshTimer = nil; - } - [currentRemote halt]; - [statusItem release]; - [menu release]; -// [view release]; - [super dealloc]; -} - @end diff --git a/PreferencesController.m b/PreferencesController.m index 82b7f82..89a0268 100755 --- a/PreferencesController.m +++ b/PreferencesController.m @@ -14,8 +14,7 @@ mt = [tunes retain]; [mt registerDefaults]; - //Load the nib - [NSBundle loadNibNamed:@"Preferences" owner:self]; + [NSBundle loadNibNamed:@"Preferences" owner:self]; //Load the nib //Set the table view cells up [imgCell setImageScaling:NSScaleNone];