[Xfce4-commits] <thunar:master> Improve the free space label.

Nick Schermer noreply at xfce.org
Sun Oct 14 13:18:02 CEST 2012


Updating branch refs/heads/master
         to ede666209f2ce1a798035ebcf8526d63a4fc9411 (commit)
       from daa0506d3abb84c0e068accc55cb6f139ef2824b (commit)

commit ede666209f2ce1a798035ebcf8526d63a4fc9411
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Oct 14 13:09:09 2012 +0200

    Improve the free space label.

 thunar/thunar-file.c              |   25 ++++++++++++++++---------
 thunar/thunar-file.h              |    3 ++-
 thunar/thunar-list-model.c        |    2 +-
 thunar/thunar-properties-dialog.c |   23 +++++++++++++++++------
 4 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 04f00e7..710d0df 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -2230,9 +2230,10 @@ thunar_file_get_mode (const ThunarFile *file)
 
 /**
  * thunar_file_get_free_space:
- * @file              : a #ThunarFile instance.
- * @free_space_return : return location for the amount of
- *                      free space or %NULL.
+ * @file           : a #ThunarFile instance.
+ * @fs_free_return : return location for the amount of
+ *                   free space or %NULL.
+ * @fs_size_return : return location for the total volume size.
  *
  * Determines the amount of free space of the volume on
  * which @file resides. Returns %TRUE if the amount of
@@ -2243,7 +2244,8 @@ thunar_file_get_mode (const ThunarFile *file)
  **/
 gboolean
 thunar_file_get_free_space (const ThunarFile *file, 
-                            guint64          *free_space_return) 
+                            guint64          *fs_free_return,
+                            guint64          *fs_size_return)
 {
   GFileInfo *filesystem_info;
   gboolean   success = FALSE;
@@ -2256,12 +2258,17 @@ thunar_file_get_free_space (const ThunarFile *file,
 
   if (filesystem_info != NULL)
     {
-      *free_space_return = 
-        g_file_info_get_attribute_uint64 (filesystem_info,
-                                          G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+      if (fs_free_return != NULL)
+        {
+          *fs_free_return = g_file_info_get_attribute_uint64 (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+          success = g_file_info_has_attribute (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+        }
 
-      success = g_file_info_has_attribute (filesystem_info, 
-                                           G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+      if (fs_size_return != NULL)
+        {
+          *fs_size_return = g_file_info_get_attribute_uint64 (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
+          success = g_file_info_has_attribute (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
+        }
 
       g_object_unref (filesystem_info);
     }
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index 564b781..1238084 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -180,7 +180,8 @@ 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);
+                                                    guint64                *fs_free_return,
+                                                    guint64                *fs_size_return);
 gboolean          thunar_file_is_mounted           (const ThunarFile       *file);
 gboolean          thunar_file_exists               (const ThunarFile       *file);
 gboolean          thunar_file_is_directory         (const ThunarFile       *file) G_GNUC_PURE;
diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c
index d6c6e19..92f7867 100644
--- a/thunar/thunar-list-model.c
+++ b/thunar/thunar-list-model.c
@@ -2260,7 +2260,7 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store,
       file = (store->folder != NULL) ? thunar_folder_get_corresponding_file (store->folder) : NULL;
 
       /* check if we can determine the amount of free space for the volume */
-      if (G_LIKELY (file != NULL && thunar_file_get_free_space (file, &size)))
+      if (G_LIKELY (file != NULL && thunar_file_get_free_space (file, &size, NULL)))
         {
           /* humanize the free space */
           fspace_string = g_format_size (size);
diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c
index 33f4667..07fda40 100644
--- a/thunar/thunar-properties-dialog.c
+++ b/thunar/thunar-properties-dialog.c
@@ -856,12 +856,15 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog)
   const gchar       *name;
   const gchar       *path;
   GVolume           *volume;
-  guint64            size;
+  guint64            fs_free;
+  guint64            fs_size;
   GIcon             *gicon;
   glong              offset;
   gchar             *date;
   gchar             *display_name;
-  gchar             *size_string;
+  gchar             *fs_free_str;
+  gchar             *fs_size_str;
+  gchar             *fs_string;
   gchar             *str;
   gchar             *volume_name;
   ThunarFile        *file;
@@ -1044,12 +1047,20 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog)
 
   /* update the free space (only for folders) */
   if (thunar_file_is_directory (file)
-      && thunar_file_get_free_space (file, &size))
+      && thunar_file_get_free_space (file, &fs_free, &fs_size)
+      && fs_size > 0)
     {
-      size_string = g_format_size (size);
-      gtk_label_set_text (GTK_LABEL (dialog->freespace_label), size_string);
+      fs_free_str = g_format_size (fs_free);
+      fs_size_str = g_format_size (fs_size);
+      fs_string = g_strdup_printf (_("%s of %s (%d%% used)"),
+                                   fs_free_str, fs_size_str,
+                                   (gint) ((fs_size - fs_free) * 100 / fs_size));
+      g_free (fs_free_str);
+      g_free (fs_size_str);
+
+      gtk_label_set_text (GTK_LABEL (dialog->freespace_label), fs_string);
       gtk_widget_show (dialog->freespace_label);
-      g_free (size_string);
+      g_free (fs_string);
     }
   else
     {


More information about the Xfce4-commits mailing list