forked from n8gray/QLColorCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratePreviewForURL.m
More file actions
55 lines (45 loc) · 1.89 KB
/
GeneratePreviewForURL.m
File metadata and controls
55 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* This code is licensed under the GPL v2. See LICENSE.txt for details. */
#import <CoreFoundation/CoreFoundation.h>
#import <CoreServices/CoreServices.h>
#import <Foundation/Foundation.h>
#import <QuickLook/QuickLook.h>
#import "Common.h"
/* -----------------------------------------------------------------------------
Generate a preview for file
This function's job is to create preview for designated file
----------------------------------------------------------------------------- */
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options)
{
NSDate *startDate = [NSDate date];
n8log(@"Generating Preview");
if (QLPreviewRequestIsCancelled(preview))
return noErr;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Invoke colorize.sh
CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview);
int status;
NSData *output = colorizeURL(bundle, url, &status, 0);
n8log(@"Generated preview html page in %.3f sec", -[startDate timeIntervalSinceNow] );
if (status != 0 || QLPreviewRequestIsCancelled(preview)) {
#ifndef DEBUG
goto done;
#endif
}
// Now let WebKit do its thing
CFDictionaryRef emptydict =
(CFDictionaryRef)[[[NSDictionary alloc] init] autorelease];
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)output,
//kUTTypePlainText,
kUTTypeHTML,
emptydict);
done:
n8log(@"Finished preview in %.3f sec", -[startDate timeIntervalSinceNow] );
[pool release];
return noErr;
}
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
{
// implement only if supported
}