]> arthur.barton.de Git - netatalk.git/blob - etc/spotlight/slmod_sparql_map.c
Spotlight: new options for controlling query behaviour
[netatalk.git] / etc / spotlight / slmod_sparql_map.c
1 /*
2   Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
3
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.
8
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.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif /* HAVE_CONFIG_H */
18
19 #include <unistd.h>
20 #include <string.h>
21 #include <stdlib.h>
22
23 #include <atalk/logger.h>
24
25 #include "slmod_sparql_map.h"
26
27 #define NOTSUPPORTED NULL
28 #define SPECIAL      NULL
29
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"},
33
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"},
39
40     /* Common metadata */
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},
55
56     /* Image metadata */
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"},
67
68     /* Audio metadata */
69     {"kMDItemComposer",                 true, ssmt_str,   "nmm:composer"},
70     {"kMDItemMusicalGenre",             true, ssmt_str,   "nfo:genre"},
71
72     {NULL, false, ssmt_str, NULL}
73 };
74
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}
105 };
106
107 void configure_spotlight_attributes(const char *attributes_in)
108 {
109     char *attr, *attributes;
110     int i;
111
112     for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++)
113         spotlight_sparql_map[i].ssm_enabled = false;
114
115     /*
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.
119      */
120
121     attributes = strdup(attributes_in);
122
123     for (attr = strtok(attributes, ","); attr; attr = strtok(NULL, ",")) {
124
125         for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++)
126
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;
131                 break;
132         }
133     }
134
135     free(attributes);
136 }