Debian Codegraph @

qml/components/MimeTypeMapper.js

raw
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * webbrowser-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 .pragma library
20 .import Lomiri.Content 1.3 as LomiriContent
21
22 function startsWith(string, prefix) {
23 return string.indexOf(prefix) === 0;
24 }
25
26 function mimeTypeToContentType(mimeType) {
27 if(startsWith(mimeType, "image")) {
28 return LomiriContent.ContentType.Pictures;
29 } else if(startsWith(mimeType, "audio")) {
30 return LomiriContent.ContentType.Music;
31 } else if(startsWith(mimeType, "video")) {
32 return LomiriContent.ContentType.Videos;
33 } else if(startsWith(mimeType, "text/x-vcard")) {
34 return LomiriContent.ContentType.Contacts;
35 } else if(startsWith(mimeType, "text")) {
36 return LomiriContent.ContentType.Documents;
37 } else {
38 return LomiriContent.ContentType.Unknown;
39 }
40 }
41
42 function contentTypeToMimeType(contentType) {
43 if (contentType === LomiriContent.ContentType.Pictures) {
44 return "image";
45 } else if (contentType === LomiriContent.ContentType.Videos) {
46 return "video";
47 }
48 }