Skip to content

Commit

Permalink
[NEW] Blitz.app can now directly open Keynote .key files. Uses undocu…
Browse files Browse the repository at this point in the history
…mented QuickLookUI.framework to pull it off.
  • Loading branch information
rentzsch committed Sep 19, 2009
1 parent 13343cb commit 6770af7
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Blitz.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
PRODUCT_VERSION = 0.1;
SDKROOT = macosx10.5;
SDKROOT = macosx10.6;
};
name = Debug;
};
Expand All @@ -349,7 +349,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
PRODUCT_VERSION = 0.1;
SDKROOT = macosx10.5;
SDKROOT = macosx10.6;
};
name = Release;
};
Expand Down
18 changes: 17 additions & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<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>
Expand All @@ -18,7 +34,7 @@
<string>application/pdf</string>
</array>
<key>CFBundleTypeName</key>
<string>DocumentType</string>
<string>PDFDocument</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>????</string>
Expand Down
6 changes: 4 additions & 2 deletions MyDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
102 changes: 87 additions & 15 deletions MyDocument.m
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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_ {
Expand All @@ -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";
}
Expand Down

0 comments on commit 6770af7

Please sign in to comment.