[gnome-autoar] mime-types: use g_content_type_is_a for mime support
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar] mime-types: use g_content_type_is_a for mime support
- Date: Fri, 3 Mar 2017 09:53:39 +0000 (UTC)
commit d7e45a2627d026b86aa518984fad48b5ff76ffb8
Author: Carlos Soriano <csoriano gnome org>
Date: Wed Mar 1 19:11:30 2017 +0100
mime-types: use g_content_type_is_a for mime support
We were using a plain text matching, which is less than ideal and prone
to error.
One clear practical issue is that rar was reported as not supported,
since the supertype is vnd.rar, not any alias like x-rar, etc.
This patch fix autoar to make sure we check for the supertypes for
reporting whether the types are supported or not.
https://bugzilla.gnome.org/show_bug.cgi?id=779431
gnome-autoar/autoar-mime-types.c | 29 +++++++++--------------------
1 files changed, 9 insertions(+), 20 deletions(-)
---
diff --git a/gnome-autoar/autoar-mime-types.c b/gnome-autoar/autoar-mime-types.c
index cb30eab..dca5c15 100644
--- a/gnome-autoar/autoar-mime-types.c
+++ b/gnome-autoar/autoar-mime-types.c
@@ -38,25 +38,8 @@ static gchar *supported_mime_types[] = {
"application/x-xz",
"application/zip",
"application/gzip",
- NULL
};
-static GHashTable *supported_mime_types_table = NULL;
-
-static void
-initialize_supported_mime_types_table (void)
-{
- int i;
-
- supported_mime_types_table = g_hash_table_new (g_str_hash,
- g_str_equal);
-
- for (i = 0; supported_mime_types[i] != NULL; ++i) {
- g_hash_table_add (supported_mime_types_table,
- supported_mime_types[i]);
- }
-}
-
/**
* autoar_check_mime_type_supported:
* @mime_type: a string representing the mime type
@@ -69,11 +52,17 @@ initialize_supported_mime_types_table (void)
gboolean
autoar_check_mime_type_supported (const gchar *mime_type)
{
- if (supported_mime_types_table == NULL) {
- initialize_supported_mime_types_table ();
+ gint i;
+ gboolean supported = FALSE;
+
+ for (i = 0; i < G_N_ELEMENTS (supported_mime_types); i++) {
+ if (g_content_type_is_a (mime_type, supported_mime_types[i])) {
+ supported = TRUE;
+ break;
+ }
}
- return g_hash_table_contains (supported_mime_types_table, mime_type);
+ return supported;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]