[gtk+/gtk-3-22] Improve GContentType usage
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-22] Improve GContentType usage
- Date: Thu, 9 Mar 2017 04:09:09 +0000 (UTC)
commit e387f807e4a6da663bca3f8d0b75f1cdbd66465d
Author: TingPing <tingping tingping se>
Date: Wed Mar 8 22:52:58 2017 -0500
Improve GContentType usage
Convert to content type where needed.
Should fix various issues on Windows and OS X.
https://bugzilla.gnome.org/show_bug.cgi?id=734946
gtk/gtkfilefilter.c | 19 +++++++++++++++----
gtk/gtkrecentfilter.c | 17 ++++++++++++++---
gtk/gtkrecentmanager.c | 6 ++++--
gtk/inspector/resource-list.c | 12 ++++++++++--
4 files changed, 43 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkfilefilter.c b/gtk/gtkfilefilter.c
index c843cc3..e86f2d8 100644
--- a/gtk/gtkfilefilter.c
+++ b/gtk/gtkfilefilter.c
@@ -669,13 +669,24 @@ gtk_file_filter_filter (GtkFileFilter *filter,
if ((filter_info->contains & rule->needed) != rule->needed)
continue;
-
+
switch (rule->type)
{
case FILTER_RULE_MIME_TYPE:
- if (filter_info->mime_type != NULL &&
- g_content_type_is_a (filter_info->mime_type, rule->u.mime_type))
- return TRUE;
+ if (filter_info->mime_type != NULL)
+ {
+ gchar *filter_content_type, *rule_content_type;
+ gboolean match;
+
+ filter_content_type = g_content_type_from_mime_type (filter_info->mime_type);
+ rule_content_type = g_content_type_from_mime_type (rule->u.mime_type);
+ match = g_content_type_is_a (filter_content_type, rule_content_type);
+ g_free (filter_content_type);
+ g_free (rule_content_type);
+
+ if (match)
+ return TRUE;
+ }
break;
case FILTER_RULE_PATTERN:
if (filter_info->display_name != NULL &&
diff --git a/gtk/gtkrecentfilter.c b/gtk/gtkrecentfilter.c
index bf32dbf..4062db5 100644
--- a/gtk/gtkrecentfilter.c
+++ b/gtk/gtkrecentfilter.c
@@ -743,9 +743,20 @@ gtk_recent_filter_filter (GtkRecentFilter *filter,
switch (rule->type)
{
case FILTER_RULE_MIME_TYPE:
- if (filter_info->mime_type != NULL &&
- g_content_type_is_a (filter_info->mime_type, rule->u.mime_type))
- return TRUE;
+ if (filter_info->mime_type != NULL)
+ {
+ gchar *filter_content_type, *rule_content_type;
+ gboolean match;
+
+ filter_content_type = g_content_type_from_mime_type (filter_info->mime_type);
+ rule_content_type = g_content_type_from_mime_type (rule->u.mime_type);
+ match = g_content_type_is_a (filter_content_type, rule_content_type);
+ g_free (filter_content_type);
+ g_free (rule_content_type);
+
+ if (match)
+ return TRUE;
+ }
break;
case FILTER_RULE_APPLICATION:
if (filter_info->applications)
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c
index f2dd510..64c6080 100644
--- a/gtk/gtkrecentmanager.c
+++ b/gtk/gtkrecentmanager.c
@@ -775,7 +775,7 @@ gtk_recent_manager_add_item_query_info (GObject *source_object,
GtkRecentManager *manager = user_data;
GtkRecentData recent_data;
GFileInfo *file_info;
- gchar *uri, *basename;
+ gchar *uri, *basename, *content_type;
uri = g_file_get_uri (file);
@@ -801,8 +801,10 @@ gtk_recent_manager_add_item_query_info (GObject *source_object,
else
{
basename = g_file_get_basename (file);
- recent_data.mime_type = g_content_type_guess (basename, NULL, 0, NULL);
+ content_type = g_content_type_guess (basename, NULL, 0, NULL);
+ recent_data.mime_type = g_content_type_get_mime_type (content_type);
g_free (basename);
+ g_free (content_type);
}
recent_data.app_name = g_strdup (g_get_application_name ());
diff --git a/gtk/inspector/resource-list.c b/gtk/inspector/resource-list.c
index 16e9651..9208251 100644
--- a/gtk/inspector/resource-list.c
+++ b/gtk/inspector/resource-list.c
@@ -187,6 +187,11 @@ populate_details (GtkInspectorResourceList *rl,
else
{
gchar *text;
+ gchar *content_image;
+ gchar *content_text;
+
+ content_image = g_content_type_from_mime_type ("image/*");
+ content_text = g_content_type_from_mime_type ("text/*");
data = g_bytes_get_data (bytes, &size);
type = g_content_type_guess (name, data, size, NULL);
@@ -199,12 +204,12 @@ populate_details (GtkInspectorResourceList *rl,
gtk_label_set_text (GTK_LABEL (rl->priv->size_label), text);
g_free (text);
- if (g_content_type_is_a (type, "text/*"))
+ if (g_content_type_is_a (type, content_text))
{
gtk_text_buffer_set_text (rl->priv->buffer, data, -1);
gtk_stack_set_visible_child_name (GTK_STACK (rl->priv->content), "text");
}
- else if (g_content_type_is_a (type, "image/*"))
+ else if (g_content_type_is_a (type, content_image))
{
gtk_image_set_from_resource (GTK_IMAGE (rl->priv->image), path);
gtk_stack_set_visible_child_name (GTK_STACK (rl->priv->content), "image");
@@ -217,6 +222,9 @@ populate_details (GtkInspectorResourceList *rl,
g_free (type);
g_bytes_unref (bytes);
+
+ g_free (content_image);
+ g_free (content_text);
}
g_free (path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]