Implement simple Quick Look plugins that generate a preview and/or thumbnail image using Apple's latest Quick Look APIs. The approach is to load and render any thumbnail images that may have been embedded in .od* files when they were last saved. Fortunately, LibreOffice, OpenOffice, and NeoOffice have been saving thumbnail images by default in .od* files since at least the mid-2000s so this approach should work with most unencrypted .od* files. Note: the plugins appear to work in unsigned builds using the following steps to enable them: 1. Install LibreOfficeDev.app from an unsigned .dmg (e.g. nightly master builds) but the plugins in instdir/LibreOfficeDev.app in a local build are not usable. 2. Launch LibreOfficeDev.app to register the plugins. 3. Launch the System Preferences application, navigate to the Login Items & Extensions panel, and in the Extensions section, click on the icon next to the Quick Look entry to see a list of installed extensions. 4. If macOS has successfully found and loaded the plugins, there should be two extensions listed under LibreOfficeDev. If they are disabled, enable both. 5. Press Command-Option-Escape, select the Finder in the dialog that appears, and press the Relaunch button. The Finder should now display the thumbnail images in .od* files. Change-Id: I094afbc56b684cc85b12ed996e060818bfe8ad46 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178393 Reviewed-by: Patrick Luby <guibomacdev@gmail.com> Tested-by: Jenkins Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
59 lines
1.8 KiB
Objective-C
59 lines
1.8 KiB
Objective-C
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#import <Quartz/Quartz.h>
|
|
|
|
#import "PreviewViewController.h"
|
|
#import "OOoSpotlightAndQuickLookImporter.h"
|
|
|
|
@implementation PreviewViewController
|
|
|
|
- (void)preparePreviewOfFileAtURL:(NSURL *)url completionHandler:(void (^)(NSError * _Nullable))handler {
|
|
if (!url || ![url isFileURL]) {
|
|
handler([[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorUnsupportedURL userInfo:nil]);
|
|
return;
|
|
}
|
|
|
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
|
|
|
OOoSpotlightAndQuickLookImporter *importer = [OOoSpotlightAndQuickLookImporter new];
|
|
|
|
NSImage *image = nil;
|
|
@try {
|
|
image = [importer importDocumentThumbnail:[url path]];
|
|
}
|
|
@catch (NSException *exception) {
|
|
NSLog(@"preparePreviewOfFileAtURL: Caught %@: %@", [exception name], [exception reason]);
|
|
}
|
|
|
|
[importer release];
|
|
|
|
if (!image) {
|
|
handler([[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorUnsupportedURL userInfo:nil]);
|
|
[pool release];
|
|
return;
|
|
}
|
|
|
|
// Make image automatic scale to the size of the view while preserving the
|
|
// image's aspect ratio by using a CALayer to handle image drawing:
|
|
// https://stackoverflow.com/questions/23002653/nsimageview-image-aspect-fill
|
|
self.view.layer = [CALayer layer];
|
|
self.view.layer.contentsGravity = kCAGravityResizeAspect;
|
|
self.view.layer.contents = image;
|
|
self.view.wantsLayer = YES;
|
|
|
|
handler(nil);
|
|
|
|
[pool release];
|
|
}
|
|
|
|
@end
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|