From d5073c59508437256ca260c83e85bbf61f25846a Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 6 Sep 2019 21:43:40 +0300 Subject: [PATCH] Simplify tap_is_archive() and detect that the file is an archive by it's MIME type icon Signed-off-by: Sergey Ponomarev --- thunar-archive-plugin/tap-provider.c | 64 ++++++++++------------------ 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/thunar-archive-plugin/tap-provider.c b/thunar-archive-plugin/tap-provider.c index ac90e7f..ad7992b 100644 --- a/thunar-archive-plugin/tap-provider.c +++ b/thunar-archive-plugin/tap-provider.c @@ -92,40 +92,6 @@ struct _TapProvider -static const gchar TAP_MIME_TYPES[][34] = { - "application/x-7z-compressed", - "application/x-7z-compressed-tar", - "application/x-ar", - "application/x-arj", - "application/x-bzip", - "application/x-bzip-compressed-tar", - "application/x-compress", - "application/x-compressed-tar", - "application/x-deb", - "application/x-gtar", - "application/x-gzip", - "application/x-lha", - "application/x-lhz", - "application/x-lzma", - "application/x-lzma-compressed-tar", - "application/x-rar", - "application/x-rar-compressed", - "application/x-tar", - "application/x-xz", - "application/x-xz-compressed-tar", - "application/x-zip", - "application/x-zip-compressed", - "application/zip", - "multipart/x-zip", - "application/x-rpm", - "application/x-jar", - "application/x-java-archive", - "application/x-lzop", - "application/x-zoo", - "application/x-cd-image", - "application/x-7z-compressed", -}; - static GQuark tap_item_files_quark; static GQuark tap_item_folder_quark; static GQuark tap_item_provider_quark; @@ -195,13 +161,29 @@ tap_provider_finalize (GObject *object) static gboolean tap_is_archive (ThunarxFileInfo *file_info) { - guint n; - - for (n = 0; n < G_N_ELEMENTS (TAP_MIME_TYPES); ++n) - if (thunarx_file_info_has_mime_type (file_info, TAP_MIME_TYPES[n])) - return TRUE; - - return FALSE; + const gchar *content_type; + gchar *generic_icon_name; + gboolean file_is_archive; + + content_type = thunarx_file_info_get_mime_type (file_info); + 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