From 9e8173bc74fce7d0849ec423f71a63083ffdd25a Mon Sep 17 00:00:00 2001 From: matthewleon Date: Fri, 29 Feb 2008 21:54:09 +0000 Subject: [PATCH] PlaylistEntry cleanup. --- Playlist/PlaylistEntry.h | 7 +++- Playlist/PlaylistEntry.m | 63 ++++++++++++++---------------- Spotlight/SpotlightPlaylistEntry.m | 6 +++ 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/Playlist/PlaylistEntry.h b/Playlist/PlaylistEntry.h index e6506ab4c..3e679a08a 100644 --- a/Playlist/PlaylistEntry.h +++ b/Playlist/PlaylistEntry.h @@ -42,9 +42,12 @@ typedef enum { BOOL seekable; } -- (void)setMetadata: (NSDictionary *)m; ++ (NSSet *)keyPathsForValuesAffectingDisplay; ++ (NSSet *)keyPathsForValuesAffectingLength; ++ (NSSet *)keyPathsForValuesAffectingPath; ++ (NSSet *)keyPathsForValuesAffectingFilename; + - (void)readMetadataThread; -- (void)setProperties: (NSDictionary *)p; - (void)readPropertiesThread; @property(readonly) NSString *display; diff --git a/Playlist/PlaylistEntry.m b/Playlist/PlaylistEntry.m index 230510c73..2ecea70d3 100644 --- a/Playlist/PlaylistEntry.m +++ b/Playlist/PlaylistEntry.m @@ -22,7 +22,6 @@ @synthesize artist; @synthesize album; -@synthesize title; @synthesize genre; @synthesize year; @synthesize track; @@ -35,21 +34,26 @@ @synthesize seekable; -+ (void)initialize { - [self setKeys:[NSArray arrayWithObjects:@"artist",@"title",nil] triggerChangeNotificationsForDependentKey:@"display"]; - [self setKeys:[NSArray arrayWithObjects:@"totalFrames",nil] triggerChangeNotificationsForDependentKey:@"length"]; - [self setKeys:[NSArray arrayWithObjects:@"URL",nil] triggerChangeNotificationsForDependentKey:@"path"]; - [self setKeys:[NSArray arrayWithObjects:@"URL",nil] triggerChangeNotificationsForDependentKey:@"filename"]; +// The following read-only keys depend on the values of other properties + ++ (NSSet *)keyPathsForValuesAffectingDisplay +{ + return [NSSet setWithObjects:@"artist",@"title",nil]; } -- (void)setProperties:(NSDictionary *)dict ++ (NSSet *)keyPathsForValuesAffectingLength { - [self setTotalFrames: [[dict objectForKey:@"totalFrames" ] longLongValue]]; - [self setBitrate: [[dict objectForKey:@"bitrate" ] intValue]]; - [self setChannels: [[dict objectForKey:@"channels" ] intValue]]; - [self setBitsPerSample: [[dict objectForKey:@"bitsPerSample" ] intValue]]; - [self setSampleRate: [[dict objectForKey:@"sampleRate" ] floatValue]]; - [self setSeekable: [[dict objectForKey:@"seekable" ] boolValue]]; + return [NSSet setWithObject:@"totalFrames"]; +} + ++ (NSSet *)keyPathsForValuesAffectingPath +{ + return [NSSet setWithObject:@"URL"]; +} + ++ (NSSet *)keyPathsForValuesAffectingFilename +{ + return [NSSet setWithObject:@"URL"]; } - (void)readPropertiesThread @@ -62,32 +66,14 @@ return; } - [self performSelectorOnMainThread:@selector(setProperties:) withObject:properties waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(setValuesForKeysWithDictionary:) withObject:properties waitUntilDone:YES]; } -- (void)setMetadata: (NSDictionary *)m -{ - NSString *ti = [m objectForKey:@"title"]; - - if (ti == nil || [ti isEqualToString:@""]) { - self.title = [[self.URL path] lastPathComponent]; - } - else { - self.title = ti; - } - - self.artist = [m objectForKey:@"artist"]; - self.album = [m objectForKey:@"album"]; - self.genre = [m objectForKey:@"genre"]; - self.year = [m objectForKey:@"year"]; - self.track = [m objectForKey:@"track"]; -} - - (void)readMetadataThread { NSDictionary *metadata = [AudioMetadataReader metadataForURL:self.URL]; - [self performSelectorOnMainThread:@selector(setMetadata:) withObject:metadata waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(setValuesForKeysWithDictionary:) withObject:metadata waitUntilDone:YES]; } @@ -105,6 +91,17 @@ } } +// Get the URL if the title is blank +@synthesize title; +- (NSString *)title +{ + if(self.URL && (title == nil || [title isEqualToString:@""])) + { + return [[self.URL path] lastPathComponent]; + } + return [[title retain] autorelease]; +} + @dynamic length; - (NSNumber *)length { diff --git a/Spotlight/SpotlightPlaylistEntry.m b/Spotlight/SpotlightPlaylistEntry.m index aef362ed3..af2af31ca 100644 --- a/Spotlight/SpotlightPlaylistEntry.m +++ b/Spotlight/SpotlightPlaylistEntry.m @@ -75,6 +75,12 @@ static NSDictionary *importKeys; return entry; } +// Length is no longer a dependent key ++ (NSSet *)keyPathsForValuesAffectingLength +{ + return Nil; +} + @synthesize length; @end \ No newline at end of file