Warning, /graphics/krita/krita/integration/quicklook/GeneratePreviewForURL.m is written in an unsupported language. File is not indexed.
0001 /*
0002 * This file is part of Krita
0003 *
0004 * Copyright (c) 2015 Algorithmus <angelus.tenebrae@gmail.com>
0005 * Copyright (c) 2015 beelzy <alvina.lee@innoactive.de>
0006 * Copyright (c) 2020 L. E. Segovia <amy@amyspark.me>
0007 *
0008 * This program is free software; you can redistribute it and/or modify
0009 * it under the terms of the GNU General Public License as published by
0010 * the Free Software Foundation; either version 2 of the License, or
0011 * (at your option) any later version.
0012 *
0013 * This program is distributed in the hope that it will be useful,
0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0016 * GNU General Public License for more details.
0017 *
0018 * You should have received a copy of the GNU General Public License
0019 * along with this program; if not, write to the Free Software
0020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0021 * USA.
0022 */
0023
0024 #include "UnzipTask.h"
0025 #import <Cocoa/Cocoa.h>
0026 #include <CoreFoundation/CoreFoundation.h>
0027 #include <CoreServices/CoreServices.h>
0028 #include <QuickLook/QuickLook.h>
0029
0030 OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
0031 CFURLRef url, CFStringRef contentTypeUTI,
0032 CFDictionaryRef options);
0033 void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview);
0034
0035 /* -----------------------------------------------------------------------------
0036 Generate a preview for file
0037
0038 This function's job is to create preview for designated file
0039 -----------------------------------------------------------------------------
0040 */
0041
0042 OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
0043 CFURLRef url, CFStringRef contentTypeUTI,
0044 CFDictionaryRef options) {
0045 @autoreleasepool {
0046 NSData *appPlist =
0047 UnzipTask([(__bridge NSURL *)url path], @"mergedimage.png");
0048
0049 if (QLPreviewRequestIsCancelled(preview)) {
0050 return noErr;
0051 }
0052
0053 if ([appPlist length]) {
0054 NSImage *appIcon = [[NSImage alloc] initWithData:appPlist];
0055
0056 NSImageRep *rep = [[appIcon representations] objectAtIndex:0];
0057
0058 NSSize canvasSize = NSMakeSize(rep.pixelsWide, rep.pixelsHigh);
0059 NSRect renderRect = NSMakeRect(0.0, 0.0, rep.pixelsWide, rep.pixelsHigh);
0060
0061 CGContextRef _context =
0062 QLPreviewRequestCreateContext(preview, canvasSize, true, NULL);
0063
0064 if (_context) {
0065 NSGraphicsContext *_graphicsContext =
0066 [NSGraphicsContext graphicsContextWithGraphicsPort:_context
0067 flipped:NO];
0068
0069 [NSGraphicsContext setCurrentContext:_graphicsContext];
0070 [appIcon drawInRect:renderRect];
0071
0072 QLPreviewRequestFlushContext(preview, _context);
0073 CFRelease(_context);
0074 }
0075
0076 return noErr;
0077 }
0078
0079 return NSFileNoSuchFileError;
0080 }
0081 }
0082
0083 void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) {
0084 // Implement only if supported
0085 }