#import "MenuTunes.h"
#import "PreferencesController.h"
#import "HotKeyCenter.h"
-#import "StatusWindowController.h"
+#import "StatusWindow.h"
@interface MenuTunes(Private)
- (ITMTRemote *)loadRemote;
{
if ( ( self = [super init] ) ) {
remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
+ statusWindow = [StatusWindow sharedWindow];
}
return self;
}
menu = [[NSMenu alloc] initWithTitle:@""];
isAppRunning = [currentRemote isAppRunning];
- if (isAppRunning)
- {
+ if (isAppRunning) {
[self rebuildMenu];
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5
target:self
selector:@selector(timerUpdate)
userInfo:nil
repeats:YES];
- }
- else
- {
+ } else {
menu = [[NSMenu alloc] initWithTitle:@""];
[[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
[[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:@"menu"]) {
- bool found = NO;
+ BOOL found = NO;
NSMutableDictionary *loginwindow;
NSMutableArray *loginarray;
int i;
keyEquivalent:@""];
[playPauseMenuItem setTarget:self];
- if (tempCombo)
- {
+ if (tempCombo) {
[self setKeyEquivalentForCode:[tempCombo keyCode]
andModifiers:[tempCombo modifiers] onItem:playPauseMenuItem];
[tempCombo release];
keyEquivalent:@""];
[nextTrack setTarget:self];
- if (tempCombo)
- {
+ if (tempCombo) {
[self setKeyEquivalentForCode:[tempCombo keyCode]
andModifiers:[tempCombo modifiers] onItem:nextTrack];
[tempCombo release];
keyEquivalent:@""];
[prevTrack setTarget:self];
- if (tempCombo)
- {
+ if (tempCombo) {
[self setKeyEquivalentForCode:[tempCombo keyCode]
andModifiers:[tempCombo modifiers] onItem:prevTrack];
[tempCombo release];
[self rebuildEQPresetsMenu];
}
- if (trackInfoIndex > -1)
- {
+ if (trackInfoIndex > -1) {
NSString *curSongName, *curAlbumName = @"", *curArtistName = @"";
curSongName = [currentRemote currentSongTitle];
int curIndex = [currentRemote currentPlaylistIndex];
int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
+
if (!isPlayingRadio) {
if (numSongs > 0) {
int curTrack = [currentRemote currentSongIndex];
NSMenuItem *songItem;
songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""];
[songItem setTarget:self];
- [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
+ [songItem setRepresentedObject:[NSNumber numberWithInt:i + 1]];
[upcomingSongsMenu addItem:songItem];
[songItem release];
} else {
NSArray *playlists = [currentRemote playlists];
int i, curPlaylist = [currentRemote currentPlaylistIndex];
- if (isPlayingRadio)
- {
+ if (isPlayingRadio) {
curPlaylist = 0;
}
if (playlistMenu && ([playlists count] == [playlistMenu numberOfItems]))
NSMenuItem *tempItem;
tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
[tempItem setTarget:self];
- [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
+ [tempItem setRepresentedObject:[NSNumber numberWithInt:i + 1]];
[playlistMenu addItem:tempItem];
[tempItem release];
}
for (i = 0; i < [eqPresets count]; i++) {
NSString *setName = [eqPresets objectAtIndex:i];
NSMenuItem *tempItem;
+ if (setName) {
tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""];
[tempItem setTarget:self];
[tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
[eqMenu addItem:tempItem];
[tempItem release];
+ }
}
[eqItem setSubmenu:eqMenu];
//Called when the timer fires.
- (void)timerUpdate
{
+ NSLog(@"%i", [currentRemote playerState]);
if ([currentRemote playerState] != stopped) {
int trackPlayingIndex = [currentRemote currentSongIndex];
int playlist = [currentRemote currentPlaylistIndex];
if (trackPlayingIndex != lastSongIndex) {
- bool wasPlayingRadio = isPlayingRadio;
+ BOOL wasPlayingRadio = isPlayingRadio;
isPlayingRadio = [[currentRemote classOfPlaylistAtIndex:playlist] isEqualToString:@"radio tuner playlist"];
if (isPlayingRadio && !wasPlayingRadio) {
int i;
[menu insertItem:temp atIndex:trackInfoIndex + 1];
[temp release];
}
+
[self updateMenu];
lastSongIndex = trackPlayingIndex;
- }
- else
- {
+ } else {
if (playlist != [currentRemote currentPlaylistIndex]) {
- bool wasPlayingRadio = isPlayingRadio;
+ BOOL wasPlayingRadio = isPlayingRadio;
isPlayingRadio = [[currentRemote classOfPlaylistAtIndex:playlist] isEqualToString:@"radio tuner playlist"];
if (isPlayingRadio && !wasPlayingRadio) {
int i;
- for (i = 0; i < [playlistMenu numberOfItems]; i++)
- {
+ for (i = 0; i < [playlistMenu numberOfItems]; i++) {
[[playlistMenu itemAtIndex:i] setState:NSOffState];
}
}
- (void)showCurrentTrackInfo
{
NSString *trackName = [currentRemote currentSongTitle];
- if (!statusController && [trackName length]) {
+ if (!statusWindow && [trackName length]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *stringToShow = @"";
}
}
- statusController = [[StatusWindowController alloc] init];
- [statusController setTrackInfo:stringToShow];
+ [statusWindow setText:stringToShow];
[NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(fadeAndCloseStatusWindow)
- (void)showUpcomingSongs
{
int curPlaylist = [currentRemote currentPlaylistIndex];
- if (!statusController) {
+ if (!statusWindow) {
int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
if (numSongs > 0) {
int i;
NSString *songs = @"";
- statusController = [[StatusWindowController alloc] init];
+ statusWindow = [ITTransientStatusWindow sharedWindow];
for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
if (i <= numSongs) {
NSString *curSong = [currentRemote songTitleAtIndex:i];
songs = [songs stringByAppendingString:@"\n"];
}
}
- [statusController setUpcomingSongs:songs];
+ [statusWindow setText:songs];
[NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(fadeAndCloseStatusWindow)
- (void)fadeAndCloseStatusWindow
{
- [statusController fadeWindowOut];
- [statusController release];
- statusController = nil;
+ [statusWindow orderOut:self];
}
- (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
{ shiftKey, NSShiftKeyMask },
};
- for (i = 0; i < 6; i++)
- {
- if (modifiers & carbonToCocoa[i][0])
- {
+ for (i = 0; i < 6; i++) {
+ if (modifiers & carbonToCocoa[i][0]) {
cocoaModifiers += carbonToCocoa[i][1];
}
}
[super dealloc];
}
-@end
\ No newline at end of file
+@end