[Xfce4-commits] [xfce/thunar] 01/04: Fix for bug 10864 - thunar incorrectly showing file sizes

noreply at xfce.org noreply at xfce.org
Sat Dec 20 01:36:55 CET 2014


This is an automated email from the git hooks/post-receive script.

andrzejr pushed a commit to branch master
in repository xfce/thunar.

commit 5bce93830d1005273a4af0fc45417418c671f28c
Author: Andre Miranda <andreldm1989 at gmail.com>
Date:   Wed Dec 17 00:53:32 2014 -0300

    Fix for bug 10864 - thunar incorrectly showing file sizes
---
 thunar/thunar-file.c               |   11 ++++++++-
 thunar/thunar-gio-extensions.c     |   21 ++++++++++------
 thunar/thunar-list-model.c         |   11 ++++++---
 thunar/thunar-preferences-dialog.c |    8 +++++-
 thunar/thunar-preferences.c        |   13 ++++++++++
 thunar/thunar-size-label.c         |   31 +++++++++++++++++-------
 thunar/thunar-transfer-job.c       |   47 +++++++++++++++++++++++-------------
 7 files changed, 104 insertions(+), 38 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 7a75c06..080f202 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -67,6 +67,7 @@
 #include <thunar/thunar-util.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-icon-factory.h>
+#include <thunar/thunar-preferences.h>
 
 
 
@@ -2160,8 +2161,16 @@ thunar_file_get_mode_string (const ThunarFile *file)
 gchar *
 thunar_file_get_size_string (const ThunarFile *file)
 {
+  ThunarPreferences *preferences;
+  gboolean           file_size_binary;
+
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
-  return g_format_size (thunar_file_get_size (file));
+
+  preferences = thunar_preferences_get ();
+  g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL);
+  g_object_unref (preferences);
+
+  return g_format_size_full (thunar_file_get_size (file), file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
 }
 
 
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index 369c1f4..9c852d9 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -34,6 +34,7 @@
 
 #include <thunar/thunar-file.h>
 #include <thunar/thunar-gio-extensions.h>
+#include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-util.h>
 
