Fixed a problem with the time updating in the status window.
[MenuTunes.git] / MainController.m
index 7b008dd..201edef 100755 (executable)
@@ -1080,6 +1080,8 @@ static MainController *sharedController;
             NS_HANDLER
                 [self networkError:localException];
             NS_ENDHANDLER
+                       _timeUpdateCount = 0;
+                       [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
         }
 
         if ( [df boolForKey:@"showTrackNumber"] ) {
@@ -1136,6 +1138,26 @@ static MainController *sharedController;
                                                    image:art];
 }
 
+- (void)updateTime:(NSTimer *)timer
+{
+       StatusWindow *sw = [StatusWindow sharedWindow];
+       _timeUpdateCount++;
+       if (_timeUpdateCount < (int)[sw exitDelay] + (int)[[sw exitEffect] effectTime] + (int)[[sw entryEffect] effectTime]) {
+               NSString *time = nil;
+               NS_DURING
+                       time = [NSString stringWithFormat:@"%@: %@ / %@",
+                                               NSLocalizedString(@"time", @"Time"),
+                                               [[self currentRemote] currentSongElapsed],
+                                               [[self currentRemote] currentSongLength]];
+                       [[StatusWindowController sharedController] updateTime:time];
+               NS_HANDLER
+                       [self networkError:localException];
+               NS_ENDHANDLER
+       } else {
+               [timer invalidate];
+       }
+}
+
 - (void)showUpcomingSongs
 {
     int numSongs = 0;
@@ -1330,15 +1352,17 @@ static MainController *sharedController;
 
 - (void)toggleSongShufflable
 {
-       NS_DURING
-        BOOL flag = ![[self currentRemote] currentSongShufflable];
-        ITDebugLog(@"Toggling shufflability.");
-        [[self currentRemote] setCurrentSongShufflable:flag];
-        //Show song shufflability status window
-        //[statusWindowController showSongShuffabilityWindow:flag];
-    NS_HANDLER
-        [self networkError:localException];
-    NS_ENDHANDLER
+       if ([self songIsPlaying]) {
+               NS_DURING
+                       BOOL flag = ![[self currentRemote] currentSongShufflable];
+                       ITDebugLog(@"Toggling shufflability.");
+                       [[self currentRemote] setCurrentSongShufflable:flag];
+                       //Show song shufflability status window
+                       [statusWindowController showSongShufflabilityWindow:flag];
+               NS_HANDLER
+                       [self networkError:localException];
+               NS_ENDHANDLER
+       }
 }
 
 - (void)registerNowOK