[Xfce4-commits] r30047 - in thunar/branches/migration-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Fri Jun 19 17:34:06 CEST 2009


Author: jannis
Date: 2009-06-19 15:34:06 +0000 (Fri, 19 Jun 2009)
New Revision: 30047

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-file.c
   thunar/branches/migration-to-gio/thunar/thunar-file.h
Log:
	* thunar/thunar-file.{c,h}: Add "mountable::*" namespace to the file
	  info attributes we request from the GFileInfo. In
	  thunar_file_load(), check for type G_FILE_TYPE_MOUNTABLE and set
	  is_mounted to FALSE if its G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT is
	  TRUE. Add function thunar_file_get_target_location() which returns
	  a GFile for the target location of a file of type
	  G_FILE_TYPE_SHORTCUT or G_FILE_TYPE_MOUNTABLE and otherwise returns
	  NULL. Don't assume all files have a content type - shortcuts and
	  mountables don't. Work around this in thunar_file_is_desktop_file()
	  and thunar_file_list_get_applications(). Check if we have a
	  GFileInfo before querying the original path in
	  thunar_file_get_original_path().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-06-19 15:34:00 UTC (rev 30046)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-06-19 15:34:06 UTC (rev 30047)
@@ -1,3 +1,18 @@
+2009-06-19	Jannis Pohlmann <jannis at xfce.org>
+
+	* thunar/thunar-file.{c,h}: Add "mountable::*" namespace to the file
+	  info attributes we request from the GFileInfo. In
+	  thunar_file_load(), check for type G_FILE_TYPE_MOUNTABLE and set
+	  is_mounted to FALSE if its G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT is
+	  TRUE. Add function thunar_file_get_target_location() which returns
+	  a GFile for the target location of a file of type
+	  G_FILE_TYPE_SHORTCUT or G_FILE_TYPE_MOUNTABLE and otherwise returns
+	  NULL. Don't assume all files have a content type - shortcuts and
+	  mountables don't. Work around this in thunar_file_is_desktop_file()
+	  and thunar_file_list_get_applications(). Check if we have a
+	  GFileInfo before querying the original path in
+	  thunar_file_get_original_path().
+
 2009-06-17	Jannis Pohlmann <jannis at xfce.org>
 
 	* thunar/thunar-file.c: Use special icon names for root folders other

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-06-19 15:34:00 UTC (rev 30046)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-06-19 15:34:06 UTC (rev 30047)
@@ -68,12 +68,13 @@
 
 /* File attribute namespaces being used */
 #define THUNAR_FILE_G_FILE_INFO_NAMESPACE \
+  "access::*," \
+  "mountable::*," \
+  "preview::*," \
   "standard::*," \
-  "unix::*," \
-  "access::*," \
   "time::*," \
   "thumbnail::*," \
-  "preview::*"
+  "unix::*"
 
 #define THUNAR_FILE_G_FILE_INFO_FILESYSTEM_NAMESPACE \
   "filesystem::*"
@@ -577,7 +578,7 @@
   ThunarFile *file;
 
   _thunar_return_if_fail (G_IS_FILE (path));
-
+  
   file = thunar_file_cache_lookup (path);
   if (G_LIKELY (file != NULL))
     {
@@ -791,11 +792,19 @@
   file->info = g_file_query_info (file->gfile,
                                   THUNAR_FILE_G_FILE_INFO_NAMESPACE,
                                   G_FILE_QUERY_INFO_NONE,
-                                  cancellable,
-                                  &err);
+                                  cancellable, &err);
 
-  if (err != NULL)
+  if (err == NULL)
     {
+      if (g_file_info_get_file_type (file->info) == G_FILE_TYPE_MOUNTABLE)
+        {
+          file->is_mounted = 
+            !g_file_info_get_attribute_boolean (file->info,
+                                                G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT);
+        }
+    }
+  else
+    {
       if (err->domain == G_IO_ERROR && err->code == G_IO_ERROR_NOT_MOUNTED)
         {
           file->is_mounted = FALSE;
@@ -1854,6 +1863,24 @@
 
 
 
+GFile *
+thunar_file_get_target_location (const ThunarFile *file)
+{
+  const gchar *uri;
+
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+
+  if (file->info == NULL)
+    return g_object_ref (file->gfile);
+  
+  uri = g_file_info_get_attribute_string (file->info,
+                                          G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
+
+  return (uri != NULL) ? g_file_new_for_uri (uri) : NULL;
+}
+
+
+
 /**
  * thunar_file_get_mode:
  * @file : a #ThunarFile instance.
@@ -2169,13 +2196,21 @@
 gboolean
 thunar_file_is_desktop_file (const ThunarFile *file)
 {
+  const gchar *content_type;
+  gboolean     is_desktop_file = FALSE;
+
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
 
   if (file->info == NULL)
     return FALSE;
 
-  return g_content_type_equals (g_file_info_get_content_type (file->info), "application/x-desktop")
-         && !g_str_has_suffix (thunar_file_get_basename (file), ".directory");
+  content_type = g_file_info_get_content_type (file->info);
+
+  if (content_type != NULL)
+    is_desktop_file = g_content_type_equals (content_type, "application/x-desktop");
+
+  return is_desktop_file 
+    && !g_str_has_suffix (thunar_file_get_basename (file), ".directory");
 }
 
 
@@ -2251,8 +2286,14 @@
 thunar_file_get_original_path (const ThunarFile *file)
 {
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
-  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->info), NULL);
-  return g_file_info_get_attribute_string (file->info, "trash::orig-file");
+
+  if (file->info == NULL)
+    return NULL;
+
+  if (g_file_info_has_attribute (file->info, "trash::orig-file"))
+    return g_file_info_get_attribute_string (file->info, "trash::orig-file");
+  else
+    return NULL;
 }
 
 
@@ -3173,7 +3214,7 @@
       current_type = thunar_file_get_content_type (lp->data);
 
       /* no need to check anything if this file has the same mime type as the previous file */
-      if (lp->prev != NULL)
+      if (current_type != NULL && lp->prev != NULL)
         {
           previous_type = thunar_file_get_content_type (lp->prev->data);
           if (G_LIKELY (g_content_type_equals (previous_type, current_type)))
@@ -3181,7 +3222,7 @@
         }
 
       /* determine the list of applications that can open this file */
-      list = g_app_info_get_all_for_type (current_type);
+      list = current_type == NULL ? NULL : g_app_info_get_all_for_type (current_type);
       if (G_UNLIKELY (applications == NULL))
         {
           /* first file, so just use the applications list */

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-06-19 15:34:00 UTC (rev 30046)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-06-19 15:34:06 UTC (rev 30047)
@@ -185,6 +185,7 @@
 guint64           thunar_file_get_size             (const ThunarFile       *file);
 GAppInfo         *thunar_file_get_default_handler  (const ThunarFile       *file);
 GFileType         thunar_file_get_kind             (const ThunarFile       *file);
+GFile            *thunar_file_get_target_location  (const ThunarFile       *file);
 ThunarFileMode    thunar_file_get_mode             (const ThunarFile       *file);
 gboolean          thunar_file_get_free_space       (const ThunarFile       *file, 
                                                     guint64                *free_space_return);




More information about the Xfce4-commits mailing list