[Xfce4-commits] <thunar:master> Fix properties dialog crash with files with unknown content type.

Jannis Pohlmann noreply at xfce.org
Sat Feb 19 15:54:01 CET 2011


Updating branch refs/heads/master
         to bdaafeca93422438c25e76e237bd766cfef71bcf (commit)
       from b3f4ba8174af70d4aed5068333014ddd0d5e620d (commit)

commit bdaafeca93422438c25e76e237bd766cfef71bcf
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sat Feb 19 15:52:53 2011 +0100

    Fix properties dialog crash with files with unknown content type.

 NEWS                              |    1 +
 thunar/thunar-chooser-button.c    |   97 +++++++++++++++++++------------------
 thunar/thunar-properties-dialog.c |   23 ++++++---
 3 files changed, 66 insertions(+), 55 deletions(-)

diff --git a/NEWS b/NEWS
index 3129193..266a258 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 1.3.x
 =====
 - Fix crash when trying to thumbnail a file with unknown content type.
+- Fix properties dialog crash with files with unknown content type.
 
 1.3.0
 =====
diff --git a/thunar/thunar-chooser-button.c b/thunar/thunar-chooser-button.c
index 757d8a1..fb9489a 100644
--- a/thunar/thunar-chooser-button.c
+++ b/thunar/thunar-chooser-button.c
@@ -1,8 +1,8 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
  * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>
  * Copyright (c) 2010      Nick Schermer <nick at xfce.org>
+ * Copyright (c) 2009-2011 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
@@ -432,56 +432,59 @@ thunar_chooser_button_file_changed (ThunarChooserButton *chooser_button,
 
   /* determine the content type of the file */
   content_type = thunar_file_get_content_type (file);
-
-  /* setup a useful tooltip for the button */
-  description = g_content_type_get_description (content_type);
-  thunar_gtk_widget_set_tooltip (GTK_WIDGET (chooser_button),
-                                 _("The selected application is used to open "
-                                   "this and other files of type \"%s\"."),
-                                 description);
-  g_free (description);
-
-  /* determine the default application for that content type */
-  app_info = g_app_info_get_default_for_type (content_type, FALSE);
-  if (G_LIKELY (app_info != NULL))
+  if (content_type != NULL)
     {
-      /* determine all applications that claim to be able to handle the file */
-      app_infos = g_app_info_get_all_for_type (content_type);
-      app_infos = g_list_sort (app_infos, thunar_chooser_button_sort_applications);
-      
-      /* add all possible applications */
-      for (lp = app_infos, i = 0; lp != NULL; lp = lp->next, ++i)
+      /* setup a useful tooltip for the button */
+      description = g_content_type_get_description (content_type);
+      thunar_gtk_widget_set_tooltip (GTK_WIDGET (chooser_button),
+                                     _("The selected application is used to open "
+                                       "this and other files of type \"%s\"."),
+                                     description);
+      g_free (description);
+
+      /* determine the default application for that content type */
+      app_info = g_app_info_get_default_for_type (content_type, FALSE);
+      if (G_LIKELY (app_info != NULL))
         {
-          /* insert the item into the store */
-          gtk_list_store_insert_with_values (chooser_button->store, &iter, i,
-                                             THUNAR_CHOOSER_BUTTON_STORE_COLUMN_NAME,
-                                             g_app_info_get_name (lp->data),
-                                             THUNAR_CHOOSER_BUTTON_STORE_COLUMN_APPLICATION,
-                                             lp->data,
-                                             THUNAR_CHOOSER_BUTTON_STORE_COLUMN_ICON,
-                                             g_app_info_get_icon (lp->data),
-                                             THUNAR_CHOOSER_BUTTON_STORE_COLUMN_SENSITIVE,
-                                             TRUE,
-                                             -1);
-
-          /* pre-select the default application */
-          if (g_app_info_equal (lp->data, app_info))
-            gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser_button), &iter);
-
-          /* release the application */
-          g_object_unref (lp->data);
+          /* determine all applications that claim to be able to handle the file */
+          app_infos = g_app_info_get_all_for_type (content_type);
+          app_infos = g_list_sort (app_infos, thunar_chooser_button_sort_applications);
+          
+          /* add all possible applications */
+          for (lp = app_infos, i = 0; lp != NULL; lp = lp->next, ++i)
+            {
+              /* insert the item into the store */
+              gtk_list_store_insert_with_values (chooser_button->store, &iter, i,
+                                                 THUNAR_CHOOSER_BUTTON_STORE_COLUMN_NAME,
+                                                 g_app_info_get_name (lp->data),
+                                                 THUNAR_CHOOSER_BUTTON_STORE_COLUMN_APPLICATION,
+                                                 lp->data,
+                                                 THUNAR_CHOOSER_BUTTON_STORE_COLUMN_ICON,
+                                                 g_app_info_get_icon (lp->data),
+                                                 THUNAR_CHOOSER_BUTTON_STORE_COLUMN_SENSITIVE,
+                                                 TRUE,
+                                                 -1);
+
+              /* pre-select the default application */
+              if (g_app_info_equal (lp->data, app_info))
+                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser_button), &iter);
+
+              /* release the application */
+              g_object_unref (lp->data);
+            }
+
+          /* release the application list */
+          g_list_free (app_infos);
+
+          /* release the default application */
+          g_object_unref (app_info);
+
+          /* assume we have some applications in the list */
+          chooser_button->has_default_application = TRUE;
         }
