From 89ab18574aa76862b19e280afba31f952fdf5597 Mon Sep 17 00:00:00 2001 From: Andre Miranda Date: Mon, 9 Mar 2015 22:35:47 -0300 Subject: [PATCH] Caching property file_size_binary in ThunarTransferJob (bug #11450) Also moving other queries for this property to where it is used. --- thunar/thunar-gio-extensions.c | 9 +++++---- thunar/thunar-size-label.c | 18 ++++++++++-------- thunar/thunar-transfer-job.c | 31 +++++++++++++++---------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c index 3cd9824..3473d7b 100644 --- a/thunar/thunar-gio-extensions.c +++ b/thunar/thunar-gio-extensions.c @@ -421,13 +421,14 @@ thunar_g_file_get_free_space_string (GFile *file) _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) { + /* query file_size_binary property */ + preferences = thunar_preferences_get (); + g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL); + g_object_unref (preferences); + 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 */ diff --git a/thunar/thunar-size-label.c b/thunar/thunar-size-label.c index 1afaea7..eff5fcc 100644 --- a/thunar/thunar-size-label.c +++ b/thunar/thunar-size-label.c @@ -274,10 +274,6 @@ thunar_size_label_files_changed (ThunarSizeLabel *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)) { @@ -307,6 +303,11 @@ thunar_size_label_files_changed (ThunarSizeLabel *size_label) } else { + /* query file_size_binary property */ + preferences = thunar_preferences_get (); + g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL); + g_object_unref (preferences); + /* this is going to be quick, stop and hide the spinner */ gtk_spinner_stop (GTK_SPINNER (size_label->spinner)); gtk_widget_hide (size_label->spinner); @@ -377,15 +378,16 @@ thunar_size_label_status_update (ThunarDeepCountJob *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)) { + /* query file_size_binary property */ + preferences = thunar_preferences_get (); + g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL); + g_object_unref (preferences); + /* update the label */ 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); diff --git a/thunar/thunar-transfer-job.c b/thunar/thunar-transfer-job.c index 2f15c71..9998bc8 100644 --- a/thunar/thunar-transfer-job.c +++ b/thunar/thunar-transfer-job.c @@ -74,6 +74,8 @@ struct _ThunarTransferJob guint64 total_progress; guint64 file_progress; guint64 transfer_rate; + + gboolean file_size_binary; }; struct _ThunarTransferNode @@ -117,6 +119,7 @@ thunar_transfer_job_init (ThunarTransferJob *job) job->last_total_progress = 0; job->transfer_rate = 0; job->start_time = 0; + job->file_size_binary = FALSE; } @@ -681,15 +684,9 @@ thunar_transfer_job_veryify_destination (ThunarTransferJob *transfer_job, 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; @@ -736,7 +733,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_full (transfer_job->total_size - free_space, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT); + size_string = g_format_size_full (transfer_job->total_size - free_space, transfer_job->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"), @@ -784,6 +781,8 @@ thunar_transfer_job_execute (ExoJob *job, GFile *target_parent; gchar *base_name; gchar *parent_display_name; + ThunarPreferences *preferences; + gboolean file_size_binary; _thunar_return_val_if_fail (THUNAR_IS_TRANSFER_JOB (job), FALSE); _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -798,6 +797,12 @@ thunar_transfer_job_execute (ExoJob *job, thumbnail_cache = thunar_application_get_thumbnail_cache (application); g_object_unref (application); + /* cache property file_size_binary */ + preferences = thunar_preferences_get (); + g_object_get (preferences, "misc-file-size-binary", &file_size_binary, NULL); + g_object_unref (preferences); + transfer_job->file_size_binary = file_size_binary; + for (sp = transfer_job->source_node_list, tp = transfer_job->target_file_list; sp != NULL && tp != NULL && err == NULL; sp = snext, tp = tnext) @@ -1080,20 +1085,14 @@ thunar_transfer_job_get_status (ThunarTransferJob *job) 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_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); + total_size_str = g_format_size_full (job->total_size, job->file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT); + total_progress_str = g_format_size_full (job->total_progress, job->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); @@ -1103,7 +1102,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_full (job->transfer_rate, file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT); + transfer_rate_str = g_format_size_full (job->transfer_rate, job->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) -- 2.3.1