[nautilus] content-bar: move more content type handling



commit 293bffd2472fb574e782b1ebf1f192dc006fa719
Author: Carlos Soriano <csoriano gnome org>
Date:   Mon Mar 7 11:24:01 2016 +0100

    content-bar: move more content type handling
    
    And rely on file-utilities to check whether we can should handle
    those mime types.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762703

 libnautilus-private/nautilus-file-utilities.c |   25 +++++++++++++++++++++++++
 libnautilus-private/nautilus-file-utilities.h |    2 ++
 src/nautilus-x-content-bar.c                  |    8 +-------
 3 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index 87b53f6..94b3e9c 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -1065,6 +1065,31 @@ get_message_for_two_content_types (char **content_types)
 }
 
 gboolean
+should_handle_content_type (char *content_type)
+{
+        GAppInfo *default_app;
+
+        default_app = g_app_info_get_default_for_type (content_type, FALSE);
+
+        return !g_str_has_prefix (content_type, "x-content/blank-") &&
+               !g_content_type_is_a (content_type, "x-content/win32-software") &&
+               default_app != NULL;
+}
+
+gboolean
+should_handle_content_types (char ** content_types)
+{
+        int i;
+
+        for (i = 0; content_types[i] != NULL; i++) {
+                if (should_handle_content_type (content_types[i]))
+                        return TRUE;
+        }
+
+        return FALSE;
+}
+
+gboolean
 nautilus_file_selection_equal (GList *selection_a,
                               GList *selection_b)
 {
diff --git a/libnautilus-private/nautilus-file-utilities.h b/libnautilus-private/nautilus-file-utilities.h
index 81dfa0a..9b39ccc 100644
--- a/libnautilus-private/nautilus-file-utilities.h
+++ b/libnautilus-private/nautilus-file-utilities.h
@@ -90,6 +90,8 @@ void nautilus_get_x_content_types_for_mount_async (GMount *mount,
                                                   gpointer user_data);
 char * get_message_for_content_type (const char *content_type);
 char * get_message_for_two_content_types (char **content_types);
+gboolean should_handle_content_type (char *content_type);
+gboolean should_handle_content_types (char **content_type);
 
 gboolean nautilus_file_selection_equal (GList *selection_a, GList *selection_b);
 
diff --git a/src/nautilus-x-content-bar.c b/src/nautilus-x-content-bar.c
index e783dc9..e4a6c1e 100644
--- a/src/nautilus-x-content-bar.c
+++ b/src/nautilus-x-content-bar.c
@@ -95,16 +95,10 @@ nautilus_x_content_bar_set_x_content_types (NautilusXContentBar *bar, const char
        apps = g_ptr_array_new ();
        g_ptr_array_set_free_func (apps, g_object_unref);
        for (n = 0; x_content_types[n] != NULL; n++) {
-               if (g_str_has_prefix (x_content_types[n], "x-content/blank-"))
-                       continue;
-
-               if (g_content_type_is_a (x_content_types[n], "x-content/win32-software"))
+               if (!should_handle_content_type (x_content_types[n]))
                        continue;
 
                default_app = g_app_info_get_default_for_type (x_content_types[n], FALSE);
-               if (default_app == NULL)
-                       continue;
-
                g_ptr_array_add (types, g_strdup (x_content_types[n]));
                g_ptr_array_add (apps, default_app);
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]