From cf46d16a56444ff722f3641a5358ca78458b57a1 Mon Sep 17 00:00:00 2001 From: vspader Date: Mon, 3 Mar 2008 02:25:52 +0000 Subject: [PATCH] Remove concurrency! Mwahaha! Also, moved updateTotalTime so it's done after all operations. Now it's actually usable while loading time. --- Playlist/PlaylistController.m | 5 ----- Playlist/PlaylistLoader.m | 25 ++++++++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 89174987d..41ebe3265 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -73,7 +73,6 @@ [super awakeFromNib]; [self addObserver:self forKeyPath:@"arrangedObjects" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil]; - [self addObserver:self forKeyPath:@"arrangedObjects.length" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -83,10 +82,6 @@ [self updatePlaylistIndexes]; [self updateTotalTime]; } - else if ([keyPath isEqualToString:@"length"]) - { - [self updateTotalTime]; - } } - (void)updatePlaylistIndexes diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index 2edaeaaa5..eec7d8685 100755 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -267,28 +267,39 @@ //Select the first entry in the group that was just added [playlistController setSelectionIndex:index]; - + [self performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries]; +} + +- (void)loadInfoForEntries:(NSArray *)entries +{ NSOperationQueue *queue; queue = [[[NSApplication sharedApplication] delegate] sharedOperationQueue]; + NSInvocationOperation *oldReadEntryInfoOperation = Nil; for (PlaylistEntry *pe in entries) { NSInvocationOperation *readEntryInfoOperation; - readEntryInfoOperation = [[NSInvocationOperation alloc] + readEntryInfoOperation = [[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(readEntryInfo:) - object:pe]; - + object:pe]autorelease]; + if (oldReadEntryInfoOperation) + { + [readEntryInfoOperation addDependency:oldReadEntryInfoOperation]; + [oldReadEntryInfoOperation release]; + } [readEntryInfoOperation addObserver:self forKeyPath:@"isFinished" options:NSKeyValueObservingOptionNew context:NULL]; [queue addOperation:readEntryInfoOperation]; - - [readEntryInfoOperation release]; + oldReadEntryInfoOperation = [readEntryInfoOperation retain]; } + [oldReadEntryInfoOperation release]; - return; + [queue waitUntilAllOperationsAreFinished]; + + [playlistController performSelectorOnMainThread:@selector(updateTotalTime) withObject:nil waitUntilDone:NO]; } - (NSDictionary *)readEntryInfo:(PlaylistEntry *)pe