Skip to content

Commit 044d8c2

Browse files
committed
Add xar spotlight plugin for Mac OS X
1 parent 783dc77 commit 044d8c2

File tree

7 files changed

+737
-0
lines changed

7 files changed

+737
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Localized versions of Info.plist keys */
2+
3+
CFBundleShortVersionString = "1.0";
4+
CFBundleGetInfoString = "xar version 1.0, Copyright (c) 2007 __MyCompanyName__.";
5+
NSHumanReadableCopyright = "Copyright (c) 2007 __MyCompanyName__.";
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ----------
2+
3+
4+
This file is only needed if you are defining a custom importer attribute.
5+
Most importer plugins will not need to do this.
6+
Add this file to your project's localized resources if you have defined a custom attribute.
7+
8+
9+
----------*/
10+
11+
12+
/* Localized DisplayNames for your custom metadata attributes */
13+
/* The form is: "myMetadataKey" = "My Metadata Key"; */
14+
/* The name on the left is the name defined in schema.xml */
15+
/* The name on the right is what the user will see */
16+
"com_Foo_YourAttrName" = "Your Localized Attr Name";
17+
18+
19+
/* Localized Description of you custom metadata attributes */
20+
/* The form is: "myMetadataKey.Description" = "stuff";
21+
/* com_Foo_YourAttrName should be definded in the schema.xml file */
22+
/* The value on the right will be displayed by the Finder etc.. */
23+
"com_Foo_YourAttrName.Description" = "Localized description of your attribute";

xarmdimport/GetMetadataForFile.c

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <CoreFoundation/CoreFoundation.h>
2+
#include <CoreServices/CoreServices.h>
3+
4+
#include <xar/xar.h>
5+
6+
/* -----------------------------------------------------------------------------
7+
Step 1
8+
Set the UTI types the importer supports
9+
10+
Modify the CFBundleDocumentTypes entry in Info.plist to contain
11+
an array of Uniform Type Identifiers (UTI) for the LSItemContentTypes
12+
that your importer can handle
13+
14+
----------------------------------------------------------------------------- */
15+
16+
/* -----------------------------------------------------------------------------
17+
Step 2
18+
Implement the GetMetadataForFile function
19+
20+
Implement the GetMetadataForFile function below to scrape the relevant
21+
metadata from your document and return it as a CFDictionary using standard keys
22+
(defined in MDItem.h) whenever possible.
23+
----------------------------------------------------------------------------- */
24+
25+
/* -----------------------------------------------------------------------------
26+
Step 3 (optional)
27+
If you have defined new attributes, update the schema.xml file
28+
29+
Edit the schema.xml file to include the metadata keys that your importer returns.
30+
Add them to the <allattrs> and <displayattrs> elements.
31+
32+
Add any custom types that your importer requires to the <attributes> element
33+
34+
<attribute name="com_mycompany_metadatakey" type="CFString" multivalued="true"/>
35+
36+
----------------------------------------------------------------------------- */
37+
38+
39+
40+
/* -----------------------------------------------------------------------------
41+
Get metadata attributes from file
42+
43+
This function's job is to extract useful information your file format supports
44+
and return it as a dictionary
45+
----------------------------------------------------------------------------- */
46+
47+
Boolean GetMetadataForFile(void* thisInterface,
48+
CFMutableDictionaryRef attributes,
49+
CFStringRef contentTypeUTI,
50+
CFStringRef pathToFile)
51+
{
52+
/* Pull any available metadata from the file at the specified path */
53+
/* Return the attribute keys and attribute values in the dict */
54+
/* Return TRUE if successful, FALSE if there was no data provided */
55+
char cpath[PATH_MAX];
56+
xar_t x;
57+
xar_file_t f;
58+
xar_iter_t i;
59+
CFMutableStringRef filelist;
60+
61+
if( CFStringGetCString(pathToFile, cpath, sizeof(cpath), kCFStringEncodingUTF8) == FALSE )
62+
return FALSE;
63+
64+
x = xar_open(cpath, READ);
65+
if( !x )
66+
return FALSE;
67+
68+
i = xar_iter_new();
69+
if( !i )
70+
return FALSE;
71+
72+
filelist = CFStringCreateMutable(NULL, 0);
73+
for(f = xar_file_first(x, i); f; f = xar_file_next(i)) {
74+
const char *path;
75+
path = xar_get_path(f);
76+
CFStringAppendCString(filelist, " ", kCFStringEncodingUTF8);
77+
CFStringAppendCString(filelist, path, kCFStringEncodingUTF8);
78+
}
79+
CFDictionarySetValue(attributes, kMDItemTextContent, filelist);
80+
CFDictionarySetValue(attributes, kMDItemKind, CFSTR("XAR!"));
81+
CFDictionarySetValue(attributes, kMDItemCreator, CFSTR("xar"));
82+
CFRelease(filelist);
83+
84+
xar_close(x);
85+
return TRUE;
86+
}

