Skip to content

Commit

Permalink
Merge pull request #57 from MaddTheSane/ARCback
Browse files Browse the repository at this point in the history
Convert to ARC
  • Loading branch information
tarwich committed Sep 14, 2015
2 parents 9b401ed + 9ef4a83 commit ea1a41e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
Binary file modified English.lproj/InfoPlist.strings
Binary file not shown.
8 changes: 5 additions & 3 deletions GeneratePreviewForURL.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options)
{
CFDataRef data = (CFDataRef) renderMarkdown((NSURL*) url);
@autoreleasepool {
NSData *data = renderMarkdown((__bridge NSURL*) url);

if (data) {
CFDictionaryRef props = (CFDictionaryRef) [NSDictionary dictionary];
QLPreviewRequestSetDataRepresentation(preview, data, kUTTypeHTML, props);
NSDictionary *props = [[NSDictionary alloc] init];
QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef)data, kUTTypeHTML, (__bridge CFDictionaryRef)props);
}

return noErr;
}
}

void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
Expand Down
6 changes: 4 additions & 2 deletions GenerateThumbnailForURL.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ OSStatus GenerateThumbnailForURL(void *thisInterface,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options, CGSize maxSize)
{
NSData *data = renderMarkdown((NSURL*) url);
@autoreleasepool {
NSData *data = renderMarkdown((__bridge NSURL*) url);

if (data) {
NSRect viewRect = NSMakeRect(0.0, 0.0, 600.0, 800.0);
Expand All @@ -29,7 +30,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface,
NSMakeSize((maxSize.width * (600.0/800.0)),
maxSize.height));

WebView* webView = [[[WebView alloc] initWithFrame: viewRect] autorelease];
WebView* webView = [[WebView alloc] initWithFrame: viewRect];
[webView scaleUnitSquareToSize: scaleSize];
[[[webView mainFrame] frameView] setAllowsScrolling:NO];
[[webView mainFrame] loadData: data
Expand Down Expand Up @@ -62,6 +63,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface,
}

return noErr;
}
}

void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)
Expand Down
30 changes: 18 additions & 12 deletions QLMarkdown.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
08FB77B6FE84183AC02AAC07 /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
0A80BFA40E21A2E200C8BF14 /* markdown.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = markdown.h; sourceTree = "<group>"; };
0A80BFA60E21A2ED00C8BF14 /* markdown.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = markdown.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -109,6 +109,7 @@
);
name = QLMarkdown;
sourceTree = "<group>";
usesTabs = 0;
};
089C1671FE841209C02AAC07 /* External Frameworks and Libraries */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -333,60 +334,65 @@
2CA3261F0896AD4900168862 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = NO;
HEADER_SEARCH_PATHS = "./discount-config";
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = /Library/QuickLook;
PRODUCT_NAME = QLMarkdown;
SDKROOT = macosx;
VALID_ARCHS = "i386 x86_64";
WRAPPER_EXTENSION = qlgenerator;
ZERO_LINK = YES;
};
name = Debug;
};
2CA326200896AD4900168862 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = NO;
HEADER_SEARCH_PATHS = "./discount-config";
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = /Library/QuickLook;
PRODUCT_NAME = QLMarkdown;
SDKROOT = macosx;
VALID_ARCHS = "i386 x86_64";
WRAPPER_EXTENSION = qlgenerator;
};
name = Release;
};
2CA326230896AD4900168862 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = "";
SDKROOT = macosx;
STRIP_INSTALLED_PRODUCT = NO;
WARNING_CFLAGS = "-Wall";
};
name = Debug;
};
2CA326240896AD4900168862 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "ppc i386 ppc64 x86_64";
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
SDKROOT = "";
SDKROOT = macosx;
WARNING_CFLAGS = "-Wall";
};
name = Release;
Expand Down
6 changes: 4 additions & 2 deletions markdown.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

NSData* renderMarkdown(NSURL* url)
{
NSString *styles = [NSString stringWithContentsOfFile:[[NSBundle bundleWithIdentifier: @"com.fiatdev.QLMarkdown"]
@autoreleasepool {
NSString *styles = [[NSString alloc] initWithContentsOfFile:[[NSBundle bundleWithIdentifier: @"com.fiatdev.QLMarkdown"]
pathForResource:@"styles" ofType:@"css"]
encoding:NSUTF8StringEncoding
error:nil];

NSStringEncoding usedEncoding = 0;
NSError *e = nil;

NSString *source = [NSString stringWithContentsOfURL:url usedEncoding:&usedEncoding error:&e];
NSString *source = [[NSString alloc] initWithContentsOfURL:url usedEncoding:&usedEncoding error:&e];

if (usedEncoding == 0) {
NSLog(@"Wasn't able to determine encoding for file “%@", [url path]);
Expand All @@ -27,4 +28,5 @@

free(output);
return [html dataUsingEncoding:NSUTF8StringEncoding];
}
}

0 comments on commit ea1a41e

Please sign in to comment.