2 Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
23 #include <atalk/logger.h>
25 #include "slmod_sparql_map.h"
27 #define NOTSUPPORTED NULL
30 struct spotlight_sparql_map spotlight_sparql_map[] = {
31 /* ssm_spotlight_attr ssm_enabled, ssm_type, ssm_sparql_attr */
32 {"*", true, ssmt_fts, "fts:match"},
34 /* Filesystem metadata */
35 {"kMDItemFSLabel", true, ssmt_num, NOTSUPPORTED},
36 {"kMDItemDisplayName", true, ssmt_str, "nfo:fileName"},
37 {"kMDItemFSName", true, ssmt_str, "nfo:fileName"},
38 {"kMDItemFSContentChangeDate", true, ssmt_date, "nfo:fileLastModified"},
41 {"kMDItemTextContent", true, ssmt_fts, "fts:match"},
42 {"kMDItemContentCreationDate", true, ssmt_date, "nie:contentCreated"},
43 {"kMDItemContentModificationDate", true, ssmt_date, "nfo:fileLastModified"},
44 {"kMDItemAttributeChangeDate", true, ssmt_date, "nfo:fileLastModified"},
45 {"kMDItemLastUsedDate", true, ssmt_date, "nfo:fileLastAccessed"},
46 {"kMDItemAuthors", true, ssmt_str, "dc:creator"},
47 {"kMDItemCopyright", true, ssmt_str, "nie:copyright"},
48 {"kMDItemCountry", true, ssmt_str, "nco:country"},
49 {"kMDItemCreator", true, ssmt_str, "dc:creator"},
50 {"kMDItemDurationSeconds", true, ssmt_num, "nfo:duration"},
51 {"kMDItemNumberOfPages", true, ssmt_num, "nfo:pageCount"},
52 {"kMDItemTitle", true, ssmt_str, "nie:title"},
53 {"_kMDItemGroupId", true, ssmt_type, SPECIAL},
54 {"kMDItemContentTypeTree", true, ssmt_type, SPECIAL},
57 {"kMDItemPixelWidth", true, ssmt_num, "nfo:width"},
58 {"kMDItemPixelHeight", true, ssmt_num, "nfo:height"},
59 {"kMDItemColorSpace", true, ssmt_str, "nexif:colorSpace"},
60 {"kMDItemBitsPerSample", true, ssmt_num, "nfo:colorDepth"},
61 {"kMDItemFocalLength", true, ssmt_num, "nmm:focalLength"},
62 {"kMDItemISOSpeed", true, ssmt_num, "nmm:isoSpeed"},
63 {"kMDItemOrientation", true, ssmt_bool, "nfo:orientation"},
64 {"kMDItemResolutionWidthDPI", true, ssmt_num, "nfo:horizontalResolution"},
65 {"kMDItemResolutionHeightDPI", true, ssmt_num, "nfo:verticalResolution"},
66 {"kMDItemExposureTimeSeconds", true, ssmt_num, "nmm:exposureTime"},
69 {"kMDItemComposer", true, ssmt_str, "nmm:composer"},
70 {"kMDItemMusicalGenre", true, ssmt_str, "nfo:genre"},
72 {NULL, false, ssmt_str, NULL}
75 struct MDTypeMap MDTypeMap[] = {
76 {"1", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#Email"},
77 {"2", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Contact"},
78 {"3", kMDTypeMapNotSup, NULL}, /* PrefPane */
79 {"4", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Font"},
80 {"5", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Bookmark"},
81 {"6", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Contact"},
82 {"7", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video"},
83 {"8", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Executable"},
84 {"9", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Folder"},
85 {"10", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Audio"},
86 {"11", kMDTypeMapMime, "application/pdf"},
87 {"12", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Presentation"},
88 {"13", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Image"},
89 {"public.jpeg", kMDTypeMapMime, "image/jpeg"},
90 {"public.tiff", kMDTypeMapMime, "image/tiff"},
91 {"com.compuserve.gif", kMDTypeMapMime, "image/gif"},
92 {"public.png", kMDTypeMapMime, "image/png"},
93 {"com.microsoft.bmp", kMDTypeMapMime, "image/bmp"},
94 {"public.content", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Document"},
95 {"public.mp3", kMDTypeMapMime, "audio/mpeg"},
96 {"public.mpeg-4-audio", kMDTypeMapMime, "audio/x-aac"},
97 {"com.apple.application", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Software"},
98 {"public.text", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#TextDocument"},
99 {"public.plain-text", kMDTypeMapMime, "text/plain"},
100 {"public.rtf", kMDTypeMapMime, "text/rtf"},
101 {"public.html", kMDTypeMapMime, "text/html"},
102 {"public.xml", kMDTypeMapMime, "text/xml"},
103 {"public.source-code", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#SourceCode"},
104 {NULL, kMDTypeMapNotSup, NULL}
107 void configure_spotlight_attributes(const char *attributes_in)
109 char *attr, *attributes;
112 for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++)
113 spotlight_sparql_map[i].ssm_enabled = false;
116 * Go through the attribute map and for every element scan
117 * attributes_in with strtok(). If it's contained, keep it
118 * enabled, otherwise disable it.
121 attributes = strdup(attributes_in);
123 for (attr = strtok(attributes, ","); attr; attr = strtok(NULL, ",")) {
125 for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++)
127 if (strcmp(attr, spotlight_sparql_map[i].ssm_spotlight_attr) == 0) {
128 LOG(log_info, logtype_sl, "Enabling Spotlight attribute: %s",
129 spotlight_sparql_map[i].ssm_spotlight_attr);
130 spotlight_sparql_map[i].ssm_enabled = true;