forked from fletcher/MMD-QuickLook
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
427 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#import <CoreFoundation/CoreFoundation.h> | ||
#import <CoreServices/CoreServices.h> | ||
#import <QuickLook/QuickLook.h> | ||
#import <Cocoa/Cocoa.h> | ||
|
||
/* ----------------------------------------------------------------------------- | ||
Generate a preview for file | ||
This function's job is to create preview for designated file | ||
----------------------------------------------------------------------------- */ | ||
|
||
NSData* processMMD(NSURL* url); | ||
NSData* processOPML2MMD(NSURL* url); | ||
|
||
BOOL logDebug = YES; | ||
|
||
|
||
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) | ||
{ | ||
if (logDebug) | ||
NSLog(@"generate preview for content type: %@",contentTypeUTI); | ||
|
||
CFDataRef previewData; | ||
|
||
if (CFStringCompare(contentTypeUTI, CFSTR("org.opml.opml"), 0) == kCFCompareEqualTo) | ||
{ | ||
// Preview an OPML file | ||
|
||
previewData = (CFDataRef) processOPML2MMD((NSURL*) url); | ||
} else { | ||
// Preview a text file | ||
|
||
previewData = (CFDataRef) processMMD((NSURL*) url); | ||
} | ||
|
||
if (previewData) { | ||
if (logDebug) | ||
NSLog(@"preview generated"); | ||
|
||
CFDictionaryRef properties = (CFDictionaryRef) [NSDictionary dictionary]; | ||
QLPreviewRequestSetDataRepresentation(preview, previewData, kUTTypeHTML, properties); | ||
} | ||
|
||
return noErr; | ||
} | ||
|
||
NSData* processOPML2MMD(NSURL* url) | ||
{ | ||
if (logDebug) | ||
NSLog(@"create preview for OPML file %@",[url path]); | ||
|
||
NSString *path2MMD = [[NSBundle bundleWithIdentifier:@"net.fletcherpenney.quicklook"] pathForResource:@"multimarkdown" ofType:nil]; | ||
|
||
NSTask* task = [[NSTask alloc] init]; | ||
[task setLaunchPath: [path2MMD stringByExpandingTildeInPath]]; | ||
|
||
[task setArguments: [NSArray arrayWithObjects: nil]]; | ||
|
||
NSPipe *writePipe = [NSPipe pipe]; | ||
NSFileHandle *writeHandle = [writePipe fileHandleForWriting]; | ||
[task setStandardInput: writePipe]; | ||
|
||
NSPipe *readPipe = [NSPipe pipe]; | ||
[task setStandardOutput:readPipe]; | ||
|
||
[task launch]; | ||
|
||
|
||
NSString *theData = [NSString stringWithContentsOfFile:[url path] encoding:NSUTF8StringEncoding error:nil]; | ||
|
||
NSXMLDocument *opmlDocument = [[NSXMLDocument alloc] initWithXMLString:theData | ||
options:0 | ||
error:nil]; | ||
NSURL *styleFilePath = [[NSBundle bundleWithIdentifier:@"net.fletcherpenney.quicklook"] URLForResource:@"opml2mmd" | ||
withExtension:@"xslt"]; | ||
|
||
NSData *mmdContents = [opmlDocument objectByApplyingXSLTAtURL:styleFilePath | ||
arguments:nil | ||
error:nil]; | ||
|
||
[opmlDocument release]; | ||
|
||
[writeHandle writeData:mmdContents]; | ||
|
||
[writeHandle closeFile]; | ||
|
||
|
||
NSData *mmdData = [[readPipe fileHandleForReading] readDataToEndOfFile]; | ||
|
||
[task release]; | ||
return mmdData; | ||
} | ||
|
||
NSData* processMMD(NSURL* url) | ||
{ | ||
if (logDebug) | ||
NSLog(@"create preview for MMD file %@",[url path]); | ||
|
||
NSString *path2MMD = [[NSBundle bundleWithIdentifier:@"net.fletcherpenney.quicklook"] pathForResource:@"multimarkdown" ofType:nil]; | ||
|
||
NSTask* task = [[NSTask alloc] init]; | ||
[task setLaunchPath: [path2MMD stringByExpandingTildeInPath]]; | ||
|
||
[task setArguments: [NSArray arrayWithObjects: nil]]; | ||
|
||
NSPipe *writePipe = [NSPipe pipe]; | ||
NSFileHandle *writeHandle = [writePipe fileHandleForWriting]; | ||
[task setStandardInput: writePipe]; | ||
|
||
NSPipe *readPipe = [NSPipe pipe]; | ||
[task setStandardOutput:readPipe]; | ||
|
||
[task launch]; | ||
|
||
NSString *theData = [NSString stringWithContentsOfFile:[url path] encoding:NSUTF8StringEncoding error:nil]; | ||
|
||
[writeHandle writeData:[theData dataUsingEncoding:NSUTF8StringEncoding]]; | ||
|
||
[writeHandle closeFile]; | ||
|
||
|
||
NSData *mmdData = [[readPipe fileHandleForReading] readDataToEndOfFile]; | ||
|
||
[task release]; | ||
return mmdData; | ||
} | ||
|
||
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview) | ||
{ | ||
// implement only if supported | ||
} |
10 changes: 6 additions & 4 deletions
10
...kdown QuickLook/GenerateThumbnailForURL.c → ...kdown QuickLook/GenerateThumbnailForURL.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.