From 61dde2b2fd5999f5655f06d174a5178c4476acc9 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Mon, 2 Sep 2019 13:42:21 +0300 Subject: [PATCH 2/2] thunarx: implement thunarx_file_info_is_archive Signed-off-by: Sergey Ponomarev --- thunar/thunar-file.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 90026dc7..0126df91 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -2784,10 +2784,32 @@ thunar_file_is_directory (const ThunarFile *file) gboolean thunar_file_is_archive (const ThunarFile *file) { + const gchar *content_type; + gchar *generic_icon_name; + gboolean file_is_archive; + if (thunar_file_is_directory (file)) return FALSE; - /* TODO */ - return FALSE; + + content_type = thunar_file_get_content_type (THUNAR_FILE (file)); + if (content_type == NULL) + { + return FALSE; + } + + /* If icon for the content is "package-x-generic" then the type is archive. + * GLib internally uses a shared-mime-info library to determine a content type and it's description. + * Unfortunately the shared-mime-info doesn't have a clear flag that the type is an archive. + * But all archive types (tar, zip, gz etc) always have the same icon "package-x-generic". + * So we can use the content type's icon name to determine that it is an archive or compressed file. + */ + generic_icon_name = g_content_type_get_generic_icon_name (content_type); + if (generic_icon_name == NULL) { + return FALSE; + } + file_is_archive = g_strcmp0 (generic_icon_name, "package-x-generic") == 0; + g_free (generic_icon_name); + return file_is_archive; } -- 2.20.1