00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <CoreFoundation/CoreFoundation.h>
00016 #include <CoreFoundation/CFPlugInCOM.h>
00017 #include <CoreServices/CoreServices.h>
00018 #include <QuickLook/QuickLook.h>
00019
00020
00021
00022
00023
00024
00025 #define PLUGIN_ID "9E28C44E-DE9B-4941-8963-405BD216DD9D"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize);
00041 void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail);
00042
00043
00044 OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);
00045 void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview);
00046
00047
00048 typedef struct __QuickLookGeneratorPluginType
00049 {
00050 void *conduitInterface;
00051 CFUUIDRef factoryID;
00052 UInt32 refCount;
00053 } QuickLookGeneratorPluginType;
00054
00055
00056
00057
00058
00059
00060
00061 QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID);
00062 void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance);
00063 HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv);
00064 void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID);
00065 ULONG QuickLookGeneratorPluginAddRef(void *thisInstance);
00066 ULONG QuickLookGeneratorPluginRelease(void *thisInstance);
00067
00068
00069
00070
00071
00072
00073 static QLGeneratorInterfaceStruct myInterfaceFtbl = {
00074 NULL,
00075 QuickLookGeneratorQueryInterface,
00076 QuickLookGeneratorPluginAddRef,
00077 QuickLookGeneratorPluginRelease,
00078 NULL,
00079 NULL,
00080 NULL,
00081 NULL
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID)
00093 {
00094 QuickLookGeneratorPluginType *theNewInstance;
00095
00096 theNewInstance = (QuickLookGeneratorPluginType *)malloc(sizeof(QuickLookGeneratorPluginType));
00097 memset(theNewInstance,0,sizeof(QuickLookGeneratorPluginType));
00098
00099
00100 theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct));
00101 memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl,sizeof(QLGeneratorInterfaceStruct));
00102
00103
00104 theNewInstance->factoryID = CFRetain(inFactoryID);
00105 CFPlugInAddInstanceForFactory(inFactoryID);
00106
00107
00108 theNewInstance->refCount = 1;
00109 return theNewInstance;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance)
00121 {
00122 CFUUIDRef theFactoryID;
00123
00124 theFactoryID = thisInstance->factoryID;
00125
00126 free(thisInstance->conduitInterface);
00127
00128
00129 free(thisInstance);
00130 if (theFactoryID){
00131 CFPlugInRemoveInstanceForFactory(theFactoryID);
00132 CFRelease(theFactoryID);
00133 }
00134 }
00135
00136
00137
00138
00139
00140
00141 HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv)
00142 {
00143 CFUUIDRef interfaceID;
00144
00145 interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid);
00146
00147 if (CFEqual(interfaceID,kQLGeneratorCallbacksInterfaceID)){
00148
00149
00150
00151
00152 ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GenerateThumbnailForURL = GenerateThumbnailForURL;
00153 ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->CancelThumbnailGeneration = CancelThumbnailGeneration;
00154 ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GeneratePreviewForURL = GeneratePreviewForURL;
00155 ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->CancelPreviewGeneration = CancelPreviewGeneration;
00156 ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType*)thisInstance)->conduitInterface)->AddRef(thisInstance);
00157 *ppv = thisInstance;
00158 CFRelease(interfaceID);
00159 return S_OK;
00160 }else{
00161
00162 *ppv = NULL;
00163 CFRelease(interfaceID);
00164 return E_NOINTERFACE;
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 ULONG QuickLookGeneratorPluginAddRef(void *thisInstance)
00176 {
00177 ((QuickLookGeneratorPluginType *)thisInstance )->refCount += 1;
00178 return ((QuickLookGeneratorPluginType*) thisInstance)->refCount;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187 ULONG QuickLookGeneratorPluginRelease(void *thisInstance)
00188 {
00189 ((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1;
00190 if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0){
00191 DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance );
00192 return 0;
00193 }else{
00194 return ((QuickLookGeneratorPluginType*) thisInstance )->refCount;
00195 }
00196 }
00197
00198
00199
00200
00201 void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID)
00202 {
00203 QuickLookGeneratorPluginType *result;
00204 CFUUIDRef uuid;
00205
00206
00207
00208
00209 if (CFEqual(typeID,kQLGeneratorTypeID)){
00210 uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
00211 result = AllocQuickLookGeneratorPluginType(uuid);
00212 CFRelease(uuid);
00213 return result;
00214 }
00215
00216 return NULL;
00217 }
00218