Permalink
Browse files

Updates preparing for release. Trying to add Thumbnails.

  • Loading branch information...
1 parent c03b1aa commit af0262fd06f7f48c8545ae2737c8f9c2f40ef8da @ghutchis committed Oct 28, 2010
Showing with 199 additions and 220 deletions.
  1. +7 −0 ChemLook.xcodeproj/project.pbxproj
  2. +1 −0 Common.h
  3. +100 −0 Common.m
  4. +4 −97 GeneratePreviewForURL.m
  5. +56 −0 GenerateThumbnailForURL.m
  6. +20 −0 Info.plist
  7. +11 −123 ReadMe.txt
@@ -211,7 +211,14 @@
};
buildConfigurationList = 2CA326220896AD4900168862 /* Build configuration list for PBXProject "ChemLook" */;
compatibilityVersion = "Xcode 3.0";
+ developmentRegion = English;
hasScannedForEncodings = 1;
+ knownRegions = (
+ English,
+ Japanese,
+ French,
+ German,
+ );
mainGroup = 089C166AFE841209C02AAC07 /* QLColorCode */;
projectDirPath = "";
projectRoot = "";
View
@@ -15,3 +15,4 @@
// Status is 0 on success, nonzero on error (like a shell command)
NSString *babelURL(CFBundleRef myBundle, CFURLRef url, int *status, bool singleMol);
+NSString *PreviewUrl(CFBundleRef myBundle, CFURLRef url);
View
100 Common.m
@@ -77,3 +77,103 @@
}
return output;
}
+
+NSString *PreviewUrl(CFBundleRef bundle, CFURLRef url)
+{
+ // Save the extension for future comparisons
+ CFStringRef extension = CFURLCopyPathExtension(url);
+
+ // Now we load the molecule, but it depends on the extension
+ // SDF / MOLfile can be read directly
+ // PDB can be read directly, but we use a different JavaScript function in the HTML
+ NSString *moleculeData = NULL;
+ bool singleMol = true;
+ if (CFStringCompare(extension, CFSTR("sdf"), kCFCompareCaseInsensitive) == 0
+ || CFStringCompare(extension, CFSTR("mdl"), kCFCompareCaseInsensitive) == 0
+ || CFStringCompare(extension, CFSTR("mol"), kCFCompareCaseInsensitive) == 0
+ || CFStringCompare(extension, CFSTR("pdb"), kCFCompareCaseInsensitive) == 0) {
+ // use this file directly, we can read it using JavaScript
+ moleculeData = [NSString stringWithContentsOfURL:(NSURL*)url
+ encoding:NSUTF8StringEncoding
+ error:&error];
+ if (moleculeData == nil) {
+ // an error occurred
+ NSLog(@"Error reading molecule %@\n",
+ [error localizedFailureReason]);
+ goto done;
+ }
+ } else {
+ // We need to pass this through babel to read
+ int status;
+ // If we have a CDX or CDXML, try to join all molecules into one SDF
+ singleMol = !(CFStringCompare(extension, CFSTR("cdx"), kCFCompareCaseInsensitive) == 0
+ || CFStringCompare(extension, CFSTR("cdxml"), kCFCompareCaseInsensitive) == 0);
+
+ moleculeData = babelURL(bundle, url, &status, singleMol);
+ if (status != 0 || moleculeData == nil) {
+ // an error occurred
+ NSLog(@"Error reading molecule %@\n",
+ [error localizedFailureReason]);
+ return nil;
+ }
+ }
+
+ // Load the chemlook.html file template as a string for substitution
+ CFURLRef templateURL;
+ if (singleMol) {
+ templateURL = CFBundleCopyResourceURL(bundle, CFSTR("chemlook.html"), NULL, NULL);
+ } else {
+ templateURL = CFBundleCopyResourceURL(bundle, CFSTR("chemlook-2d.html"), NULL, NULL);
+ }
+
+ NSString *templateString = [NSString stringWithContentsOfURL:(NSURL*)templateURL
+ encoding:NSUTF8StringEncoding
+ error:&error];
+ if (templateString == nil) {
+ // an error occurred
+ NSLog(@"Error reading template %@\n",
+ [error localizedFailureReason]);
+ }
+ CFRelease(templateURL);
+
+ // Now load the JavaScript files
+ CFURLRef libsURL = CFBundleCopyResourceURL(bundle, CFSTR("ChemDoodleWeb-libs.js"), NULL, NULL);
+ NSString *libsData = [NSString stringWithContentsOfURL:(NSURL*)libsURL
+ encoding:NSUTF8StringEncoding
+ error:&error];
+ if (libsData == nil){
+ // an error occurred
+ NSLog(@"Error reading libs %@\n",
+ [error localizedFailureReason]);
+ }
+ CFRelease(libsURL);
+
+ CFURLRef mainURL = CFBundleCopyResourceURL(bundle, CFSTR("ChemDoodleWeb.js"), NULL, NULL);
+ NSString *mainData = [NSString stringWithContentsOfURL:(NSURL*)mainURL
+ encoding:NSUTF8StringEncoding
+ error:&error];
+ if (mainData == nil){
+ // an error occurred
+ NSLog(@"Error reading main %@\n",
+ [error localizedFailureReason]);
+ }
+ CFRelease(mainURL);
+
+ NSString *cleanedMol = [moleculeData stringByReplacingOccurrencesOfString:@"\r"
+ withString:@""];
+ NSString *escapedMol = [cleanedMol stringByReplacingOccurrencesOfString:@"\n"
+ withString:@"\\n"];
+
+ NSString *readFunction = @"readMOL";
+ if (CFStringCompare(extension, CFSTR("pdb"), kCFCompareCaseInsensitive) == 0)
+ readFunction = @"readPDB";
+ // OK, the template has several strings, so let's format them
+ NSString *outputString = [NSString stringWithFormat:templateString,
+ libsData,
+ mainData,
+ escapedMol,
+ readFunction,
+ nil];
+
+ return outputString;
+}
View
@@ -25,106 +25,13 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSError *error;
-
- // Save the extension for future comparisons
- CFStringRef extension = CFURLCopyPathExtension(url);
-
+
// We need the path of the bundle to get the HTML template and JavaScript
CFBundleRef bundle = QLPreviewRequestGetGeneratorBundle(preview);
- // Now we load the molecule, but it depends on the extension
- // SDF / MOLfile can be read directly
- // PDB can be read directly, but we use a different JavaScript function in the HTML
- NSString *moleculeData = NULL;
- bool singleMol = true;
- if (CFStringCompare(extension, CFSTR("sdf"), kCFCompareCaseInsensitive) == 0
- || CFStringCompare(extension, CFSTR("mdl"), kCFCompareCaseInsensitive) == 0
- || CFStringCompare(extension, CFSTR("mol"), kCFCompareCaseInsensitive) == 0
- || CFStringCompare(extension, CFSTR("pdb"), kCFCompareCaseInsensitive) == 0) {
- // use this file directly, we can read it using JavaScript
- moleculeData = [NSString stringWithContentsOfURL:(NSURL*)url
- encoding:NSUTF8StringEncoding
- error:&error];
- if (moleculeData == nil) {
- // an error occurred
- NSLog(@"Error reading molecule %@\n",
- [error localizedFailureReason]);
- goto done;
- }
- } else {
- // We need to pass this through babel to read
- int status;
- // If we have a CDX or CDXML, try to join all molecules into one SDF
- singleMol = !(CFStringCompare(extension, CFSTR("cdx"), kCFCompareCaseInsensitive) == 0
- || CFStringCompare(extension, CFSTR("cdxml"), kCFCompareCaseInsensitive) == 0);
-
- moleculeData = babelURL(bundle, url, &status, singleMol);
- if (status != 0 || moleculeData == nil) {
- // an error occurred
- NSLog(@"Error reading molecule %@\n",
- [error localizedFailureReason]);
- goto done;
- }
- }
-
- // Load the chemlook.html file template as a string for substitution
- CFURLRef templateURL;
- if (singleMol) {
- templateURL = CFBundleCopyResourceURL(bundle, CFSTR("chemlook.html"), NULL, NULL);
- } else {
- templateURL = CFBundleCopyResourceURL(bundle, CFSTR("chemlook-2d.html"), NULL, NULL);
- }
-
- NSString *templateString = [NSString stringWithContentsOfURL:(NSURL*)templateURL
- encoding:NSUTF8StringEncoding
- error:&error];
- if (templateString == nil) {
- // an error occurred
- NSLog(@"Error reading template %@\n",
- [error localizedFailureReason]);
- }
- CFRelease(templateURL);
-
- // Now load the JavaScript files
- CFURLRef libsURL = CFBundleCopyResourceURL(bundle, CFSTR("ChemDoodleWeb-libs.js"), NULL, NULL);
- NSString *libsData = [NSString stringWithContentsOfURL:(NSURL*)libsURL
- encoding:NSUTF8StringEncoding
- error:&error];
- if (libsData == nil){
- // an error occurred
- NSLog(@"Error reading libs %@\n",
- [error localizedFailureReason]);
- }
- CFRelease(libsURL);
-
- CFURLRef mainURL = CFBundleCopyResourceURL(bundle, CFSTR("ChemDoodleWeb.js"), NULL, NULL);
- NSString *mainData = [NSString stringWithContentsOfURL:(NSURL*)mainURL
- encoding:NSUTF8StringEncoding
- error:&error];
- if (mainData == nil){
- // an error occurred
- NSLog(@"Error reading main %@\n",
- [error localizedFailureReason]);
- }
- CFRelease(mainURL);
-
- NSString *cleanedMol = [moleculeData stringByReplacingOccurrencesOfString:@"\r"
- withString:@""];
- NSString *escapedMol = [cleanedMol stringByReplacingOccurrencesOfString:@"\n"
- withString:@"\\n"];
-
- NSString *readFunction = @"readMOL";
- if (CFStringCompare(extension, CFSTR("pdb"), kCFCompareCaseInsensitive) == 0)
- readFunction = @"readPDB";
- // OK, the template has several strings, so let's format them
- NSString *outputString = [NSString stringWithFormat:templateString,
- libsData,
- mainData,
- escapedMol,
- readFunction,
- nil];
-
- // Set the properties of the QuickLook view
+ NSString *outputString = PreviewUrl(url, bundle);
+
+ // Set the properties of the QuickLook view
// UTF-8 -- not that there's text
// text/html content to use WebKit preview
NSMutableDictionary *properties = [[NSMutableDictionary alloc] init];
View
@@ -5,6 +5,7 @@
#include <WebKit/WebKit.h>
#define minSize 32
+#define windowSize 600.0
/* -----------------------------------------------------------------------------
Generate a thumbnail for file
@@ -20,6 +21,61 @@
CFDictionaryRef options,
CGSize maxSize)
{
+ // For some reason we seem to get called for small thumbnails even though
+ // we put a min size in our .plist file...
+ if (maxSize.width < minSize || maxSize.height < minSize)
+ return noErr;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ // Render as though there is an 600x600 window, and fill the thumbnail
+ // vertically.
+
+ NSRect renderRect = NSMakeRect(0.0, 0.0, windowSize, windowSize);
+ float scale = maxSize.height/windowSize;
+ NSSize scaleSize = NSMakeSize(scale, scale);
+ CGSize thumbSize = NSSizeToCGSize(NSMakeSize(maxSize.width, maxSize.height));
+
+ /* Based on example code from quicklook-dev mailing list */
+ // NSSize previewSize = NSSizeFromCGSize(maxSize);
+ int status;
+ CFBundleRef bundle = QLThumbnailRequestGetGeneratorBundle(thumbnail);
+ NSString *outputString = PreviewUrl(url, bundle);
+
+ CFDataRef data = CFStringCreateExternalRepresentation(NULL, (CFStringRef)outputString, kCFStringEncodingUTF8, 0);
+
+ //NSRect previewRect;
+ //previewRect.size = previewSize;
+
+ WebView* webView = [[WebView alloc] initWithFrame:renderRect];
+ [webView scaleUnitSquareToSize:scaleSize];
+ [[[webView mainFrame] frameView] setAllowsScrolling:NO];
+
+ [[webView mainFrame] loadData:(NSData*)data MIMEType:@"text/html"
+ textEncodingName:@"UTF-8" baseURL:nil];
+
+ while([webView isLoading]) {
+ CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
+ }
+
+ // Get a context to render into
+ CGContextRef context =
+ QLThumbnailRequestCreateContext(thumbnail, thumbSize, false, NULL);
+
+ if(context != NULL) {
+ NSGraphicsContext* nsContext =
+ [NSGraphicsContext
+ graphicsContextWithGraphicsPort:(void *)context
+ flipped:[webView isFlipped]];
+
+ [webView displayRectIgnoringOpacity:[webView bounds]
+ inContext:nsContext];
+
+ QLThumbnailRequestFlushContext(thumbnail, context);
+
+ CFRelease(context);
+ }
+
+ [pool release];
return noErr;
}
View
@@ -17,6 +17,8 @@
<string>net.sourceforge.openbabel.pdb</string>
<string>net.sourceforge.openbabel.cml</string>
<string>net.sourceforge.openbabel.mdl</string>
+ <string>net.sourceforge.openbabel.gamout</string>
+ <string>net.sourceforge.openbabel.qcout</string>
<string>com.gaussian.cube</string>
<string>com.gaussian.output</string>
<string>com.gaussian.fchk</string>
@@ -165,6 +167,24 @@
</array>
</dict>
</dict>
+ <dict>
+ <key>UTTypeConformsTo</key>
+ <array>
+ <string>public.plain-text</string>
+ <string>public.text</string>
+ </array>
+ <key>UTTypeDescription</key>
+ <string>Q-Chem Output</string>
+ <key>UTTypeIdentifier</key>
+ <string>net.sourceforge.openbabel.qcout</string>
+ <key>UTTypeTagSpecification</key>
+ <dict>
+ <key>public.filename-extension</key>
+ <array>
+ <string>qcout</string>
+ </array>
+ </dict>
+ </dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
Oops, something went wrong.

0 comments on commit af0262f

Please sign in to comment.