#import <QuickLook/QLThumbnailImage.h>
@implementation NSImage (NSImageAdditions)
+(NSImage *) quicklookIconForURL:(NSURL *)url ofSize:(NSSize)aSize iconMode:(BOOL)iconMode
{
NSImage *image = nil;
if( url && [[NSFileManager defaultManager] fileExistsAtPath:[url path]] )
{
CFMutableDictionaryRef options;
if( iconMode )
{
options = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, NULL, NULL );
CFDictionaryAddValue( options, kQLThumbnailOptionIconModeKey, kCFBooleanTrue );
}
if( NSEqualSizes( aSize, NSZeroSize ) )
aSize = NSMakeSize( 128.0, 128.0 );
CGImageRef thumbnailRef = QLThumbnailImageCreate( kCFAllocatorDefault, (CFURLRef)url, NSSizeToCGSize( aSize ), options );
if( thumbnailRef )
{
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:thumbnailRef];
image = [[[NSImage alloc] init] autorelease];
[image addRepresentation:imageRep];
[imageRep release];
CFRelease( thumbnailRef );
}
if( options )
CFRelease( options );
}
return( image );
}
@end