blob: bae493f67f5af771dcbbe6ec30f3bf00407c03a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
namespace Xmpp {
// FileInfo.get_content_type() returns a content type. On Linux, that's the same as the mime type, but on Windows and MacOS it's not.
// Since content type and mime type are both strings, this util class introduces some type checks around that.
public class FileContentType {
string content_type = null;
public FileContentType.from_file_info(FileInfo file_info) {
content_type = file_info.get_content_type();
}
public FileContentType.from_mime_type(string mime_type) {
content_type = ContentType.from_mime_type(mime_type);
}
public FileContentType.from_file(File file) {
try {
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
this.from_file_info(file_info);
} catch (Error e) {
warning("Failed reading file content type: %s", e.message);
}
}
public string? get_mime_type() {
return ContentType.get_mime_type(content_type);
}
public string? get_generic_icon_name() {
return ContentType.get_generic_icon_name(content_type);
}
public string? get_description() {
return ContentType.get_description(content_type);
}
public bool is_image() {
return get_mime_type().has_prefix("image");
}
}
}
|