Skip to content

Commit

Permalink
Merge pull request whomwah#4 from roblourens/master
Browse files Browse the repository at this point in the history
Now works with ISO encoded files as well
  • Loading branch information
whomwah committed Oct 28, 2011
2 parents bc5eb28 + 305ee7b commit 257883e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
66 changes: 35 additions & 31 deletions QuickLookStephenProject/GeneratePreviewForURL.m
Expand Up @@ -3,40 +3,44 @@
#include <QuickLook/QuickLook.h>
#import <Foundation/Foundation.h>

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

// Generate a preview for the document with the given url
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
if (QLPreviewRequestIsCancelled(preview))
{
if (QLPreviewRequestIsCancelled(preview))
return noErr;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
[props setObject:@"UTF-8" forKey:(NSString *)kQLPreviewPropertyTextEncodingNameKey];
[props setObject:@"text/plain" forKey:(NSString *)kQLPreviewPropertyMIMETypeKey];
[props setObject:[NSNumber numberWithInt:700] forKey:(NSString *)kQLPreviewPropertyWidthKey];
[props setObject:[NSNumber numberWithInt:500] forKey:(NSString *)kQLPreviewPropertyHeightKey];

NSString *text = [NSString stringWithContentsOfURL:(NSURL *)url
encoding:NSUTF8StringEncoding
error:nil];

QLPreviewRequestSetDataRepresentation(
preview,
(CFDataRef)[text dataUsingEncoding:NSUTF8StringEncoding],
kUTTypeHTML,
(CFDictionaryRef)props);


[pool release];

return noErr;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
[props setObject:@"text/plain" forKey:(NSString *)kQLPreviewPropertyMIMETypeKey];
[props setObject:[NSNumber numberWithInt:700] forKey:(NSString *)kQLPreviewPropertyWidthKey];
[props setObject:[NSNumber numberWithInt:800] forKey:(NSString *)kQLPreviewPropertyHeightKey];

NSStringEncoding encodingUsed;
NSString *text = [NSString stringWithContentsOfURL:(NSURL *)url
usedEncoding:&encodingUsed
error:nil];

// If the encoding could not be determined using usedEncoding, try Latin1
if (text == nil)
{
text = [NSString stringWithContentsOfURL:(NSURL *)url
encoding:NSISOLatin1StringEncoding
error:nil];
encodingUsed = NSISOLatin1StringEncoding;
}

QLPreviewRequestSetDataRepresentation(
preview,
(CFDataRef)[text dataUsingEncoding:encodingUsed],
kUTTypeHTML,
(CFDictionaryRef)props);


[pool release];

return noErr;
}

void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
Expand Down
2 changes: 1 addition & 1 deletion QuickLookStephenProject/Info.plist
Expand Up @@ -60,7 +60,7 @@
<key>QLPreviewWidth</key>
<real>800</real>
<key>QLSupportsConcurrentRequests</key>
<false/>
<true/>
<key>QLThumbnailMinimumSize</key>
<real>17</real>
</dict>
Expand Down
Expand Up @@ -219,6 +219,7 @@
2CA3261F0896AD4900168862 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_MODEL_TUNING = G5;
Expand All @@ -234,6 +235,7 @@
2CA326200896AD4900168862 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = NO;
Expand Down

0 comments on commit 257883e

Please sign in to comment.