[Xfce4-commits] <thunar:master> Change how Thunar picks the default handler for a file (bug #6167).

Jannis Pohlmann noreply at xfce.org
Tue Oct 19 16:02:01 CEST 2010


Updating branch refs/heads/master
         to 8fae46156ce617d3639486e10a3d91b878c75f17 (commit)
       from c4c9c6ab55e7eba3d12d6c7fdf04a168f97598b7 (commit)

commit 8fae46156ce617d3639486e10a3d91b878c75f17
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue Oct 19 15:53:11 2010 +0200

    Change how Thunar picks the default handler for a file (bug #6167).
    
    It appears that g_file_query_default_handler() prefers URI scheme
    handlers over content type handlers. This is inappropriate if we want to
    open a file for which we already know the content type (as is the case
    with most local files).
    
    Using g_file_query_default_handler() as the only way to pick the default
    handler for a file somewhat collides with exo-gio-module, which sets the
    default handler for a few URI schemes, such as http:// and file://.
    
    This was problematic only when launching a file from outside (e.g. by
    running "Thunar <file>" or by calling the D-Bus Launch() method. In
    internal situations, Thunar used thunar_file_list_get_applications()
    which prioritizes the content type.
    
    We now use g_app_info_get_default_for_content_type() first and only fall
    back to g_file_query_default_handler() if the content type is unknown or
    we don't have a default handler for it.

 thunar/thunar-file.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index b8b80fb..75b0a02 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -1,7 +1,7 @@
 /* $Id$ */
 /*-
  * Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -1797,8 +1797,27 @@ thunar_file_get_size (const ThunarFile *file)
 GAppInfo *
 thunar_file_get_default_handler (const ThunarFile *file) 
 {
+  const gchar *content_type;
+  GAppInfo    *app_info = NULL;
+  gboolean     must_support_uris = FALSE;
+  gchar       *path;
+
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
-  return g_file_query_default_handler (THUNAR_FILE ((file))->gfile, NULL, NULL);
+
+  content_type = thunar_file_get_content_type (file);
+  if (content_type != NULL)
+    {
+      path = g_file_get_path (file->gfile);
+      must_support_uris = (path == NULL);
+      g_free (path);
+
+      app_info = g_app_info_get_default_for_type (content_type, must_support_uris);
+    }
+
+  if (app_info == NULL)
+    app_info = g_file_query_default_handler (file->gfile, NULL, NULL);
+
+  return app_info;
 }
 
 



More information about the Xfce4-commits mailing list