Skip to content

Commit

Permalink
Initial checkin of the code from my repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
n8gray committed Nov 30, 2007
0 parents commit 5a70003
Show file tree
Hide file tree
Showing 12 changed files with 1,359 additions and 0 deletions.
Binary file added English.lproj/InfoPlist.strings
Binary file not shown.
106 changes: 106 additions & 0 deletions GeneratePreviewForURL.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* This code is licensed under the GPL v2. See LICENSE.txt for details. */

#import <CoreFoundation/CoreFoundation.h>
#import <CoreServices/CoreServices.h>
#import <Foundation/Foundation.h>
#import <QuickLook/QuickLook.h>

#import <limits.h> // PATH_MAX


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

NSData *runTask(NSString *script, int *exitCode) {
NSTask *task = [[NSTask alloc] init];
[task setCurrentDirectoryPath:@"/tmp"]; /* XXX: Fix this */
//[task setEnvironment:env];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:[NSArray arrayWithObjects:@"-c", script, nil]];

NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task setStandardError: pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[task launch];

NSData *data;
data = [file readDataToEndOfFile];
[task waitUntilExit];

/* NSString *string;
string = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding]; */

*exitCode = [task terminationStatus];
[task release];
/* [data release]; */
/* The docs claim this isn't needed, but we leak descriptors otherwise */
[file closeFile];
/*[pipe release];*/

return data;
}


OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options)
{
if (QLPreviewRequestIsCancelled(preview))
return noErr;

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

// Invoke colorize.sh
unsigned char *targetBuf = malloc(PATH_MAX);
unsigned char *rsrcDirBuf = malloc(PATH_MAX);
CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview);
CFURLRef rsrcDirURL = CFBundleCopyResourcesDirectoryURL(bundle);

if (!CFURLGetFileSystemRepresentation(url, YES, targetBuf, PATH_MAX)
|| !CFURLGetFileSystemRepresentation(rsrcDirURL, YES, rsrcDirBuf, PATH_MAX))
{
NSLog(@"QLColorCode: CFURLGetFileSystemRepresentation failed");
goto done;
}
NSString *cmd = [NSString stringWithFormat:
@"\"%s/colorize.sh\" \"%s\" \"%s\"",
rsrcDirBuf, rsrcDirBuf, targetBuf];

int status;
NSData *output = runTask(cmd, &status);

if (status != 0) {
NSLog(@"QLColorCode: colorize.sh failed with exit code %d", status);
//goto done;
}
if (QLPreviewRequestIsCancelled(preview))
goto done;
// Now let WebKit do its thing
//NSLog(@"**************** Passing the data along **********************");
CFDictionaryRef emptydict =
(CFDictionaryRef)[[[NSDictionary alloc] init] autorelease];
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)output,
//kUTTypePlainText,
kUTTypeHTML,
emptydict);

done:
free(targetBuf);
free(rsrcDirBuf);
[pool release];
return noErr;
}

void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
{
// implement only if supported
}
19 changes: 19 additions & 0 deletions GenerateThumbnailForURL.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <QuickLook/QuickLook.h>

/* -----------------------------------------------------------------------------
Generate a thumbnail for file
This function's job is to create thumbnail for designated file as fast as possible
----------------------------------------------------------------------------- */

OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{
return noErr;
}

void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)
{
// implement only if supported
}
211 changes: 211 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>QLGenerator</string>
<key>LSItemContentTypes</key>
<array>
<string>public.source-code</string>
<string>public.xml</string>
<string>org.ocaml.ocaml-source</string>
<string>com.apple.property-list</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>org.n8gray.qlcolorcode</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleVersion</key>
<string>0.2</string>
<key>CFBundleShortVersionString</key>
<string>1</string>
<key>CFPlugInDynamicRegisterFunction</key>
<string></string>
<key>CFPlugInDynamicRegistration</key>
<string>NO</string>
<key>CFPlugInFactories</key>
<dict>
<key>C044543D-70A1-46D8-A908-4B8AEA1197A4</key>
<string>QuickLookGeneratorPluginFactory</string>
</dict>
<key>CFPlugInTypes</key>
<dict>
<key>5E2D9680-5022-40FA-B806-43349622E5B9</key>
<array>
<string>C044543D-70A1-46D8-A908-4B8AEA1197A4</string>
</array>
</dict>
<key>CFPlugInUnloadFunction</key>
<string></string>
<!-- Change following property to <true/> if the generators supports
multiple concurrent requests -->
<key>QLSupportsConcurrentRequests</key>
<true/>
<!-- Change following property to <true/> if the generators needs
to be run on main thread -->
<key>QLNeedsToBeRunInMainThread</key>
<false/>
<!-- Change following property to indicate the minimum useful size for a thumbnail the generator
can produce. If your generator is fast enough, you can remove the minimum size so to appear in lists -->
<key>QLThumbnailMinimumSize</key>
<real>48</real>
<!-- Change following properites to indicate the preview size to use if preview generation takes too long -->
<key>QLPreviewWidth</key>
<real>800</real>
<key>QLPreviewHeight</key>
<real>800</real>

<!-- For this plugin to be invoked, Launch Services has to understand that
a given file is "source-code". For things like .c and .m files that's
not a problem; they're in the system already. But for .ml files
we have to inform the system ourselves. If there is a file type that
is supported by pygments but this plugin is not being called to
quicklook it, try adding a type identifier for it below. -->
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>org.ocaml.ocaml-source</string>
<key>UTTypeReferenceURL</key>
<string>http://www.ocaml.org/</string>
<key>UTTypeDescription</key>
<string>OCaml Source File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>ml</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.ocaml.ocaml-interface</string>
<key>UTTypeReferenceURL</key>
<string>http://www.ocaml.org/</string>
<key>UTTypeDescription</key>
<string>OCaml Interface File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>mli</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.haskell.haskell-source</string>
<key>UTTypeReferenceURL</key>
<string>http://www.haskell.org/</string>
<key>UTTypeDescription</key>
<string>Haskell Source File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>hs</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.haskell.literate-haskell-source</string>
<key>UTTypeReferenceURL</key>
<string>http://www.haskell.org/</string>
<key>UTTypeDescription</key>
<string>Literate Haskell Source File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>lhs</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.n8gray.tex-source</string>
<key>UTTypeDescription</key>
<string>Tex Source File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>tex</string>
<string>sty</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.n8gray.scheme-source</string>
<key>UTTypeDescription</key>
<string>scheme Source File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>scm</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>org.n8gray.ini-source</string>
<key>UTTypeDescription</key>
<string>.ini Source File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.source-code</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>ini</string>
</array>
<key>public.mime-type</key>
<string>text/x-ini</string>
</dict>
</dict>
</array>
</dict>
</plist>
Loading

0 comments on commit 5a70003

Please sign in to comment.