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

Jannis Pohlmann jannis at xfce.org
Sat Apr 11 01:51:35 CEST 2009


Author: jannis
Date: 2009-04-10 23:51:35 +0000 (Fri, 10 Apr 2009)
New Revision: 29761

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-file.c
   thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
   thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
Log:
	* thunar/thunar-file.{c,h}: Re-implement thunar_file_get_size_string()
	  based on GFileInfo and the new function g_file_size_humanize().
	  Re-implement thunar_file_get_deletion_date(),
	  thunar_file_get_original_path() as well. They currently fail because
	  there are no GFileInfos for objects in the Thunar trash at the
	  moment. Also rewrite thunar_file_is_desktop() and make sure to
	  reload the GFileInfo in thunar_file_reload().
	* thunar/thunar-gio-extensions.{c,h}: Add new method
	  g_file_size_humanize() to create nice file size labels.

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-10 23:14:49 UTC (rev 29760)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-10 23:51:35 UTC (rev 29761)
@@ -1,5 +1,17 @@
 2009-04-11	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-file.{c,h}: Re-implement thunar_file_get_size_string()
+	  based on GFileInfo and the new function g_file_size_humanize().
+	  Re-implement thunar_file_get_deletion_date(),
+	  thunar_file_get_original_path() as well. They currently fail because
+	  there are no GFileInfos for objects in the Thunar trash at the
+	  moment. Also rewrite thunar_file_is_desktop() and make sure to
+	  reload the GFileInfo in thunar_file_reload().
+	* thunar/thunar-gio-extensions.{c,h}: Add new method
+	  g_file_size_humanize() to create nice file size labels.
+
+2009-04-11	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-file.{c,h}: Re-implement thunar_file_get_parent(), 
 	  thunar_file_launch(), thunar_file_is_root() and
 	  thunar_file_has_parent() based on GFile/GFileInfo/GAppInfo.

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-10 23:14:49 UTC (rev 29760)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-10 23:51:35 UTC (rev 29761)
@@ -1309,16 +1309,11 @@
  * Return value: the size of @file in a human readable
  *               format.
  **/
-gchar*
+gchar *
 thunar_file_get_size_string (const ThunarFile *file)
 {
-  ThunarVfsFileSize size;
-
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
-
-  size = thunar_file_get_size (file);
-
-  return thunar_vfs_humanize_size (size, NULL, 0);
+  return g_file_size_humanize (thunar_file_get_size (file));
 }
 
 
@@ -1410,22 +1405,19 @@
 thunar_file_get_deletion_date (const ThunarFile *file,
                                ThunarDateStyle   date_style)
 {
-  time_t time;
-  gchar *date;
+  const gchar *date;
+  time_t       time;
 
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->ginfo), NULL);
 
-  /* query the DeletionDate from the trash backend */
-  date = thunar_vfs_info_get_metadata (file->info, THUNAR_VFS_INFO_METADATA_TRASH_DELETION_DATE, NULL);
+  date = g_file_info_get_attribute_string (file->ginfo, "trash::deletion-date");
   if (G_UNLIKELY (date == NULL))
     return NULL;
 
   /* try to parse the DeletionDate (RFC 3339 string) */
   time = thunar_util_time_from_rfc3339 (date);
 
-  /* release the DeletionDate */
-  g_free (date);
-
   /* humanize the time value */
   return thunar_util_humanize_file_time (time, date_style);
 }
@@ -1450,9 +1442,8 @@
 thunar_file_get_original_path (const ThunarFile *file)
 {
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
-
-  /* query the OriginalPath from the trash backend */
-  return thunar_vfs_info_get_metadata (file->info, THUNAR_VFS_INFO_METADATA_TRASH_ORIGINAL_PATH, NULL);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->ginfo), NULL);
+  return g_strdup (g_file_info_get_attribute_string (file->ginfo, "trash::orig-file"));
 }
 
 
@@ -1683,20 +1674,14 @@
 gboolean
 thunar_file_is_desktop (const ThunarFile *file)
 {
-#if GLIB_CHECK_VERSION(2,14,0)
-  gchar file_path[THUNAR_VFS_PATH_MAXSTRLEN];
+  gboolean is_desktop = FALSE;
+  gchar *path;
 
-  file_path[0] = '\0';
-  thunar_vfs_path_to_string (thunar_file_get_path (file), file_path,
-                             sizeof (file_path), NULL);
+  path = g_file_get_path (file->gfile);
+  is_desktop = g_str_equal (path, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP));
+  g_free (path);
 
-  /* g_get_user_special_dir () always returns something for the desktop */
-  return exo_str_is_equal (file_path, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP));
-#else /* GLIB_CHECK_VERSION(2,14,0) */
-return (!thunar_vfs_path_is_root (thunar_file_get_path (file))
-        && thunar_vfs_path_is_home (thunar_vfs_path_get_parent (thunar_file_get_path (file)))
-        && exo_str_is_equal (thunar_file_get_display_name (file), "Desktop"));
-#endif /* GLIB_CHECK_VERSION(2,14,0) */
+  return is_desktop;
 }
 
 
@@ -1933,6 +1918,11 @@
       thunar_vfs_info_unref (file->info);
       file->info = info;
 
+      if (file->ginfo != NULL)
+        g_object_unref (file->ginfo);
+
+      thunar_file_load (file, NULL, NULL);
+
       /* ... and tell others */
       thunar_file_changed (file);
     }

Modified: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-10 23:14:49 UTC (rev 29760)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-10 23:51:35 UTC (rev 29761)
@@ -191,3 +191,22 @@
     g_object_unref (lp->data);
   g_list_free (list);
 }
+
+
+
+gchar *
+g_file_size_humanize (guint64 size)
+{
+  gchar *buffer;
+
+  if (G_UNLIKELY (size > 1024ul * 1024ul * 1024ul))
+    buffer = g_strdup_printf ("%0.1f GB", size / (1024.0 * 1024.0 * 1024.0));
+  else if (size > 1024ul * 1024ul)
+    buffer = g_strdup_printf ("%0.1f MB", size / (1024.0 * 1024.0));
+  else if (size > 1024ul)
+    buffer = g_strdup_printf ("%0.1f kB", size / 1024.0);
+  else
+    buffer = g_strdup_printf ("%lu B", (gulong) size);
+
+  return buffer;
+}

Modified: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h	2009-04-10 23:14:49 UTC (rev 29760)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h	2009-04-10 23:51:35 UTC (rev 29761)
@@ -36,6 +36,8 @@
 GList   *g_file_list_copy            (GList       *list);
 void     g_file_list_free            (GList       *list);
 
+gchar   *g_file_size_humanize        (guint64      size);
+
 G_END_DECLS
 
 #endif /* !__THUNAR_GLIB_EXTENSIONS_H__ */




More information about the Xfce4-commits mailing list