Skip to content
Browse files

Add a custom schema file

This has two benefits.

The first is that we can create custom attributes for things we can
extract (e.g. illustrators) that Spotlight has no concept of (i.e. the
kMDItemFoo things)

So this creates attributes for illustrators and translators. Note the
name is reverse DNS style with "." replaced with "_". Note also that "-"
needs to be replaced or the schema file will be unparseable at runtime -
I used "_" for that too.

The second benefit is that this allows us to customize the "More info"
panel in the Finder "Get Info" window. This is quite cool.

It would be nice if the More info panel could display our custom
attributes, but it doesn't seem to. There's no obvious way for it to map
the attribute name org_idpf_foo to a friendly label.

I commented out the "Indexed nnnn characters" things.
  • Loading branch information...
1 parent 2cf1ba9 commit 4a328ab4483e29fd10365b16290306102f3b01b8 @chrisridd committed Mar 4, 2012
Showing with 53 additions and 3 deletions.
  1. +4 −0 epub.xcodeproj/project.pbxproj
  2. +10 −3 epubMDI/MySpotlightImporter.m
  3. +39 −0 epubMDI/schema.xml
View
4 epub.xcodeproj/project.pbxproj
@@ -51,6 +51,7 @@
675FAB5C14D9BF780065603A /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = D78388991354AA7600E7937B /* zip.c */; };
6783BD9F14FA8C1C00696991 /* NSString+HTML.m in Sources */ = {isa = PBXBuildFile; fileRef = 674D09CF14CF2C6800127A36 /* NSString+HTML.m */; };
67909CE914F37D9E009819B2 /* NSDate+OPF.m in Sources */ = {isa = PBXBuildFile; fileRef = 67E3077214E9A24A0004C1D8 /* NSDate+OPF.m */; };
+ 67932B221503FEA600D61278 /* schema.xml in Resources */ = {isa = PBXBuildFile; fileRef = 67932B211503FEA600D61278 /* schema.xml */; };
67BE43EE14DEC886003C7DFC /* fake-adept.epub in Resources */ = {isa = PBXBuildFile; fileRef = 67BE43EB14DEC886003C7DFC /* fake-adept.epub */; };
67BE43EF14DEC886003C7DFC /* fake-fairplay.epub in Resources */ = {isa = PBXBuildFile; fileRef = 67BE43EC14DEC886003C7DFC /* fake-fairplay.epub */; };
67BE43F014DEC886003C7DFC /* fake-kobo.epub in Resources */ = {isa = PBXBuildFile; fileRef = 67BE43ED14DEC886003C7DFC /* fake-kobo.epub */; };
@@ -121,6 +122,7 @@
675FAB4A14D9B8760065603A /* EpubTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EpubTests.h; sourceTree = "<group>"; };
675FAB4B14D9B8760065603A /* EpubTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EpubTests.m; sourceTree = "<group>"; };
675FAB4D14D9B8760065603A /* EpubTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "EpubTests-Prefix.pch"; sourceTree = "<group>"; };
+ 67932B211503FEA600D61278 /* schema.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = schema.xml; sourceTree = "<group>"; };
67BE43EB14DEC886003C7DFC /* fake-adept.epub */ = {isa = PBXFileReference; lastKnownFileType = file; path = "fake-adept.epub"; sourceTree = "<group>"; };
67BE43EC14DEC886003C7DFC /* fake-fairplay.epub */ = {isa = PBXFileReference; lastKnownFileType = file; path = "fake-fairplay.epub"; sourceTree = "<group>"; };
67BE43ED14DEC886003C7DFC /* fake-kobo.epub */ = {isa = PBXFileReference; lastKnownFileType = file; path = "fake-kobo.epub"; sourceTree = "<group>"; };
@@ -224,6 +226,7 @@
235DC65414EFB3C800D28657 /* InfoPlist.strings */,
235DC65714EFB3C800D28657 /* main.c */,
235DC65F14EFB3C800D28657 /* epubMDI-Prefix.pch */,
+ 67932B211503FEA600D61278 /* schema.xml */,
);
name = "Supporting Files";
sourceTree = "<group>";
@@ -507,6 +510,7 @@
files = (
235DC65614EFB3C800D28657 /* InfoPlist.strings in Resources */,
674566961502B4810012224C /* entities.plist in Resources */,
+ 67932B221503FEA600D61278 /* schema.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
13 epubMDI/MySpotlightImporter.m
@@ -39,7 +39,14 @@ - (BOOL)importFileAtPath:(NSString *)filePath attributes:(NSMutableDictionary *)
[spotlightData setObject:editors forKey:(NSString *)kMDItemEditors];
// illustrators
+ NSArray *illustrators = [epub illustrators];
+ if ([illustrators count] > 0)
+ [spotlightData setObject:illustrators forKey:@"org_idpf_epub_container_metadata_illustrators"];
+
// translators
+ NSArray *translators = [epub translators];
+ if ([translators count] > 0)
+ [spotlightData setObject:translators forKey:@"org_idpf_epub_container_metadata_translators"];
// synopsis kMDItemHeadline ?
NSString *synopsis = [[epub synopsis] stringByStrippingHTML];
@@ -74,12 +81,12 @@ - (BOOL)importFileAtPath:(NSString *)filePath attributes:(NSMutableDictionary *)
if (text)
[content appendString:text];
} while (text);
- NSString *tmp = [NSString stringWithFormat:@"Indexed %lu", [content length]];
- [spotlightData setObject:tmp forKey:(NSString *)kMDItemComment];
+ //NSString *tmp = [NSString stringWithFormat:@"Indexed %lu", [content length]];
+ //[spotlightData setObject:tmp forKey:(NSString *)kMDItemComment];
[spotlightData setObject:content forKey:(NSString *)kMDItemTextContent];
[content release];
} else {
- [spotlightData setObject:@"No indexed content" forKey:(NSString *)kMDItemComment];
+ //[spotlightData setObject:@"No indexed content" forKey:(NSString *)kMDItemComment];
}
[epub release];
View
39 epubMDI/schema.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema version="1.0" xmlns="http://www.apple.com/metadata"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.apple.com/metadata
+ file:///System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Resources/MetadataSchema.xsd">
+ <note>
+ Custom attributes indexed by this EPUB metadata importer.
+ </note>
+ <attributes>
+ <attribute name="org_idpf_epub_container_metadata_illustrators" multivalued="true" type="CFString"/>
+ <attribute name="org_idpf_epub_container_metadata_translators" multivalued="true" type="CFString"/>
+ </attributes>
+ <types>
+ <type name="org.idpf.epub-container">
+ <allattrs>
+ kMDItemDisplayName
+ kMDItemAuthors
+ kMDItemPublishers
+ kMDItemContributors
+ kMDItemEditors
+ org_idpf_epub_container_metadata_illustrators
+ org_idpf_epub_container_metadata_translators
+ kMDItemHeadline
+ kMDItemIdentifier
+ kMDItemDueDate
+ kMDItemSecurityMethod
+ kMDItemComment
+ kMDItemTextContent
+ </allattrs>
+ <displayattrs>
+ kMDItemDisplayName
+ kMDItemAuthors
+ kMDItemPublishers
+ kMDItemDueDate
+ kMDItemSecurityMethod
+ </displayattrs>
+ </type>
+ </types>
+</schema>

0 comments on commit 4a328ab

Please sign in to comment.
Something went wrong with that request. Please try again.