Dekko
ContentType.qml
1 /* Copyright (C) 2016 - 2017 Dan Chapman <dpniel@ubuntu.com>
2 
3  This file is part of Dekko email client for Ubuntu devices
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License or (at your option) version 3
9 
10  This program 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 pragma Singleton
19 import QtQuick 2.4
20 import Lomiri.Components 1.3
21 import Lomiri.Content 1.1 as CH
22 
23 Item {
24 
25  function resolveType(fileUrl) {
26  console.log("resolveContentType for file", fileUrl)
27  var extension = d.__fileExtension(fileUrl)
28  extension = extension.toLowerCase()
29  console.log("file extension:", extension)
30  var contentType = d.contentMap[extension]
31 
32  if (contentType === undefined) {
33  console.log("Unrecognized extension", extension)
34  contentType = CH.ContentType.All
35  }
36 
37  console.log("returning contentType:", contentType)
38 
39  return contentType
40  }
41 
42  QtObject {
43  id: d
44 
45  function __fileExtension(fileUrl) {
46  var lastDotIndex = fileUrl.lastIndexOf('.')
47  return lastDotIndex > -1 ? fileUrl.substring(lastDotIndex + 1) : ''
48  }
49 
50  property var contentMap: {
51  'png': CH.ContentType.Pictures,
52  'jpg': CH.ContentType.Pictures,
53  'jpeg': CH.ContentType.Pictures,
54  'bmp': CH.ContentType.Pictures,
55  'gif': CH.ContentType.Pictures,
56 
57  'mp3': CH.ContentType.Music,
58  'ogg': CH.ContentType.Music,
59  'wav': CH.ContentType.Music,
60  'm4a': CH.ContentType.Music,
61  'opus': CH.ContentType.Music,
62  'flac': CH.ContentType.Music,
63 
64  'avi': CH.ContentType.Videos,
65  'mpeg': CH.ContentType.Videos,
66  'mp4': CH.ContentType.Videos,
67  'mkv': CH.ContentType.Videos,
68  'mov': CH.ContentType.Videos,
69  'wmv': CH.ContentType.Videos,
70 
71  'txt': CH.ContentType.Documents,
72  'doc': CH.ContentType.Documents,
73  'docx': CH.ContentType.Documents,
74  'xls': CH.ContentType.Documents,
75  'xlsx': CH.ContentType.Documents,
76  'ppt': CH.ContentType.Documents,
77  'pptx': CH.ContentType.Documents,
78  'pdf': CH.ContentType.Documents,
79  'odt': CH.ContentType.Documents,
80  'ott': CH.ContentType.Documents,
81  'oth': CH.ContentType.Documents,
82  'ods': CH.ContentType.Documents,
83  'ots': CH.ContentType.Documents,
84  'html': CH.ContentType.Documents,
85  'odp': CH.ContentType.Documents,
86  'otp': CH.ContentType.Documents,
87  'odf': CH.ContentType.Documents,
88  'odg': CH.ContentType.Documents,
89  'otg': CH.ContentType.Documents,
90  'odm': CH.ContentType.Documents,
91 
92  'vcard': CH.ContentType.Contacts,
93  'vcf': CH.ContentType.Contacts
94  }
95  }
96 }