Adding the new StatusWindow in rudimentary fashion. It builds with no warnings,...
[MenuTunes.git] / MenuTunes.m
index 1dd7df6..d03da70 100755 (executable)
@@ -10,7 +10,7 @@ Things to do:
 #import "MenuTunes.h"
 #import "PreferencesController.h"
 #import "HotKeyCenter.h"
 #import "MenuTunes.h"
 #import "PreferencesController.h"
 #import "HotKeyCenter.h"
-#import "StatusWindowController.h"
+#import "StatusWindow.h"
 
 @interface MenuTunes(Private)
 - (ITMTRemote *)loadRemote;
 
 @interface MenuTunes(Private)
 - (ITMTRemote *)loadRemote;
@@ -36,6 +36,7 @@ Things to do:
 {
     if ( ( self = [super init] ) ) {
         remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
 {
     if ( ( self = [super init] ) ) {
         remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
+        statusWindow = [StatusWindow sharedWindow];
     }
     return self;
 }
     }
     return self;
 }
@@ -53,17 +54,14 @@ Things to do:
     menu = [[NSMenu alloc] initWithTitle:@""];
     
     isAppRunning = [currentRemote isAppRunning];
     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];
         [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];
         menu = [[NSMenu alloc] initWithTitle:@""];
         [[menu addItemWithTitle:@"Open iTunes" action:@selector(openiTunes:) keyEquivalent:@""] setTarget:self];
         [[menu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
@@ -236,8 +234,7 @@ Things to do:
                                     keyEquivalent:@""];
             [playPauseMenuItem setTarget:self];
             
                                     keyEquivalent:@""];
             [playPauseMenuItem setTarget:self];
             
-            if (tempCombo)
-            {
+            if (tempCombo) {
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:playPauseMenuItem];
                 [tempCombo release];
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:playPauseMenuItem];
                 [tempCombo release];
@@ -249,8 +246,7 @@ Things to do:
                                         keyEquivalent:@""];
             
             [nextTrack setTarget:self];
                                         keyEquivalent:@""];
             
             [nextTrack setTarget:self];
-            if (tempCombo)
-            {
+            if (tempCombo) {
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:nextTrack];
                 [tempCombo release];
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:nextTrack];
                 [tempCombo release];
@@ -262,8 +258,7 @@ Things to do:
                                         keyEquivalent:@""];
             
             [prevTrack setTarget:self];
                                         keyEquivalent:@""];
             
             [prevTrack setTarget:self];
-            if (tempCombo)
-            {
+            if (tempCombo) {
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:prevTrack];
                 [tempCombo release];
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:prevTrack];
                 [tempCombo release];
@@ -334,8 +329,7 @@ Things to do:
         [self rebuildEQPresetsMenu];
     }
     
         [self rebuildEQPresetsMenu];
     }
     
