Skip to content

Commit 5a70003

Browse files
committed
Initial checkin of the code from my repository.
0 parents  commit 5a70003

File tree

12 files changed

+1359
-0
lines changed

12 files changed

+1359
-0
lines changed

English.lproj/InfoPlist.strings

396 Bytes
Binary file not shown.

GeneratePreviewForURL.m

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* This code is licensed under the GPL v2. See LICENSE.txt for details. */
2+
3+
#import <CoreFoundation/CoreFoundation.h>
4+
#import <CoreServices/CoreServices.h>
5+
#import <Foundation/Foundation.h>
6+
#import <QuickLook/QuickLook.h>
7+
8+
#import <limits.h> // PATH_MAX
9+
10+
11+
/* -----------------------------------------------------------------------------
12+
Generate a preview for file
13+
14+
This function's job is to create preview for designated file
15+
----------------------------------------------------------------------------- */
16+
17+
NSData *runTask(NSString *script, int *exitCode) {
18+
NSTask *task = [[NSTask alloc] init];
19+
[task setCurrentDirectoryPath:@"/tmp"]; /* XXX: Fix this */
20+
//[task setEnvironment:env];
21+
[task setLaunchPath:@"/bin/sh"];
22+
[task setArguments:[NSArray arrayWithObjects:@"-c", script, nil]];
23+
24+
NSPipe *pipe;
25+
pipe = [NSPipe pipe];
26+
[task setStandardOutput: pipe];
27+
[task setStandardError: pipe];
28+
29+
NSFileHandle *file;
30+
file = [pipe fileHandleForReading];
31+
32+
[task launch];
33+
34+
NSData *data;
35+
data = [file readDataToEndOfFile];
36+
[task waitUntilExit];
37+
38+
/* NSString *string;
39+
string = [[NSString alloc] initWithData: data
40+
encoding: NSUTF8StringEncoding]; */
41+
42+
*exitCode = [task terminationStatus];
43+
[task release];
44+
/* [data release]; */
45+
/* The docs claim this isn't needed, but we leak descriptors otherwise */
46+
[file closeFile];
47+
/*[pipe release];*/
48+
49+
return data;
50+
}
51+
52+
53+
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
54+
CFURLRef url, CFStringRef contentTypeUTI,
55+
CFDictionaryRef options)
56+
{
57+
if (QLPreviewRequestIsCancelled(preview))
58+
return noErr;
59+
60+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
61+
62+
// Invoke colorize.sh
63+
unsigned char *targetBuf = malloc(PATH_MAX);
64+
unsigned char *rsrcDirBuf = malloc(PATH_MAX);
65+
CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview);
66+
CFURLRef rsrcDirURL = CFBundleCopyResourcesDirectoryURL(bundle);
67+
68+
if (!CFURLGetFileSystemRepresentation(url, YES, targetBuf, PATH_MAX)
69+
|| !CFURLGetFileSystemRepresentation(rsrcDirURL, YES, rsrcDirBuf, PATH_MAX))
70+
{
71+
NSLog(@"QLColorCode: CFURLGetFileSystemRepresentation failed");
72+
goto done;
73+
}
74+
NSString *cmd = [NSString stringWithFormat:
75+
@"\"%s/colorize.sh\" \"%s\" \"%s\"",
76+
rsrcDirBuf, rsrcDirBuf, targetBuf];
77+
78+
int status;
79+
NSData *output = runTask(cmd, &status);
80+
81+
if (status != 0) {
82+
NSLog(@"QLColorCode: colorize.sh failed with exit code %d", status);
83+
//goto done;
84+
}
85+
if (QLPreviewRequestIsCancelled(preview))
86+
goto done;
87+
// Now let WebKit do its thing
88+
//NSLog(@"**************** Passing the data along **********************");
89+
CFDictionaryRef emptydict =
90+
(CFDictionaryRef)[[[NSDictionary alloc] init] autorelease];
91+
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)output,
92+
//kUTTypePlainText,
93+
kUTTypeHTML,
94+
emptydict);
95+
96+
done:
97+
free(targetBuf);
98+
free(rsrcDirBuf);
99+
[pool release];
100+
return noErr;
101+
}
102+
103+
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
104+
{
105+
// implement only if supported
106+
}

