Debian Codegraph @

src/app/qml/content-hub/contenttyperesolver.js

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Canonical Ltd
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 version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Arto Jalkanen <[email protected]>
17 */
18 .import Lomiri.Content 1.3 as CH
19
20 /**
21 * For now a simple static mapping of file extensions to ContentHub types.
22 * This is enough for RTM, but in the future a better strategy would be
23 * for asking for the MIME-type of the file and mapping that to the
24 * ContentType
25 */
26
27 function extToContentType(ext) {
28 switch(ext) {
29 case "art":
30 case "bmp":
31 case "cdr":
32 case "cdt":
33 case "cpt":
34 case "cr2":
35 case "crw":
36 case "djv":
37 case "djvu":
38 case "erf":
39 case "gif":
40 case "ico":
41 case "ief":
42 case "jng":
43 case "jp2":
44 case "jpe":
45 case "jpeg":
46 case "jpf":
47 case "jpg":
48 case "jpg2":
49 case "jpm":
50 case "jpx":
51 case "nef":
52 case "orf":
53 case "pat":
54 case "pbm":
55 case "pcx":
56 case "pgm":
57 case "png":
58 case "pnm":
59 case "ppm":
60 case "psd":
61 case "ras":
62 case "rgb":
63 case "svg":
64 case "svgz":
65 case "tif":
66 case "tiff":
67 case "wbmp":
68 case "xbm":
69 case "xpm":
70 case "xwd":
71 return CH.ContentType.Pictures;
72 case "3gp":
73 case "asf":
74 case "asx":
75 case "avi":
76 case "axv":
77 case "dif":
78 case "dl":
79 case "dv":
80 case "fli":
81 case "flv":
82 case "gl":
83 case "lsf":
84 case "lsx":
85 case "m4v":
86 case "mkv":
87 case "mng":
88 case "mov":
89 case "movie":
90 case "mp4":
91 case "mpe":
92 case "mpeg":
93 case "mpg":
94 case "mpv":
95 case "mxu":
96 case "ogv":
97 case "qt":
98 case "ts":
99 case "webm":
100 case "wm":
101 case "wmv":
102 case "wmx":
103 case "wvx":
104 return CH.ContentType.Videos;
105 case "aif":
106 case "aifc":
107 case "aiff":
108 case "amr":
109 case "au":
110 case "awb":
111 case "axa":
112 case "csd":
113 case "flac":
114 case "gsm":
115 case "kar":
116 case "m3u":
117 case "m4a":
118 case "mid":
119 case "midi":
120 case "mp2":
121 case "mp3":
122 case "mpega":
123 case "mpga":
124 case "oga":
125 case "ogg":
126 case "opus":
127 case "orc":
128 case "pls":
129 case "ra":
130 case "ram":
131 case "rm":
132 case "sco":
133 case "sd2":
134 case "sid":
135 case "snd":
136 case "spx":
137 case "wav":
138 case "wax":
139 case "wma":
140 return CH.ContentType.Music;
141 case "vcard":
142 case "vcf":
143 return CH.ContentType.Contacts;
144 case "323":
145 case "appcache":
146 case "asc":
147 case "bib":
148 case "boo":
149 case "brf":
150 case "c":
151 case "c++":
152 case "cc":
153 case "cls":
154 case "cpp":
155 case "csh":
156 case "css":
157 case "csv":
158 case "cxx":
159 case "d":
160 case "diff":
161 case "doc":
162 case "docx":
163 case "etx":
164 case "gcd":
165 case "h":
166 case "hh":
167 case "h++":
168 case "hpp":
169 case "hs":
170 case "htc":
171 case "htm":
172 case "html":
173 case "hxx":
174 case "ics":
175 case "icz":
176 case "jad":
177 case "java":
178 case "lhs":
179 case "ltx":
180 case "ly":
181 case "mml":
182 case "moc":
183 case "odp":
184 case "ods":
185 case "odt":
186 case "p":
187 case "pas":
188 case "patch":
189 case "pdf":
190 case "pl":
191 case "pm":
192 case "pot":
193 case "ppt":
194 case "pptx":
195 case "py":
196 case "rtx":
197 case "scala":
198 case "sct":
199 case "sfv":
200 case "sh":
201 case "shtml":
202 case "srt":
203 case "sty":
204 case "tcl":
205 case "tex":
206 case "text":
207 case "tk":
208 case "tm":
209 case "tsv":
210 case "ttl":
211 case "txt":
212 case "uls":
213 case "vcs":
214 case "wml":
215 case "wmls":
216 case "wsc":
217 case "xls":
218 case "xlsx":
219 return CH.ContentType.Documents;
220 case "epub":
221 case "mobi":
222 case "lit":
223 case "fb2":
224 case "azw":
225 case "tpz":
226 return CH.ContentType.EBooks;
227 default:
228 return CH.ContentType.Unknown;
229 }
230 }
231
232 function resolveContentType(fileUrl) {
233 console.log("resolveContentType for file", fileUrl)
234 var extension = __fileExtension(fileUrl)
235 extension = extension.toLowerCase()
236 console.log("file extension:", extension)
237 var contentType = extToContentType(extension)
238
239 if (typeof contentType === undefined) {
240 console.log("Unrecognized extension", extension)
241 contentType = CH.ContentType.Unknown
242 }
243
244 console.log("returning contentType:", contentType)
245
246 return contentType
247 }
248
249 function __fileExtension(fileUrl) {
250 var lastDotIndex = fileUrl.lastIndexOf('.')
251 return lastDotIndex > -1 ? fileUrl.substring(lastDotIndex + 1) : ''
252 }