Fixed Spotlight import.

CQTexperiment
matthewleon 2008-02-18 16:55:31 +00:00
parent d23b6b4ee5
commit aa3b716e09
6 changed files with 37 additions and 3 deletions

View File

@ -41,6 +41,8 @@
- (void)setShuffleIndex:(NSNumber *)si;
- (NSNumber *)shuffleIndex;
// Hack for KVC compliance
- (void)setUrl:(NSURL *)u;
- (void)setURL:(NSURL *)u;
- (NSURL *)url;
- (void)setCurrent:(NSNumber *) b;

View File

@ -98,6 +98,13 @@
return idx;
}
// Hack for kvc compliance - fix this
-(void)setUrl:(NSURL *)u
{
[self setURL:u];
}
-(void)setURL:(NSURL *)u
{
[u retain];

View File

@ -19,7 +19,7 @@ static NSDictionary *importKeys;
{
// We need to translate the path string to a full URL
NSArray *URLTransform =
[NSArray arrayWithObjects:@"URL", @"StringToURLTransformer", nil];
[NSArray arrayWithObjects:@"url", @"PathToURLTransformer", nil];
// Extract the artist name from the authors array
NSArray *artistTransform =
@ -62,8 +62,7 @@ static NSDictionary *importKeys;
[NSValueTransformer valueTransformerForName:[importTarget objectAtIndex:1]];
id transformedValue = [transformer transformedValue:
[songAttributes objectForKey:mdKey]];
[entry setValue: transformedValue
forKey: importKey];
[entry setValue:transformedValue forKey: importKey];
}
// The importKeys dictionary contains something strange...
else

View File

@ -20,4 +20,8 @@
@interface AuthorToArtistTransformer: NSValueTransformer {}
@end
@interface PathToURLTransformer: NSValueTransformer {}
@end

View File

@ -48,5 +48,25 @@ static SpotlightWindowController * searchController;
- (id)transformedValue:(id)value {
return [value objectAtIndex:0];
}
@end
@implementation PathToURLTransformer
+ (Class)transformedValueClass { return [NSURL class]; }
+ (BOOL)allowsReverseTransformation { return YES; }
// Convert from path to NSURL
- (id)transformedValue:(id)value {
if (value == nil) return nil;
return [NSURL fileURLWithPath:value];
}
// Convert from NSURL to path
- (id)reverseTransformedValue:(id)value {
if (value == nil) return nil;
return [value path];
}
@end

View File

@ -44,6 +44,8 @@ static NSPredicate * musicOnlyPredicate = nil;
[NSValueTransformer setValueTransformer:pausingQueryTransformer forName:@"PausingQueryTransformer"];
NSValueTransformer *authorToArtistTransformer = [[[AuthorToArtistTransformer alloc]init]autorelease];
[NSValueTransformer setValueTransformer:authorToArtistTransformer forName:@"AuthorToArtistTransformer"];
NSValueTransformer *pathToURLTransformer = [[[PathToURLTransformer alloc]init]autorelease];
[NSValueTransformer setValueTransformer:pathToURLTransformer forName:@"PathToURLTransformers"];
}
- (id)init