forked from anthonygelibert/QLColorCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateThumbnailForURL.m
More file actions
54 lines (41 loc) · 1.79 KB
/
GenerateThumbnailForURL.m
File metadata and controls
54 lines (41 loc) · 1.79 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
@import Cocoa;
@import CoreFoundation;
@import QuickLook;
#import "Common.h"
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize);
void CancelThumbnailGeneration(void *thisInterface, QLThumbnailRequestRef thumbnail);
/* -----------------------------------------------------------------------------
Generate a thumbnail for file
This function's job is to create thumbnail for designated file as fast as possible
----------------------------------------------------------------------------- */
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{
@autoreleasepool {
NSStringEncoding usedEncoding = 0;
NSError *readError = nil;
[NSString stringWithContentsOfURL:(__bridge NSURL*)url usedEncoding:&usedEncoding error:&readError];
if (usedEncoding == 0) {
NSLog(@"Failed to determine encoding for file %@", [(__bridge NSURL*)url path]);
return noErr;
}
if (QLThumbnailRequestIsCancelled(thumbnail))
return noErr;
NSDictionary *previewProperties = @{
(NSString *)kQLPreviewPropertyStringEncodingKey : @( usedEncoding )
};
NSDictionary *properties = @{
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey : @"text/html"
};
QLThumbnailRequestSetThumbnailWithURLRepresentation(
thumbnail,
url,
kUTTypePlainText,
(__bridge CFDictionaryRef)previewProperties,
(__bridge CFDictionaryRef)properties);
return noErr;
}
}
void CancelThumbnailGeneration(void *thisInterface, QLThumbnailRequestRef thumbnail)
{
// Implement only if supported
}