diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c index 99b9e54..7cee548 100644 --- a/thunar/thunar-dialogs.c +++ b/thunar/thunar-dialogs.c @@ -519,6 +519,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, gchar *size_string; gchar *text; gint response; + gboolean file_size_binary; _thunar_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), THUNAR_JOB_RESPONSE_CANCEL); _thunar_return_val_if_fail (THUNAR_IS_FILE (src_file), THUNAR_JOB_RESPONSE_CANCEL); @@ -527,6 +528,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, /* determine the style used to format dates */ preferences = thunar_preferences_get (); g_object_get (G_OBJECT (preferences), "misc-date-style", &date_style, NULL); + g_object_get (G_OBJECT (preferences), "misc-file-size-binary", &file_size_binary, NULL); g_object_unref (G_OBJECT (preferences)); /* setup the confirmation dialog */ @@ -613,7 +615,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); - size_string = thunar_file_get_size_string (dst_file); + size_string = thunar_file_get_size_string_formatted (dst_file, file_size_binary); date_string = thunar_file_get_date_string (dst_file, THUNAR_FILE_DATE_MODIFIED, date_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); @@ -644,7 +646,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); - size_string = thunar_file_get_size_string (src_file); + size_string = thunar_file_get_size_string_formatted (src_file, file_size_binary); date_string = thunar_file_get_date_string (src_file, THUNAR_FILE_DATE_MODIFIED, date_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 7a75c06..60fe3e7 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -2167,6 +2167,29 @@ thunar_file_get_size_string (const ThunarFile *file) /** + * thunar_file_get_size_string_formatted: + * @file : a #ThunarFile instance. + * @file_size_binary : indicates if file size format + * should be binary or not. + * + * Returns the size of the file as text in a human readable + * format in decimal or binary format. You'll need to free + * the result using g_free() if you're done with it. + * + * Return value: the size of @file in a human readable + * format. + **/ +gchar * +thunar_file_get_size_string_formatted (const ThunarFile *file, const gboolean file_size_binary) +{ + _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL); + return g_format_size_full (thunar_file_get_size (file), + file_size_binary ? G_FORMAT_SIZE_IEC_UNITS : G_FORMAT_SIZE_DEFAULT); +} + + + +/** * thunar_file_get_volume: * @file : a #ThunarFile instance. * diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index 74ed6f8..d7a09d2 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -114,145 +114,147 @@ typedef void (*ThunarFileGetFunc) (GFile *location, -GType thunar_file_get_type (void) G_GNUC_CONST; - -ThunarFile *thunar_file_get (GFile *file, - GError **error); -ThunarFile *thunar_file_get_with_info (GFile *file, - GFileInfo *info, - gboolean not_mounted); -ThunarFile *thunar_file_get_for_uri (const gchar *uri, - GError **error); -void thunar_file_get_async (GFile *location, - GCancellable *cancellable, - ThunarFileGetFunc func, - gpointer user_data); - -GFile *thunar_file_get_file (const ThunarFile *file) G_GNUC_PURE; - -GFileInfo *thunar_file_get_info (const ThunarFile *file) G_GNUC_PURE; - -ThunarFile *thunar_file_get_parent (const ThunarFile *file, - GError **error); - -gboolean thunar_file_check_loaded (ThunarFile *file); - -gboolean thunar_file_execute (ThunarFile *file, - GFile *working_directory, - gpointer parent, - GList *path_list, - GError **error); - -gboolean thunar_file_launch (ThunarFile *file, - gpointer parent, - const gchar *startup_id, - GError **error); - -gboolean thunar_file_rename (ThunarFile *file, - const gchar *name, - GCancellable *cancellable, - gboolean called_from_job, - GError **error); - -GdkDragAction thunar_file_accepts_drop (ThunarFile *file, - GList *path_list, - GdkDragContext *context, - GdkDragAction *suggested_action_return); - -guint64 thunar_file_get_date (const ThunarFile *file, - ThunarFileDateType date_type) G_GNUC_PURE; - -gchar *thunar_file_get_date_string (const ThunarFile *file, - ThunarFileDateType date_type, - ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -gchar *thunar_file_get_mode_string (const ThunarFile *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -gchar *thunar_file_get_size_string (const ThunarFile *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; - -GVolume *thunar_file_get_volume (const ThunarFile *file); - -ThunarGroup *thunar_file_get_group (const ThunarFile *file); -ThunarUser *thunar_file_get_user (const ThunarFile *file); - -const gchar *thunar_file_get_content_type (ThunarFile *file); -gboolean thunar_file_load_content_type (ThunarFile *file); -const gchar *thunar_file_get_symlink_target (const ThunarFile *file); -const gchar *thunar_file_get_basename (const ThunarFile *file) G_GNUC_CONST; -gboolean thunar_file_is_symlink (const ThunarFile *file); -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) G_GNUC_PURE; -GFile *thunar_file_get_target_location (const ThunarFile *file); -ThunarFileMode thunar_file_get_mode (const ThunarFile *file); -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; -gboolean thunar_file_is_shortcut (const ThunarFile *file) G_GNUC_PURE; -gboolean thunar_file_is_mountable (const ThunarFile *file) G_GNUC_PURE; -gboolean thunar_file_is_local (const ThunarFile *file); -gboolean thunar_file_is_parent (const ThunarFile *file, - const ThunarFile *child); -gboolean thunar_file_is_gfile_ancestor (const ThunarFile *file, - GFile *ancestor); -gboolean thunar_file_is_ancestor (const ThunarFile *file, - const ThunarFile *ancestor); -gboolean thunar_file_is_executable (const ThunarFile *file); -gboolean thunar_file_is_writable (const ThunarFile *file); -gboolean thunar_file_is_hidden (const ThunarFile *file); -gboolean thunar_file_is_home (const ThunarFile *file); -gboolean thunar_file_is_regular (const ThunarFile *file) G_GNUC_PURE; -gboolean thunar_file_is_trashed (const ThunarFile *file); -gboolean thunar_file_is_desktop_file (const ThunarFile *file, - gboolean *is_secure); -const gchar *thunar_file_get_display_name (const ThunarFile *file) G_GNUC_CONST; - -gchar *thunar_file_get_deletion_date (const ThunarFile *file, - ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -const gchar *thunar_file_get_original_path (const ThunarFile *file); -guint32 thunar_file_get_item_count (const ThunarFile *file); - -gboolean thunar_file_is_chmodable (const ThunarFile *file); -gboolean thunar_file_is_renameable (const ThunarFile *file); -gboolean thunar_file_can_be_trashed (const ThunarFile *file); - -GList *thunar_file_get_emblem_names (ThunarFile *file); -void thunar_file_set_emblem_names (ThunarFile *file, - GList *emblem_names); - -const gchar *thunar_file_get_custom_icon (const ThunarFile *file); -gboolean thunar_file_set_custom_icon (ThunarFile *file, - const gchar *custom_icon, - GError **error); - -const gchar *thunar_file_get_thumbnail_path (ThunarFile *file); -ThunarFileThumbState thunar_file_get_thumb_state (const ThunarFile *file); -void thunar_file_set_thumb_state (ThunarFile *file, - ThunarFileThumbState state); -GIcon *thunar_file_get_preview_icon (const ThunarFile *file); -GFilesystemPreviewType thunar_file_get_preview_type (const ThunarFile *file); -const gchar *thunar_file_get_icon_name (ThunarFile *file, - ThunarFileIconState icon_state, - GtkIconTheme *icon_theme); - -void thunar_file_watch (ThunarFile *file); -void thunar_file_unwatch (ThunarFile *file); - -void thunar_file_reload (ThunarFile *file); - -void thunar_file_destroy (ThunarFile *file); - - -gint thunar_file_compare_by_name (const ThunarFile *file_a, - const ThunarFile *file_b, - gboolean case_sensitive) G_GNUC_PURE; - -ThunarFile *thunar_file_cache_lookup (const GFile *file); -gchar *thunar_file_cached_display_name (const GFile *file); - - -GList *thunar_file_list_get_applications (GList *file_list); -GList *thunar_file_list_to_thunar_g_file_list (GList *file_list); - -gboolean thunar_file_is_desktop (const ThunarFile *file); +GType thunar_file_get_type (void) G_GNUC_CONST; + +ThunarFile *thunar_file_get (GFile *file, + GError **error); +ThunarFile *thunar_file_get_with_info (GFile *file, + GFileInfo *info, + gboolean not_mounted); +ThunarFile *thunar_file_get_for_uri (const gchar *uri, + GError **error); +void thunar_file_get_async (GFile *location, + GCancellable *cancellable, + ThunarFileGetFunc func, + gpointer user_data); + +GFile *thunar_file_get_file (const ThunarFile *file) G_GNUC_PURE; + +GFileInfo *thunar_file_get_info (const ThunarFile *file) G_GNUC_PURE; + +ThunarFile *thunar_file_get_parent (const ThunarFile *file, + GError **error); + +gboolean thunar_file_check_loaded (ThunarFile *file); + +gboolean thunar_file_execute (ThunarFile *file, + GFile *working_directory, + gpointer parent, + GList *path_list, + GError **error); + +gboolean thunar_file_launch (ThunarFile *file, + gpointer parent, + const gchar *startup_id, + GError **error); + +gboolean thunar_file_rename (ThunarFile *file, + const gchar *name, + GCancellable *cancellable, + gboolean called_from_job, + GError **error); + +GdkDragAction thunar_file_accepts_drop (ThunarFile *file, + GList *path_list, + GdkDragContext *context, + GdkDragAction *suggested_action_return); + +guint64 thunar_file_get_date (const ThunarFile *file, + ThunarFileDateType date_type) G_GNUC_PURE; + +gchar *thunar_file_get_date_string (const ThunarFile *file, + ThunarFileDateType date_type, + ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +gchar *thunar_file_get_mode_string (const ThunarFile *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +gchar *thunar_file_get_size_string (const ThunarFile *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +gchar *thunar_file_get_size_string_formatted (const ThunarFile *file, + const gboolean file_size_binary); + +GVolume *thunar_file_get_volume (const ThunarFile *file); + +ThunarGroup *thunar_file_get_group (const ThunarFile *file); +ThunarUser *thunar_file_get_user (const ThunarFile *file); + +const gchar *thunar_file_get_content_type (ThunarFile *file); +gboolean thunar_file_load_content_type (ThunarFile *file); +const gchar *thunar_file_get_symlink_target (const ThunarFile *file); +const gchar *thunar_file_get_basename (const ThunarFile *file) G_GNUC_CONST; +gboolean thunar_file_is_symlink (const ThunarFile *file); +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) G_GNUC_PURE; +GFile *thunar_file_get_target_location (const ThunarFile *file); +ThunarFileMode thunar_file_get_mode (const ThunarFile *file); +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; +gboolean thunar_file_is_shortcut (const ThunarFile *file) G_GNUC_PURE; +gboolean thunar_file_is_mountable (const ThunarFile *file) G_GNUC_PURE; +gboolean thunar_file_is_local (const ThunarFile *file); +gboolean thunar_file_is_parent (const ThunarFile *file, + const ThunarFile *child); +gboolean thunar_file_is_gfile_ancestor (const ThunarFile *file, + GFile *ancestor); +gboolean thunar_file_is_ancestor (const ThunarFile *file, + const ThunarFile *ancestor); +gboolean thunar_file_is_executable (const ThunarFile *file); +gboolean thunar_file_is_writable (const ThunarFile *file); +gboolean thunar_file_is_hidden (const ThunarFile *file); +gboolean thunar_file_is_home (const ThunarFile *file); +gboolean thunar_file_is_regular (const ThunarFile *file) G_GNUC_PURE; +gboolean thunar_file_is_trashed (const ThunarFile *file); +gboolean thunar_file_is_desktop_file (const ThunarFile *file, + gboolean *is_secure); +const gchar *thunar_file_get_display_name (const ThunarFile *file) G_GNUC_CONST; + +gchar *thunar_file_get_deletion_date (const ThunarFile *file, + ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +const gchar *thunar_file_get_original_path (const ThunarFile *file); +guint32 thunar_file_get_item_count (const ThunarFile *file); + +gboolean thunar_file_is_chmodable (const ThunarFile *file); +gboolean thunar_file_is_renameable (const ThunarFile *file); +gboolean thunar_file_can_be_trashed (const ThunarFile *file); + +GList *thunar_file_get_emblem_names (ThunarFile *file); +void thunar_file_set_emblem_names (ThunarFile *file, + GList *emblem_names); + +const gchar *thunar_file_get_custom_icon (const ThunarFile *file); +gboolean thunar_file_set_custom_icon (ThunarFile *file, + const gchar *custom_icon, + GError **error); + +const gchar *thunar_file_get_thumbnail_path (ThunarFile *file); +ThunarFileThumbState thunar_file_get_thumb_state (const ThunarFile *file); +void thunar_file_set_thumb_state (ThunarFile *file, + ThunarFileThumbState state); +GIcon *thunar_file_get_preview_icon (const ThunarFile *file); +GFilesystemPreviewType thunar_file_get_preview_type (const ThunarFile *file); +const gchar *thunar_file_get_icon_name (ThunarFile *file, + ThunarFileIconState icon_state, + GtkIconTheme *icon_theme); + +void thunar_file_watch (ThunarFile *file); +void thunar_file_unwatch (ThunarFile *file); + +void thunar_file_reload (ThunarFile *file); + +void thunar_file_destroy (ThunarFile *file); + + +gint thunar_file_compare_by_name (const ThunarFile *file_a, + const ThunarFile *file_b, + gboolean case_sensitive) G_GNUC_PURE; + +ThunarFile *thunar_file_cache_lookup (const GFile *file); +gchar *thunar_file_cached_display_name (const GFile *file); + + +GList *thunar_file_list_get_applications (GList *file_list); +GList *thunar_file_list_to_thunar_g_file_list (GList *file_list); + +gboolean thunar_file_is_desktop (const ThunarFile *file); /** * thunar_file_is_root: 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 #include +#include #include #include @@ -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..9684758 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -50,6 +50,7 @@ enum PROP_FOLDERS_FIRST, PROP_NUM_FILES, PROP_SHOW_HIDDEN, + PROP_FILE_SIZE_BINARY, N_PROPERTIES }; @@ -184,6 +185,9 @@ static void thunar_list_model_set_date_style (ThunarListMod static gint thunar_list_model_get_num_files (ThunarListModel *store); static gboolean thunar_list_model_get_folders_first (ThunarListModel *store); +static gboolean thunar_list_model_get_file_size_binary (ThunarListModel *store); +static void thunar_list_model_set_file_size_binary (ThunarListModel *store, + gboolean file_size_binary); struct _ThunarListModelClass { @@ -210,6 +214,7 @@ struct _ThunarListModel GSList *hidden; ThunarFolder *folder; gboolean show_hidden : 1; + gboolean file_size_binary : 1; ThunarDateStyle date_style; /* Use the shared ThunarFileMonitor instance, so we @@ -328,6 +333,18 @@ thunar_list_model_class_init (ThunarListModelClass *klass) FALSE, EXO_PARAM_READWRITE); + /** + * ThunarListModel::misc-file-size-binary: + * + * Tells whether to format file size in binary. + **/ + list_model_props[PROP_FILE_SIZE_BINARY] = + g_param_spec_boolean ("file-size-binary", + "file-size-binary", + "file-size-binary", + FALSE, + EXO_PARAM_READWRITE); + /* install properties */ g_object_class_install_properties (gobject_class, N_PROPERTIES, list_model_props); @@ -479,6 +496,10 @@ thunar_list_model_get_property (GObject *object, g_value_set_boolean (value, thunar_list_model_get_show_hidden (store)); break; + case PROP_FILE_SIZE_BINARY: + g_value_set_boolean (value, thunar_list_model_get_file_size_binary (store)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -517,6 +538,10 @@ thunar_list_model_set_property (GObject *object, thunar_list_model_set_show_hidden (store, g_value_get_boolean (value)); break; + case PROP_FILE_SIZE_BINARY: + thunar_list_model_set_file_size_binary (store, g_value_get_boolean (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -716,7 +741,7 @@ thunar_list_model_get_value (GtkTreeModel *model, case THUNAR_COLUMN_SIZE: g_value_init (value, G_TYPE_STRING); - g_value_take_string (value, thunar_file_get_size_string (file)); + g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); break; case THUNAR_COLUMN_TYPE: @@ -1966,6 +1991,57 @@ thunar_list_model_set_show_hidden (ThunarListModel *store, /** + * thunar_list_model_get_file_size_binary: + * @store : a valid #ThunarListModel object. + * + * Returns %TRUE if the file size should be formatted + * as binary. + * + * Return value: %TRUE if file size format is binary. + **/ +static gboolean +thunar_list_model_get_file_size_binary (ThunarListModel *store) +{ + _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); + return store->file_size_binary; +} + + + +/** + * thunar_list_model_set_file_size_binary: + * @store : a valid #ThunarListModel object. + * @file_size_binary : %TRUE to format file size as binary. + * + * If @file_size_binary is %TRUE the file size should be + * formatted as binary. + **/ +static void +thunar_list_model_set_file_size_binary (ThunarListModel *store, + gboolean file_size_binary) +{ + _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); + + /* normalize the setting */ + file_size_binary = !!file_size_binary; + + /* check if we have a new setting */ + if (store->file_size_binary != file_size_binary) + { + /* apply the new setting */ + store->file_size_binary = file_size_binary; + + /* resort the model with the new setting */ + thunar_list_model_sort (store); + + /* notify listeners */ + g_object_notify_by_pspec (G_OBJECT (store), list_model_props[PROP_FILE_SIZE_BINARY]); + } +} + + + +/** * thunar_list_model_get_file: * @store : a #ThunarListModel. * @iter : a valid #GtkTreeIter for @store. @@ -2161,9 +2237,12 @@ 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); + file_size_binary = thunar_list_model_get_file_size_binary(store); + if (selected_items == NULL) { /* try to determine a file for the current folder */ @@ -2176,7 +2255,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 +2273,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); @@ -2231,7 +2310,7 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store, } else if (G_UNLIKELY (thunar_file_is_symlink (file))) { - size_string = thunar_file_get_size_string (file); + size_string = thunar_file_get_size_string_formatted (file, file_size_binary); text = g_strdup_printf (_("\"%s\" (%s) link to %s"), thunar_file_get_display_name (file), size_string, thunar_file_get_symlink_target (file)); g_free (size_string); @@ -2247,7 +2326,7 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store, else if (thunar_file_is_regular (file)) { description = g_content_type_get_description (content_type); - size_string = thunar_file_get_size_string (file); + size_string = thunar_file_get_size_string_formatted (file, file_size_binary); /* I18N, first %s is the display name of the file, 2nd the file size, 3rd the content type */ text = g_strdup_printf (_("\"%s\" (%s) %s"), thunar_file_get_display_name (file), size_string, description); @@ -2326,7 +2405,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..c893142 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 format")); + 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 #endif +#include #include +#include #include #include -#include @@ -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-standard-view.c b/thunar/thunar-standard-view.c index 6d5dd48..f428e3d 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -693,6 +693,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view) exo_binding_new (G_OBJECT (standard_view->preferences), "misc-case-sensitive", G_OBJECT (standard_view->model), "case-sensitive"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-date-style", G_OBJECT (standard_view->model), "date-style"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-folders-first", G_OBJECT (standard_view->model), "folders-first"); + exo_binding_new (G_OBJECT (standard_view->preferences), "misc-file-size-binary", G_OBJECT (standard_view->model), "file-size-binary"); /* setup the icon renderer */ standard_view->icon_renderer = thunar_icon_renderer_new (); 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 #include #include +#include #include #include #include @@ -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)