Updated playlistLoader to be CONCURRENT! Mwahahaha!

total time is now automatically updated by observing PlaylistController.arrangedObjects.length
CQTexperiment
vspader 2008-03-03 02:09:56 +00:00
parent 6a4b661208
commit 276176a80c
2 changed files with 13 additions and 12 deletions

View File

@ -73,15 +73,20 @@
[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
{
if ([keyPath isEqualToString:@"arrangedObjects"])
if ([keyPath isEqualToString:@"arrangedObjects"])
{
[self updatePlaylistIndexes];
[self updateTotalTime];
}
else if ([keyPath isEqualToString:@"length"])
{
[self updateTotalTime];
}
}
- (void)updatePlaylistIndexes

View File

@ -271,27 +271,23 @@
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]autorelease];
if (oldReadEntryInfoOperation)
{
[readEntryInfoOperation addDependency:oldReadEntryInfoOperation];
[oldReadEntryInfoOperation release];
}
object:pe];
[readEntryInfoOperation addObserver:self
forKeyPath:@"isFinished"
options:NSKeyValueObservingOptionNew
context:NULL];
[queue addOperation:readEntryInfoOperation];
oldReadEntryInfoOperation = [readEntryInfoOperation retain];
[readEntryInfoOperation release];
}
[oldReadEntryInfoOperation release];
return;
}
@ -323,7 +319,6 @@
else
{
[pe setValuesForKeysWithDictionary:entryInfo];
[playlistController updateTotalTime];
}
return;
}
@ -339,6 +334,7 @@
// stop observing
[object removeObserver:self forKeyPath:keyPath];
[self performSelectorOnMainThread:@selector(processEntryInfo:) withObject:object waitUntilDone:NO];
}
else
{