14OSStatus
GeneratePreviewForURL(
void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
16 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
19 NSDate *startDate = [NSDate date];
23 NSString *fullPath = (NSString*)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
26 NSLog(
@"GeneratePreviewForURL %@", fullPath);
30 if (QLPreviewRequestIsCancelled(preview)) {
36 NSMutableDictionary *props = [[[NSMutableDictionary alloc] init] autorelease];
37 [props setObject: @"UTF-8" forKey: (NSString *)kQLPreviewPropertyTextEncodingNameKey];
38 [props setObject: @"text/html" forKey: (NSString *)kQLPreviewPropertyMIMETypeKey];
40 [props setObject: [NSString stringWithFormat: @"Contents of %s", basename((char*)[fullPath UTF8String])] forKey: (NSString *)kQLPreviewPropertyDisplayNameKey];
43 NSMutableString *html = [[[NSMutableString alloc] init] autorelease];
44 [html appendString: @"<html>"];
45 [html appendString: @"<head><style type=\"text/css\">"];
46 [html appendString: @"body, td, th, p, div { font-family: Arial, Helvetica, sans-serif; font-size: 12px }"];
47 [html appendString: @"</style></head>"];
48 [html appendString: @"<body bgcolor=white>"];
51 if (
ReadFile(fullPath, html, preview) == -1) {
56 [html appendString: @"</body></html>"];
59 NSLog(
@"Scanned file %@ in %.3f sec",
60 fullPath, -[startDate timeIntervalSinceNow]);
64 if (QLPreviewRequestIsCancelled(preview)) {
70 QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)[html dataUsingEncoding: NSUTF8StringEncoding], kUTTypeHTML, (CFDictionaryRef)props);