File: GBThumbnailProvider.m

package info (click to toggle)
sameboy 1.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 10,528 kB
  • sloc: ansic: 29,948; objc: 22,249; asm: 1,424; pascal: 1,373; makefile: 1,065; xml: 111
file content (27 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (2)
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
#import "GBThumbnailProvider.h"

extern OSStatus GBQuickLookRender(CGContextRef cgContext, CFURLRef url, bool showBorder);

@interface QLThumbnailReply (private)
@property unsigned iconFlavor;
@end

@implementation GBThumbnailProvider

- (void)provideThumbnailForFileRequest:(QLFileThumbnailRequest *)request completionHandler:(void (^)(QLThumbnailReply *, NSError *))handler
{
    CGSize size = {64, 64};
    CGSize maximumSize = request.maximumSize;
    while (size.width <= maximumSize.width / 2 &&
           size.width <= maximumSize.height / 2) {
        size.width *= 2;
    }
    size.height = size.width;
    QLThumbnailReply *reply = [QLThumbnailReply replyWithContextSize:size drawingBlock: ^BOOL(CGContextRef context) {
        return !GBQuickLookRender(context, (__bridge CFURLRef)request.fileURL, true);
    }];
    reply.iconFlavor = 0;
    handler(reply, nil);
}

@end