Implemented time ticking in song info status window.
authorKent Sutherland <ksuther@ithinksw.com>
Tue, 13 Sep 2005 03:35:54 +0000 (03:35 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Tue, 13 Sep 2005 03:35:54 +0000 (03:35 +0000)
More fixes to the new playlist implementation.

MainController.h
MainController.m
MenuController.m
StatusWindow.h
StatusWindow.m
StatusWindowController.h
StatusWindowController.m

index 36323bc..5fb00ec 100755 (executable)
@@ -46,6 +46,7 @@
     NSTimer *registerTimer;
     BOOL timerUpdating, _checkingForServer, _popped, _open, _needsPolling;
     BOOL blinged;
     NSTimer *registerTimer;
     BOOL timerUpdating, _checkingForServer, _popped, _open, _needsPolling;
     BOOL blinged;
+       int _timeUpdateCount; //Keeps track of how many times the time has been updated in the info status window
     NSLock *_serverCheckLock;
 }
 + (MainController *)sharedController;
     NSLock *_serverCheckLock;
 }
 + (MainController *)sharedController;
index 7b008dd..9a8b493 100755 (executable)
@@ -1080,6 +1080,8 @@ static MainController *sharedController;
             NS_HANDLER
                 [self networkError:localException];
             NS_ENDHANDLER
             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"] ) {
         }
 
         if ( [df boolForKey:@"showTrackNumber"] ) {
@@ -1136,6 +1138,23 @@ static MainController *sharedController;
                                                    image:art];
 }
 
                                                    image:art];
 }
 
+- (void)updateTime:(NSTimer *)timer
+{
+       _timeUpdateCount++;
+       if (_timeUpdateCount > (int)[df floatForKey:@"statusWindowVanishDelay"] - 1) {
+               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
+       }
+}
+
 - (void)showUpcomingSongs
 {
     int numSongs = 0;
 - (void)showUpcomingSongs
 {
     int numSongs = 0;
index 50ffb98..7c418be 100755 (executable)
                        [tempItem setTag:p + [nextNode index] + 1];
                        [tempItem setTarget:self];
                }
                        [tempItem setTag:p + [nextNode index] + 1];
                        [tempItem setTarget:self];
                }
+               
+               PlaylistNode *root = node;
+               while ([root type] == ITMTPlaylistNode || [root type] == ITMTFolderNode) {
+                       root = [root parent];
+               }
+               
+               if ([root index] == [[[MainController sharedController] currentRemote] currentSourceIndex] && [nextNode index] == _currentPlaylist) {
+                       [tempItem setState:NSOnState];
+               }
        }
 }
 
        }
 }
 
         }
                
                //Add other sources as needed (shared music, iPods, CDs)
         }
                
                //Add other sources as needed (shared music, iPods, CDs)
-        for (i = 2; i < [playlists count]; i++) {
+        for (i = [playlists count] - 1; i > 1 ; i--) {
             PlaylistNode *nextSource = [playlists objectAtIndex:i];
             if ([nextSource type] != ITMTRemoteRadioSource) {
                 NSString *name = [nextSource name];
             PlaylistNode *nextSource = [playlists objectAtIndex:i];
             if ([nextSource type] != ITMTRemoteRadioSource) {
                 NSString *name = [nextSource name];
             }
         }
     }
             }
         }
     }
