From 9f3f7588636708025db28cc70fd58cc167f82ef8 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Mon, 2 Sep 2019 12:25:49 +0300 Subject: [PATCH 4/4] sendto plugin: get rid of archives content types and use shared-mime-info instead Signed-off-by: Sergey Ponomarev --- plugins/thunar-sendto-email/main.c | 56 +++++++++--------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/plugins/thunar-sendto-email/main.c b/plugins/thunar-sendto-email/main.c index 0b1ba237..b724980c 100644 --- a/plugins/thunar-sendto-email/main.c +++ b/plugins/thunar-sendto-email/main.c @@ -74,36 +74,6 @@ struct _TseData -/* well known archive types */ -static const char *TSE_MIME_TYPES[] = { - "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-rar", - "application/x-rar-compressed", - "application/x-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", -}; - - - /* compress response ids */ enum { @@ -146,23 +116,29 @@ static gboolean tse_file_is_archive (GFileInfo *file_info) { const gchar *content_type; - guint n; + gchar *generic_icon_name; + gboolean file_is_archive; + /* determine the content type */ content_type = g_file_info_get_content_type (file_info); if (content_type == NULL) { return FALSE; } - for (n = 0; n < G_N_ELEMENTS (TSE_MIME_TYPES); ++n) - { - /* check if this mime type matches */ - if (g_content_type_is_a (content_type, TSE_MIME_TYPES[n])) - { - /* yep, that's a match then */ - return TRUE; - } + + /* 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; } - 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