2012-02-10 70 views
6

如何刪除在quicklook插件中創建的縮略圖的捲曲圖標?從qlgenerator中刪除捲曲的角落縮略圖

截圖當前圖標:enter image description here

截圖的我想要的東西:enter image description here

GeneratePreviewForURL.m:

#include <CoreFoundation/CoreFoundation.h> 
#include <CoreServices/CoreServices.h> 
#include <QuickLook/QuickLook.h> 

#import "GenerateIcon.h" 

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options); 
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview); 

/* ----------------------------------------------------------------------------- 
    Generate a preview for file 

    This function's job is to create preview for designated file 
    ----------------------------------------------------------------------------- */ 

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) 
{ 
    // To complete your generator please implement the function GeneratePreviewForURL in GeneratePreviewForURL.c 

    [GenerateIcon generatePreviewWithRef:preview URL:url]; 

    return noErr; 
} 

void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) 
{ 
    // Implement only if supported 
} 

GenerateIcon.m:

// 
// GenerateIcon.m 
// Windows Binary Icon 
// 
// Created by Asger Hautop Drewsen on 2/5/12. 
// Copyright (c) 2012 Asger Drewsen. All rights reserved. 
// 

#import "GenerateIcon.h" 

@implementation GenerateIcon 

+(void) generateThumbnailWithRef:(QLThumbnailRequestRef)requestRef URL:(CFURLRef)url 
{ 
    [GenerateIcon generateMultiWithThumbnailRef:requestRef PreviewRef:nil URL:url]; 
} 
+(void) generatePreviewWithRef:(QLPreviewRequestRef)requestRef URL:(CFURLRef)url 
{ 
    [GenerateIcon generateMultiWithThumbnailRef:nil PreviewRef:requestRef URL:url]; 
} 

    +(void) generateMultiWithThumbnailRef:(QLThumbnailRequestRef)thumbnail PreviewRef:(QLPreviewRequestRef)preview URL:(CFURLRef)url 
{ 
    @autoreleasepool { 

     NSString * tempDir = NSTemporaryDirectory(); 
     if (tempDir == nil) 
      tempDir = @"/tmp"; 

     NSFileManager *fileManager = [[NSFileManager alloc] init]; 

     NSString *directory = [tempDir stringByAppendingFormat: [NSString stringWithFormat:@"%@-%.0f", @"exe-icons", [NSDate timeIntervalSinceReferenceDate] * 1000.0]]; 

     //NSString *directory = [tempDir stringByAppendingPathComponent:@"com.tyilo.exe-icons"]; 

     /*for (NSString *file in [fileManager contentsOfDirectoryAtPath:directory error:nil]) 
     { 
     [fileManager removeItemAtPath:file error:nil]; 
     }*/ 

     [fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:nil]; 

     [[NSTask launchedTaskWithLaunchPath:@"/usr/local/bin/wrestool" arguments:[NSArray arrayWithObjects: 
                        @"-t", 
                        @"group_icon", 
                        @"-o", 
                        directory, 
                        @"-x", 
                        [(__bridge NSURL *)url path], 
                        nil]] waitUntilExit]; 

     NSArray *icons = [fileManager contentsOfDirectoryAtPath:directory error:nil]; 

     if (icons.count > 0) 
     { 
      NSImage *image = [[NSImage alloc] initWithContentsOfFile:[directory stringByAppendingPathComponent: [icons objectAtIndex:0]]]; 
      NSData *thumbnailData = [image TIFFRepresentation]; 
      CGSize size = image.size; 
      NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys: 
             [NSNumber numberWithInt:size.width],kQLPreviewPropertyWidthKey, 
             [NSNumber numberWithInt:size.height],kQLPreviewPropertyHeightKey, 
             nil]; 
      CGContextRef CGContext; 
      if (thumbnail) 
      { 
       CGContext = QLThumbnailRequestCreateContext(thumbnail, size, TRUE, (__bridge CFDictionaryRef)properties); 
      } 
      else 
      { 
       CGContext = QLPreviewRequestCreateContext(preview, size, TRUE, (__bridge CFDictionaryRef)properties); 
      } 
      if(CGContext) { 
       NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:(void *)CGContext flipped:size.width > size.height]; 
       if(context) { 
        //These two lines of code are just good safe programming… 
        [NSGraphicsContext saveGraphicsState]; 
        [NSGraphicsContext setCurrentContext:context]; 

        NSBitmapImageRep *thumbnailBitmap = [NSBitmapImageRep imageRepWithData:thumbnailData]; 
        [thumbnailBitmap draw]; 

        //This line sets the context back to what it was when we're done 
        [NSGraphicsContext restoreGraphicsState]; 
       } 

       // When we are done with our drawing code QLThumbnailRequestFlushContext() is called to flush the context 
       if (thumbnail) 
       { 
        QLThumbnailRequestFlushContext(thumbnail, CGContext); 
       } 
       else 
       { 
        QLPreviewRequestFlushContext(preview, CGContext); 
       } 

       // Release the CGContext 
       CFRelease(CGContext); 
      } 
      /*NSLog(@"%@", [directory stringByAppendingPathComponent: [icons objectAtIndex:0]]); 
      CGImageRef image = (__bridge CGImageRef) [[NSImage alloc] initByReferencingFile:[directory stringByAppendingPathComponent: [icons objectAtIndex:0]]]; 
      QLThumbnailRequestSetImage(thumbnail, image, properties);*/ 
     } 
     else 
     { 
      NSLog(@"Failed to generate thumbnail!"); 
     } 
    } 
} 

@end 

編輯:添加了屏幕截圖。

+0

您是否找到解決方案? – Mark 2014-11-13 14:59:34

+0

@Mark No我從來沒有。 – Tyilo 2014-11-13 15:38:59

回答

0

你的圖標的方面是由快速查看自動選擇,沒有公開的方式來定製它。你的類型一致性樹是什麼?請參閱Uniform Type Identifiers Overview。請注意,您的類型一致性樹不一定會轉換成您想要從Quick Look獲得的內容,但至少您會有一個理智的起點。

+1

我只是想去除捲曲的角落,我不知道你剛剛寫了什麼 – Tyilo 2012-02-10 01:01:22

+0

Quick Look生成的圖標的方面是從你的類型聲明(這包括例如放置一個捲曲的角落)推斷出來的。當你聲明你的UTI時,你需要指定你的類型一致性(UTTypeConformsTo)。我的問題是:你自己的類型符合什麼類型? – Julien 2012-02-10 01:14:05

+0

它目前符合'public.item',但它只適用於exe文件。我應該把它改成別的東西嗎? – Tyilo 2012-02-10 01:16:28

5

我來這個問題有點遲了!

您需要添加無證「IconFlavor」鍵的屬性字典,你提供給QLThumbnailRequestCreateContext()或QLThumbnailRequestSetXXX(),並給它一個最小的裝飾價值1。

查看here舉例。在該文件的頂部是我發現的「IconFlavour」的一些其他值。

+0

完美!你,先生,值得一枚獎牌。你是怎麼發現的?順便說一句,kQLThumbnailIconPlainFlavor對於exe圖標比kQLThumbnailIconShadowFlavor有更好的結果。 – vitormm 2016-05-24 14:14:38