Permalink
Browse files

Working initial version

  • Loading branch information...
besi committed Mar 9, 2011
1 parent 9be89f9 commit 9948ad596bf2a37f6ddfad2678c96765e8f8cc64
Showing with 84 additions and 7 deletions.
  1. +18 −0 Dot.h
  2. +42 −0 Dot.m
  3. +16 −7 GeneratePreviewForURL.m
  4. +8 −0 quicklook-dot.xcodeproj/project.pbxproj
View
18 Dot.h
@@ -0,0 +1,18 @@
+//
+// Dot.h
+// quicklook-dot
+//
+// Created by Besi on 09.03.11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface Dot : NSObject {
+}
+
++(NSData *)dataFromDotFile: (NSURL *) dotFile;
+
+
+@end
View
42 Dot.m
@@ -0,0 +1,42 @@
+//
+// Dot.m
+// quicklook-dot
+//
+// Created by Besi on 09.03.11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "Dot.h"
+
+
+@implementation Dot
+
++(NSData *)dataFromDotFile: (NSURL *) dotFile
+{
+ NSTask *task;
+ task = [[NSTask alloc] init];
+ [task setLaunchPath: @"/usr/bin/dot"];
+
+ NSArray *arguments;
+ NSString *dotPath = [dotFile path];
+
+ NSLog(@"Path: %@",dotPath);
+
+
+ arguments = [NSArray arrayWithObjects:dotPath, @"-Tpng", nil];
+ [task setArguments: arguments];
+
+ NSPipe *pipe;
+ pipe = [NSPipe pipe];
+ [task setStandardOutput: pipe];
+
+ NSFileHandle *file;
+ file = [pipe fileHandleForReading];
+
+ [task launch];
+
+ return [file readDataToEndOfFile];
+}
+
+
+@end
View
@@ -3,13 +3,15 @@
#include <QuickLook/QuickLook.h>
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
+#include "Dot.h"
/* -----------------------------------------------------------------------------
Generate a preview for file
This function's job is to create preview for designated file
----------------------------------------------------------------------------- */
+
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
@@ -22,20 +24,27 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CGContextRef cgContext = QLPreviewRequestCreateContext(preview, *(CGSize *)&canvasSize, true, NULL);
if(cgContext) {
- NSData *imageData = [NSData dataWithContentsOfFile:@"/Users/besi/Dropbox/projects/gurgelisms-air/doc/setup.png"];
+ NSData *imageData = [Dot dataFromDotFile: (NSURL *)url ];
- CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData ((CFDataRef)imageData);
- CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
+
+ CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData ((CFDataRef)imageData);
+ CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
- CGContextDrawImage(cgContext,CGRectMake(0, 0, 400, 400), image);
+ CGContextDrawImage(cgContext,CGRectMake(0, 0, 400, 400), image);
- QLPreviewRequestFlushContext(preview, cgContext); CFRelease(cgContext);
- } [pool release]; return noErr;
+ QLPreviewRequestFlushContext(preview, cgContext); CFRelease(cgContext);
+ }
-}
+ [pool release];
+
+ return noErr;
+}
+
+
+
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
{
// implement only if supported
@@ -16,6 +16,8 @@
CD3F0DD51327E3110088B552 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD3F0DD41327E3110088B552 /* Foundation.framework */; };
CD3F0DEC1327E36F0088B552 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD3F0DEB1327E36F0088B552 /* CoreData.framework */; };
CD55E28B1328203E0051B5D2 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD55E28A1328203E0051B5D2 /* AppKit.framework */; };
+ CD55E2E8132828F20051B5D2 /* Dot.h in Headers */ = {isa = PBXBuildFile; fileRef = CD55E2E6132828F20051B5D2 /* Dot.h */; };
+ CD55E2E9132828F20051B5D2 /* Dot.m in Sources */ = {isa = PBXBuildFile; fileRef = CD55E2E7132828F20051B5D2 /* Dot.m */; };
F28CFBFD0A3EC0AF000ABFF5 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F28CFBFC0A3EC0AF000ABFF5 /* ApplicationServices.framework */; };
F28CFC030A3EC0C6000ABFF5 /* QuickLook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F28CFC020A3EC0C6000ABFF5 /* QuickLook.framework */; };
/* End PBXBuildFile section */
@@ -32,6 +34,8 @@
CD3F0DD41327E3110088B552 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
CD3F0DEB1327E36F0088B552 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
CD55E28A1328203E0051B5D2 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
+ CD55E2E6132828F20051B5D2 /* Dot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Dot.h; sourceTree = "<group>"; };
+ CD55E2E7132828F20051B5D2 /* Dot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Dot.m; sourceTree = "<group>"; };
F28CFBFC0A3EC0AF000ABFF5 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = "<absolute>"; };
F28CFC020A3EC0C6000ABFF5 /* QuickLook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickLook.framework; path = /System/Library/Frameworks/QuickLook.framework; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
@@ -94,6 +98,8 @@
61E3BCFA0870B4F2002186A0 /* GenerateThumbnailForURL.m */,
2C05A19B06CAA52B00D84F6F /* GeneratePreviewForURL.m */,
08FB77B6FE84183AC02AAC07 /* main.c */,
+ CD55E2E6132828F20051B5D2 /* Dot.h */,
+ CD55E2E7132828F20051B5D2 /* Dot.m */,
);
name = Source;
sourceTree = "<group>";
@@ -113,6 +119,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
+ CD55E2E8132828F20051B5D2 /* Dot.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -192,6 +199,7 @@
8D576312048677EA00EA77CD /* main.c in Sources */,
2C05A19C06CAA52B00D84F6F /* GeneratePreviewForURL.m in Sources */,
61E3BCFB0870B4F2002186A0 /* GenerateThumbnailForURL.m in Sources */,
+ CD55E2E9132828F20051B5D2 /* Dot.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 9948ad5

Please sign in to comment.