-    ITDebugLog(@"Checking the current source.");
        NS_DURING
        if (_currentPlaylist != -1) {
                if ( (source == ITMTRemoteSharedLibrarySource) || (source == ITMTRemoteiPodSource) || (source == ITMTRemoteGenericDeviceSource) || (source == ITMTRemoteCDSource) ) {
                        tempItem = [playlistsMenu itemAtIndex:[playlistsMenu numberOfItems] + [indices indexOfObject:[NSNumber numberWithInt:[[[MainController sharedController] currentRemote] currentSourceIndex]]] - [indices count]];
                        [tempItem setState:NSOnState];
        NS_DURING
        if (_currentPlaylist != -1) {
                if ( (source == ITMTRemoteSharedLibrarySource) || (source == ITMTRemoteiPodSource) || (source == ITMTRemoteGenericDeviceSource) || (source == ITMTRemoteCDSource) ) {
                        tempItem = [playlistsMenu itemAtIndex:[playlistsMenu numberOfItems] + [indices indexOfObject:[NSNumber numberWithInt:[[[MainController sharedController] currentRemote] currentSourceIndex]]] - [indices count]];
                        [tempItem setState:NSOnState];
-                       [[[tempItem submenu] itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
-               } else if (source == ITMTRemoteLibrarySource && _currentPlaylist) {
-                       [[playlistsMenu itemAtIndex:_currentPlaylist - 2] setState:NSOnState];
                }
        }
        NS_HANDLER
                }
        }
        NS_HANDLER
index 7bc9762..d44de93 100755 (executable)
@@ -21,6 +21,7 @@
 @interface StatusWindow : ITTransientStatusWindow {
     NSImage            *_image;
     BOOL                _locked;
 @interface StatusWindow : ITTransientStatusWindow {
     NSImage            *_image;
     BOOL                _locked;
+       NSTextField                *_textField;
 }
 
 - (void)setImage:(NSImage *)newImage;
 }
 
 - (void)setImage:(NSImage *)newImage;
@@ -37,5 +38,6 @@
                               target:(id)target
                        defaultAction:(SEL)okAction
                      alternateAction:(SEL)alternateAction;
                               target:(id)target
                        defaultAction:(SEL)okAction
                      alternateAction:(SEL)alternateAction;
-                         
+
+- (void)updateTime:(NSString *)time range:(NSRange)range;
 @end
 @end
index 0fdc52d..6e4768f 100755 (executable)
         
 //      Display the window.
         [[self contentView] setNeedsDisplay:YES];
         
 //      Display the window.
         [[self contentView] setNeedsDisplay:YES];
-
+               _textField = textField;
     }
 }
 
     }
 }
 
     }
 }
 
     }
 }
 
+- (void)updateTime:(NSString *)time range:(NSRange)range
+{
+       NSMutableAttributedString *string = [[_textField attributedStringValue] mutableCopy];
+       [string replaceCharactersInRange:range withString:time];
+       [_textField setAttributedStringValue:[string autorelease]];
+       [[self contentView] setNeedsDisplay:YES];
+}
+
 - (NSTimeInterval)animationResizeTime:(NSRect)newFrame
 {
     return (NSTimeInterval)0.25;
 - (NSTimeInterval)animationResizeTime:(NSRect)newFrame
 {
     return (NSTimeInterval)0.25;
index c5a4566..b192d36 100755 (executable)
@@ -27,6 +27,7 @@ typedef enum {
 @interface StatusWindowController : NSObject {
     StatusWindow   *_window;
     NSUserDefaults *df;
 @interface StatusWindowController : NSObject {
     StatusWindow   *_window;
     NSUserDefaults *df;
+       NSRange _timeRange;
 }
 
 + (StatusWindowController *)sharedController;
 }
 
 + (StatusWindowController *)sharedController;
@@ -55,5 +56,6 @@ typedef enum {
                            playCount:                   (int)playCount
                                image:             (NSImage *)art;
 
                            playCount:                   (int)playCount
                                image:             (NSImage *)art;
 
+- (void)updateTime:(NSString *)time;
 
 @end
 
 @end
index e06176f..269681d 100755 (executable)
@@ -153,6 +153,7 @@ static StatusWindowController *sharedController;
         //text = [text stringByAppendingString:[@"\n" stringByAppendingString:composer]];
     }
     if ( time ) {
         //text = [text stringByAppendingString:[@"\n" stringByAppendingString:composer]];
     }
     if ( time ) {
+               _timeRange = NSMakeRange([[text mutableString] length] + 1, [time length]);
                [[text mutableString] appendFormat:@"\n%@", time];
         //text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
     }
                [[text mutableString] appendFormat:@"\n%@", time];
         //text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
     }
@@ -353,4 +354,11 @@ static StatusWindowController *sharedController;
        [_window setLocked:YES];
 }
 
        [_window setLocked:YES];
 }
 
+- (void)updateTime:(NSString *)time
+{
+       if (time && [time length]) {
+               [_window updateTime:time range:_timeRange];
+       }
+}
+
 @end
\ No newline at end of file
 @end
\ No newline at end of file