-    if (trackInfoIndex > -1)
-    {
+    if (trackInfoIndex > -1) {
         NSString *curSongName, *curAlbumName = @"", *curArtistName = @"";
         curSongName = [currentRemote currentSongTitle];
         
         NSString *curSongName, *curAlbumName = @"", *curArtistName = @"";
         curSongName = [currentRemote currentSongTitle];
         
@@ -444,6 +438,7 @@ Things to do:
     int curIndex = [currentRemote currentPlaylistIndex];
     int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
     int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
     int curIndex = [currentRemote currentPlaylistIndex];
     int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
     int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
+    
     if (!isPlayingRadio) {
         if (numSongs > 0) {
             int curTrack = [currentRemote currentSongIndex];
     if (!isPlayingRadio) {
         if (numSongs > 0) {
             int curTrack = [currentRemote currentSongIndex];
@@ -479,8 +474,7 @@ Things to do:
     NSArray *playlists = [currentRemote playlists];
     int i, curPlaylist = [currentRemote currentPlaylistIndex];
     
     NSArray *playlists = [currentRemote playlists];
     int i, curPlaylist = [currentRemote currentPlaylistIndex];
     
-    if (isPlayingRadio)
-    {
+    if (isPlayingRadio) {
         curPlaylist = 0;
     }
     if (playlistMenu && ([playlists count] == [playlistMenu numberOfItems]))
         curPlaylist = 0;
     }
     if (playlistMenu && ([playlists count] == [playlistMenu numberOfItems]))
@@ -520,11 +514,13 @@ Things to do:
     for (i = 0; i < [eqPresets count]; i++) {
         NSString *setName = [eqPresets objectAtIndex:i];
         NSMenuItem *tempItem;
     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];
         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];
     
     }
     [eqItem setSubmenu:eqMenu];
     
@@ -578,6 +574,7 @@ Things to do:
 //Called when the timer fires.
 - (void)timerUpdate
 {
 //Called when the timer fires.
 - (void)timerUpdate
 {
+    NSLog(@"%i", [currentRemote playerState]);
     if ([currentRemote playerState] != stopped) {
         int trackPlayingIndex = [currentRemote currentSongIndex];
         int playlist = [currentRemote currentPlaylistIndex];
     if ([currentRemote playerState] != stopped) {
         int trackPlayingIndex = [currentRemote currentSongIndex];
         int playlist = [currentRemote currentPlaylistIndex];
@@ -597,18 +594,16 @@ Things to do:
                 [menu insertItem:temp atIndex:trackInfoIndex + 1];
                 [temp release];
             }
                 [menu insertItem:temp atIndex:trackInfoIndex + 1];
                 [temp release];
             }
+            
             [self updateMenu];
             lastSongIndex = trackPlayingIndex;
             [self updateMenu];
             lastSongIndex = trackPlayingIndex;
-        }
-        else
-        {
+        } else {
             if (playlist != [currentRemote currentPlaylistIndex]) {
                 BOOL wasPlayingRadio = isPlayingRadio;
                 isPlayingRadio = [[currentRemote classOfPlaylistAtIndex:playlist] isEqualToString:@"radio tuner playlist"];
                 if (isPlayingRadio && !wasPlayingRadio) {
                     int i;
             if (playlist != [currentRemote currentPlaylistIndex]) {
                 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];
                     }
                 }
                         [[playlistMenu itemAtIndex:i] setState:NSOffState];
                     }
                 }
@@ -774,7 +769,7 @@ Things to do:
 - (void)showCurrentTrackInfo
 {
     NSString *trackName = [currentRemote currentSongTitle];
 - (void)showCurrentTrackInfo
 {
     NSString *trackName = [currentRemote currentSongTitle];
-    if (!statusController && [trackName length]) {
+    if (!statusWindow && [trackName length]) {
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         NSString *stringToShow = @"";
         
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         NSString *stringToShow = @"";
         
@@ -814,8 +809,7 @@ Things to do:
             }
         }
         
             }
         }
         
-        statusController = [[StatusWindowController alloc] init];
-        [statusController setTrackInfo:stringToShow];
+        [statusWindow setText:stringToShow];
         [NSTimer scheduledTimerWithTimeInterval:3.0
                                     target:self
                                     selector:@selector(fadeAndCloseStatusWindow)
         [NSTimer scheduledTimerWithTimeInterval:3.0
                                     target:self
                                     selector:@selector(fadeAndCloseStatusWindow)
@@ -827,7 +821,7 @@ Things to do:
 - (void)showUpcomingSongs
 {
     int curPlaylist = [currentRemote currentPlaylistIndex];
 - (void)showUpcomingSongs
 {
     int curPlaylist = [currentRemote currentPlaylistIndex];
-    if (!statusController) {
+    if (!statusWindow) {
         int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
         
         if (numSongs > 0) {
         int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
         
         if (numSongs > 0) {
@@ -836,7 +830,7 @@ Things to do:
             int i;
             NSString *songs = @"";
             
             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];
             for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
                 if (i <= numSongs) {
                     NSString *curSong = [currentRemote songTitleAtIndex:i];
@@ -844,7 +838,7 @@ Things to do:
                     songs = [songs stringByAppendingString:@"\n"];
                 }
             }
                     songs = [songs stringByAppendingString:@"\n"];
                 }
             }
-            [statusController setUpcomingSongs:songs];
+            [statusWindow setText:songs];
             [NSTimer scheduledTimerWithTimeInterval:3.0
                         target:self
                         selector:@selector(fadeAndCloseStatusWindow)
             [NSTimer scheduledTimerWithTimeInterval:3.0
                         target:self
                         selector:@selector(fadeAndCloseStatusWindow)
@@ -856,9 +850,7 @@ Things to do:
 
 - (void)fadeAndCloseStatusWindow
 {
 
 - (void)fadeAndCloseStatusWindow
 {
-    [statusController fadeWindowOut];
-    [statusController release];
-    statusController = nil;
+    [statusWindow orderOut:self];
 }
 
 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
 }
 
 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
@@ -875,10 +867,8 @@ Things to do:
         { shiftKey, NSShiftKeyMask },
     };
     
         { 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];
         }
     }
             cocoaModifiers += carbonToCocoa[i][1];
         }
     }
@@ -1069,4 +1059,4 @@ Things to do:
     [super dealloc];
 }
 
     [super dealloc];
 }
 
-@end
\ No newline at end of file
+@end