@@ -410,19 +411,25 @@ thunar_g_file_get_free_space (GFile   *file,
 gchar *
 thunar_g_file_get_free_space_string (GFile *file)
 {
-  gchar   *fs_free_str;
-  gchar   *fs_size_str;
-  guint64  fs_free;
-  guint64  fs_size;
-  gchar   *fs_string = NULL;
+  gchar             *fs_free_str;
+  gchar             *fs_size_str;
+  guint64            fs_free;
+  guint64            fs_size;
+  gchar             *fs_string = NULL;
+  ThunarPreferences *preferences;
+  gboolean           file_size_binary;
 
   _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
 
+  preferences = thunar_preferences_get ();
+  g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL);
+  g_object_unref (preferences);
+
   if (thunar_g_file_get_free_space (file, &fs_free, &fs_size)
       && fs_size > 0)
     {
-      fs_free_str = g_format_size (fs_free);
-      fs_size_str = g_format_size (fs_size);
+      fs_free_str = g_format_size_full (fs_free, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
+      fs_size_str = g_format_size_full (fs_size, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
       /* free disk space string */
       fs_string = g_strdup_printf (_("%s of %s (%d%% used)"),
                                    fs_free_str, fs_size_str,
diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c
index 33b36fd..eb06c95 100644
--- a/thunar/thunar-list-model.c
+++ b/thunar/thunar-list-model.c
@@ -2161,9 +2161,14 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store,
   gint               nrows;
   ThunarPreferences *preferences;
   gboolean           show_image_size;
+  gboolean           file_size_binary;
 
   _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), NULL);
 
+  preferences = thunar_preferences_get ();
+  g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL);
+  g_object_unref (preferences);
+
   if (selected_items == NULL)
     {
       /* try to determine a file for the current folder */
@@ -2176,7 +2181,7 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store,
           && thunar_g_file_get_free_space (thunar_file_get_file (file), &size, NULL)))
         {
           /* humanize the free space */
-          fspace_string = g_format_size (size);
+          fspace_string = g_format_size_full (size, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
           size_summary = 0;
 
           row = g_sequence_get_begin_iter (store->rows);
@@ -2194,7 +2199,7 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store,
           if (size_summary > 0)
             {
               /* generate a text which includes the size of all items in the folder */
-              size_string = g_format_size (size_summary);
+              size_string = g_format_size_full (size_summary, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
               text = g_strdup_printf (ngettext ("%d item (%s), Free space: %s", "%d items (%s), Free space: %s", nrows),
                                       nrows, size_string, fspace_string);
               g_free (size_string);
@@ -2326,7 +2331,7 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store,
      /* text for the items in the folder */
      if (non_folder_count > 0)
         {
-          size_string = g_format_size (size_summary);
+          size_string = g_format_size_full (size_summary, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
           if (folder_count > 0)
             {
               /* item count if there are also folders in the selection */
diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c
index 162b902..a7ed452 100644
--- a/thunar/thunar-preferences-dialog.c
+++ b/thunar/thunar-preferences-dialog.c
@@ -254,7 +254,7 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog)
   gtk_frame_set_label_widget (GTK_FRAME (frame), label);
   gtk_widget_show (label);
 
-  table = gtk_table_new (3, 2, FALSE);
+  table = gtk_table_new (4, 3, FALSE);
   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
   gtk_table_set_col_spacings (GTK_TABLE (table), 12);
   gtk_container_set_border_width (GTK_CONTAINER (table), 12);
@@ -300,6 +300,12 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog)
   gtk_table_attach (GTK_TABLE (table), button, 0, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
   gtk_widget_show (button);
 
+  button = gtk_check_button_new_with_mnemonic (_("Show file size in binary"));
+  exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-file-size-binary", G_OBJECT (button), "active");
+  gtk_widget_set_tooltip_text (button, _("Select this option to show file size in binary format instead of decimal."));
+  gtk_table_attach (GTK_TABLE (table), button, 0, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+  gtk_widget_show (button);
+
   frame = g_object_new (GTK_TYPE_FRAME, "border-width", 0, "shadow-type", GTK_SHADOW_NONE, NULL);
   gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0);
   gtk_widget_show (frame);
diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c
index 41c07d8..8409ccb 100644
--- a/thunar/thunar-preferences.c
+++ b/thunar/thunar-preferences.c
@@ -89,6 +89,7 @@ enum
   PROP_MISC_TAB_CLOSE_MIDDLE_CLICK,
   PROP_MISC_TEXT_BESIDE_ICONS,
   PROP_MISC_THUMBNAIL_MODE,
+  PROP_MISC_FILE_SIZE_BINARY,
   PROP_SHORTCUTS_ICON_EMBLEMS,
   PROP_SHORTCUTS_ICON_SIZE,
   PROP_TREE_ICON_EMBLEMS,
@@ -676,6 +677,18 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
                          EXO_PARAM_READWRITE);
 
   /**
+   * ThunarPreferences:misc-file-size-binary:
+   *
+   * Show file size in binary format instead of decimal.
+   **/
+  preferences_props[PROP_MISC_FILE_SIZE_BINARY] =
+      g_param_spec_boolean ("misc-file-size-binary",
+                            "MiscFileSizeBinary",
+                            NULL,
+                            FALSE,
+                            EXO_PARAM_READWRITE);
+
+  /**
    * ThunarPreferences:shortcuts-icon-emblems:
    *
    * Whether to display emblems for file icons (if defined) in the
diff --git a/thunar/thunar-size-label.c b/thunar/thunar-size-label.c
index eff53e7..f33e19a 100644
--- a/thunar/thunar-size-label.c
+++ b/thunar/thunar-size-label.c
@@ -30,10 +30,11 @@
 #include <locale.h>
 #endif
 
+#include <thunar/thunar-deep-count-job.h>
 #include <thunar/thunar-gtk-extensions.h>
+#include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-size-label.h>
-#include <thunar/thunar-deep-count-job.h>
 
 
 
@@ -264,13 +265,19 @@ thunar_size_label_button_press_event (GtkWidget       *ebox,
 static void
 thunar_size_label_files_changed (ThunarSizeLabel *size_label)
 {
-  gchar   *size_string;
-  guint64  size;
+  gchar             *size_string;
+  guint64            size;
+  ThunarPreferences *preferences;
+  gboolean           file_size_binary;
 
   _thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
   _thunar_return_if_fail (size_label->files != NULL);
   _thunar_return_if_fail (THUNAR_IS_FILE (size_label->files->data));
 
+  preferences = thunar_preferences_get ();
+  g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL);
+  g_object_unref (preferences);
+
   /* cancel the pending job (if any) */
   if (G_UNLIKELY (size_label->job != NULL))
     {
@@ -308,7 +315,7 @@ thunar_size_label_files_changed (ThunarSizeLabel *size_label)
       size = thunar_file_get_size (THUNAR_FILE (size_label->files->data));
 
       /* setup the new label */
-      size_string = g_format_size_full (size, G_FORMAT_SIZE_LONG_FORMAT);
+      size_string = g_format_size_full (size, file_size_binary ? G_FORMAT_SIZE_LONG_FORMAT | G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_LONG_FORMAT);
       gtk_label_set_text (GTK_LABEL (size_label->label), size_string);
       g_free (size_string);
     }
@@ -359,22 +366,28 @@ thunar_size_label_status_update (ThunarDeepCountJob *job,
                                  guint               unreadable_directory_count,
                                  ThunarSizeLabel    *size_label)
 {
-  gchar *size_string;
-  gchar *text;
-  guint  n;
-  gchar *unreable_text;
+  gchar             *size_string;
+  gchar             *text;
+  guint              n;
+  gchar             *unreable_text;
+  ThunarPreferences *preferences;
+  gboolean           file_size_binary;
 
   _thunar_return_if_fail (THUNAR_IS_DEEP_COUNT_JOB (job));
   _thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
   _thunar_return_if_fail (size_label->job == job);
 
+  preferences = thunar_preferences_get ();
+  g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL);
+  g_object_unref (preferences);
+
   /* determine the total number of items */
   n = file_count + directory_count + unreadable_directory_count;
 
   if (G_LIKELY (n > unreadable_directory_count))
     {
       /* update the label */
-      size_string = g_format_size (total_size);
+      size_string = g_format_size_full (total_size, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
       text = g_strdup_printf (ngettext ("%u item, totalling %s", "%u items, totalling %s", n), n, size_string);
       g_free (size_string);
       
diff --git a/thunar/thunar-transfer-job.c b/thunar/thunar-transfer-job.c
index b33557c..2f15c71 100644
--- a/thunar/thunar-transfer-job.c
+++ b/thunar/thunar-transfer-job.c
@@ -30,6 +30,7 @@
 #include <thunar/thunar-io-scan-directory.h>
 #include <thunar/thunar-io-jobs-util.h>
 #include <thunar/thunar-job.h>
+#include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-thumbnail-cache.h>
 #include <thunar/thunar-transfer-job.h>
@@ -672,17 +673,23 @@ static gboolean
 thunar_transfer_job_veryify_destination (ThunarTransferJob  *transfer_job,
                                          GError            **error)
 {
-  GFileInfo *filesystem_info;
-  guint64     free_space;
-  GFile     *dest;
-  GFileInfo *dest_info;
-  gchar     *dest_name = NULL;
-  gchar     *base_name;
-  gboolean   succeed = TRUE;
-  gchar     *size_string;
+  GFileInfo         *filesystem_info;
+  guint64             free_space;
+  GFile             *dest;
+  GFileInfo         *dest_info;
+  gchar             *dest_name = NULL;
+  gchar             *base_name;
+  gboolean           succeed = TRUE;
+  gchar             *size_string;
+  ThunarPreferences *preferences;
+  gboolean           file_size_binary;
 
   _thunar_return_val_if_fail (THUNAR_IS_TRANSFER_JOB (transfer_job), FALSE);
 
+  preferences = thunar_preferences_get ();
+  g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL);
+  g_object_unref (preferences);
+
   /* no target file list */
   if (transfer_job->target_file_list == NULL)
     return TRUE;
@@ -729,7 +736,7 @@ thunar_transfer_job_veryify_destination (ThunarTransferJob  *transfer_job,
       free_space = g_file_info_get_attribute_uint64 (filesystem_info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
       if (transfer_job->total_size > free_space)
         {
-          size_string = g_format_size (transfer_job->total_size - free_space);
+          size_string = g_format_size_full (transfer_job->total_size - free_space, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
           succeed = thunar_job_ask_no_size (THUNAR_JOB (transfer_job),
                                              _("Error while copying to \"%s\": %s more space is "
                                                "required to copy to the destination"),
@@ -1068,19 +1075,25 @@ thunar_transfer_job_new (GList                *source_node_list,
 gchar *
 thunar_transfer_job_get_status (ThunarTransferJob *job)
 {
-  gchar   *total_size_str;
-  gchar   *total_progress_str;
-  gchar   *transfer_rate_str;
-  GString *status;
-  gulong   remaining_time;
+  gchar             *total_size_str;
+  gchar             *total_progress_str;
+  gchar             *transfer_rate_str;
+  GString           *status;
+  gulong             remaining_time;
+  ThunarPreferences *preferences;
+  gboolean           file_size_binary;
 
   _thunar_return_val_if_fail (THUNAR_IS_TRANSFER_JOB (job), NULL);
 
+  preferences = thunar_preferences_get ();
+  g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL);
+  g_object_unref (preferences);
+
   status = g_string_sized_new (100);
 
   /* transfer status like "22.6MB of 134.1MB" */
-  total_size_str = g_format_size (job->total_size);
-  total_progress_str = g_format_size (job->total_progress);
+  total_size_str = g_format_size_full (job->total_size, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
+  total_progress_str = g_format_size_full (job->total_progress, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
   g_string_append_printf (status, _("%s of %s"), total_progress_str, total_size_str);
   g_free (total_size_str);
   g_free (total_progress_str);
@@ -1090,7 +1103,7 @@ thunar_transfer_job_get_status (ThunarTransferJob *job)
       && (job->last_update_time - job->start_time) > MINIMUM_TRANSFER_TIME)
     {
       /* remaining time based on the transfer speed */
-      transfer_rate_str = g_format_size (job->transfer_rate);
+      transfer_rate_str = g_format_size_full (job->transfer_rate, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT);
       remaining_time = (job->total_size - job->total_progress) / job->transfer_rate;
 
       if (remaining_time > 0)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list