2012-08-12 12:11:33 +00:00
|
|
|
//==============================================================================
|
|
|
|
//
|
|
|
|
// DO NO MODIFY THE CONTENT OF THIS FILE
|
|
|
|
//
|
|
|
|
// This file contains the generic CFPlug-in code necessary for your generator
|
|
|
|
// To complete your generator implement the function in GenerateThumbnailForURL/GeneratePreviewForURL.c
|
|
|
|
//
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
#include <CoreFoundation/CFPlugInCOM.h>
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#include <QuickLook/QuickLook.h>
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Don't modify this line
|
|
|
|
#define PLUGIN_ID "FDF02409-6B04-4738-973D-1AADB4FC34D8"
|
|
|
|
|
|
|
|
//
|
|
|
|
// Below is the generic glue code for all plug-ins.
|
|
|
|
//
|
|
|
|
// You should not have to modify this code aside from changing
|
|
|
|
// names if you decide to change the names defined in the Info.plist
|
|
|
|
//
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// typedefs
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// The thumbnail generation function to be implemented in GenerateThumbnailForURL.c
|
2021-08-15 09:41:48 +00:00
|
|
|
OSStatus GenerateThumbnailForURL(
|
|
|
|
void* thisInterface,
|
|
|
|
QLThumbnailRequestRef thumbnail,
|
|
|
|
CFURLRef url,
|
|
|
|
CFStringRef contentTypeUTI,
|
|
|
|
CFDictionaryRef options,
|
|
|
|
CGSize maxSize);
|
2012-08-12 12:11:33 +00:00
|
|
|
void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail);
|
|
|
|
|
|
|
|
// The preview generation function to be implemented in GeneratePreviewForURL.c
|
2021-08-15 09:41:48 +00:00
|
|
|
OSStatus GeneratePreviewForURL(
|
|
|
|
void* thisInterface,
|
|
|
|
QLPreviewRequestRef preview,
|
|
|
|
CFURLRef url,
|
|
|
|
CFStringRef contentTypeUTI,
|
|
|
|
CFDictionaryRef options);
|
|
|
|
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview);
|
2012-08-12 12:11:33 +00:00
|
|
|
|
|
|
|
// The layout for an instance of QuickLookGeneratorPlugIn
|
|
|
|
typedef struct __QuickLookGeneratorPluginType
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
void* conduitInterface;
|
|
|
|
CFUUIDRef factoryID;
|
|
|
|
UInt32 refCount;
|
2012-08-12 12:11:33 +00:00
|
|
|
} QuickLookGeneratorPluginType;
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// prototypes
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Forward declaration for the IUnknown implementation.
|
|
|
|
//
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
QuickLookGeneratorPluginType* AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID);
|
|
|
|
void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType* thisInstance);
|
|
|
|
HRESULT QuickLookGeneratorQueryInterface(void* thisInstance, REFIID iid, LPVOID* ppv);
|
|
|
|
void* QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID);
|
|
|
|
ULONG QuickLookGeneratorPluginAddRef(void* thisInstance);
|
|
|
|
ULONG QuickLookGeneratorPluginRelease(void* thisInstance);
|
2012-08-12 12:11:33 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// myInterfaceFtbl definition
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// The QLGeneratorInterfaceStruct function table.
|
|
|
|
//
|
2021-08-15 09:41:48 +00:00
|
|
|
static QLGeneratorInterfaceStruct myInterfaceFtbl = { //
|
|
|
|
NULL, //
|
2012-08-12 12:11:33 +00:00
|
|
|
QuickLookGeneratorQueryInterface,
|
|
|
|
QuickLookGeneratorPluginAddRef,
|
|
|
|
QuickLookGeneratorPluginRelease,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// AllocQuickLookGeneratorPluginType
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Utility function that allocates a new instance.
|
|
|
|
// You can do some initial setup for the generator here if you wish
|
|
|
|
// like allocating globals etc...
|
|
|
|
//
|
2021-08-15 09:41:48 +00:00
|
|
|
QuickLookGeneratorPluginType* AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID)
|
2012-08-12 12:11:33 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
QuickLookGeneratorPluginType* theNewInstance;
|
|
|
|
|
|
|
|
theNewInstance = (QuickLookGeneratorPluginType*)malloc(sizeof(QuickLookGeneratorPluginType));
|
|
|
|
memset(theNewInstance, 0, sizeof(QuickLookGeneratorPluginType));
|
|
|
|
|
2012-08-12 16:19:06 +00:00
|
|
|
/* Point to the function table Malloc enough to store the stuff and copy the filler from myInterfaceFtbl over */
|
2012-08-12 12:11:33 +00:00
|
|
|
theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct));
|
2021-08-15 09:41:48 +00:00
|
|
|
memcpy(theNewInstance->conduitInterface, &myInterfaceFtbl, sizeof(QLGeneratorInterfaceStruct));
|
|
|
|
|
2012-08-12 16:19:06 +00:00
|
|
|
/* Retain and keep an open instance refcount for each factory. */
|
2021-09-24 12:56:57 +00:00
|
|
|
theNewInstance->factoryID = static_cast<CFUUIDRef>(CFRetain(inFactoryID));
|
2012-08-12 12:11:33 +00:00
|
|
|
CFPlugInAddInstanceForFactory(inFactoryID);
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2012-08-12 16:19:06 +00:00
|
|
|
/* This function returns the IUnknown interface so set the refCount to one. */
|
2012-08-12 12:11:33 +00:00
|
|
|
theNewInstance->refCount = 1;
|
|
|
|
return theNewInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// DeallocQuickLookGeneratorPluginType
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Utility function that deallocates the instance when
|
|
|
|
// the refCount goes to zero.
|
|
|
|
// In the current implementation generator interfaces are never deallocated
|
|
|
|
// but implement this as this might change in the future
|
|
|
|
//
|
2021-08-15 09:41:48 +00:00
|
|
|
void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType* thisInstance)
|
2012-08-12 12:11:33 +00:00
|
|
|
{
|
|
|
|
CFUUIDRef theFactoryID;
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2012-08-12 12:11:33 +00:00
|
|
|
theFactoryID = thisInstance->factoryID;
|
2012-08-12 16:19:06 +00:00
|
|
|
/* Free the conduitInterface table up */
|
2012-08-12 12:11:33 +00:00
|
|
|
free(thisInstance->conduitInterface);
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2012-08-12 16:19:06 +00:00
|
|
|
/* Free the instance structure */
|
2012-08-12 12:11:33 +00:00
|
|
|
free(thisInstance);
|
2021-08-15 09:41:48 +00:00
|
|
|
if (theFactoryID)
|
|
|
|
{
|
2012-08-12 12:11:33 +00:00
|
|
|
CFPlugInRemoveInstanceForFactory(theFactoryID);
|
|
|
|
CFRelease(theFactoryID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// QuickLookGeneratorQueryInterface
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Implementation of the IUnknown QueryInterface function.
|
|
|
|
//
|
2021-08-15 09:41:48 +00:00
|
|
|
HRESULT QuickLookGeneratorQueryInterface(void* thisInstance, REFIID iid, LPVOID* ppv)
|
2012-08-12 12:11:33 +00:00
|
|
|
{
|
|
|
|
CFUUIDRef interfaceID;
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, iid);
|
|
|
|
|
|
|
|
if (CFEqual(interfaceID, kQLGeneratorCallbacksInterfaceID))
|
|
|
|
{
|
2012-08-12 16:19:06 +00:00
|
|
|
/* If the Right interface was requested, bump the ref count,
|
|
|
|
* set the ppv parameter equal to the instance, and
|
|
|
|
* return good status.
|
|
|
|
*/
|
2021-08-15 09:41:48 +00:00
|
|
|
QLGeneratorInterfaceStruct* const
|
|
|
|
qlGeneratorIface = (QLGeneratorInterfaceStruct*)((QuickLookGeneratorPluginType*)thisInstance)->conduitInterface;
|
|
|
|
qlGeneratorIface->GenerateThumbnailForURL = GenerateThumbnailForURL;
|
|
|
|
qlGeneratorIface->CancelThumbnailGeneration = CancelThumbnailGeneration;
|
|
|
|
qlGeneratorIface->GeneratePreviewForURL = GeneratePreviewForURL;
|
|
|
|
qlGeneratorIface->CancelPreviewGeneration = CancelPreviewGeneration;
|
|
|
|
qlGeneratorIface->AddRef(thisInstance);
|
2012-08-12 12:11:33 +00:00
|
|
|
*ppv = thisInstance;
|
|
|
|
CFRelease(interfaceID);
|
|
|
|
return S_OK;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-12 12:11:33 +00:00
|
|
|
/* Requested interface unknown, bail with error. */
|
|
|
|
*ppv = NULL;
|
|
|
|
CFRelease(interfaceID);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// QuickLookGeneratorPluginAddRef
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Implementation of reference counting for this type. Whenever an interface
|
|
|
|
// is requested, bump the refCount for the instance. NOTE: returning the
|
|
|
|
// refcount is a convention but is not required so don't rely on it.
|
|
|
|
//
|
2021-08-15 09:41:48 +00:00
|
|
|
ULONG QuickLookGeneratorPluginAddRef(void* thisInstance)
|
2012-08-12 12:11:33 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
((QuickLookGeneratorPluginType*)thisInstance)->refCount += 1;
|
|
|
|
return ((QuickLookGeneratorPluginType*)thisInstance)->refCount;
|
2012-08-12 12:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// QuickLookGeneratorPluginRelease
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// When an interface is released, decrement the refCount.
|
|
|
|
// If the refCount goes to zero, deallocate the instance.
|
|
|
|
//
|
2021-08-15 09:41:48 +00:00
|
|
|
ULONG QuickLookGeneratorPluginRelease(void* thisInstance)
|
2012-08-12 12:11:33 +00:00
|
|
|
{
|
|
|
|
((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1;
|
2021-08-15 09:41:48 +00:00
|
|
|
if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0)
|
|
|
|
{
|
|
|
|
DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance);
|
2012-08-12 12:11:33 +00:00
|
|
|
return 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ((QuickLookGeneratorPluginType*)thisInstance)->refCount;
|
2012-08-12 12:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// QuickLookGeneratorPluginFactory
|
|
|
|
// -----------------------------------------------------------------------------
|
2021-08-15 09:41:48 +00:00
|
|
|
void* QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID)
|
2012-08-12 12:11:33 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
QuickLookGeneratorPluginType* result;
|
|
|
|
CFUUIDRef uuid;
|
|
|
|
|
2012-08-12 16:19:06 +00:00
|
|
|
/* If correct type is being requested, allocate an
|
|
|
|
* instance of kQLGeneratorTypeID and return the IUnknown interface.
|
|
|
|
*/
|
2021-08-15 09:41:48 +00:00
|
|
|
if (CFEqual(typeID, kQLGeneratorTypeID))
|
|
|
|
{
|
|
|
|
uuid = CFUUIDCreateFromString(kCFAllocatorDefault, CFSTR(PLUGIN_ID));
|
2012-08-12 12:11:33 +00:00
|
|
|
result = AllocQuickLookGeneratorPluginType(uuid);
|
|
|
|
CFRelease(uuid);
|
|
|
|
return result;
|
|
|
|
}
|
2012-08-12 16:19:06 +00:00
|
|
|
/* If the requested type is incorrect, return NULL. */
|
2012-08-12 12:11:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|