From 8cd402b5d3e43c95046af7ac0e4cb3cde2d622bc Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Tue, 13 Sep 2005 03:35:54 +0000 Subject: [PATCH] Implemented time ticking in song info status window. More fixes to the new playlist implementation. --- MainController.h | 1 + MainController.m | 19 +++++++++++++++++++ MenuController.m | 15 ++++++++++----- StatusWindow.h | 4 +++- StatusWindow.m | 10 +++++++++- StatusWindowController.h | 2 ++ StatusWindowController.m | 8 ++++++++ 7 files changed, 52 insertions(+), 7 deletions(-) diff --git a/MainController.h b/MainController.h index 36323bc..5fb00ec 100755 --- a/MainController.h +++ b/MainController.h @@ -46,6 +46,7 @@ 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; diff --git a/MainController.m b/MainController.m index 7b008dd..9a8b493 100755 --- a/MainController.m +++ b/MainController.m @@ -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,23 @@ static MainController *sharedController; 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; diff --git a/MenuController.m b/MenuController.m index 50ffb98..7c418be 100755 --- a/MenuController.m +++ b/MenuController.m @@ -700,6 +700,15 @@ [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]; + } } } @@ -746,7 +755,7 @@ } //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]; @@ -765,15 +774,11 @@ } } } - 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]; - [[[tempItem submenu] itemAtIndex:_currentPlaylist - 1] setState:NSOnState]; - } else if (source == ITMTRemoteLibrarySource && _currentPlaylist) { - [[playlistsMenu itemAtIndex:_currentPlaylist - 2] setState:NSOnState]; } } NS_HANDLER diff --git a/StatusWindow.h b/StatusWindow.h index 7bc9762..d44de93 100755 --- a/StatusWindow.h +++ b/StatusWindow.h @@ -21,6 +21,7 @@ @interface StatusWindow : ITTransientStatusWindow { NSImage *_image; BOOL _locked; + NSTextField *_textField; } - (void)setImage:(NSImage *)newImage; @@ -37,5 +38,6 @@ target:(id)target defaultAction:(SEL)okAction alternateAction:(SEL)alternateAction; - + +- (void)updateTime:(NSString *)time range:(NSRange)range; @end diff --git a/StatusWindow.m b/StatusWindow.m index 0fdc52d..6e4768f 100755 --- a/StatusWindow.m +++ b/StatusWindow.m @@ -256,7 +256,7 @@ // Display the window. [[self contentView] setNeedsDisplay:YES]; - + _textField = textField; } } @@ -491,6 +491,14 @@ } } +- (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; diff --git a/StatusWindowController.h b/StatusWindowController.h index c5a4566..b192d36 100755 --- a/StatusWindowController.h +++ b/StatusWindowController.h @@ -27,6 +27,7 @@ typedef enum { @interface StatusWindowController : NSObject { StatusWindow *_window; NSUserDefaults *df; + NSRange _timeRange; } + (StatusWindowController *)sharedController; @@ -55,5 +56,6 @@ typedef enum { playCount: (int)playCount image: (NSImage *)art; +- (void)updateTime:(NSString *)time; @end diff --git a/StatusWindowController.m b/StatusWindowController.m index e06176f..269681d 100755 --- a/StatusWindowController.m +++ b/StatusWindowController.m @@ -153,6 +153,7 @@ static StatusWindowController *sharedController; //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]]; } @@ -353,4 +354,11 @@ static StatusWindowController *sharedController; [_window setLocked:YES]; } +- (void)updateTime:(NSString *)time +{ + if (time && [time length]) { + [_window updateTime:time range:_timeRange]; + } +} + @end \ No newline at end of file -- 2.20.1