diff options
| author | fiaxh <git@lightrise.org> | 2025-04-21 12:53:34 +0200 |
|---|---|---|
| committer | fiaxh <git@lightrise.org> | 2025-12-19 12:14:28 +0100 |
| commit | 5fb3de6443eaf0d94f1ccd07dee94b124708fe16 (patch) | |
| tree | 6c96cc222a0b7b0114c093c2b00abb1bda669c5f /main/src/ui | |
| parent | f777856517ce39c4004be61c2661cc15377648fc (diff) | |
Handle content type != mime type
Diffstat (limited to 'main/src/ui')
6 files changed, 23 insertions, 25 deletions
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"); } |
