aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdino/src/entity/file_transfer.vala16
-rw-r--r--libdino/src/service/file_manager.vala10
-rw-r--r--libdino/src/service/notification_events.vala2
-rw-r--r--libdino/src/service/sfs_metadata.vala6
-rw-r--r--libdino/src/service/util.vala6
-rw-r--r--main/src/ui/conversation_content_view/file_default_widget.vala18
-rw-r--r--main/src/ui/conversation_content_view/file_image_widget.vala2
-rw-r--r--main/src/ui/conversation_content_view/file_widget.vala15
-rw-r--r--main/src/ui/conversation_selector/conversation_selector_row.vala2
-rw-r--r--main/src/ui/file_send_overlay.vala6
-rw-r--r--main/src/ui/util/file_metadata_providers.vala5
-rw-r--r--plugins/http-files/src/file_provider.vala6
-rw-r--r--plugins/http-files/src/file_sender.vala6
-rw-r--r--plugins/omemo/src/file_transfer/file_encryptor.vala2
-rw-r--r--plugins/openpgp/src/file_transfer/file_decryptor.vala2
-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
19 files changed, 100 insertions, 60 deletions
diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala
index 7b146c9a..0454acd3 100644
--- a/libdino/src/entity/file_transfer.vala
+++ b/libdino/src/entity/file_transfer.vala
@@ -66,7 +66,7 @@ public class FileTransfer : Object {
set { server_file_name_ = value; }
}
public string path { get; set; }
- public string? mime_type { get; set; }
+ public FileContentType? content_type { get; set; }
public int64 size { get; set; }
public State state { get; set; default=State.NOT_STARTED; }
public int provider { get; set; }
@@ -80,7 +80,7 @@ public class FileTransfer : Object {
owned get {
return new Xep.FileMetadataElement.FileMetadata() {
name = this.file_name,
- mime_type = this.mime_type,
+ content_type = this.content_type,
size = this.size,
desc = this.desc,
date = this.modification_date,
@@ -93,7 +93,7 @@ public class FileTransfer : Object {
}
set {
this.file_name = value.name;
- this.mime_type = value.mime_type;
+ this.content_type = value.content_type;
this.size = value.size;
this.desc = value.desc;
this.modification_date = value.date;
@@ -140,7 +140,9 @@ public class FileTransfer : Object {
encryption = (Encryption) row[db.file_transfer.encryption];
file_name = row[db.file_transfer.file_name];
path = row[db.file_transfer.path];
- mime_type = row[db.file_transfer.mime_type];
+ if (row[db.file_transfer.mime_type] != null) {
+ content_type = new FileContentType.from_mime_type(row[db.file_transfer.mime_type]);
+ }
size = (int64) row[db.file_transfer.size];
state = (State) row[db.file_transfer.state];
provider = row[db.file_transfer.provider];
@@ -197,7 +199,7 @@ public class FileTransfer : Object {
if (file_sharing_id != null) builder.value(db.file_transfer.file_sharing_id, file_sharing_id);
if (path != null) builder.value(db.file_transfer.path, path);
- if (mime_type != null) builder.value(db.file_transfer.mime_type, mime_type);
+ if (content_type != null) builder.value(db.file_transfer.mime_type, content_type.get_mime_type());
if (path != null) builder.value(db.file_transfer.path, path);
if (modification_date != null) builder.value(db.file_transfer.modification_date, (long) modification_date.to_unix());
if (width != -1) builder.value(db.file_transfer.width, width);
@@ -280,8 +282,8 @@ public class FileTransfer : Object {
update_builder.set(db.file_transfer.file_name, file_name); break;
case "path":
update_builder.set(db.file_transfer.path, path); break;
- case "mime-type":
- update_builder.set(db.file_transfer.mime_type, mime_type); break;
+ case "content-type":
+ update_builder.set(db.file_transfer.mime_type, content_type.get_mime_type()); break;
case "size":
update_builder.set(db.file_transfer.size, (long) size); break;
case "state":
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala
index 434fd0e7..8c196dd7 100644
--- a/libdino/src/service/file_manager.vala
+++ b/libdino/src/service/file_manager.vala
@@ -110,7 +110,7 @@ public class FileManager : StreamInteractionModule, Object {
try {
var file_meta = new FileMeta();
file_meta.size = file_transfer.size;
- file_meta.mime_type = file_transfer.mime_type;
+ file_meta.content_type = file_transfer.content_type;
FileSender file_sender = null;
FileEncryptor file_encryptor = null;
@@ -244,7 +244,7 @@ public class FileManager : StreamInteractionModule, Object {
file_transfer.size = (int)file_meta.size;
file_transfer.file_name = file_meta.file_name;
- file_transfer.mime_type = file_meta.mime_type;
+ file_transfer.content_type = file_meta.content_type;
}
return file_meta;
}
@@ -332,9 +332,9 @@ public class FileManager : StreamInteractionModule, Object {
file_transfer.path = file.get_basename();
FileInfo file_info = file_transfer.get_file().query_info("*", FileQueryInfoFlags.NONE);
- if (file_info.get_content_type() != "application/octet-stream" || file_transfer.mime_type == null) {
+ if (file_info.get_content_type() != "application/octet-stream" || file_transfer.content_type == null) {
// Only overwrite mime_type if it's better than what we had before.
- file_transfer.mime_type = file_info.get_content_type();
+ file_transfer.content_type = new FileContentType.from_file_info(file_info);
}
file_transfer.state = FileTransfer.State.COMPLETE;
@@ -436,7 +436,7 @@ public errordomain FileReceiveError {
public class FileMeta {
public int64 size = -1;
- public string? mime_type = null;
+ public FileContentType? content_type = null;
public string? file_name = null;
public Encryption encryption = Encryption.NONE;
}
diff --git a/libdino/src/service/notification_events.vala b/libdino/src/service/notification_events.vala
index 8771b5a9..3e077dfc 100644
--- a/libdino/src/service/notification_events.vala
+++ b/libdino/src/service/notification_events.vala
@@ -83,7 +83,7 @@ public class NotificationEvents : StreamInteractionModule, Object {
break;
case FileItem.TYPE:
FileTransfer file_transfer = ((FileItem) item).file_transfer;
- bool is_image = file_transfer.mime_type != null && file_transfer.mime_type.has_prefix("image");
+ bool is_image = file_transfer.content_type != null && file_transfer.content_type.is_image();
// Don't notify on file transfers in a groupchat set to "mention only"
if (notify == Conversation.NotifySetting.HIGHLIGHT) return;
diff --git a/libdino/src/service/sfs_metadata.vala b/libdino/src/service/sfs_metadata.vala
index f0058c4e..6d05f97f 100644
--- a/libdino/src/service/sfs_metadata.vala
+++ b/libdino/src/service/sfs_metadata.vala
@@ -22,7 +22,7 @@ namespace Dino {
FileInfo info = file.query_info("*", FileQueryInfoFlags.NONE);
metadata.name = info.get_display_name();
- metadata.mime_type = info.get_content_type();
+ metadata.content_type = new FileContentType.from_file_info(info);
metadata.size = info.get_size();
metadata.date = info.get_modification_date_time();
@@ -36,8 +36,8 @@ namespace Dino {
public class ImageFileMetadataProvider: Dino.FileMetadataProvider, Object {
public bool supports_file(File file) {
- string mime_type = file.query_info("*", FileQueryInfoFlags.NONE).get_content_type();
- return Dino.Util.is_pixbuf_supported_mime_type(mime_type);
+ FileContentType content_type = new FileContentType.from_file(file);
+ return Dino.Util.is_pixbuf_supported_content_type(content_type);
}
private const int[] THUMBNAIL_DIMS = { 1, 2, 3, 4, 8 };
diff --git a/libdino/src/service/util.vala b/libdino/src/service/util.vala
index 6eacdd33..e85e2005 100644
--- a/libdino/src/service/util.vala
+++ b/libdino/src/service/util.vala
@@ -30,8 +30,10 @@ public class Util {
}
}
- public static bool is_pixbuf_supported_mime_type(string mime_type) {
- if (mime_type == null) return false;
+ public static bool is_pixbuf_supported_content_type(Xmpp.FileContentType? content_type) {
+ if (content_type == null) return false;
+
+ string mime_type = content_type.get_mime_type();
foreach (Gdk.PixbufFormat pixbuf_format in Gdk.Pixbuf.get_formats()) {
foreach (string pixbuf_mime in pixbuf_format.get_mime_types()) {
diff --git a/main/src/ui/conversation_content_view/file_default_widget.vala b/main/src/ui/conversation_content_view/file_default_widget.vala
index f9e4015e..b731c9df 100644
--- a/main/src/ui/conversation_content_view/file_default_widget.vala
+++ b/main/src/ui/conversation_content_view/file_default_widget.vala
@@ -39,21 +39,21 @@ public class FileDefaultWidget : Box {
});
}
- public void set_static_file_info(string? mime_type) {
+ public void set_static_file_info(Xmpp.FileContentType? content_type) {
spinner.stop(); // A hidden spinning spinner still uses CPU. Deactivate asap
image_stack.set_visible_child_name("content_type_image");
- content_type_image.icon_name = get_file_icon_name(mime_type);
- mime_label.label = mime_type != null ? ContentType.get_description(mime_type) : null;
+ content_type_image.icon_name = get_file_icon_name(content_type);
+ mime_label.label = content_type != null ? content_type.get_description() : null;
}
- public void update_file_info(string? mime_type, FileTransfer.State state, bool direction, int64 size, int64 transferred_bytes) {
+ public void update_file_info(Xmpp.FileContentType? content_type, FileTransfer.State state, bool direction, int64 size, int64 transferred_bytes) {
this.state = state;
spinner.stop(); // A hidden spinning spinner still uses CPU. Deactivate asap
- content_type_image.icon_name = get_file_icon_name(mime_type);
- string? mime_description = mime_type != null ? ContentType.get_description(mime_type) : null;
+ content_type_image.icon_name = get_file_icon_name(content_type);
+ string? mime_description = content_type != null ? content_type.get_description() : null;
switch (state) {
case FileTransfer.State.COMPLETE:
@@ -134,10 +134,10 @@ public class FileDefaultWidget : Box {
file_menu.opacity = 0;
}
- private static string get_file_icon_name(string? mime_type) {
- if (mime_type == null) return "dino-file-symbolic";
+ private static string get_file_icon_name(Xmpp.FileContentType? content_type) {
+ if (content_type == null) return "dino-file-symbolic";
- string generic_icon_name = ContentType.get_generic_icon_name(mime_type) ?? "";
+ string generic_icon_name = content_type.get_generic_icon_name() ?? "";
switch (generic_icon_name) {
case "audio-x-generic": return "dino-file-music-symbolic";
case "image-x-generic": return "dino-file-image-symbolic";
diff --git a/main/src/ui/conversation_content_view/file_image_widget.vala b/main/src/ui/conversation_content_view/file_image_widget.vala
index f39dd30a..7bc8c6ce 100644
--- a/main/src/ui/conversation_content_view/file_image_widget.vala
+++ b/main/src/ui/conversation_content_view/file_image_widget.vala
@@ -232,7 +232,7 @@ public class FileImageWidget : Widget {
}
public static bool can_display(FileTransfer file_transfer) {
- return file_transfer.mime_type != null && Dino.Util.is_pixbuf_supported_mime_type(file_transfer.mime_type) &&
+ return file_transfer.content_type != null && Dino.Util.is_pixbuf_supported_content_type(file_transfer.content_type) &&
(file_transfer.state == FileTransfer.State.COMPLETE || file_transfer.thumbnails.size > 0);
}
diff --git a/main/src/ui/conversation_content_view/file_widget.vala b/main/src/ui/conversation_content_view/file_widget.vala
index cb734e5f..45972e1c 100644
--- a/main/src/ui/conversation_content_view/file_widget.vala
+++ b/main/src/ui/conversation_content_view/file_widget.vala
@@ -2,6 +2,7 @@ using Gee;
using Gdk;
using Gtk;
using Pango;
+using Xmpp;
using Dino.Entities;
@@ -50,7 +51,7 @@ public class FileWidget : SizeRequestBin {
private FileTransfer file_transfer;
public FileTransfer.State file_transfer_state { get; set; }
- public string file_transfer_mime_type { get; set; }
+ public FileContentType file_transfer_content_type { get; set; }
private State? state = null;
private FileDefaultWidgetController default_widget_controller;
@@ -84,10 +85,10 @@ public class FileWidget : SizeRequestBin {
// });
file_transfer.bind_property("state", this, "file-transfer-state");
- file_transfer.bind_property("mime-type", this, "file-transfer-mime-type");
+ file_transfer.bind_property("content-type", this, "file-transfer-content-type");
this.notify["file-transfer-state"].connect(update_widget);
- this.notify["file-transfer-mime-type"].connect(update_widget);
+ this.notify["file-transfer-content-type"].connect(update_widget);
}
private async void update_widget() {
@@ -202,7 +203,7 @@ public class FileDefaultWidgetController : Object {
private FileDefaultWidget widget;
private FileTransfer? file_transfer;
public string file_transfer_state { get; set; }
- public string file_transfer_mime_type { get; set; }
+ public FileContentType file_transfer_content_type { get; set; }
public int64 file_transfer_transferred_bytes { get; set; }
private FileTransfer.State state;
@@ -213,7 +214,7 @@ public class FileDefaultWidgetController : Object {
widget.clicked.connect(on_clicked);
this.notify["file-transfer-state"].connect(update_file_info);
- this.notify["file-transfer-mime-type"].connect(update_file_info);
+ this.notify["file-transfer-content-type"].connect(update_file_info);
this.notify["file-transfer-transferred-bytes"].connect(update_file_info);
}
@@ -224,7 +225,7 @@ public class FileDefaultWidgetController : Object {
widget.name_label.label = file_transfer.file_name;
file_transfer.bind_property("state", this, "file-transfer-state");
- file_transfer.bind_property("mime-type", this, "file-transfer-mime-type");
+ file_transfer.bind_property("content-type", this, "file-transfer-content-type");
file_transfer.bind_property("transferred-bytes", this, "file-transfer-transferred-bytes");
update_file_info();
@@ -232,7 +233,7 @@ public class FileDefaultWidgetController : Object {
private void update_file_info() {
state = file_transfer.state;
- widget.update_file_info(file_transfer.mime_type, file_transfer.state, file_transfer.direction, file_transfer.size, file_transfer.transferred_bytes);
+ widget.update_file_info(file_transfer.content_type, file_transfer.state, file_transfer.direction, file_transfer.size, file_transfer.transferred_bytes);
}
private void on_clicked() {
diff --git a/main/src/ui/conversation_selector/conversation_selector_row.vala b/main/src/ui/conversation_selector/conversation_selector_row.vala
index 7410937a..566406f9 100644
--- a/main/src/ui/conversation_selector/conversation_selector_row.vala
+++ b/main/src/ui/conversation_selector/conversation_selector_row.vala
@@ -186,7 +186,7 @@ public class ConversationSelectorRow : ListBoxRow {
nick_label.label = transfer.direction == Message.DIRECTION_SENT ? _("Me") + ": " : "";
}
- bool file_is_image = transfer.mime_type != null && transfer.mime_type.has_prefix("image");
+ bool file_is_image = transfer.content_type != null && transfer.content_type.is_image();
change_label_attribute(message_label, attr_style_new(Pango.Style.ITALIC));
if (transfer.direction == Message.DIRECTION_SENT) {
message_label.label = (file_is_image ? _("Image sent") : _("File sent") );
diff --git a/main/src/ui/file_send_overlay.vala b/main/src/ui/file_send_overlay.vala
index 130dc492..0067e09d 100644
--- a/main/src/ui/file_send_overlay.vala
+++ b/main/src/ui/file_send_overlay.vala
@@ -31,9 +31,9 @@ public class FileSendOverlay : Adw.Dialog {
private async void load_file_widget(File file, FileInfo file_info) {
string file_name = file_info.get_display_name();
- string mime_type = file_info.get_content_type();
+ var content_type = new Xmpp.FileContentType.from_file_info(file_info);
- bool is_image = Dino.Util.is_pixbuf_supported_mime_type(mime_type);
+ bool is_image = Dino.Util.is_pixbuf_supported_content_type(content_type);
Widget? widget = null;
if (is_image) {
@@ -47,7 +47,7 @@ public class FileSendOverlay : Adw.Dialog {
if (widget == null) {
FileDefaultWidget default_widget = new FileDefaultWidget();
default_widget.name_label.label = file_name;
- default_widget.set_static_file_info(mime_type);
+ default_widget.set_static_file_info(content_type);
widget = default_widget;
}
diff --git a/main/src/ui/util/file_metadata_providers.vala b/main/src/ui/util/file_metadata_providers.vala
index c01b1a71..a77f109c 100644
--- a/main/src/ui/util/file_metadata_providers.vala
+++ b/main/src/ui/util/file_metadata_providers.vala
@@ -7,10 +7,7 @@ namespace Dino.Ui.Util {
public class AudioVideoFileMetadataProvider: Dino.FileMetadataProvider, Object {
public bool supports_file(File file) {
- string? mime_type = file.query_info("*", FileQueryInfoFlags.NONE).get_content_type();
- if (mime_type == null) {
- return false;
- }
+ string mime_type = new FileContentType.from_file(file).get_mime_type();
return mime_type.has_prefix("audio") || mime_type.has_prefix("video");
}
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index 3a6c9e49..702dd3b3 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -92,7 +92,7 @@ public class FileProvider : Dino.FileProvider, Object {
if (name.down() == "content-type") content_type = val;
if (name.down() == "content-length") content_length = val;
});
- file_meta.mime_type = content_type;
+ file_meta.content_type = new FileContentType.from_mime_type(content_type);
if (content_length != null) {
file_meta.size = int64.parse(content_length);
}
@@ -131,7 +131,7 @@ public class FileProvider : Dino.FileProvider, Object {
if (file_transfer.provider == FileManager.SFS_PROVIDER_ID) {
var file_meta = new HttpFileMeta();
file_meta.size = file_transfer.size;
- file_meta.mime_type = file_transfer.mime_type;
+ file_meta.content_type = file_transfer.content_type;
file_meta.file_name = file_transfer.file_name;
file_meta.message = null;
return file_meta;
@@ -145,7 +145,7 @@ public class FileProvider : Dino.FileProvider, Object {
var file_meta = new HttpFileMeta();
file_meta.size = file_transfer.size;
- file_meta.mime_type = file_transfer.mime_type;
+ file_meta.content_type = file_transfer.content_type;
file_meta.file_name = extract_file_name_from_url(message.body);
diff --git a/plugins/http-files/src/file_sender.vala b/plugins/http-files/src/file_sender.vala
index cce4ac8e..ad92a3a0 100644
--- a/plugins/http-files/src/file_sender.vala
+++ b/plugins/http-files/src/file_sender.vala
@@ -28,7 +28,7 @@ public class HttpFileSender : FileSender, Object {
if (stream == null) return null;
try {
- var slot_result = yield stream_interactor.module_manager.get_module(file_transfer.account, Xmpp.Xep.HttpFileUpload.Module.IDENTITY).request_slot(stream, file_transfer.server_file_name, file_meta.size, file_meta.mime_type);
+ var slot_result = yield stream_interactor.module_manager.get_module(file_transfer.account, Xmpp.Xep.HttpFileUpload.Module.IDENTITY).request_slot(stream, file_transfer.server_file_name, file_meta.size, file_meta.content_type);
send_data.url_down = slot_result.url_get;
send_data.url_up = slot_result.url_put;
send_data.headers = slot_result.headers;
@@ -145,9 +145,9 @@ public class HttpFileSender : FileSender, Object {
#if SOUP_3_0
string transfer_host = Uri.parse(file_send_data.url_up, UriFlags.NONE).get_host();
put_message.accept_certificate.connect((peer_cert, errors) => { return ConnectionManager.on_invalid_certificate(transfer_host, peer_cert, errors); });
- put_message.set_request_body(file_meta.mime_type, file_transfer.input_stream, (ssize_t) file_meta.size);
+ put_message.set_request_body(file_meta.content_type.get_mime_type(), file_transfer.input_stream, (ssize_t) file_meta.size);
#else
- put_message.request_headers.set_content_type(file_meta.mime_type, null);
+ put_message.request_headers.set_content_type(file_meta.content_type.get_mime_type(), null);
put_message.request_headers.set_content_length(file_meta.size);
put_message.request_body.set_accumulate(false);
put_message.wrote_headers.connect(() => transfer_more_bytes(file_transfer.input_stream, put_message.request_body));
diff --git a/plugins/omemo/src/file_transfer/file_encryptor.vala b/plugins/omemo/src/file_transfer/file_encryptor.vala
index 53e394b7..58be7ef1 100644
--- a/plugins/omemo/src/file_transfer/file_encryptor.vala
+++ b/plugins/omemo/src/file_transfer/file_encryptor.vala
@@ -38,7 +38,7 @@ public class OmemoFileEncryptor : Dino.FileEncryptor, Object {
omemo_http_file_meta.iv = iv;
omemo_http_file_meta.key = key;
omemo_http_file_meta.size = file_transfer.size + 16;
- omemo_http_file_meta.mime_type = "application/octet-stream";
+ omemo_http_file_meta.content_type = new FileContentType.from_mime_type("application/octet-stream");
file_transfer.input_stream = new ConverterInputStream(file_transfer.input_stream, new SymmetricCipherEncrypter((owned) cipher, 16));
} catch (Crypto.Error error) {
throw new FileSendError.ENCRYPTION_FAILED("OMEMO file encryption error: %s".printf(error.message));
diff --git a/plugins/openpgp/src/file_transfer/file_decryptor.vala b/plugins/openpgp/src/file_transfer/file_decryptor.vala
index 202fa9c9..bc8add41 100644
--- a/plugins/openpgp/src/file_transfer/file_decryptor.vala
+++ b/plugins/openpgp/src/file_transfer/file_decryptor.vala
@@ -17,7 +17,7 @@ public class PgpFileDecryptor : FileDecryptor, Object {
}
public bool can_decrypt_file(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) {
- return file_transfer.file_name.has_suffix("pgp") || file_transfer.mime_type == "application/pgp-encrypted";
+ return file_transfer.file_name.has_suffix("pgp") || file_transfer.content_type.get_mime_type() == "application/pgp-encrypted";
}
public async InputStream decrypt_file(InputStream encrypted_stream, Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) throws FileReceiveError {
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) {