GenerateThumbnailForURL.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <CoreFoundation/CoreFoundation.h>
2+
#include <CoreServices/CoreServices.h>
3+
#include <QuickLook/QuickLook.h>
4+
5+
/* -----------------------------------------------------------------------------
6+
Generate a thumbnail for file
7+
8+
This function's job is to create thumbnail for designated file as fast as possible
9+
----------------------------------------------------------------------------- */
10+
11+
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
12+
{
13+
return noErr;
14+
}
15+
16+
void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail)
17+
{
18+
// implement only if supported
19+
}

Info.plist

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleDocumentTypes</key>
8+
<array>
9+
<dict>
10+
<key>CFBundleTypeRole</key>
11+
<string>QLGenerator</string>
12+
<key>LSItemContentTypes</key>
13+
<array>
14+
<string>public.source-code</string>
15+
<string>public.xml</string>
16+
<string>org.ocaml.ocaml-source</string>
17+
<string>com.apple.property-list</string>
18+
</array>
19+
</dict>
20+
</array>
21+
<key>CFBundleExecutable</key>
22+
<string>${EXECUTABLE_NAME}</string>
23+
<key>CFBundleName</key>
24+
<string>${PRODUCT_NAME}</string>
25+
<key>CFBundleIconFile</key>
26+
<string></string>
27+
<key>CFBundleIdentifier</key>
28+
<string>org.n8gray.qlcolorcode</string>
29+
<key>CFBundleInfoDictionaryVersion</key>
30+
<string>6.0</string>
31+
<key>CFBundleVersion</key>
32+
<string>0.2</string>
33+
<key>CFBundleShortVersionString</key>
34+
<string>1</string>
35+
<key>CFPlugInDynamicRegisterFunction</key>
36+
<string></string>
37+
<key>CFPlugInDynamicRegistration</key>
38+
<string>NO</string>
39+
<key>CFPlugInFactories</key>
40+
<dict>
41+
<key>C044543D-70A1-46D8-A908-4B8AEA1197A4</key>
42+
<string>QuickLookGeneratorPluginFactory</string>
43+
</dict>
44+
<key>CFPlugInTypes</key>
45+
<dict>
46+
<key>5E2D9680-5022-40FA-B806-43349622E5B9</key>
47+
<array>
48+
<string>C044543D-70A1-46D8-A908-4B8AEA1197A4</string>
49+
</array>
50+
</dict>
51+
<key>CFPlugInUnloadFunction</key>
52+
<string></string>
53+
<!-- Change following property to <true/> if the generators supports
54+
multiple concurrent requests -->
55+
<key>QLSupportsConcurrentRequests</key>
56+
<true/>
57+
<!-- Change following property to <true/> if the generators needs
58+
to be run on main thread -->
59+
<key>QLNeedsToBeRunInMainThread</key>
60+
<false/>
61+
<!-- Change following property to indicate the minimum useful size for a thumbnail the generator
62+
can produce. If your generator is fast enough, you can remove the minimum size so to appear in lists -->
63+
<key>QLThumbnailMinimumSize</key>
64+
<real>48</real>
65+
<!-- Change following properites to indicate the preview size to use if preview generation takes too long -->
66+
<key>QLPreviewWidth</key>
67+
<real>800</real>
68+
<key>QLPreviewHeight</key>
69+
<real>800</real>
70+
71+
<!-- For this plugin to be invoked, Launch Services has to understand that
72+
a given file is "source-code". For things like .c and .m files that's
73+
not a problem; they're in the system already. But for .ml files
74+
we have to inform the system ourselves. If there is a file type that
75+
is supported by pygments but this plugin is not being called to
76+
quicklook it, try adding a type identifier for it below. -->
77+
<key>UTImportedTypeDeclarations</key>
78+
<array>
79+
<dict>
80+
<key>UTTypeIdentifier</key>
81+
<string>org.ocaml.ocaml-source</string>
82+
<key>UTTypeReferenceURL</key>
83+
<string>http://www.ocaml.org/</string>
84+
<key>UTTypeDescription</key>
85+
<string>OCaml Source File</string>
86+
<key>UTTypeConformsTo</key>
87+
<array>
88+
<string>public.source-code</string>
89+
</array>
90+
<key>UTTypeTagSpecification</key>
91+
<dict>
92+
<key>public.filename-extension</key>
93+
<array>
94+
<string>ml</string>
95+
</array>
96+
</dict>
97+
</dict>
98+
<dict>
99+
<key>UTTypeIdentifier</key>
100+
<string>org.ocaml.ocaml-interface</string>
101+
<key>UTTypeReferenceURL</key>
102+
<string>http://www.ocaml.org/</string>
103+
<key>UTTypeDescription</key>
104+
<string>OCaml Interface File</string>
105+
<key>UTTypeConformsTo</key>
106+
<array>
107+
<string>public.source-code</string>
108+
</array>
109+
<key>UTTypeTagSpecification</key>
110+
<dict>
111+
<key>public.filename-extension</key>
112+
<array>
113+
<string>mli</string>
114+
</array>
115+
</dict>
116+
</dict>
117+
<dict>
118+
<key>UTTypeIdentifier</key>
119+
<string>org.haskell.haskell-source</string>
120+
<key>UTTypeReferenceURL</key>
121+
<string>http://www.haskell.org/</string>
122+
<key>UTTypeDescription</key>
123+
<string>Haskell Source File</string>
124+
<key>UTTypeConformsTo</key>
125+
<array>
126+
<string>public.source-code</string>
127+
</array>
128+
<key>UTTypeTagSpecification</key>
129+
<dict>
130+
<key>public.filename-extension</key>
131+
<array>
132+
<string>hs</string>
133+
</array>
134+
</dict>
135+
</dict>
136+
<dict>
137+
<key>UTTypeIdentifier</key>
138+
<string>org.haskell.literate-haskell-source</string>
139+
<key>UTTypeReferenceURL</key>
140+
<string>http://www.haskell.org/</string>
141+
<key>UTTypeDescription</key>
142+
<string>Literate Haskell Source File</string>
143+
<key>UTTypeConformsTo</key>
144+
<array>
145+
<string>public.source-code</string>
146+
</array>
147+
<key>UTTypeTagSpecification</key>
148+
<dict>
149+
<key>public.filename-extension</key>
150+
<array>
151+
<string>lhs</string>
152+
</array>
153+
</dict>
154+
</dict>
155+
<dict>
156+
<key>UTTypeIdentifier</key>
157+
<string>org.n8gray.tex-source</string>
158+
<key>UTTypeDescription</key>
159+
<string>Tex Source File</string>
160+
<key>UTTypeConformsTo</key>
161+
<array>
162+
<string>public.source-code</string>
163+
</array>
164+
<key>UTTypeTagSpecification</key>
165+
<dict>
166+
<key>public.filename-extension</key>
167+
<array>
168+
<string>tex</string>
169+
<string>sty</string>
170+
</array>
171+
</dict>
172+
</dict>
173+
<dict>
174+
<key>UTTypeIdentifier</key>
175+
<string>org.n8gray.scheme-source</string>
176+
<key>UTTypeDescription</key>
177+
<string>scheme Source File</string>
178+
<key>UTTypeConformsTo</key>
179+
<array>
180+
<string>public.source-code</string>
181+
</array>
182+
<key>UTTypeTagSpecification</key>
183+
<dict>
184+
<key>public.filename-extension</key>
185+
<array>
186+
<string>scm</string>
187+
</array>
188+
</dict>
189+
</dict>
190+
<dict>
191+
<key>UTTypeIdentifier</key>
192+
<string>org.n8gray.ini-source</string>
193+
<key>UTTypeDescription</key>
194+
<string>.ini Source File</string>
195+
<key>UTTypeConformsTo</key>
196+
<array>
197+
<string>public.source-code</string>
198+
</array>
199+
<key>UTTypeTagSpecification</key>
200+
<dict>
201+
<key>public.filename-extension</key>
202+
<array>
203+
<string>ini</string>
204+
</array>
205+
<key>public.mime-type</key>
206+
<string>text/x-ini</string>
207+
</dict>
208+
</dict>
209+
</array>
210+
</dict>
211+
</plist>

0 commit comments

Comments
 (0)