-
-      /* release the application list */
-      g_list_free (app_infos);
-
-      /* release the default application */
-      g_object_unref (app_info);
-
-      /* assume we have some applications in the list */
-      chooser_button->has_default_application = TRUE;
     }
-  else
+  
+  if (content_type == NULL || !chooser_button->has_default_application)
     {
       /* add the "No application selected" item and set as active */
       gtk_list_store_insert_with_values (chooser_button->store, &iter, 0,
diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c
index f52c20b..c189e26 100644
--- a/thunar/thunar-properties-dialog.c
+++ b/thunar/thunar-properties-dialog.c
@@ -900,15 +900,22 @@ thunar_properties_dialog_update (ThunarPropertiesDialog *dialog)
 
   /* update the content type */
   content_type = thunar_file_get_content_type (dialog->file);
-  if (G_UNLIKELY (g_content_type_equals (content_type, "inode/symlink")))
-    str = g_strdup (_("broken link"));
-  else if (G_UNLIKELY (thunar_file_is_symlink (dialog->file)))
-    str = g_strdup_printf (_("link to %s"), thunar_file_get_symlink_target (dialog->file));
+  if (content_type != NULL)
+    {
+      if (G_UNLIKELY (g_content_type_equals (content_type, "inode/symlink")))
+        str = g_strdup (_("broken link"));
+      else if (G_UNLIKELY (thunar_file_is_symlink (dialog->file)))
+        str = g_strdup_printf (_("link to %s"), thunar_file_get_symlink_target (dialog->file));
+      else
+        str = g_content_type_get_description (content_type);
+      gtk_widget_set_tooltip_text (dialog->kind_ebox, content_type);
+      gtk_label_set_text (GTK_LABEL (dialog->kind_label), str);
+      g_free (str);
+    }
   else
-    str = g_content_type_get_description (content_type);
-  gtk_widget_set_tooltip_text (dialog->kind_ebox, content_type);
-  gtk_label_set_text (GTK_LABEL (dialog->kind_label), str);
-  g_free (str);
+    {
+      gtk_label_set_text (GTK_LABEL (dialog->kind_label), _("unknown"));
+    }
 
   /* update the application chooser (shown only for non-executable regular files!) */
   g_object_set (G_OBJECT (dialog->openwith_chooser),



More information about the Xfce4-commits mailing list