aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2025-04-21 12:53:34 +0200
committerfiaxh <git@lightrise.org>2025-12-19 12:14:28 +0100
commit5fb3de6443eaf0d94f1ccd07dee94b124708fe16 (patch)
tree6c96cc222a0b7b0114c093c2b00abb1bda669c5f /libdino
parentf777856517ce39c4004be61c2661cc15377648fc (diff)
Handle content type != mime type
Diffstat (limited to 'libdino')
-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
5 files changed, 22 insertions, 18 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()) {