-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathGeneratePreviewForURL.c
38 lines (30 loc) · 1.22 KB
/
GeneratePreviewForURL.c
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
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>
#include "quicklooknfo.h"
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
if (QLPreviewRequestIsCancelled(preview))
return noErr;
CFDataRef data = createHTMLPreview( url );
if (!data || QLPreviewRequestIsCancelled(preview)) {
if (data)
CFRelease(data);
return noErr;
}
CFStringRef keys[1];
CFStringRef values[1];
values[0] = CFStringCreateWithCString(NULL, "UTF-8", kCFStringEncodingUTF8);
keys[0] = kQLPreviewPropertyTextEncodingNameKey;
CFDictionaryRef properties = CFDictionaryCreate(NULL, (const void **) &keys, (const void **) &values, 1, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)data,
kUTTypeHTML,
properties);
CFRelease(data);
CFRelease(values[0]);
CFRelease(properties);
return noErr;
}
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
{
}