Database Reference
In-Depth Information
[attachments setValue:imageDict forKey:@ "preview-image" ];
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
[properties setValue:attachments
forKey:(id)kQLPreviewPropertyAttachmentsKey];
[properties setValue:@ "text/html"
forKey:(id)kQLPreviewPropertyMIMETypeKey];
[properties setValue:@ "UTF-8"
forKey:(id)kQLPreviewPropertyTextEncodingNameKey];
[properties setValue:@ "Recipe"
forKey:(id)kQLPreviewPropertyDisplayNameKey];
For Quick Look to be able to use the HTML page that we are handing to it, it
requires that we describe the document and include any attachments it has.
This helps improve the performance of the HTML rendering, since it does not
have to fetch any of the attachments. Therefore, in this section, we are setting
up the properties for the HTML page, including specifying its encoding, the
MIME type, and the attachments. We also give it a display name that will be
used outside the HTML page.
Spotlight/QuickLookPlugin/GeneratePreviewForURL.m
NSBundle *bundle = [NSBundle bundleWithIdentifier:bundleID];
NSString *templatePath = [bundle pathForResource:@ "preview" ofType:@ "html" ];
NSURL *templateURL = [NSURL fileURLWithPath:templatePath];
NSError *error = nil;
NSXMLDocument *template;
template = [[[NSXMLDocument alloc] initWithContentsOfURL:(NSURL*)templateURL
options:NSXMLDocumentTidyHTML
error:&error] autorelease];
if (!template) {
NSLog(@ "Failed to build template: %@" , error);
return noErr;
}
Once all the preliminaries are complete, we need to retrieve the HTML template
from our bundle. Since this code is not actually being called from our bundle,
we cannot just perform [NSBundlemainBundle] and get a reference to our NSBundle .
(If we tried, we would actually get a reference to /usr/bin/qlmanage !) Instead, we
have to request it by its UTI . With a reference to the bundle, we can then
retrieve the path to preview.html , which we will be using as our template. Once
we have loaded the HTML file into an NSXMLDocument , it is time to substitute
the placeholders in that file with real data.
Spotlight/QuickLookPlugin/GeneratePreviewForURL.m
//Updating the Title
error = nil;
NSXMLElement *element = [[template nodesForXPath:
 
 
 
Search WWH ::




Custom Search