Browse files

[NEW] Blitz.app can now directly open Keynote .key files. Uses undocu…

…mented QuickLookUI.framework to pull it off.
  • Loading branch information...
1 parent 13343cb commit 6770af7608d76e7424d2c181d93b4951f7b8006a @rentzsch committed Sep 19, 2009
Showing with 110 additions and 20 deletions.
  1. +2 −2 Blitz.xcodeproj/project.pbxproj
  2. +17 −1 Info.plist
  3. +4 −2 MyDocument.h
  4. +87 −15 MyDocument.m
View
4 Blitz.xcodeproj/project.pbxproj
@@ -333,7 +333,7 @@
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
PRODUCT_VERSION = 0.1;
- SDKROOT = macosx10.5;
+ SDKROOT = macosx10.6;
};
name = Debug;
};
@@ -349,7 +349,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
PRODUCT_VERSION = 0.1;
- SDKROOT = macosx10.5;
+ SDKROOT = macosx10.6;
};
name = Release;
};
View
18 Info.plist
@@ -9,6 +9,22 @@
<dict>
<key>CFBundleTypeExtensions</key>
<array>
+ <string>key</string>
+ </array>
+ <key>CFBundleTypeName</key>
+ <string>KeynoteDocument</string>
+ <key>CFBundleTypeRole</key>
+ <string>Viewer</string>
+ <key>LSTypeIsPackage</key>
+ <false/>
+ <key>NSDocumentClass</key>
+ <string>MyDocument</string>
+ <key>NSPersistentStoreTypeKey</key>
+ <string>XML</string>
+ </dict>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array>
<string>pdf</string>
</array>
<key>CFBundleTypeIconFile</key>
@@ -18,7 +34,7 @@
<string>application/pdf</string>
</array>
<key>CFBundleTypeName</key>
- <string>DocumentType</string>
+ <string>PDFDocument</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>????</string>
View
6 MyDocument.h
@@ -3,11 +3,13 @@
@class BlitzPDFView;
-@interface MyDocument : NSDocument {
+@interface MyDocument : NSDocument <QLPreviewPanelDataSource, QLPreviewPanelDelegate> {
IBOutlet BlitzPDFView *pdfView;
@private PDFDocument *pdfDocument;
@private NSTimer *timer;
- @private BOOL isInFullScreenMode;
+ @private BOOL isInFullScreenMode;
+
+ QLPreviewPanel *previewPanel;
}
@property (retain, nonatomic) IBOutlet BlitzPDFView *pdfView;
View
102 MyDocument.m
@@ -1,6 +1,12 @@
#import "MyDocument.h"
#import "BlitzPDFView.h"
+@interface NSObject (UndocumentedQuickLookUI)
+- (id)_previewView; // -[QLPreviewPanelController _previewView]
+- (id)displayBundle; // -[QLDisplayBundle displayBundle];
+- (PDFDocument*)pdfDocument; // -[QLDisplayBundle pdfDocument]
+@end
+
@interface MyDocument ()
@property (retain, nonatomic) PDFDocument *pdfDocument;
@property (retain, nonatomic) NSTimer *timer;
@@ -16,27 +22,30 @@ - (void)toggleFullScreenMode {
self.isInFullScreenMode = NO;
}
else {
- NSWindow *window = [[[self windowControllers] objectAtIndex:0] window];
+ // TODO
+ //NSWindow *window = [[[self windowControllers] objectAtIndex:0] window];
//self.isInFullScreenMode = [self.pdfView enterFullScreenMode: window.screen withOptions: nil];
}
}
-- (void)windowControllerDidLoadNib:(NSWindowController*)controller_ {
- [super windowControllerDidLoadNib:controller_];
-
- if (!self.pdfDocument) {
- self.pdfDocument = [[PDFDocument alloc] init];
- }
+- (void)initPDFView {
[self.pdfView setDocument:self.pdfDocument];
self.pdfView.secondsElapsed = 0;
self.timer = [[NSTimer scheduledTimerWithTimeInterval:1.0
- target:self
- selector:@selector(updateElapsedTimer:)
- userInfo:nil
- repeats:YES] retain];
- self.isInFullScreenMode = NO;
- [self toggleFullScreenMode];
+ target:self
+ selector:@selector(updateElapsedTimer:)
+ userInfo:nil
+ repeats:YES] retain];
+ self.isInFullScreenMode = NO;
+ [self toggleFullScreenMode];
+}
+
+- (void)windowControllerDidLoadNib:(NSWindowController*)controller_ {
+ [super windowControllerDidLoadNib:controller_];
+ if (self.pdfDocument) {
+ [self initPDFView];
+ }
}
- (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError {
@@ -45,9 +54,46 @@ - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSErr
return NO;
}
+- (void)pollPDFPageCount:(NSTimer*)timer_ {
+ id myQLPreviewPanelController = [[QLPreviewPanel sharedPreviewPanel] windowController];
+ //NSLog(@"myQLPreviewPanelController: %@", myQLPreviewPanelController);
+
+ id myQLPreviewView = [myQLPreviewPanelController _previewView];
+ //NSLog(@"myQLPreviewView: %@", myQLPreviewView);
+
+ id myQLDisplayBundle = [myQLPreviewView displayBundle];
+ //NSLog(@"myQLDisplayBundle: %@", myQLDisplayBundle);
+
+ PDFDocument *pdfDisplayBundlePDFDocument = [myQLDisplayBundle pdfDocument];
+ //NSLog(@"pdfDisplayBundlePDFDocument: %@", pdfDisplayBundlePDFDocument);
+
+ NSLog(@"pageCount: %d", [pdfDisplayBundlePDFDocument pageCount]);
+ if ([pdfDisplayBundlePDFDocument pageCount] >= 20) {
+ [timer_ invalidate];
+ self.pdfDocument = pdfDisplayBundlePDFDocument;
+ [self initPDFView];
+ [[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
+ }
+}
+
- (BOOL)readFromURL:(NSURL *)initWithURL ofType:(NSString *)typeName error:(NSError **)outError {
- self.pdfDocument = [[PDFDocument alloc] initWithURL:initWithURL];
- return self.pdfDocument ? YES : NO;
+ if ([typeName isEqualToString:@"PDFDocument"]) {
+ self.pdfDocument = [[PDFDocument alloc] initWithURL:initWithURL];
+ return self.pdfDocument ? YES : NO;
+ } else if ([typeName isEqualToString:@"KeynoteDocument"]) {
+ [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
+ // Poor man's window-hiding since we can't immediately orderOut the panel (crashes):
+ [[QLPreviewPanel sharedPreviewPanel] setFrameTopLeftPoint:NSMakePoint(-5000, -5000)];
+
+ [NSTimer scheduledTimerWithTimeInterval:1
+ target:self
+ selector:@selector(pollPDFPageCount:)
+ userInfo:nil
+ repeats:YES];
+ return YES;
+ } else {
+ return NO;
+ }
}
- (void)updateElapsedTimer:(NSTimer*)timer_ {
@@ -66,6 +112,32 @@ - (void)updateElapsedTimer:(NSTimer*)timer_ {
//--
+- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel *)panel {
+ return YES;
+}
+
+- (void)beginPreviewPanelControl:(QLPreviewPanel *)panel {
+ previewPanel = [panel retain];
+ panel.delegate = self;
+ panel.dataSource = self;
+}
+
+- (void)endPreviewPanelControl:(QLPreviewPanel *)panel {
+ [previewPanel release];
+ previewPanel = nil;
+}
+
+- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel {
+ return 1;
+}
+
+- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index {
+ return [self fileURL];
+ //return [NSURL fileURLWithPath:@"/Users/wolf/code/github/Blitz/blitz-example.pdf"];//[selectedDownloads objectAtIndex:index];
+}
+
+//--
+
- (NSString *)windowNibName {
return @"MyDocument";
}

0 comments on commit 6770af7

Please sign in to comment.