From 50630078a5b4891fe0b50a6cadb7514bfc8d4f11 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Mon, 21 Jul 2014 20:23:01 +0000 Subject: OS X: Implement the memory card QuickLook preview. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@91017 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/Pcsxr-QL/GeneratePreviewForURL.m | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'macosx/Pcsxr-QL/GeneratePreviewForURL.m') diff --git a/macosx/Pcsxr-QL/GeneratePreviewForURL.m b/macosx/Pcsxr-QL/GeneratePreviewForURL.m index 619a5cee..24031a1c 100644 --- a/macosx/Pcsxr-QL/GeneratePreviewForURL.m +++ b/macosx/Pcsxr-QL/GeneratePreviewForURL.m @@ -84,5 +84,31 @@ OSStatus GeneratePreviewForFreeze(void *thisInterface, QLPreviewRequestRef previ static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestRef preview, NSURL *url, NSDictionary *options) { NSArray *memCards = CreateArrayByEnumeratingMemoryCardAtURL(url); - return unimpErr; + NSMutableString *htmlStr = [[NSMutableString alloc] initWithCapacity:memCards.count * 200]; + NSMutableDictionary *htmlDict = [[NSMutableDictionary alloc] initWithCapacity:memCards.count]; + int i; + for (PcsxrMemoryObject *obj in memCards) { + NSImage *theImage = [obj firstMemImage]; + NSData *tiffData = [theImage TIFFRepresentation]; + NSBitmapImageRep *bmImg = [NSBitmapImageRep imageRepWithData:tiffData]; + NSData *pngData = [bmImg representationUsingType:NSPNGFileType properties:nil]; + NSDictionary *imgProps = @{(NSString *)kQLPreviewPropertyAttachmentDataKey: pngData, + (NSString *)kQLPreviewPropertyMIMETypeKey: @"image/png"}; + NSString *imgName = [[@(i++) stringValue] stringByAppendingPathComponent:@"png"]; + [htmlStr appendFormat:@"%@%i\n", imgName, obj.sjisName, obj.blockSize]; + htmlDict[imgName] = imgProps; + } + + NSString *theStr = [[NSString alloc] initWithFormat:@"\n\n\n%@\n
ImageImageCount
\n\n", htmlStr]; + + NSData *data = [theStr dataUsingEncoding:NSUTF8StringEncoding]; + NSDictionary *previewDict = + @{(NSString *)kQLPreviewPropertyAttachmentsKey: htmlDict, + (NSString *)kQLPreviewPropertyDisplayNameKey: [url lastPathComponent], + (NSString *)kQLPreviewPropertyWidthKey: @400, + (NSString *)kQLPreviewPropertyHeightKey: @400}; + + QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef)(data), kUTTypeHTML, (__bridge CFDictionaryRef)(previewDict)); + + return noErr; } -- cgit v1.2.3