diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c index 911a276..d0e2c9d 100644 --- a/thunar/thunar-dialogs.c +++ b/thunar/thunar-dialogs.c @@ -523,6 +523,7 @@ thunar_dialogs_show_job_ask_replace (GtkWindow *parent, gchar *size_string; gchar *text; gint response; + gboolean file_size_exact; gboolean file_size_binary; _thunar_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), THUNAR_JOB_RESPONSE_CANCEL); @@ -532,6 +533,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-exact", &file_size_exact, NULL); g_object_get (G_OBJECT (preferences), "misc-file-size-binary", &file_size_binary, NULL); g_object_unref (G_OBJECT (preferences)); @@ -619,7 +621,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_formatted (dst_file, file_size_binary); + size_string = thunar_file_get_size_string_formatted (dst_file, file_size_exact, 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); @@ -650,7 +652,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_formatted (src_file, file_size_binary); + size_string = thunar_file_get_size_string_formatted (src_file, file_size_exact, 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 3262dfb..6e150dd 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -2265,22 +2265,35 @@ thunar_file_get_size_string (const ThunarFile *file) /** * thunar_file_get_size_string_formatted: * @file : a #ThunarFile instance. + * @file_size_exact : indicates if the file size format + * should be human readable or exact. * @file_size_binary : indicates if file size format - * should be binary or not. + * should use binary prefix. * - * Returns the size of the file as text in a human readable - * format in decimal or binary format. You'll need to free + * Returns the size of the file as text as an exact byte count, + * or in decimal or binary prefixed 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_file_get_size_string_formatted (const ThunarFile *file, const gboolean file_size_exact, 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); + if (file_size_exact) + { +#ifndef G_OS_WIN32 + return g_strdup_printf ("%'"G_GUINT64_FORMAT, thunar_file_get_size (file)); +#else + return g_strdup_printf ("%"G_GUINT64_FORMAT, thunar_file_get_size (file)); +#endif + } + else + { + 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-file.h b/thunar/thunar-file.h index cfc3d05..9d884cb 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -169,6 +169,7 @@ gchar *thunar_file_get_date_string (const ThunarFile 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_exact, const gboolean file_size_binary); GVolume *thunar_file_get_volume (const ThunarFile *file); diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 9e6d83c..ed735f6 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_EXACT, PROP_FILE_SIZE_BINARY, N_PROPERTIES }; @@ -212,6 +213,7 @@ struct _ThunarListModel GSList *hidden; ThunarFolder *folder; gboolean show_hidden : 1; + gboolean file_size_exact : 1; gboolean file_size_binary : 1; ThunarDateStyle date_style; @@ -332,6 +334,18 @@ thunar_list_model_class_init (ThunarListModelClass *klass) EXO_PARAM_READWRITE); /** + * ThunarListModel::misc-file-size-exact: + * + * Tells whether to show exact file size. + **/ + list_model_props[PROP_FILE_SIZE_EXACT] = + g_param_spec_boolean ("file-size-exact", + "file-size-exact", + "file-size-exact", + FALSE, + EXO_PARAM_READWRITE); + + /** * ThunarListModel::misc-file-size-binary: * * Tells whether to format file size in binary. @@ -494,6 +508,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_EXACT: + g_value_set_boolean (value, thunar_list_model_get_file_size_exact (store)); + break; + case PROP_FILE_SIZE_BINARY: g_value_set_boolean (value, thunar_list_model_get_file_size_binary (store)); break; @@ -536,6 +554,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_EXACT: + thunar_list_model_set_file_size_exact (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; @@ -739,7 +761,8 @@ 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_formatted (file, THUNAR_LIST_MODEL (model)->file_size_binary)); + g_value_take_string (value, thunar_file_get_size_string_formatted (file, THUNAR_LIST_MODEL (model)->file_size_exact, + THUNAR_LIST_MODEL (model)->file_size_binary)); break; case THUNAR_COLUMN_TYPE: @@ -2001,6 +2024,63 @@ thunar_list_model_set_show_hidden (ThunarListModel *store, /** + * thunar_list_model_get_file_size_exact: + * @store : a valid #ThunarListModel object. + * + * Returns %TRUE if the file size should be formatted + * as exact value in bytes. + * + * Return value: %TRUE if file size format is binary. + **/ +gboolean +thunar_list_model_get_file_size_exact (ThunarListModel *store) +{ + _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); + return store->file_size_exact; +} + + + +/** + * thunar_list_model_set_file_size_exact: + * @store : a valid #ThunarListModel object. + * @file_size_exact : %TRUE to format file size as exact value in bytes. + * + * If @file_size_exact is %TRUE the file size should be + * formatted as exact bytecount. + **/ +void +thunar_list_model_set_file_size_exact (ThunarListModel *store, + gboolean file_size_exact) +{ + _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); + + /* normalize the setting */ + file_size_exact = !!file_size_exact; + + /* check if we have a new setting */ + if (store->file_size_exact != file_size_exact) + { + /* apply the new setting */ + store->file_size_exact = file_size_exact; + + /* 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_EXACT]); + + /* emit a "changed" signal for each row, so the display is + reloaded with the new exact file size setting */ + gtk_tree_model_foreach (GTK_TREE_MODEL (store), + (GtkTreeModelForeachFunc) gtk_tree_model_row_changed, + NULL); + } +} + + + +/** * thunar_list_model_get_file_size_binary: * @store : a valid #ThunarListModel object. * @@ -2253,10 +2333,12 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store, gint nrows; ThunarPreferences *preferences; gboolean show_image_size; + gboolean file_size_exact; gboolean file_size_binary; _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), NULL); + file_size_exact = thunar_list_model_get_file_size_exact(store); file_size_binary = thunar_list_model_get_file_size_binary(store); if (selected_items == NULL) @@ -2326,7 +2408,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_formatted (file, file_size_binary); + size_string = thunar_file_get_size_string_formatted (file, file_size_exact, 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); @@ -2342,7 +2424,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_formatted (file, file_size_binary); + size_string = thunar_file_get_size_string_formatted (file, file_size_exact, 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); diff --git a/thunar/thunar-list-model.h b/thunar/thunar-list-model.h index 459ee7a..caa4236 100644 --- a/thunar/thunar-list-model.h +++ b/thunar/thunar-list-model.h @@ -49,6 +49,10 @@ gboolean thunar_list_model_get_show_hidden (ThunarListModel *sto void thunar_list_model_set_show_hidden (ThunarListModel *store, gboolean show_hidden); +gboolean thunar_list_model_get_file_size_exact (ThunarListModel *store); +void thunar_list_model_set_file_size_exact (ThunarListModel *store, + gboolean file_size_exact); + gboolean thunar_list_model_get_file_size_binary (ThunarListModel *store); void thunar_list_model_set_file_size_binary (ThunarListModel *store, gboolean file_size_binary); diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index 057766e..9e72b70 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 (4, 3, FALSE); + table = gtk_table_new (5, 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,12 +300,18 @@ 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.")); + button = gtk_check_button_new_with_mnemonic (_("Show exact file size")); + exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-file-size-exact", G_OBJECT (button), "active"); + gtk_widget_set_tooltip_text (button, _("Select this option to show exact file size in bytes.")); gtk_table_attach (GTK_TABLE (table), button, 0, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (button); + button = gtk_check_button_new_with_mnemonic (_("Use binary prefix (KiB, MiB, ...)")); + 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 use binary prefix in human readable format instead of decimal.")); + gtk_table_attach (GTK_TABLE (table), button, 0, 2, 4, 5, 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 9a86ae1..156ec84 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -90,6 +90,7 @@ enum PROP_MISC_TAB_CLOSE_MIDDLE_CLICK, PROP_MISC_TEXT_BESIDE_ICONS, PROP_MISC_THUMBNAIL_MODE, + PROP_MISC_FILE_SIZE_EXACT, PROP_MISC_FILE_SIZE_BINARY, PROP_SHORTCUTS_ICON_EMBLEMS, PROP_SHORTCUTS_ICON_SIZE, @@ -694,9 +695,21 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** + * ThunarPreferences:misc-file-size-exact: + * + * Show exact file size in bytes instead of human readable format. + **/ + preferences_props[PROP_MISC_FILE_SIZE_EXACT] = + g_param_spec_boolean ("misc-file-size-exact", + "MiscFileSizeExact", + NULL, + FALSE, + EXO_PARAM_READWRITE); + + /** * ThunarPreferences:misc-file-size-binary: * - * Show file size in binary format instead of decimal. + * Show human readable file size with binary prefix instead of decimal. **/ preferences_props[PROP_MISC_FILE_SIZE_BINARY] = g_param_spec_boolean ("misc-file-size-binary", diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c index 67135d2..7cfec6a 100644 --- a/thunar/thunar-properties-dialog.c +++ b/thunar/thunar-properties-dialog.c @@ -65,7 +65,8 @@ enum { PROP_0, PROP_FILES, - PROP_FILE_SIZE_BINARY, + PROP_FILE_SIZE_EXACT, + PROP_FILE_SIZE_BINARY }; /* Signal identifiers */ diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c index ef2a5d2..d3d5c21 100644 --- a/thunar/thunar-shortcuts-model.c +++ b/thunar/thunar-shortcuts-model.c @@ -63,6 +63,7 @@ enum { PROP_0, PROP_HIDDEN_BOOKMARKS, + PROP_FILE_SIZE_EXACT, PROP_FILE_SIZE_BINARY }; @@ -172,6 +173,7 @@ struct _ThunarShortcutsModel ThunarPreferences *preferences; gchar **hidden_bookmarks; + gboolean file_size_exact; gboolean file_size_binary; ThunarDeviceMonitor *device_monitor; @@ -230,9 +232,22 @@ thunar_shortcuts_model_class_init (ThunarShortcutsModelClass *klass) EXO_PARAM_READWRITE)); /** + * ThunarPropertiesDialog:file_size_exact: + * + * Whether the file size should be shown as exact bytecount or in human readable format. + **/ + g_object_class_install_property (gobject_class, + PROP_FILE_SIZE_EXACT, + g_param_spec_boolean ("file-size-exact", + "FileSizeExact", + NULL, + FALSE, + EXO_PARAM_READWRITE)); + + /** * ThunarPropertiesDialog:file_size_binary: * - * Whether the file size should be shown in binary or decimal. + * Whether the file size should be shown with binary or decimal prefix. **/ g_object_class_install_property (gobject_class, PROP_FILE_SIZE_BINARY, @@ -286,6 +301,10 @@ thunar_shortcuts_model_init (ThunarShortcutsModel *model) exo_binding_new (G_OBJECT (model->preferences), "hidden-bookmarks", G_OBJECT (model), "hidden-bookmarks"); + /* exact file size */ + exo_binding_new (G_OBJECT (model->preferences), "misc-file-size-exact", + G_OBJECT (model), "file-size-exact"); + /* binary file size */ exo_binding_new (G_OBJECT (model->preferences), "misc-file-size-binary", G_OBJECT (model), "file-size-binary"); diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 6b078e3..13baa21 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -703,6 +703,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-exact", G_OBJECT (standard_view->model), "file-size-exact"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-file-size-binary", G_OBJECT (standard_view->model), "file-size-binary"); /* setup the icon renderer */