From 824ba75383c8182e61e9047202ceff03a0fddd61 Mon Sep 17 00:00:00 2001 From: Simon Steinbeiss Date: Sun, 30 Nov 2014 17:21:13 +0100 Subject: [PATCH] Add a progressbar to the freespace indicator in the properties dialog This should help with visualising the free space in a more intuitive way. --- thunar/thunar-properties-dialog.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c index 6e6fa8d..e463c77 100644 --- a/thunar/thunar-properties-dialog.c +++ b/thunar/thunar-properties-dialog.c @@ -138,7 +138,7 @@ struct _ThunarPropertiesDialog GtkWidget *deleted_label; GtkWidget *modified_label; GtkWidget *accessed_label; - GtkWidget *freespace_label; + GtkWidget *freespace_bar; GtkWidget *volume_image; GtkWidget *volume_label; GtkWidget *permissions_chooser; @@ -497,11 +497,10 @@ thunar_properties_dialog_init (ThunarPropertiesDialog *dialog) gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 3); gtk_widget_show (label); - dialog->freespace_label = g_object_new (GTK_TYPE_LABEL, "xalign", 0.0f, NULL); - gtk_label_set_selectable (GTK_LABEL (dialog->freespace_label), TRUE); - exo_binding_new (G_OBJECT (dialog->freespace_label), "visible", G_OBJECT (label), "visible"); - gtk_table_attach (GTK_TABLE (table), dialog->freespace_label, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 3); - gtk_widget_show (dialog->freespace_label); + dialog->freespace_bar = g_object_new (GTK_TYPE_PROGRESS_BAR, NULL); + exo_binding_new (G_OBJECT (dialog->freespace_bar), "visible", G_OBJECT (label), "visible"); + gtk_table_attach (GTK_TABLE (table), dialog->freespace_bar, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 3); + gtk_widget_show (dialog->freespace_bar); ++row; @@ -858,6 +857,10 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog) ThunarFile *file; ThunarFile *parent_file; gboolean show_chooser; + guint64 fs_free; + guint64 fs_size; + gdouble fs_fraction = 0.0; + _thunar_return_if_fail (THUNAR_IS_PROPERTIES_DIALOG (dialog)); _thunar_return_if_fail (g_list_length (dialog->files) == 1); @@ -1037,20 +1040,27 @@ thunar_properties_dialog_update_single (ThunarPropertiesDialog *dialog) if (thunar_file_is_directory (file)) { fs_string = thunar_g_file_get_free_space_string (thunar_file_get_file (file)); + if (thunar_g_file_get_free_space (thunar_file_get_file (file), &fs_free, &fs_size) + && fs_size > 0) + { + /* free disk space fraction */ + fs_fraction = ((fs_size - fs_free) * 100 / fs_size); + } if (fs_string != NULL) { - gtk_label_set_text (GTK_LABEL (dialog->freespace_label), fs_string); - gtk_widget_show (dialog->freespace_label); + gtk_progress_bar_set_text (GTK_PROGRESS_BAR (dialog->freespace_bar), fs_string); + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (dialog->freespace_bar), fs_fraction / 100); + gtk_widget_show (dialog->freespace_bar); g_free (fs_string); } else { - gtk_widget_hide (dialog->freespace_label); + gtk_widget_hide (dialog->freespace_bar); } } else { - gtk_widget_hide (dialog->freespace_label); + gtk_widget_hide (dialog->freespace_bar); } /* update the volume */ @@ -1107,7 +1117,7 @@ thunar_properties_dialog_update_multiple (ThunarPropertiesDialog *dialog) gtk_widget_hide (dialog->deleted_label); gtk_widget_hide (dialog->modified_label); gtk_widget_hide (dialog->accessed_label); - gtk_widget_hide (dialog->freespace_label); + gtk_widget_hide (dialog->freespace_bar); gtk_widget_hide (dialog->origin_label); gtk_widget_hide (dialog->openwith_chooser); gtk_widget_hide (dialog->link_label); -- 1.9.1