xarmdimport/Info.plist

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
6+
<!--
7+
If your application does not already define a UTI, you may want to declare it
8+
here, so that your documents are recognized by systems which do not have your
9+
application installed.
10+
11+
To export this declaration, fill in the fields with your applications
12+
information, and uncomment the block of XML.
13+
-->
14+
15+
16+
<key>UTExportedTypeDeclarations</key>
17+
<array>
18+
<dict>
19+
<key>UTTypeIdentifier</key>
20+
<string>xar.xar</string>
21+
<key>UTTypeReferenceURL</key>
22+
<string>http://code.google.com/p/xar</string>
23+
<key>UTTypeDescription</key>
24+
<string>xar!</string>
25+
<key>UTTypeConformsTo</key>
26+
<array>
27+
<string>public.data</string>
28+
<string>public.content</string>
29+
<!--
30+
<string>public.composite-content</string>
31+
-->
32+
</array>
33+
<key>UTTypeTagSpecification</key>
34+
<dict>
35+
<key>com.apple.ostype</key>
36+
<array>
37+
<string>XAR!</string>
38+
</array>
39+
<key>public.filename-extension</key>
40+
<array>
41+
<string>xar</string>
42+
</array>
43+
</dict>
44+
</dict>
45+
</array>
46+
47+
48+
<key>CFBundleDevelopmentRegion</key>
49+
<string>English</string>
50+
<key>CFBundleDocumentTypes</key>
51+
<array>
52+
<dict>
53+
<key>CFBundleTypeRole</key>
54+
<string>MDImporter</string>
55+
<key>LSItemContentTypes</key>
56+
<array>
57+
<string>xar.xar</string>
58+
</array>
59+
</dict>
60+
</array>
61+
<key>CFBundleExecutable</key>
62+
<string>xar</string>
63+
<key>CFBundleName</key>
64+
<string>xar</string>
65+
<key>CFBundleIconFile</key>
66+
<string></string>
67+
<key>CFBundleIdentifier</key>
68+
<string>xar.mdimporter.xar</string>
69+
<key>CFBundleInfoDictionaryVersion</key>
70+
<string>6.0</string>
71+
<key>CFBundleVersion</key>
72+
<string>1.0</string>
73+
<key>CFPlugInDynamicRegisterFunction</key>
74+
<string></string>
75+
<key>CFPlugInDynamicRegistration</key>
76+
<string>NO</string>
77+
<key>CFPlugInFactories</key>
78+
<dict>
79+
<key>29B07665-67D5-4EE1-A5C1-9D967441B787</key>
80+
<string>MetadataImporterPluginFactory</string>
81+
</dict>
82+
<key>CFPlugInTypes</key>
83+
<dict>
84+
<key>8B08C4BF-415B-11D8-B3F9-0003936726FC</key>
85+
<array>
86+
<string>29B07665-67D5-4EE1-A5C1-9D967441B787</string>
87+
</array>
88+
</dict>
89+
<key>CFPlugInUnloadFunction</key>
90+
<string></string>
91+
</dict>
92+
</plist>

0 commit comments

Comments
 (0)