Warning, /graphics/krita/krita/integration/quicklookng/ThumbnailProvider.swift is written in an unsupported language. File is not indexed.
0001 /*
0002 * This file is part of Krita
0003 *
0004 * Copyright (c) 2020 L. E. Segovia <amy@amyspark.me>
0005 *
0006 * This program is free software; you can redistribute it and/or modify
0007 * it under the terms of the GNU General Public License as published by
0008 * the Free Software Foundation; either version 2 of the License, or
0009 * (at your option) any later version.
0010 *
0011 * This program is distributed in the hope that it will be useful,
0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0014 * GNU General Public License for more details.
0015 *
0016 * You should have received a copy of the GNU General Public License
0017 * along with this program; if not, write to the Free Software
0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0019 * USA.
0020 */
0021
0022 import AppKit
0023 import QuickLookThumbnailing
0024
0025 class ThumbnailProvider: QLThumbnailProvider {
0026
0027 override func provideThumbnail(for request: QLFileThumbnailRequest, _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) {
0028
0029 // There are three ways to provide a thumbnail through a QLThumbnailReply. Only one of them should be used.
0030
0031 // First way: Draw the thumbnail into the current context, set up with UIKit's coordinate system.
0032 /* handler(QLThumbnailReply(contextSize: request.maximumSize, currentContextDrawing: { () -> Bool in
0033 // Draw the thumbnail here.
0034
0035 // Return true if the thumbnail was successfully drawn inside this block.
0036 return true
0037 }), nil) */
0038
0039
0040
0041 // Second way: Draw the thumbnail into a context passed to your block, set up with Core Graphics's coordinate system.
0042 handler(QLThumbnailReply(contextSize: request.maximumSize, drawing: { (context: CGContext) -> Bool in
0043 // Draw the thumbnail here.
0044
0045 var appPlist = UnzipTask(request.fileURL.path, "preview.png")
0046
0047 // Not made with Krita. Find ORA thumbnail instead.
0048 if (appPlist == nil || appPlist!.isEmpty) {
0049 appPlist =
0050 UnzipTask(request.fileURL.path, "Thumbnails/thumbnail.png");
0051 }
0052
0053 if (appPlist != nil && !appPlist!.isEmpty) {
0054 let appIcon = NSImage.init(data: appPlist!);
0055
0056 let rep = appIcon!.representations.first!;
0057
0058 var renderRect = NSMakeRect(0.0, 0.0, CGFloat(rep.pixelsWide), CGFloat(rep.pixelsHigh));
0059
0060 let cgImage = appIcon?.cgImage(forProposedRect: &renderRect, context: nil, hints: nil);
0061
0062 context.draw(cgImage!, in: renderRect);
0063 } else {
0064 return false;
0065 }
0066
0067 // Return true if the thumbnail was successfully drawn inside this block.
0068 return true
0069 }), nil)
0070
0071 // Third way: Set an image file URL.
0072 /* handler(QLThumbnailReply(imageFileURL: Bundle.main.url(forResource: "fileThumbnail", withExtension: "jpg")!), nil) */
0073 }
0074 }