aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala')
-rw-r--r--xmpp-vala/meson.build1
-rw-r--r--xmpp-vala/src/file_content_type.vala37
-rw-r--r--xmpp-vala/src/module/xep/0363_http_file_upload.vala6
-rw-r--r--xmpp-vala/src/module/xep/0446_file_metadata_element.vala12
4 files changed, 47 insertions, 9 deletions
diff --git a/xmpp-vala/meson.build b/xmpp-vala/meson.build
index d4bfc9c2..4769a8a6 100644
--- a/xmpp-vala/meson.build
+++ b/xmpp-vala/meson.build
@@ -132,6 +132,7 @@ sources = files(
'src/module/xep/0447_stateless_file_sharing.vala',
'src/module/xep/0461_replies.vala',
'src/module/xep/0482_call_invites.vala',
+ 'src/file_content_type.vala',
'src/util.vala',
)
c_args = [
diff --git a/xmpp-vala/src/file_content_type.vala b/xmpp-vala/src/file_content_type.vala
new file mode 100644
index 00000000..0f91b547
--- /dev/null
+++ b/xmpp-vala/src/file_content_type.vala
@@ -0,0 +1,37 @@
+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) {
+ FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
+ this.from_file_info(file_info);
+ }
+
+ 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");
+ }
+ }
+} \ No newline at end of file
diff --git a/xmpp-vala/src/module/xep/0363_http_file_upload.vala b/xmpp-vala/src/module/xep/0363_http_file_upload.vala
index c7b8fb59..cba422ba 100644
--- a/xmpp-vala/src/module/xep/0363_http_file_upload.vala
+++ b/xmpp-vala/src/module/xep/0363_http_file_upload.vala
@@ -24,7 +24,7 @@ public class Module : XmppStreamModule {
public string url_put { get; set; }
public HashMap<string, string> headers { get; set; }
}
- public async SlotResult request_slot(XmppStream stream, string filename, int64 file_size, string? content_type) throws HttpFileTransferError {
+ public async SlotResult request_slot(XmppStream stream, string filename, int64 file_size, FileContentType? content_type) throws HttpFileTransferError {
Flag? flag = stream.get_flag(Flag.IDENTITY);
if (flag == null) {
throw new HttpFileTransferError.SLOT_REQUEST("No flag");
@@ -35,14 +35,14 @@ public class Module : XmppStreamModule {
case NS_URI_0:
request_node = new StanzaNode.build("request", NS_URI_0).add_self_xmlns();
request_node.put_attribute("filename", filename).put_attribute("size", file_size.to_string());
- if (content_type != null) request_node.put_attribute("content-type", content_type);
+ if (content_type != null) request_node.put_attribute("content-type", content_type.get_mime_type());
break;
case NS_URI:
request_node = new StanzaNode.build("request", NS_URI).add_self_xmlns()
.put_node(new StanzaNode.build("filename", NS_URI).put_node(new StanzaNode.text(filename)))
.put_node(new StanzaNode.build("size", NS_URI).put_node(new StanzaNode.text(file_size.to_string())));
if (content_type != null) {
- request_node.put_node(new StanzaNode.build("content-type", NS_URI).put_node(new StanzaNode.text(content_type)));
+ request_node.put_node(new StanzaNode.build("content-type", NS_URI).put_node(new StanzaNode.text(content_type.get_mime_type())));
}
break;
}
diff --git a/xmpp-vala/src/module/xep/0446_file_metadata_element.vala b/xmpp-vala/src/module/xep/0446_file_metadata_element.vala
index cbe0d2c1..ebdcbcfa 100644
--- a/xmpp-vala/src/module/xep/0446_file_metadata_element.vala
+++ b/xmpp-vala/src/module/xep/0446_file_metadata_element.vala
@@ -3,7 +3,7 @@ namespace Xmpp.Xep.FileMetadataElement {
public class FileMetadata {
public string? name { get; set; }
- public string? mime_type { get; set; }
+ public FileContentType? content_type { get; set; }
public int64 size { get; set; default=-1; }
public string? desc { get; set; }
public DateTime? date { get; set; }
@@ -19,10 +19,10 @@ namespace Xmpp.Xep.FileMetadataElement {
if (this.name != null) {
node.put_node(new StanzaNode.build("name", NS_URI).put_node(new StanzaNode.text(this.name)));
}
- if (this.mime_type != null) {
+ if (this.content_type != null) {
// TODO remove the media_type node, it was implemented by accident and temporary provides backwards-compatibility
- node.put_node(new StanzaNode.build("media_type", NS_URI).put_node(new StanzaNode.text(this.mime_type)));
- node.put_node(new StanzaNode.build("media-type", NS_URI).put_node(new StanzaNode.text(this.mime_type)));
+ node.put_node(new StanzaNode.build("media_type", NS_URI).put_node(new StanzaNode.text(this.content_type.get_mime_type())));
+ node.put_node(new StanzaNode.build("media-type", NS_URI).put_node(new StanzaNode.text(this.content_type.get_mime_type())));
}
if (this.size != -1) {
node.put_node(new StanzaNode.build("size", NS_URI).put_node(new StanzaNode.text(this.size.to_string())));
@@ -72,11 +72,11 @@ namespace Xmpp.Xep.FileMetadataElement {
// TODO remove media_type handling, it was implemented by accident and temporary provides backwards-compatibility
StanzaNode? mime_node_bad = file_node.get_subnode("media_type");
if (mime_node_bad != null && mime_node_bad.get_string_content() != null) {
- metadata.mime_type = mime_node_bad.get_string_content();
+ metadata.content_type = new FileContentType.from_mime_type(mime_node_bad.get_string_content());
}
StanzaNode? mime_node = file_node.get_subnode("media-type");
if (mime_node != null && mime_node.get_string_content() != null) {
- metadata.mime_type = mime_node.get_string_content();
+ metadata.content_type = new FileContentType.from_mime_type(mime_node.get_string_content());
}
StanzaNode? size_node = file_node.get_subnode("size");
if (size_node != null && size_node.get_string_content() != null) {