| Derived from | |
| Framework | QuickLook/QuickLook.h |
| Companion guide | |
| Declared in | QLGenerator.h |
Quick Look generators use the QLPreviewRequest API to help create a document preview that is returned to Quick Look clients (such as Finder and Spotlight) for display. An object of the QLPreviewRequest opaque type represents a request from a client for a preview of a document and is used to return the preview image the generator creates or locates
A generator must implement the GeneratePreviewForURL callback function to create and return a preview image requested for a given document. QLPreviewRequest gives you four ways to create or locate a preview for a document:
You can create a graphics context to draw the preview in. Graphics contexts for previews are of three kinds: bitmap, single-page vector, and multi-page vector.
For bitmap and single-page vector contexts, use the QLPreviewRequestCreateContext function.
For multi-page (PDF) contexts, use the QLPreviewRequestCreatePDFContext function.
The generator can extract the preview data from the document and return it to the client using the QLPreviewRequestSetDataRepresentation function. (For this approach to work the application’s document must save the preview as part of the document.) The generator can also dynamically generate the preview and return it with this function.
As a refinement of this same approach, the generator can dynamically generate the preview as HTML data that references attachments. It can then call QLPreviewRequestSetDataRepresentation, passing in a content type of HTML and dictionaries specifying the attachments.
Most of the other functions of QLPreviewRequest let you get the data associated with the preview request, such as the URL locating the document and the UTI identifying the content type of the document.
QLPreviewRequestCreateContext
QLPreviewRequestCreatePDFContext
QLPreviewRequestSetDataRepresentation
QLPreviewRequestFlushContext
QLPreviewRequestCopyContentUTI
QLPreviewRequestCopyOptions
QLPreviewRequestCopyURL
QLPreviewRequestGetGeneratorBundle
QLPreviewRequestIsCancelled
Returns the UTI for the preview request.
QL_EXPORT CFStringRef QLPreviewRequestCopyContentUTI( QLPreviewRequestRef preview );
The preview request object.
The UTI of the associated preview request; returns NULL if the UTI is not available. You should explicitly release this object when it is no longer needed.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hReturns the options specified for the preview request.
QL_EXPORT CFDictionaryRef QLPreviewRequestCopyOptions( QLPreviewRequestRef preview );
A preview request object.
A dictionary containing the properties specified for the preview request. See “Preview Properties” for supported options. You should explicitly release this object when it is no longer needed.
The client sets options in the preview request to give hints to the generator. (For Mac OS X v10.5 no options are supported.)
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hReturns the URL of the document for which a preview is requested.
QL_EXPORT CFURLRef QLPreviewRequestCopyURL( QLPreviewRequestRef preview );
The preview request object.
The URL identifying the file for which the preview is requested.
This function is thread safe.
QLGenerator.hCreates a graphics context to draw the preview in.
QL_EXPORT CGContextRef QLPreviewRequestCreateContext( QLPreviewRequestRef preview, CGSize size, Boolean isBitmap, CFDictionaryRef properties );
The preview request object.
The size of the preview; if isBitmap is true the size is in pixels, otherwise it is in points.
true if the preview uses a bitmap-based graphics context, false otherwise. This value of this parameter affects the interpretation of the size parameter.
A dictionary containing properties for the preview response. “Preview Properties” lists the current property keys and describes their values.
A Core Graphics graphics-context object that you can draw your preview image in. You should explicitly release this object when it is no longer needed.
You can directly draw your preview data in the graphics-context object created by this function. After calling this function, you should flush the context with QLPreviewRequestFlushContext. Also be sure to release the CGContext object.
Quick Look provides three types of graphics contexts for drawing previews: bitmap, single-page vector-based, and multi-page vector-based (for PDF previews). You use this function to acquire a context for bitmap and single-page vector drawing; the isBitmap parameter is used to distinguish between them. For multi-page contexts, use the QLPreviewRequestCreatePDFContext function.
If you prefer to work in Objective-C code, you can convert the created CGContextRef to a NSGraphicsContext object using graphicsContextWithGraphicsPort:flipped:.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hCreates a PDF context suitable to draw a multi-page preview.
QL_EXPORT CGContextRef QLPreviewRequestCreatePDFContext( QLPreviewRequestRef preview, const CGRect * mediaBox, CFDictionaryRef auxiliaryInfo, CFDictionaryRef properties); );
The preview request object.
A pointer to the media box of the context.
A media box is a rectangle that defines the size and location of the PDF page. The origin of the rectangle should typically be (0,0). If you pass NULL, Quartz uses a default page size of 8.5 by 11 inches (612 by 792 points). For information see the description for CGPDFContextCreate.
A dictionary containing PDF auxiliary information. See the description of the auxiliary dictionary keys in CGPDFContext Reference for more information about the keys and values of this dictionary.
A dictionary containing additional properties for the preview response. For information on acceptable keys and values, see “Preview Properties.”
A reference to a Core Graphics context object that is used to display a PDF version of the preview. You should explicitly release this object when it is no longer needed.
Be sure to bracket each PDF page written to the context with CGPDFContextBeginPage and CGPDFContextEndPage calls. After calling this function, you should flush the context with QLPreviewRequestFlushContext.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hFlush the context and sets the preview response.
QL_EXPORT void QLPreviewRequestFlushContext( QLPreviewRequestRef preview, CGContextRef context );
The preview request object.
The graphics context to flush.
You should call this method immediately after drawing in the graphics contexts created by QLPreviewRequestCreateContext and QLPreviewRequestCreatePDFContext.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hGet the bundle of the generator receiving the preview request.
QL_EXPORT CFBundleRef QLPreviewRequestGetGeneratorBundle( QLPreviewRequestRef preview );
The preview request object.
A reference to a bundle object representing the generator’s bundle.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hGets the type identifier for the QLPreviewReqest opaque type.
CFTypeID QLPreviewRequestGetTypeID();
The type identifier for the QLPreviewReqest opaque type.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hReturns whether the preview request has been cancelled by the client.
QL_EXPORT Boolean QLPreviewRequestIsCancelled( QLPreviewRequestRef preview );
The object representing the preview request.
true if the request is being canceled, false otherwise.
While computing the response, the generator can poll the preview request object with this function to determine if the client has cancelled the request. Alternatively, the generator can implement the CancelPreviewGeneration callback. but since that function is called in a secondary thread, it is generally safer to take the polling approach.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hSets the preview request to data saved within the document or to dynamically generated data.
QL_EXPORT void QLPreviewRequestSetDataRepresentation( QLPreviewRequest preview, CFDataRef data, CFStringRef contentTypeUTI, CFDictionary properties );
The preview request object.
The data of the preview returned to the client. .
The UTI specifying the content type of the preview.
Additional properties for the preview response. For more on supported keys and values for this dictionary, see “Preview Properties.” If the saved data is HTML, you may specify a special set of properties; see the discussion below for more information.
This function returns preview data to the client. The data is either extracted from a document (where the document’s application has saved it,) or it is dynamically generated. How Quick Look handles the data depends upon the value of contentTypeUTI. The content data of the preview must be of a native Quick Look type. Currently supported UTIs for these types are: kUTTypeImage, kUTTypePDF, kUTTypeHTML, kUTTypeXML, kUTTypePlainText, kUTTypeRTF, kUTTypeMovie, and kUTTypeAudio.
If the UTI type is kUTTypeHTML, you can have the WebKit handle the layout and display of your preview. You must provide the HTML in data plus any attachments (for example, Address Book cards, Mail messages, or Omni Outliner documents) in the properties dictionary. This dictionary takes kQLPreviewPropertyAttachmentsKey as its key and consists of one ore more subdictionaries (one per attachment). Each subdictionary uses an arbitrary string identifier as a key; the attachment should be referenced within the HTML data using the kQLPreviewContentIDScheme URL scheme (“cid”) and the identifier as the URL resource specifier—for example, “cid:the_identifier”. The keys of the subdictionary properties are kQLPreviewPropertyMIMETypeKey, kQLPreviewPropertyTextEncodingNameKey, and kQLPreviewPropertyAttachmentDataKey.
Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.
QLGenerator.hDefines a pointer to a function that Quick Look calls to cancel a preview request.
void (*CancelPreviewGeneration)( void *thisInterface, QLPreviewRequestRef preview );
The CFPlugIn COM-style interface for the generator.
The object representing the preview request.
If the client application indicates (usually because of user choice) that it is no longer interested in the preview currently being created by a Quick Look generator, this callback function is invoked. The generator can implement this function to stop creating the preview and clean up the resources used for creating it.
An alternative to implementing this callback is to periodically poll the QLPreviewRequestRef object with QLPreviewRequestIsCancelled to see if the request has been canceled.
Important: Because this function is called on a thread different from the one used to request that the preview be created, you should be extra careful about thread safety. If you have any doubts about thread safety, do not implement this callback.
Thread-safety: For a discussions of issues and possible approaches, see Overview of Generator Implementation in Quick Look Programming Guide.
QuickLook/QLGenerator.hDefines a pointer to the callback function that Quick Look calls to request a preview from a generator.
OSStatus (*GeneratePreviewForURL)( void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options );
The Xcode template for Quick Look generators automatically creates a “skeletal” function with the same name as the callback symbol name: GeneratePreviewForURL.
The CFPlugIn COM-style interface for the generator.
The object containing all information relevant to the preview request. The generator’s role is to assign a document preview (in the requested native type) to this object before it returns.
A URL (represented by a CFURLRef object) that locates the document for which a preview is requested.
The UTI specifying the content type of the document for which the preview is requested.
A dictionary of options for processing the preview. Options may be passed from the client (for example, Finder or Spotlight).
A status code representing the result of the request. For the current version of this callback, you should always return noErr.
The GeneratePreviewForURL callback function implemented by a Quick Look generator may be called one or more times concurrenly if the QLSupportsConcurrentRequests property in the generator bundle’s Info.plist file is set to true. If this is the case, use the preview parameter to distinguish among current requests. The generator might also have the QLNeedsToBeRunInMainThread property set to true, in which case the callback is always invoked in the main thread.
Thread-safety: For a discussions of issues and possible approaches, see “Overview of Generator Implementation“ in Quick Look Programming Guide.
QuickLook/QLGenerator.hAn opaque reference representing an QLPreviewRequest object.
typedef struct __QLPreviewRequest *QLPreviewRequestRef;
QLGenerator.hKeys of the properties dictionary in functions used to create a preview.
QL_EXPORT const CFStringRef kQLPreviewPropertyDisplayNameKey; QL_EXPORT const CFStringRef kQLPreviewPropertyWidthKey; QL_EXPORT const CFStringRef kQLPreviewPropertyHeightKey; QL_EXPORT const CFStringRef kQLPreviewPropertyStringEncodingKey; QL_EXPORT const CFStringRef kQLPreviewPropertyMIMETypeKey; QL_EXPORT const CFStringRef kQLPreviewPropertyTextEncodingNameKey; QL_EXPORT const CFStringRef kQLPreviewPropertyAttachmentDataKey; QL_EXPORT const CFStringRef kQLPreviewPropertyAttachmentsKey; QL_EXPORT const CFStringRef kQLPreviewContentIDScheme;
kQLPreviewPropertyDisplayNameKeySpecifies a custom display name in the preview panel. The default display name is the document title. The value must be encapsulated in a CFString object.
kQLPreviewPropertyWidthKeySpecifies the width (in points) of the preview. Note that this property is a hint; Quick Look might set the width automatically for some types of previews. The value must be encapsulated in a CFNumber object.
kQLPreviewPropertyHeightKeySpecifies the height (in points) of the preview. Note that this property is a hint; Quick Look might set the height automatically for some types of previews. The value must be encapsulated in a CFNumber object.
kQLPreviewPropertyStringEncodingKeySpecifies the string encoding (as an CFStringEncoding value) of the preview data if the native type is plain text. The value must be encapsulated in a CFNumber object.
kQLPreviewPropertyMIMETypeKeyGives the web content or attachment mime type. For the main data, the default type is “text/html”. The value is a CFString object.
kQLPreviewPropertyTextEncodingNameKeySpecifies the encoding of the web content or attachment text. For the value, use IANA encodings like “UTF-8”. The value value is a CFString object.
kQLPreviewPropertyAttachmentDataKeyGives the attachment data. The value is a CFData object.
kQLPreviewPropertyAttachmentsKeyGives the list of attachments (or sub-resources). Value is a CFDictionary object.
The keys of the dictionary are the attachment identifiers (CFString objects) that can be referenced with the cid:id URL; the values are dictionaries using the kQLPreviewPropertyAttachmentDataKey, kQLPreviewPropertyMIMETypeKey and kQLPreviewPropertyTextEncodingNameKey properties.
kQLPreviewContentIDSchemeThe cid URL scheme.
The cid URL scheme permits the HTML of a mail message to refer to the images or other data included in the message. For more information go to http://www.rfc-archive.org/getrfc.php?rfc=2111.
You use these keys to specify properties of the generated preview in the dictionary passed into the functions QLPreviewRequestCreateContext, QLPreviewRequestCreatePDFContext, and QLPreviewRequestSetDataRepresentation as the final parameter.
QuickLook/QLGenerator.h
Last updated: 2007-04-20