2012-02-10 11 views
6

¿Cómo elimino el icono curvado una miniatura crear en un complemento quicklook?Eliminar esquina rizada de qlgenerator miniatura

Captura de pantalla del icono actual: enter image description here

Captura de pantalla de lo que quiero: 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 

Edición: Capturas de pantalla añadidas.

+0

¿Encontró una solución para esto? – Mark

+0

@Mark No, nunca lo hice. – Tyilo

Respuesta

0

El aspecto de sus iconos se elige automáticamente por Vista rápida y no hay forma pública de personalizarlo. ¿Cuál es su árbol de conformidad de tipo?

Para obtener más información sobre las infecciones urinarias, vea Uniform Type Identifiers Overview. Tenga en cuenta que su árbol de conformidad de tipo no se traducirá necesariamente a lo que desea de Vista rápida, pero al menos tendrá un punto de partida sensato.

+1

Solo quiero quitar las esquinas rizadas y no tengo idea de lo que acaba de escribir – Tyilo

+0

El aspecto de los iconos producidos por Quick Look se deduce de su declaración de tipo (esto incluye si colocar una esquina curvada, por ejemplo). Cuando declara su UTI, necesita especificar su conformidad de tipo (UTTypeConformsTo). Mi pregunta es: ¿a qué tipos se ajusta tu propio tipo? – Julien

+0

Actualmente se ajusta a 'public.item', sin embargo, solo funciona con archivos exe. ¿Debo cambiarlo a algo más? – Tyilo

5

¡Llego un poco tarde a esta pregunta!

Debe agregar la clave "IconFlavor" no documentada al diccionario de propiedades que suministra a QLThumbnailRequestCreateContext() o QLThumbnailRequestSetXXX(), y darle el valor 1 para una decoración mínima.

Vea un ejemplo en here. En la parte superior de ese archivo hay algunos otros valores que he descubierto para "IconFlavour".

+0

¡Perfecto! Usted, señor, merece una medalla. ¿Cómo descubriste eso? Por cierto, kQLThumbnailIconPlainFlavor tuvo un mejor resultado para los iconos exe que kQLThumbnailIconShadowFlavor. – vitormm

Cuestiones relacionadas